camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/2] git commit: CAMEL-7919 New tests for the camel-jira component
Date Fri, 24 Oct 2014 12:35:02 GMT
Repository: camel
Updated Branches:
  refs/heads/master dee48e002 -> 007403ac4


CAMEL-7919 New tests for the camel-jira component


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/07b432c3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/07b432c3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/07b432c3

Branch: refs/heads/master
Commit: 07b432c3b4a1ae30ee56b92ee359a52fbae5a150
Parents: dee48e0
Author: Kevin Earls <kevin@kevinearls.com>
Authored: Thu Oct 23 10:40:03 2014 +0200
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Fri Oct 24 20:19:29 2014 +0800

----------------------------------------------------------------------
 components/camel-jira/pom.xml                   |   6 +
 .../jira/consumer/AbstractJIRAConsumer.java     |  20 +-
 .../component/jira/CommentConsumerTest.java     | 126 +++++++++++
 .../camel/component/jira/IssueConsumerTest.java | 125 +++++++++++
 .../component/jira/mocks/MockIssueClient.java   | 222 +++++++++++++++++++
 .../mocks/MockJerseyJiraRestClientFactory.java  |  35 +++
 .../jira/mocks/MockJiraRestClient.java          |  84 +++++++
 .../jira/mocks/MockSearchRestClient.java        | 107 +++++++++
 .../component/jira/mocks/MockSearchResult.java  |  66 ++++++
 9 files changed, 787 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/07b432c3/components/camel-jira/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-jira/pom.xml b/components/camel-jira/pom.xml
index b08f509..c0fa8ae 100644
--- a/components/camel-jira/pom.xml
+++ b/components/camel-jira/pom.xml
@@ -40,6 +40,12 @@
       <version>1.2-m01</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>com.atlassian.jira</groupId>
+      <artifactId>jira-rest-java-client-api</artifactId>
+      <version>2.0.0-m30</version>
+      <scope>test</scope>
+    </dependency>
 
     <!-- testing -->
     <dependency>

http://git-wip-us.apache.org/repos/asf/camel/blob/07b432c3/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJIRAConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJIRAConsumer.java
b/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJIRAConsumer.java
index 3d2c3bb..2ee7bc4 100644
--- a/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJIRAConsumer.java
+++ b/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJIRAConsumer.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import com.atlassian.jira.rest.client.JiraRestClient;
+import com.atlassian.jira.rest.client.SearchRestClient;
 import com.atlassian.jira.rest.client.domain.BasicIssue;
 import com.atlassian.jira.rest.client.domain.SearchResult;
 import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;
@@ -29,6 +30,7 @@ import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactor
 import org.apache.camel.Processor;
 import org.apache.camel.component.jira.JIRAEndpoint;
 import org.apache.camel.impl.ScheduledPollConsumer;
+import org.apache.camel.spi.Registry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,8 +48,18 @@ public abstract class AbstractJIRAConsumer extends ScheduledPollConsumer
{
         
         // Use a more reasonable default.
         setDelay(6000);
-        
-        final JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
+
+        JerseyJiraRestClientFactory factory;
+        Registry registry = endpoint.getCamelContext().getRegistry();
+        Object target = registry.lookupByName("JerseyJiraRestClientFactory");
+        if (target != null) {
+            LOG.debug("JerseyJiraRestClientFactory found in registry " + target.getClass().getCanonicalName());
+            factory = (JerseyJiraRestClientFactory) target;
+        } else {
+            factory = new JerseyJiraRestClientFactory();
+        }
+
+
         final URI jiraServerUri = URI.create(endpoint.getServerUrl());
         client = factory.createWithBasicHttpAuthentication(jiraServerUri, endpoint.getUsername(),
                                                            endpoint.getPassword());
@@ -63,8 +75,8 @@ public abstract class AbstractJIRAConsumer extends ScheduledPollConsumer
{
 
         List<BasicIssue> issues = new ArrayList<BasicIssue>();
         while (true) {
-            SearchResult searchResult = client.getSearchClient().searchJqlWithFullIssues(jql,
maxPerQuery,
-                                                                                        
start, null);
+            SearchRestClient searchRestClient = client.getSearchClient();
+            SearchResult searchResult = searchRestClient.searchJqlWithFullIssues(jql, maxPerQuery,start,
null);
 
             for (BasicIssue issue : searchResult.getIssues()) {
                 issues.add(issue);

http://git-wip-us.apache.org/repos/asf/camel/blob/07b432c3/components/camel-jira/src/test/java/org/apache/camel/component/jira/CommentConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/test/java/org/apache/camel/component/jira/CommentConsumerTest.java
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/CommentConsumerTest.java
new file mode 100644
index 0000000..e70b083
--- /dev/null
+++ b/components/camel-jira/src/test/java/org/apache/camel/component/jira/CommentConsumerTest.java
@@ -0,0 +1,126 @@
+/**
+ * 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.component.jira;
+
+import com.atlassian.jira.rest.client.domain.BasicIssue;
+import com.atlassian.jira.rest.client.domain.Comment;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jira.mocks.MockJerseyJiraRestClientFactory;
+import org.apache.camel.component.jira.mocks.MockJiraRestClient;
+import org.apache.camel.component.jira.mocks.MockSearchRestClient;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Date;
+
+public class CommentConsumerTest extends CamelTestSupport {
+    public static final Logger LOG = LoggerFactory.getLogger(CommentConsumerTest.class);
+    private static final String URL = "https://somerepo.atlassian.net";
+    private static final String USERNAME = "someguy";
+    private static final String PASSWORD = "xU3xjhay9yjEaZq";
+    private String JIRA_CREDENTIALS = URL + "&username=" + USERNAME + "&password="
+ PASSWORD;
+    protected MockJerseyJiraRestClientFactory factory;
+
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        factory = new MockJerseyJiraRestClientFactory();
+        registry.bind("JerseyJiraRestClientFactory", factory);
+
+        return registry;
+    }
+
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("jira://newComment?serverUrl=" + JIRA_CREDENTIALS
+                        + "&jql=RAW(project=CAMELJIRA)")
+                        .process(new NewCommentProcessor())
+                        .to("mock:result");
+            }
+        };
+    }
+
+
+    @Test(timeout=60*1000)
+    public void emptyAtStartupTest() throws Exception {
+        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");
+
+        mockResultEndpoint.expectedMessageCount(0);
+        Thread.sleep(8 * 1000);        // delay is 6 seconds
+
+        mockResultEndpoint.assertIsSatisfied();
+    }
+
+
+    @Test(timeout=60*1000)
+    public void singleIssueTest() throws Exception {
+        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");
+
+        MockJiraRestClient jiraRestClient = (MockJiraRestClient) factory.getClient();
+        MockSearchRestClient searchRestClient = (MockSearchRestClient) jiraRestClient.getSearchClient();
+        BasicIssue issue1 = searchRestClient.addIssue();
+        String commentText = "Comment added at " + new Date();
+        Comment comment1 = searchRestClient.addCommentToIssue(issue1, commentText);
+
+        mockResultEndpoint.expectedBodiesReceived(comment1);
+        Thread.sleep(8 * 1000);        // delay is 6 seconds
+
+        mockResultEndpoint.assertIsSatisfied();
+    }
+
+
+    @Test
+    public void multiIssueTest() throws Exception {
+        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");
+
+        MockJiraRestClient jiraRestClient = (MockJiraRestClient) factory.getClient();
+        MockSearchRestClient searchRestClient = (MockSearchRestClient) jiraRestClient.getSearchClient();
+        BasicIssue issue1 = searchRestClient.addIssue();
+        Comment comment1 = searchRestClient.addCommentToIssue(issue1, "Comment added at "
+ new Date());
+        BasicIssue issue2 = searchRestClient.addIssue();
+        Comment comment2 = searchRestClient.addCommentToIssue(issue2, "Comment added at "
+ new Date());
+
+        mockResultEndpoint.expectedBodiesReceivedInAnyOrder(comment1, comment2);
+        Thread.sleep(8 * 1000);        // delay is 6 seconds
+
+        mockResultEndpoint.assertIsSatisfied();
+    }
+
+    /**
+     * Log new comments.  Not really needed for this test, but useful for debugging.
+     */
+    public class NewCommentProcessor implements Processor {
+        @Override
+        public void process(Exchange exchange) throws Exception {
+            Message in = exchange.getIn();
+            Comment comment = (Comment) in.getBody();
+            LOG.debug("Got comment with id " + comment.getId() + " Body " + comment.getBody());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/07b432c3/components/camel-jira/src/test/java/org/apache/camel/component/jira/IssueConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/test/java/org/apache/camel/component/jira/IssueConsumerTest.java
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/IssueConsumerTest.java
new file mode 100644
index 0000000..57fb1f0
--- /dev/null
+++ b/components/camel-jira/src/test/java/org/apache/camel/component/jira/IssueConsumerTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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.component.jira;
+
+import com.atlassian.jira.rest.client.domain.BasicIssue;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jira.mocks.MockJerseyJiraRestClientFactory;
+import org.apache.camel.component.jira.mocks.MockJiraRestClient;
+import org.apache.camel.component.jira.mocks.MockSearchRestClient;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IssueConsumerTest extends CamelTestSupport {
+    public static final Logger LOG = LoggerFactory.getLogger(IssueConsumerTest.class);
+    private static final String URL = "https://somerepo.atlassian.net";
+    private static final String USERNAME = "someguy";
+    private static final String PASSWORD = "xU3xjhay9yjEaZq";
+    private String JIRA_CREDENTIALS = URL + "&username=" + USERNAME + "&password="
+ PASSWORD;
+    private static final String PROJECT = "camel-jira-component";
+    protected MockJerseyJiraRestClientFactory factory;
+
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        factory = new MockJerseyJiraRestClientFactory();
+        registry.bind("JerseyJiraRestClientFactory", factory);
+
+        return registry;
+    }
+
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.addComponent("jira", new JIRAComponent());
+                from("jira://newIssue?serverUrl=" + JIRA_CREDENTIALS + "&jql=project="
+ PROJECT)
+                        .process(new NewIssueProcessor())
+                        .to("mock:result");
+            }
+        };
+    }
+
+
+    @Test(timeout=60*1000)
+    public void emptyAtStartupTest() throws Exception {
+        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");
+
+        MockJiraRestClient client = (MockJiraRestClient) factory.getClient();
+        MockSearchRestClient restClient = (MockSearchRestClient) client.getSearchClient();
+        mockResultEndpoint.expectedMessageCount(0);
+        Thread.sleep(8 * 1000);        // delay is 6 seconds
+
+        mockResultEndpoint.assertIsSatisfied();
+    }
+
+
+    @Test(timeout=60*1000)
+    public void singleIssueTest() throws Exception {
+        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");
+
+        MockJiraRestClient client = (MockJiraRestClient) factory.getClient();
+        MockSearchRestClient restClient = (MockSearchRestClient) client.getSearchClient();
+        BasicIssue issue1 = restClient.addIssue();
+
+        mockResultEndpoint.expectedBodiesReceived(issue1);
+        Thread.sleep(8 * 1000);        // delay is 6 seconds
+
+        mockResultEndpoint.assertIsSatisfied();
+    }
+
+
+    @Test(timeout=60*1000)
+    public void multipleIssuesTest() throws Exception {
+        MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");
+
+        MockJiraRestClient client = (MockJiraRestClient) factory.getClient();
+        MockSearchRestClient restClient = (MockSearchRestClient) client.getSearchClient();
+        BasicIssue issue1 = restClient.addIssue();
+        BasicIssue issue2 = restClient.addIssue();
+        BasicIssue issue3 = restClient.addIssue();
+
+        mockResultEndpoint.expectedBodiesReceived(issue3, issue2, issue1);
+
+        Thread.sleep(8 * 1000);        // delay is 6 seconds
+
+        mockResultEndpoint.assertIsSatisfied();
+    }
+
+
+    /**
+     * Log new issues.  Not really needed for this test, but useful for debugging.
+     */
+    public class NewIssueProcessor implements Processor {
+        @Override
+        public void process(Exchange exchange) throws Exception {
+            Message in = exchange.getIn();
+            BasicIssue issue = in.getBody(BasicIssue.class);
+            LOG.debug("Got issue with id " + issue.getId() + " key " + issue.getKey());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/07b432c3/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockIssueClient.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockIssueClient.java
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockIssueClient.java
new file mode 100644
index 0000000..31e1f54
--- /dev/null
+++ b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockIssueClient.java
@@ -0,0 +1,222 @@
+/**
+ * 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.component.jira.mocks;
+
+import com.atlassian.jira.rest.client.GetCreateIssueMetadataOptions;
+import com.atlassian.jira.rest.client.IssueRestClient;
+import com.atlassian.jira.rest.client.ProgressMonitor;
+import com.atlassian.jira.rest.client.domain.*;
+import com.atlassian.jira.rest.client.domain.input.AttachmentInput;
+import com.atlassian.jira.rest.client.domain.input.FieldInput;
+import com.atlassian.jira.rest.client.domain.input.IssueInput;
+import com.atlassian.jira.rest.client.domain.input.LinkIssuesInput;
+import com.atlassian.jira.rest.client.domain.input.TransitionInput;
+import com.atlassian.jira.rest.client.domain.input.WorklogInput;
+import org.codehaus.jettison.json.JSONObject;
+import org.joda.time.DateTime;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.Collection;
+import java.util.Set;
+
+public class MockIssueClient implements IssueRestClient {
+    private MockSearchRestClient mockSearchRestClient;
+
+    public MockIssueClient(MockSearchRestClient mockSearchRestClient) {
+        this.mockSearchRestClient = mockSearchRestClient;
+    }
+
+    @Override
+    public BasicIssue createIssue(IssueInput issue, ProgressMonitor progressMonitor) {
+        return null;
+    }
+
+    @Override
+    public Iterable<CimProject> getCreateIssueMetadata(GetCreateIssueMetadataOptions
options, ProgressMonitor progressMonitor) {
+        return null;
+    }
+
+    @Override
+    public Issue getIssue(String issueKey, ProgressMonitor progressMonitor) {
+        String summary = null;
+        URI self = null;
+        BasicProject project = null;
+        BasicIssueType issueType = null;
+        BasicStatus status = null;
+
+        String description = null;
+        BasicPriority priority = null;
+        BasicResolution resolution = null;
+        Collection<Attachment> attachments = null;
+        BasicUser reporter = null;
+        BasicUser assignee = null;
+        DateTime creationDate = null;
+        DateTime updateDate = null;
+        DateTime dueDate = null;
+        Collection<Version> affectedVersions = null;
+        Collection<Version> fixVersions = null;
+        Collection<BasicComponent> components = null;
+        TimeTracking timeTracking = null;
+        Collection<Field> fields = null;
+        URI transitionsUri = null;
+        Collection<IssueLink> issueLinks = null;
+        BasicVotes votes = null;
+        Collection<Worklog> worklogs = null;
+        BasicWatchers watchers = null;
+        Iterable<String> expandos = null;
+        Collection<Subtask> subtasks = null;
+        Collection<ChangelogGroup> changelog = null;
+        Set<String> labels = null;
+        JSONObject rawObject = null;
+
+        BasicIssue basicIssue = mockSearchRestClient.getBasicIssue(issueKey);
+        Collection<Comment> comments = mockSearchRestClient.getCommentsForIssue(basicIssue.getId());
+        Issue issue = new Issue(summary, self, basicIssue.getKey(), basicIssue.getId(), project,
issueType, status,
+                description, priority, resolution, attachments, reporter, assignee, creationDate,
updateDate,
+                dueDate, affectedVersions, fixVersions, components, timeTracking, fields,
comments,
+                transitionsUri, issueLinks,
+                votes, worklogs, watchers, expandos, subtasks, changelog, labels, rawObject);
+        return issue;
+    }
+
+    @Override
+    public Issue getIssue(String issueKey, Iterable<Expandos> expand, ProgressMonitor
progressMonitor) {
+        return null;
+    }
+
+    @Override
+    public Watchers getWatchers(URI watchersUri, ProgressMonitor progressMonitor) {
+        return null;
+    }
+
+    @Override
+    public Votes getVotes(URI votesUri, ProgressMonitor progressMonitor) {
+        return null;
+    }
+
+    @Override
+    public Iterable<Transition> getTransitions(URI transitionsUri, ProgressMonitor
progressMonitor) {
+        return null;
+    }
+
+    @Override
+    public Iterable<Transition> getTransitions(Issue issue, ProgressMonitor progressMonitor)
{
+        return null;
+    }
+
+    @Override
+    public void transition(URI transitionsUri, TransitionInput transitionInput, ProgressMonitor
progressMonitor) {
+
+    }
+
+    @Override
+    public void transition(Issue issue, TransitionInput transitionInput, ProgressMonitor
progressMonitor) {
+
+    }
+
+    @Override
+    public void update(Issue issue, Iterable<FieldInput> fields, ProgressMonitor progressMonitor)
{
+
+    }
+
+    @Override
+    public void removeIssue(URI issueUri, boolean deleteSubtasks, ProgressMonitor progressMonitor)
{
+
+    }
+
+    @Override
+    public void removeIssue(BasicIssue issue, boolean deleteSubtasks, ProgressMonitor progressMonitor)
{
+
+    }
+
+    @Override
+    public void removeIssue(Long issueId, boolean deleteSubtasks, ProgressMonitor progressMonitor)
{
+
+    }
+
+    @Override
+    public void removeIssue(String issueKey, boolean deleteSubtasks, ProgressMonitor progressMonitor)
{
+
+    }
+
+    @Override
+    public void vote(URI votesUri, ProgressMonitor progressMonitor) {
+
+    }
+
+    @Override
+    public void unvote(URI votesUri, ProgressMonitor progressMonitor) {
+
+    }
+
+    @Override
+    public void watch(URI watchersUri, ProgressMonitor progressMonitor) {
+
+    }
+
+    @Override
+    public void unwatch(URI watchersUri, ProgressMonitor progressMonitor) {
+
+    }
+
+    @Override
+    public void addWatcher(URI watchersUri, String username, ProgressMonitor progressMonitor)
{
+
+    }
+
+    @Override
+    public void removeWatcher(URI watchersUri, String username, ProgressMonitor progressMonitor)
{
+
+    }
+
+    @Override
+    public void linkIssue(LinkIssuesInput linkIssuesInput, ProgressMonitor progressMonitor)
{
+
+    }
+
+    @Override
+    public void addAttachment(ProgressMonitor progressMonitor, URI attachmentsUri, InputStream
in, String filename) {
+
+    }
+
+    @Override
+    public void addAttachments(ProgressMonitor progressMonitor, URI attachmentsUri, AttachmentInput...
attachments) {
+
+    }
+
+    @Override
+    public void addAttachments(ProgressMonitor progressMonitor, URI attachmentsUri, File...
files) {
+
+    }
+
+    @Override
+    public void addComment(ProgressMonitor progressMonitor, URI commentsUri, Comment comment)
{
+
+    }
+
+    @Override
+    public InputStream getAttachment(ProgressMonitor pm, URI attachmentUri) {
+        return null;
+    }
+
+    @Override
+    public void addWorklog(URI worklogUri, WorklogInput worklogInput, ProgressMonitor progressMonitor)
{
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/07b432c3/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockJerseyJiraRestClientFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockJerseyJiraRestClientFactory.java
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockJerseyJiraRestClientFactory.java
new file mode 100644
index 0000000..6f51184
--- /dev/null
+++ b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockJerseyJiraRestClientFactory.java
@@ -0,0 +1,35 @@
+/**
+ * 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.component.jira.mocks;
+
+import com.atlassian.jira.rest.client.JiraRestClient;
+import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;
+
+import java.net.URI;
+
+public class MockJerseyJiraRestClientFactory extends JerseyJiraRestClientFactory {
+    MockJiraRestClient client = new MockJiraRestClient();
+
+    @Override
+    public JiraRestClient createWithBasicHttpAuthentication(URI serverUri, String username,
String password) {
+        return client;
+    }
+
+    public MockJiraRestClient getClient() {
+        return client;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/07b432c3/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockJiraRestClient.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockJiraRestClient.java
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockJiraRestClient.java
new file mode 100644
index 0000000..5ef0a3d
--- /dev/null
+++ b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockJiraRestClient.java
@@ -0,0 +1,84 @@
+/**
+ * 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.component.jira.mocks;
+
+import com.atlassian.jira.rest.client.ComponentRestClient;
+import com.atlassian.jira.rest.client.IssueRestClient;
+import com.atlassian.jira.rest.client.JiraRestClient;
+import com.atlassian.jira.rest.client.MetadataRestClient;
+import com.atlassian.jira.rest.client.ProjectRestClient;
+import com.atlassian.jira.rest.client.ProjectRolesRestClient;
+import com.atlassian.jira.rest.client.SearchRestClient;
+import com.atlassian.jira.rest.client.SessionRestClient;
+import com.atlassian.jira.rest.client.UserRestClient;
+import com.atlassian.jira.rest.client.VersionRestClient;
+import com.sun.jersey.client.apache.ApacheHttpClient;
+
+public class MockJiraRestClient implements JiraRestClient {
+    MockSearchRestClient mockSearchRestClient = new MockSearchRestClient();
+    MockIssueClient mockIssueClient = new MockIssueClient(mockSearchRestClient);
+
+    @Override
+    public IssueRestClient getIssueClient() {
+        return mockIssueClient;
+    }
+
+    @Override
+    public SessionRestClient getSessionClient() {
+        return null;
+    }
+
+    @Override
+    public UserRestClient getUserClient() {
+        return null;
+    }
+
+    @Override
+    public ProjectRestClient getProjectClient() {
+        return null;
+    }
+
+    @Override
+    public ComponentRestClient getComponentClient() {
+        return null;
+    }
+
+    @Override
+    public MetadataRestClient getMetadataClient() {
+        return null;
+    }
+
+    @Override
+    public SearchRestClient getSearchClient() {
+        return mockSearchRestClient;
+    }
+
+    @Override
+    public VersionRestClient getVersionRestClient() {
+        return null;
+    }
+
+    @Override
+    public ProjectRolesRestClient getProjectRolesRestClient() {
+        return null;
+    }
+
+    @Override
+    public ApacheHttpClient getTransportClient() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/07b432c3/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockSearchRestClient.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockSearchRestClient.java
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockSearchRestClient.java
new file mode 100644
index 0000000..ba872ff
--- /dev/null
+++ b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockSearchRestClient.java
@@ -0,0 +1,107 @@
+/**
+ * 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.component.jira.mocks;
+
+import com.atlassian.jira.rest.client.NullProgressMonitor;
+import com.atlassian.jira.rest.client.ProgressMonitor;
+import com.atlassian.jira.rest.client.SearchRestClient;
+import com.atlassian.jira.rest.client.domain.BasicIssue;
+import com.atlassian.jira.rest.client.domain.Comment;
+import com.atlassian.jira.rest.client.domain.FavouriteFilter;
+import com.atlassian.jira.rest.client.domain.SearchResult;
+import org.joda.time.DateTime;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class MockSearchRestClient implements SearchRestClient {
+    private final List<BasicIssue> issues = new ArrayList<>();
+    private final Map<Long, List<Comment>> comments = new HashMap<>();
+    private AtomicLong basicIssueId = new AtomicLong(0);
+    private String KEY_BASE = "CAMELJIRA-";
+
+    @Override
+    public SearchResult searchJql(String s, ProgressMonitor progressMonitor) {
+        return null;
+    }
+
+    @Override
+    public SearchResult searchJql(String s, int i, int i2, ProgressMonitor progressMonitor)
{
+        return null;
+    }
+
+    @Override
+    public SearchResult searchJqlWithFullIssues(String jql, int maxPerQuery, int start, ProgressMonitor
progressMonitor) {
+        List<BasicIssue> result = new ArrayList<>();
+        for (BasicIssue issue : issues) {
+            if (issue.getId() >= start) {
+                result.add(issue);
+                if (result.size() >= maxPerQuery) {
+                    break;
+                }
+            }
+        }
+        return new MockSearchResult(start, maxPerQuery, issues.size(), result);
+    }
+
+    @Override
+    public Iterable<FavouriteFilter> getFavouriteFilters(NullProgressMonitor nullProgressMonitor)
{
+        return null;
+    }
+
+    public BasicIssue addIssue() {
+        String key = KEY_BASE + basicIssueId.get();
+        BasicIssue basicIssue = new BasicIssue(null, key, basicIssueId.getAndIncrement());
+        issues.add(basicIssue);
+        return basicIssue;
+    }
+
+    public Comment addCommentToIssue(BasicIssue issue, String commentText) {
+        // URI self, String body, @Nullable BasicUser author, @Nullable BasicUser updateAuthor,
DateTime creationDate, DateTime updateDate, Visibility visibility, @Nullable Long id
+        DateTime now = new DateTime();
+        Comment comment = new Comment(null, commentText, null, null, now, null, null, issue.getId());
+        List<Comment> commentsForIssue = comments.get(issue.getId());
+        if (commentsForIssue == null) {
+            commentsForIssue = new ArrayList<Comment>();
+        }
+        commentsForIssue.add(comment);
+        comments.put(issue.getId(), commentsForIssue);
+
+        return comment;
+    }
+
+    public List<Comment> getCommentsForIssue(Long issueId) {
+        List<Comment> commentsForIssue = comments.get(issueId);
+        return comments.get(issueId);
+    }
+
+
+    public BasicIssue getBasicIssue(String key) {
+        BasicIssue emptyResponse = new BasicIssue(null, "", (long) -1);
+        for (BasicIssue bi : issues) {
+            if (bi.getKey().equals(key)) {
+                return bi;
+            }
+        }
+        return emptyResponse;
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/camel/blob/07b432c3/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockSearchResult.java
----------------------------------------------------------------------
diff --git a/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockSearchResult.java
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockSearchResult.java
new file mode 100644
index 0000000..a54b1e1
--- /dev/null
+++ b/components/camel-jira/src/test/java/org/apache/camel/component/jira/mocks/MockSearchResult.java
@@ -0,0 +1,66 @@
+/**
+ * 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.component.jira.mocks;
+
+import com.atlassian.jira.rest.client.domain.BasicIssue;
+import com.atlassian.jira.rest.client.domain.SearchResult;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+public class MockSearchResult extends SearchResult {
+    private ArrayList<? extends BasicIssue> issues;
+    private BasicIssueComparator basicIssueComparator = new BasicIssueComparator();
+
+
+    public MockSearchResult(int startIndex, int maxResults, int total, java.lang.Iterable<?
extends BasicIssue> issues) {
+        super(startIndex, maxResults, total, issues);
+        this.issues = (ArrayList<? extends BasicIssue>) issues;
+    }
+
+
+    @Override
+    public int getTotal() {
+        return issues.size();
+    }
+
+
+    @Override
+    public Iterable<? extends BasicIssue> getIssues() {
+        Collections.sort(issues, basicIssueComparator);
+        ArrayList<? extends BasicIssue> copy = new ArrayList<>(issues);
+        if (!issues.isEmpty()) {
+            issues.remove(0);
+        }
+        return copy;
+    }
+
+
+    public class BasicIssueComparator implements Comparator<BasicIssue> {
+        @Override
+        public int compare(BasicIssue issue1, BasicIssue issue2) {
+            if (issue1.getId() < issue2.getId()) {
+                return 1;
+            } else if (issue1.getId() == issue2.getId()) {
+                return 0;
+            } else {
+                return -1;
+            }
+        }
+    }
+}


Mime
View raw message