You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/05/26 09:14:07 UTC

[GitHub] [camel-quarkus] jamesnetherton opened a new pull request #2675: Jira native fixes & more test coverage

jamesnetherton opened a new pull request #2675:
URL: https://github.com/apache/camel-quarkus/pull/2675


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] aldettinger commented on a change in pull request #2675: Jira native fixes & more test coverage

Posted by GitBox <gi...@apache.org>.
aldettinger commented on a change in pull request #2675:
URL: https://github.com/apache/camel-quarkus/pull/2675#discussion_r639640661



##########
File path: integration-tests/jira/src/test/java/org/apache/camel/quarkus/component/jira/it/JiraTest.java
##########
@@ -16,33 +16,390 @@
  */
 package org.apache.camel.quarkus.component.jira.it;
 
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import com.atlassian.jira.rest.client.api.JiraRestClient;
+import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
+import com.atlassian.jira.rest.client.api.domain.Attachment;
+import com.atlassian.jira.rest.client.api.domain.BasicWatchers;
+import com.atlassian.jira.rest.client.api.domain.Issue;
+import com.atlassian.jira.rest.client.api.domain.IssueLink;
+import com.atlassian.jira.rest.client.api.domain.Worklog;
+import io.quarkus.test.common.QuarkusTestResource;
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
+import io.restassured.path.json.JsonPath;
+import org.apache.camel.component.jira.oauth.OAuthAsynchronousJiraRestClientFactory;
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.ConfigProvider;
 import org.junit.jupiter.api.Test;
 
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.matchesPattern;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 @QuarkusTest
+@QuarkusTestResource(JiraTestResource.class)
 public class JiraTest {
 
+    private static final String ISSUE_ATTACHMENT = "Camel Quarkus Test Issue Attachment";
+    private static final String ISSUE_COMMENT = "Camel Quarkus Test Issue Comment";
+    private static final String ISSUE_DESCRIPTION = "Camel Quarkus Test Issue Description";
+    private static final String ISSUE_SUMMARY = "Camel Quarkus Test Issue Summary";
+    private static final String ISSUE_TYPE = "Task";
+    private static final String UPDATED_ISSUE_SUMMARY = "Updated summary";
+    private static final JiraRestClient REST_CLIENT = getClient();
+
     @Test
-    public void testJiraComponent() {
-        String jiraUrl = System.getenv("JIRA_URL");
-        if (jiraUrl == null) {
-            jiraUrl = String.format("http://localhost:%s/jira",
-                    System.getProperty("quarkus.http.test-port", System.getProperty("quarkus.http.port")));
+    public void issueCrud() {
+        // Start issue consumer
+        RestAssured.given()
+                .pathParam("routeId", "jiraIssues")
+                .pathParam("action", "start")
+                .post("/jira/route/{routeId}/{action}")
+                .then()
+                .statusCode(204);
+
+        // Create issue
+        RestAssured.given()
+                .contentType(ContentType.TEXT)
+                .queryParam("summary", ISSUE_SUMMARY)
+                .queryParam("type", ISSUE_TYPE)
+                .body(ISSUE_DESCRIPTION)
+                .when()
+                .post("/jira/issue")
+                .then()
+                .statusCode(201)
+                .body(
+                        "description", equalTo(ISSUE_DESCRIPTION),
+                        "key", matchesPattern("[A-Z]+-[0-9]+"),
+                        "summary", equalTo(ISSUE_SUMMARY),
+                        "type", equalTo(ISSUE_TYPE));
+
+        // Read issue
+        JsonPath issueJson = RestAssured.given()
+                .queryParam("source", "new")
+                .get("/jira/issue")
+                .then()
+                .statusCode(200)
+                .body(
+                        "description", equalTo(ISSUE_DESCRIPTION),
+                        "key", matchesPattern("[A-Z]+-[0-9]+"),
+                        "summary", equalTo(ISSUE_SUMMARY),
+                        "type", equalTo(ISSUE_TYPE))
+                .extract()
+                .jsonPath();
+
+        String issueKey = issueJson.getString("key");
+
+        // Stop issue consumer
+        RestAssured.given()
+                .pathParam("routeId", "jiraIssues")
+                .pathParam("action", "stop")
+                .post("/jira/route/{routeId}/{action}")
+                .then()
+                .statusCode(204);
+
+        // Start updates consumer
+        RestAssured.given()
+                .pathParam("routeId", "jiraUpdates")
+                .pathParam("action", "start")
+                .post("/jira/route/{routeId}/{action}")
+                .then()
+                .statusCode(204);
+
+        // Update issue summary
+        RestAssured.given()
+                .pathParam("key", issueKey)
+                .body(UPDATED_ISSUE_SUMMARY)
+                .patch("/jira/issue/{key}")
+                .then()
+                .statusCode(200);
+
+        // Verify update
+        RestAssured.given()
+                .queryParam("source", "update")
+                .get("/jira/issue")
+                .then()
+                .statusCode(200)
+                .body(
+                        "description", equalTo(ISSUE_DESCRIPTION),
+                        "key", matchesPattern("[A-Z]+-[0-9]+"),
+                        "summary", equalTo(UPDATED_ISSUE_SUMMARY),
+                        "type", equalTo(ISSUE_TYPE));
+
+        // Stop updates consumer
+        RestAssured.given()
+                .pathParam("routeId", "jiraUpdates")
+                .pathParam("action", "stop")
+                .post("/jira/route/{routeId}/{action}")
+                .then()
+                .statusCode(204);
+
+        // Delete issue
+        RestAssured.given()
+                .pathParam("key", issueKey)
+                .delete("/jira/issue/{key}")
+                .then()
+                .statusCode(204);
+
+        // Verify deletion
+        await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
+            return RestAssured.given()
+                    .pathParam("key", issueKey)
+                    .get("/jira/issue/{key}")
+                    .then()
+                    .extract()
+                    .statusCode() == 404;
+        });
+    }
+
+    @Test
+    public void comments() {
+        // Create issue
+        String issueKey = createIssue();
+        try {
+            // Start comments consumer
+            RestAssured.given()
+                    .pathParam("routeId", "jiraComments")
+                    .pathParam("action", "start")
+                    .post("/jira/route/{routeId}/{action}")
+                    .then()
+                    .statusCode(204);
+
+            // Add comment
+            RestAssured.given()
+                    .pathParam("key", issueKey)
+                    .body(ISSUE_COMMENT)
+                    .post("/jira/issue/{key}/comment")
+                    .then()
+                    .statusCode(201);
+
+            // Verify comment
+            RestAssured.get("/jira/issue/comment")
+                    .then()
+                    .statusCode(200)
+                    .body(equalTo(ISSUE_COMMENT));
+
+            // Stop comments consumer
+            RestAssured.given()
+                    .pathParam("routeId", "jiraComments")
+                    .pathParam("action", "stop")
+                    .post("/jira/route/{routeId}/{action}")
+                    .then()
+                    .statusCode(204);
+        } finally {
+            deleteIssue(issueKey);
         }
+    }
+
+    @Test
+    public void attachments() {
+        // Create issue
+        String issueKey = createIssue();
+        try {
+            // Create attachment
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .pathParam("key", issueKey)
+                    .body(ISSUE_ATTACHMENT)
+                    .when()
+                    .post("/jira/issue/{key}/attach")
+                    .then()
+                    .statusCode(201);
 
-        RestAssured
-                .given()
+            // Verify attachment
+            await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
+                Issue issue = getClient().getIssueClient().getIssue(issueKey).claim();
+                assertNotNull(issue);
+
+                Iterable<Attachment> iterable = issue.getAttachments();
+                return iterable != null && iterable.iterator().hasNext();
+            });
+
+            Issue issue = getClient().getIssueClient().getIssue(issueKey).claim();
+            Attachment attachment = issue.getAttachments().iterator().next();
+            assertTrue(attachment.getFilename().startsWith("cq-jira"));
+        } finally {
+            deleteIssue(issueKey);
+        }
+    }
+
+    @Test
+    public void watchers() {
+        // Create issue
+        String issueKey = createIssue();
+        try {
+            // Unwatch issue
+            JiraRestClient client = getClient();
+            String username = client.getSessionClient().getCurrentSession().claim().getUsername();
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .pathParam("key", issueKey)
+                    .queryParam("action", "unwatch")
+                    .body(username)
+                    .when()
+                    .post("/jira/issue/{key}/watch")
+                    .then()
+                    .statusCode(200);
+
+            // Verify unwatch
+            await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
+                Issue issue = getClient().getIssueClient().getIssue(issueKey).claim();
+                assertNotNull(issue);
+
+                BasicWatchers watchers = issue.getWatchers();
+                return watchers != null && !watchers.isWatching();
+            });
+
+            // Watch issue
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .pathParam("key", issueKey)
+                    .queryParam("action", "watch")
+                    .body(username)
+                    .when()
+                    .post("/jira/issue/{key}/watch")
+                    .then()
+                    .statusCode(200);
+
+            // Verify unwatch
+            await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
+                Issue issue = getClient().getIssueClient().getIssue(issueKey).claim();
+                assertNotNull(issue);
+
+                BasicWatchers watchers = issue.getWatchers();
+                return watchers != null && watchers.isWatching();
+            });
+        } finally {
+            deleteIssue(issueKey);
+        }
+    }
+
+    @Test
+    public void issueLinks() {
+        List<String> issueKeys = new ArrayList<>();
+
+        // Create issues
+        for (int i = 0; i < 2; i++) {
+            issueKeys.add(createIssue());
+        }
+
+        try {
+            // Link issues
+            String parentKey = issueKeys.get(0);
+            String childKey = issueKeys.get(1);
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .queryParam("parentKey", parentKey)
+                    .queryParam("childKey", childKey)
+                    .when()
+                    .post("/jira/issue/link")
+                    .then()
+                    .statusCode(200);
+
+            // Verify link
+            await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
+                Issue parent = getClient().getIssueClient().getIssue(parentKey).claim();
+                assertNotNull(parent);
+
+                Iterable<IssueLink> issueLinks = parent.getIssueLinks();
+                assertNotNull(issueLinks);
+
+                IssueLink link = issueLinks.iterator().next();
+                assertNotNull(link);
+
+                return childKey.equals(link.getTargetIssueKey());
+            });
+        } finally {
+            issueKeys.forEach(this::deleteIssue);
+        }
+    }
+
+    @Test
+    public void workLog() {
+        // Create issue
+        String issueKey = createIssue();
+        try {
+            // Log work
+            RestAssured.given()
+                    .contentType(ContentType.TEXT)
+                    .pathParam("key", issueKey)
+                    .body("30")
+                    .when()
+                    .post("/jira/issue/{key}/log/work")
+                    .then()
+                    .statusCode(200);
+
+            // Verify logged work
+            await().atMost(10, TimeUnit.SECONDS).pollDelay(1, TimeUnit.SECONDS).until(() -> {
+                Issue issue = getClient().getIssueClient().getIssue(issueKey).claim();
+                assertNotNull(issue);
+
+                Iterable<Worklog> workLogs = issue.getWorklogs();
+                assertNotNull(workLogs);
+
+                Worklog workLog = workLogs.iterator().next();
+                assertNotNull(workLog);
+
+                return workLog.getMinutesSpent() == 30 && workLog.getComment().equals("Work logged: 30");
+            });
+        } finally {
+            deleteIssue(issueKey);
+        }
+    }
+
+    private String createIssue() {
+        return RestAssured.given()
                 .contentType(ContentType.TEXT)
-                .queryParam("jiraUrl", jiraUrl)
-                .body("Demo issue body")
+                .queryParam("summary", ISSUE_SUMMARY)
+                .queryParam("type", ISSUE_TYPE)
+                .body(ISSUE_DESCRIPTION)
                 .when()
-                .post("/jira/post")
+                .post("/jira/issue")
                 .then()
                 .statusCode(201)
-                .body(matchesPattern("[A-Z]+-[0-9]+"));
+                .body(
+                        "description", equalTo(ISSUE_DESCRIPTION),
+                        "key", matchesPattern("[A-Z]+-[0-9]+"),
+                        "summary", equalTo(ISSUE_SUMMARY),
+                        "type", equalTo(ISSUE_TYPE))
+                .extract()
+                .jsonPath()
+                .getString("key");
+    }
+
+    private void deleteIssue(String issueKey) {
+        try {
+            getClient().getIssueClient()
+                    .deleteIssue(issueKey, true)
+                    .claim();
+        } catch (Exception e) {
+            // Ignore - issue may not exist
+        }
+    }
+
+    private static JiraRestClient getClient() {

Review comment:
       I would consider moving this to a @BeforeAll junit 5 step if possible.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] jamesnetherton merged pull request #2675: Jira native fixes & more test coverage

Posted by GitBox <gi...@apache.org>.
jamesnetherton merged pull request #2675:
URL: https://github.com/apache/camel-quarkus/pull/2675


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] aldettinger commented on pull request #2675: Jira native fixes & more test coverage

Posted by GitBox <gi...@apache.org>.
aldettinger commented on pull request #2675:
URL: https://github.com/apache/camel-quarkus/pull/2675#issuecomment-848695986


   Looks good to me at this stage.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel-quarkus] jamesnetherton commented on pull request #2675: Jira native fixes & more test coverage

Posted by GitBox <gi...@apache.org>.
jamesnetherton commented on pull request #2675:
URL: https://github.com/apache/camel-quarkus/pull/2675#issuecomment-848754546


   Latest commit addresses review feedback, makes the Jira extension depend on `camel-quarkus-support-spring`, adds another test case and support for running the tests with OAuth creds.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org