This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new d5165e7 Improve Jira extension - Use RuntimeInitializedClassBuildItem instead of configuring additionalBuildArgs - Use application.properties for test configuration new 05ce2f6 Merge pull request #728 from jamesnetherton/jira-improvements d5165e7 is described below commit d5165e7588fb5cd25748b3258f3d0010241f052f Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Mon Feb 17 13:26:10 2020 +0000 Improve Jira extension - Use RuntimeInitializedClassBuildItem instead of configuring additionalBuildArgs - Use application.properties for test configuration Fixes #715 --- .../component/jira/deployment/JiraProcessor.java | 6 +++ extensions/jira/runtime/pom.xml | 18 --------- integration-tests/jira/README.adoc | 17 ++++++++ integration-tests/jira/pom.xml | 35 ++-------------- .../quarkus/component/jira/it/JiraResource.java | 46 +++++++--------------- .../component/jira/it/JiraRouteBuilder.java | 41 ------------------- .../jira/src/main/resources/application.properties | 26 ++++++++++++ .../camel/quarkus/component/jira/it/JiraIT.java | 7 +++- .../camel/quarkus/component/jira/it/JiraTest.java | 31 +++++++++------ poms/bom/pom.xml | 24 +++++++++++ 10 files changed, 115 insertions(+), 136 deletions(-) diff --git a/extensions/jira/deployment/src/main/java/org/apache/camel/quarkus/component/jira/deployment/JiraProcessor.java b/extensions/jira/deployment/src/main/java/org/apache/camel/quarkus/component/jira/deployment/JiraProcessor.java index 89be59f..54deed1 100644 --- a/extensions/jira/deployment/src/main/java/org/apache/camel/quarkus/component/jira/deployment/JiraProcessor.java +++ b/extensions/jira/deployment/src/main/java/org/apache/camel/quarkus/component/jira/deployment/JiraProcessor.java @@ -19,6 +19,7 @@ package org.apache.camel.quarkus.component.jira.deployment; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem; class JiraProcessor { @@ -34,4 +35,9 @@ class JiraProcessor { return new FeatureBuildItem(FEATURE); } + @BuildStep + RuntimeInitializedClassBuildItem configureRuntimeInitializedClasses() { + return new RuntimeInitializedClassBuildItem("com.google.api.client.auth.oauth.OAuthParameters"); + } + } diff --git a/extensions/jira/runtime/pom.xml b/extensions/jira/runtime/pom.xml index bfd3b3a..92e9eb8 100644 --- a/extensions/jira/runtime/pom.xml +++ b/extensions/jira/runtime/pom.xml @@ -75,24 +75,6 @@ <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jira</artifactId> - <exclusions> - <exclusion> - <groupId>javax.ws.rs</groupId> - <artifactId>jsr311-api</artifactId> - </exclusion> - <exclusion> - <groupId>com.google.code.findbugs</groupId> - <artifactId>jsr305</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient-cache</artifactId> - </exclusion> - <exclusion> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> diff --git a/integration-tests/jira/README.adoc b/integration-tests/jira/README.adoc new file mode 100644 index 0000000..e4208c6 --- /dev/null +++ b/integration-tests/jira/README.adoc @@ -0,0 +1,17 @@ +== Camel Quarkus Jira Integration Tests + +To run `camel-quarkus-jira` integration tests, you need a running Jira instance to test against. + +A simple way of doing this is to use the https://hub.docker.com/r/atlassian/jira-software[Jira Docker image]. + +Set the following environment variables: + +[source,shell] +---- +export JIRA_ISSUES_PROJECT_KEY=TEST +export JIRA_URL=http://localhost:8080/ +export JIRA_USERNAME=my-jira-username +export JIRA_PASSWORD=my-jira-password +---- + + diff --git a/integration-tests/jira/pom.xml b/integration-tests/jira/pom.xml index c0bcaf5..ff60c32 100644 --- a/integration-tests/jira/pom.xml +++ b/integration-tests/jira/pom.xml @@ -47,14 +47,6 @@ <artifactId>camel-quarkus-jira</artifactId> </dependency> <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-direct</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-log</artifactId> - </dependency> - <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> </dependency> @@ -102,6 +94,9 @@ <name>native</name> </property> </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> <build> <plugins> <plugin> @@ -121,30 +116,6 @@ </execution> </executions> </plugin> - <plugin> - <groupId>io.quarkus</groupId> - <artifactId>quarkus-maven-plugin</artifactId> - <executions> - <execution> - <id>native-image</id> - <goals> - <goal>native-image</goal> - </goals> - <configuration> - <reportErrorsAtRuntime>false</reportErrorsAtRuntime> - <cleanupServer>true</cleanupServer> - <enableHttpsUrlHandler>true</enableHttpsUrlHandler> - <enableServer>false</enableServer> - <dumpProxies>false</dumpProxies> - <graalvmHome>${graalvmHome}</graalvmHome> - <disableReports>true</disableReports> - <additionalBuildArgs> - --initialize-at-run-time=com.google.api.client.auth.oauth.OAuthParameters,--allow-incomplete-classpath - </additionalBuildArgs> - </configuration> - </execution> - </executions> - </plugin> </plugins> </build> </profile> diff --git a/integration-tests/jira/src/main/java/org/apache/camel/quarkus/component/jira/it/JiraResource.java b/integration-tests/jira/src/main/java/org/apache/camel/quarkus/component/jira/it/JiraResource.java index d0a8fd7..5d4537e 100644 --- a/integration-tests/jira/src/main/java/org/apache/camel/quarkus/component/jira/it/JiraResource.java +++ b/integration-tests/jira/src/main/java/org/apache/camel/quarkus/component/jira/it/JiraResource.java @@ -17,19 +17,21 @@ package org.apache.camel.quarkus.component.jira.it; import java.net.URI; +import java.util.HashMap; +import java.util.Map; import javax.inject.Inject; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import com.atlassian.jira.rest.client.api.RestClientException; -import org.apache.camel.ConsumerTemplate; +import com.atlassian.jira.rest.client.api.domain.Issue; import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.jira.JiraConstants; +import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.logging.Logger; @Path("/jira") @@ -37,48 +39,30 @@ public class JiraResource { private static final Logger log = Logger.getLogger(JiraResource.class); - String TEST_JIRA_URL = "https://somerepo.atlassian.net"; - String PROJECT = "TST"; - String USERNAME = "someguy"; - String PASSWORD = "my_password"; - String JIRA_CREDENTIALS = TEST_JIRA_URL + "&username=" + USERNAME + "&password=" + PASSWORD; - @Inject ProducerTemplate producerTemplate; - @Inject - ConsumerTemplate consumerTemplate; - - @Path("/get") - @GET - @Produces(MediaType.TEXT_PLAIN) - public String get() throws Exception { - final String message = consumerTemplate.receiveBodyNoWait("jira:newIssues?jiraUrl=" + JIRA_CREDENTIALS, String.class); - log.infof("Received from jira: %s", message); - return message; - } + @ConfigProperty(name = "jira.issues.project-key") + String projectKey; @Path("/post") @POST @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public Response post(String message) throws Exception { + Map<String, Object> headers = new HashMap<>(); + headers.put(JiraConstants.ISSUE_PROJECT_KEY, projectKey); + headers.put(JiraConstants.ISSUE_TYPE_NAME, "Task"); + headers.put(JiraConstants.ISSUE_SUMMARY, "Demo Bug"); log.infof("Sending to jira: %s", message); - String response = null; - int statusCode = 0; - try { - response = (String) producerTemplate.requestBody("direct:start", message, String.class); - } catch (Exception ex) { - - statusCode = ((RestClientException) ex.getCause()).getStatusCode().get(); - } + Issue issue = producerTemplate.requestBodyAndHeaders("jira:addIssue", message, headers, Issue.class); - log.infof("Got response from jira: %s", response); + log.infof("Created new issue: %s", issue.getKey()); return Response .created(new URI("https://camel.apache.org/")) - .entity(response) - .status(statusCode) + .entity(issue.getKey()) + .status(201) .build(); } } diff --git a/integration-tests/jira/src/main/java/org/apache/camel/quarkus/component/jira/it/JiraRouteBuilder.java b/integration-tests/jira/src/main/java/org/apache/camel/quarkus/component/jira/it/JiraRouteBuilder.java deleted file mode 100644 index e73f71f..0000000 --- a/integration-tests/jira/src/main/java/org/apache/camel/quarkus/component/jira/it/JiraRouteBuilder.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.quarkus.component.jira.it; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jira.JiraConstants; - -public class JiraRouteBuilder extends RouteBuilder { - String TEST_JIRA_URL = "https://somerepo.atlassian.net"; - String PROJECT = "TST"; - String USERNAME = "someguy"; - String PASSWORD = "my_password"; - String JIRA_CREDENTIALS = TEST_JIRA_URL + "&username=" + USERNAME + "&password=" + PASSWORD; - - @Override - public void configure() { - - from("direct:start") - .setHeader(JiraConstants.ISSUE_PROJECT_KEY, constant("camel-jira")) - .setHeader(JiraConstants.ISSUE_TYPE_NAME, constant("Task")) - .setHeader(JiraConstants.ISSUE_SUMMARY, constant("Demo Bug jira")) - .setHeader(JiraConstants.ISSUE_PRIORITY_NAME, constant("Low")) - .setHeader(JiraConstants.ISSUE_ASSIGNEE, constant("Freeman")) - .to("jira://addIssue?jiraUrl=" + JIRA_CREDENTIALS); - - } -} diff --git a/integration-tests/jira/src/main/resources/application.properties b/integration-tests/jira/src/main/resources/application.properties new file mode 100644 index 0000000..51f18fe --- /dev/null +++ b/integration-tests/jira/src/main/resources/application.properties @@ -0,0 +1,26 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +# +# Camel :: Jira +# +jira.issues.project-key={{env:JIRA_ISSUES_PROJECT_KEY}} + +camel.component.jira.configuration = #class:org.apache.camel.component.jira.JiraConfiguration +camel.component.jira.configuration.jira-url={{env:JIRA_URL}} +camel.component.jira.configuration.username={{env:JIRA_USERNAME}} +camel.component.jira.configuration.password={{env:JIRA_PASSWORD}} diff --git a/integration-tests/jira/src/test/java/org/apache/camel/quarkus/component/jira/it/JiraIT.java b/integration-tests/jira/src/test/java/org/apache/camel/quarkus/component/jira/it/JiraIT.java index 93e4fbc..7a1b833 100644 --- a/integration-tests/jira/src/test/java/org/apache/camel/quarkus/component/jira/it/JiraIT.java +++ b/integration-tests/jira/src/test/java/org/apache/camel/quarkus/component/jira/it/JiraIT.java @@ -17,8 +17,13 @@ package org.apache.camel.quarkus.component.jira.it; import io.quarkus.test.junit.NativeImageTest; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; @NativeImageTest -class JiraIT extends JiraTest { +@EnabledIfEnvironmentVariable(named = "JIRA_ISSUES_PROJECT_KEY", matches = "[A-Z0-9]+") +@EnabledIfEnvironmentVariable(named = "JIRA_URL", matches = ".+") +@EnabledIfEnvironmentVariable(named = "JIRA_USERNAME", matches = ".+") +@EnabledIfEnvironmentVariable(named = "JIRA_PASSWORD", matches = ".+") +public class JiraIT extends JiraTest { } diff --git a/integration-tests/jira/src/test/java/org/apache/camel/quarkus/component/jira/it/JiraTest.java b/integration-tests/jira/src/test/java/org/apache/camel/quarkus/component/jira/it/JiraTest.java index 5db5c06..424cdfd 100644 --- a/integration-tests/jira/src/test/java/org/apache/camel/quarkus/component/jira/it/JiraTest.java +++ b/integration-tests/jira/src/test/java/org/apache/camel/quarkus/component/jira/it/JiraTest.java @@ -16,26 +16,31 @@ */ package org.apache.camel.quarkus.component.jira.it; -import java.util.UUID; - import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; import io.restassured.http.ContentType; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; + +import static org.hamcrest.Matchers.matchesPattern; @QuarkusTest -class JiraTest { +@EnabledIfEnvironmentVariable(named = "JIRA_ISSUES_PROJECT_KEY", matches = "[A-Z0-9]+") +@EnabledIfEnvironmentVariable(named = "JIRA_URL", matches = ".+") +@EnabledIfEnvironmentVariable(named = "JIRA_USERNAME", matches = ".+") +@EnabledIfEnvironmentVariable(named = "JIRA_PASSWORD", matches = ".+") +public class JiraTest { @Test - public void test() { - final String msg = UUID.randomUUID().toString().replace("-", ""); - RestAssured.given() // - .contentType(ContentType.TEXT).body(msg).post("/jira/post") - .then().statusCode(404);//external jira not exist, expect to return 404 - - String body = RestAssured.get("/jira/get").asString(); - Assertions.assertEquals(body, ""); + public void testJiraComponent() { + RestAssured + .given() + .contentType(ContentType.TEXT) + .body("Demo issue body") + .when() + .post("/jira/post") + .then() + .statusCode(201) + .body(matchesPattern("[A-Z]+-[0-9]+")); } - } diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 01ae072..7e73206 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -307,6 +307,24 @@ <groupId>org.apache.camel</groupId> <artifactId>camel-jira</artifactId> <version>${camel.version}</version> + <exclusions> + <exclusion> + <groupId>javax.ws.rs</groupId> + <artifactId>jsr311-api</artifactId> + </exclusion> + <exclusion> + <groupId>com.google.code.findbugs</groupId> + <artifactId>jsr305</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient-cache</artifactId> + </exclusion> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.camel</groupId> @@ -1016,6 +1034,12 @@ <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient-cache</artifactId> <version>${httpclient.cache.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.asynchttpclient</groupId>