Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Jira extension #728

Merged
merged 1 commit into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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 {

Expand All @@ -34,4 +35,9 @@ FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
RuntimeInitializedClassBuildItem configureRuntimeInitializedClasses() {
return new RuntimeInitializedClassBuildItem("com.google.api.client.auth.oauth.OAuthParameters");
}

}
18 changes: 0 additions & 18 deletions extensions/jira/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
17 changes: 17 additions & 0 deletions integration-tests/jira/README.adoc
Original file line number Diff line number Diff line change
@@ -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
----


35 changes: 3 additions & 32 deletions integration-tests/jira/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@
<groupId>org.apache.camel.quarkus</groupId>
<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>
Expand Down Expand Up @@ -102,6 +94,9 @@
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
<build>
<plugins>
<plugin>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,68 +17,52 @@
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")
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();
}
}

This file was deleted.

26 changes: 26 additions & 0 deletions integration-tests/jira/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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}}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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]+"));
}

}
24 changes: 24 additions & 0 deletions poms/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down