You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/03/19 08:02:42 UTC
[1/5] camel git commit: CAMEL-8470 Several small fixes for
camel-linkedin
Repository: camel
Updated Branches:
refs/heads/camel-2.15.x 710b64ca8 -> 2eaeaee25
CAMEL-8470 Several small fixes for camel-linkedin
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b08443aa
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b08443aa
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b08443aa
Branch: refs/heads/camel-2.15.x
Commit: b08443aa26089b199553f6b1848f8502a9e3b626
Parents: 710b64c
Author: Tomas Rohovsky <tr...@redhat.com>
Authored: Tue Mar 10 16:38:01 2015 +0100
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Mar 19 15:00:21 2015 +0800
----------------------------------------------------------------------
.../src/main/resources/linkedin-api-schema.xsd | 6 +++---
.../src/main/resources/linkedin-api-wadl.xml | 4 +++-
2 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b08443aa/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-schema.xsd
----------------------------------------------------------------------
diff --git a/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-schema.xsd b/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-schema.xsd
index a5796f9..aa85449 100644
--- a/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-schema.xsd
+++ b/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-schema.xsd
@@ -193,12 +193,12 @@
<xs:element ref="description"/>
<xs:element ref="relation-to-viewer"/>
<xs:element ref="counts-by-category"/>
- <xs:element ref="is-open-to-non-members"/>
+ <xs:element minOccurs="0" ref="is-open-to-non-members"/>
<xs:element name="category" type="GroupCategory"/>
<xs:element ref="site-group-url"/>
<xs:element ref="contact-email"/>
<xs:element ref="locale"/>
- <xs:element ref="allow-member-invites"/>
+ <xs:element minOccurs="0" ref="allow-member-invites"/>
<xs:element ref="small-logo-url"/>
<xs:element ref="large-logo-url"/>
<xs:element ref="posts"/>
@@ -2056,7 +2056,7 @@
<xs:sequence>
<xs:element ref="id"/>
<xs:element ref="timestamp"/>
- <xs:element ref="comment"/>
+ <xs:element ref="comment" type="xs:string"/>
<xs:element ref="content"/>
<xs:element ref="visibility"/>
<xs:element ref="source"/>
http://git-wip-us.apache.org/repos/asf/camel/blob/b08443aa/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-wadl.xml
----------------------------------------------------------------------
diff --git a/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-wadl.xml b/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-wadl.xml
index c08df21..a1c092c 100644
--- a/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-wadl.xml
+++ b/components/camel-linkedin/camel-linkedin-api/src/main/resources/linkedin-api-wadl.xml
@@ -286,7 +286,6 @@
<wadl:param href="#start"/>
<wadl:param href="#count"/>
<wadl:param href="#order"/>
- <wadl:param href="#post-role"/>
<wadl:param href="#category"/>
<wadl:param href="#modified-since"/>
<wadl:param href="#fields-selector"/>
@@ -685,6 +684,9 @@
<wadl:param href="#company-id"/>
<wadl:representation mediaType="application/xml" element="tns:share"/>
</wadl:request>
+ <wadl:response>
+ <wadl:representation mediaType="application/xml" element="tns:update"/>
+ </wadl:response>
</wadl:method>
</wadl:resource>
[3/5] camel git commit: CAMEL-8497 Add support for setting a commit
status,
getting list of files associated with PR and retrieving a specific file
content.
Posted by ni...@apache.org.
CAMEL-8497 Add support for setting a commit status, getting list of files associated with PR and retrieving a specific file content.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1cb3c092
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1cb3c092
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1cb3c092
Branch: refs/heads/camel-2.15.x
Commit: 1cb3c092655646f0c0465a67091b41e6df32b083
Parents: b08443a
Author: objectiser <ga...@brownuk.com>
Authored: Tue Mar 10 11:49:19 2015 +0000
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Mar 19 15:01:29 2015 +0800
----------------------------------------------------------------------
components/camel-github/pom.xml | 5 +
.../camel/component/github/GitHubEndpoint.java | 53 ++++++-
.../camel/component/github/GitHubType.java | 3 +-
.../github/consumer/PullRequestConsumer.java | 12 +-
.../github/producer/GetCommitFileProducer.java | 82 +++++++++++
.../producer/PullRequestFilesProducer.java | 61 ++++++++
.../producer/PullRequestStateProducer.java | 83 +++++++++++
.../github/ClosePullRequestProducerTest.java | 95 -------------
.../component/github/CommitConsumerTest.java | 64 ---------
.../github/GitHubComponentTestBase.java | 8 +-
.../github/PullRequestCommentConsumerTest.java | 69 ----------
.../github/PullRequestCommentProducerTest.java | 87 ------------
.../github/PullRequestConsumerTest.java | 72 ----------
.../camel/component/github/TagConsumerTest.java | 62 ---------
.../github/consumer/CommitConsumerTest.java | 66 +++++++++
.../github/consumer/MockCommitService.java | 57 --------
.../github/consumer/MockIssueService.java | 47 -------
.../github/consumer/MockPullRequestService.java | 126 -----------------
.../github/consumer/MockRepositoryService.java | 55 --------
.../PullRequestCommentConsumerTest.java | 71 ++++++++++
.../consumer/PullRequestConsumerTest.java | 74 ++++++++++
.../github/consumer/TagConsumerTest.java | 64 +++++++++
.../producer/ClosePullRequestProducerTest.java | 97 +++++++++++++
.../PullRequestCommentProducerTest.java | 89 ++++++++++++
.../producer/PullRequestFilesProducerTest.java | 88 ++++++++++++
.../producer/PullRequestStateProducerTest.java | 94 +++++++++++++
.../github/services/MockCommitService.java | 77 +++++++++++
.../github/services/MockIssueService.java | 47 +++++++
.../github/services/MockPullRequestService.java | 138 +++++++++++++++++++
.../github/services/MockRepositoryService.java | 55 ++++++++
30 files changed, 1251 insertions(+), 750 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-github/pom.xml b/components/camel-github/pom.xml
index 819e283..cb9a4bc 100644
--- a/components/camel-github/pom.xml
+++ b/components/camel-github/pom.xml
@@ -39,6 +39,11 @@
<version>${egit-github-core-version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>${commons-codec-version}</version>
+ </dependency>
<!-- testing -->
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubEndpoint.java b/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubEndpoint.java
index a2e8b30..e29c932 100644
--- a/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubEndpoint.java
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubEndpoint.java
@@ -24,7 +24,10 @@ import org.apache.camel.component.github.consumer.PullRequestCommentConsumer;
import org.apache.camel.component.github.consumer.PullRequestConsumer;
import org.apache.camel.component.github.consumer.TagConsumer;
import org.apache.camel.component.github.producer.ClosePullRequestProducer;
+import org.apache.camel.component.github.producer.GetCommitFileProducer;
import org.apache.camel.component.github.producer.PullRequestCommentProducer;
+import org.apache.camel.component.github.producer.PullRequestFilesProducer;
+import org.apache.camel.component.github.producer.PullRequestStateProducer;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
@@ -34,19 +37,19 @@ import org.apache.camel.util.ObjectHelper;
/**
* The endpoint encapsulates portions of the GitHub API, relying on the org.eclipse.egit.github.core Java SDK.
* Available endpoint URIs include:
- *
+ *
* CONSUMERS
* github://pullRequest (new pull requests)
* github://pullRequestComment (new pull request comments)
* github://commit/[branch] (new commits)
* github://tag (new tags)
- *
+ *
* PRODUCERS
* github://pullRequestComment (create a new pull request comment; see PullRequestCommentProducer for header requirements)
- *
+ *
* The endpoints will respond with org.eclipse.egit.github.core-provided POJOs (PullRequest, CommitComment,
* RepositoryTag, RepositoryCommit, etc.)
- *
+ *
* Note: Rather than webhooks, this endpoint relies on simple polling. Reasons include:
* - concerned about reliability/stability if this somehow relied on an exposed, embedded server (Jetty?)
* - the types of payloads we're polling aren't typically large (plus, paging is available in the API)
@@ -69,7 +72,13 @@ public class GitHubEndpoint extends DefaultEndpoint {
private String repoOwner;
@UriParam
private String repoName;
-
+ @UriParam
+ private String state;
+ @UriParam
+ private String targetUrl;
+ @UriParam
+ private String encoding;
+
public GitHubEndpoint(String uri, GitHubComponent component) {
super(uri, component);
}
@@ -79,10 +88,16 @@ public class GitHubEndpoint extends DefaultEndpoint {
return new ClosePullRequestProducer(this);
} else if (type == GitHubType.PULLREQUESTCOMMENT) {
return new PullRequestCommentProducer(this);
+ } else if (type == GitHubType.PULLREQUESTSTATE) {
+ return new PullRequestStateProducer(this);
+ } else if (type == GitHubType.PULLREQUESTFILES) {
+ return new PullRequestFilesProducer(this);
+ } else if (type == GitHubType.GETCOMMITFILE) {
+ return new GetCommitFileProducer(this);
}
throw new IllegalArgumentException("Cannot create producer with type " + type);
}
-
+
public Consumer createConsumer(Processor processor) throws Exception {
if (type == GitHubType.COMMIT) {
ObjectHelper.notEmpty(branchName, "branchName", this);
@@ -140,7 +155,7 @@ public class GitHubEndpoint extends DefaultEndpoint {
public void setOauthToken(String oauthToken) {
this.oauthToken = oauthToken;
}
-
+
public boolean hasOauth() {
return oauthToken != null && oauthToken.length() > 0;
}
@@ -160,4 +175,28 @@ public class GitHubEndpoint extends DefaultEndpoint {
public void setRepoName(String repoName) {
this.repoName = repoName;
}
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public String getTargetUrl() {
+ return targetUrl;
+ }
+
+ public void setTargetUrl(String targetUrl) {
+ this.targetUrl = targetUrl;
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubType.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubType.java b/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubType.java
index c6e07de..cc831d0 100644
--- a/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubType.java
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/GitHubType.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.github;
public enum GitHubType {
- CLOSEPULLREQUEST, PULLREQUESTCOMMENT, COMMIT, PULLREQUEST, TAG
+ CLOSEPULLREQUEST, PULLREQUESTCOMMENT, COMMIT, PULLREQUEST, TAG, PULLREQUESTSTATE,
+ PULLREQUESTFILES, GETCOMMITFILE
}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/main/java/org/apache/camel/component/github/consumer/PullRequestConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/consumer/PullRequestConsumer.java b/components/camel-github/src/main/java/org/apache/camel/component/github/consumer/PullRequestConsumer.java
index 0d62f6d..32d1577 100644
--- a/components/camel-github/src/main/java/org/apache/camel/component/github/consumer/PullRequestConsumer.java
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/consumer/PullRequestConsumer.java
@@ -32,7 +32,7 @@ public class PullRequestConsumer extends AbstractGitHubConsumer {
private static final transient Logger LOG = LoggerFactory.getLogger(PullRequestConsumer.class);
private PullRequestService pullRequestService;
-
+
private int lastOpenPullRequest;
public PullRequestConsumer(GitHubEndpoint endpoint, Processor processor) throws Exception {
@@ -68,7 +68,7 @@ public class PullRequestConsumer extends AbstractGitHubConsumer {
break;
}
}
-
+
if (newPullRequests.size() > 0) {
lastOpenPullRequest = openPullRequests.get(0).getNumber();
}
@@ -76,11 +76,15 @@ public class PullRequestConsumer extends AbstractGitHubConsumer {
while (!newPullRequests.empty()) {
PullRequest newPullRequest = newPullRequests.pop();
Exchange e = getEndpoint().createExchange();
+
e.getIn().setBody(newPullRequest);
-
+
// Required by the producers. Set it here for convenience.
e.getIn().setHeader("GitHubPullRequest", newPullRequest.getNumber());
-
+ if (newPullRequest.getHead() != null) {
+ e.getIn().setHeader("GitHubPullRequestHeadCommitSHA", newPullRequest.getHead().getSha());
+ }
+
getProcessor().process(e);
}
return newPullRequests.size();
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/main/java/org/apache/camel/component/github/producer/GetCommitFileProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/GetCommitFileProducer.java b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/GetCommitFileProducer.java
new file mode 100644
index 0000000..92375b9
--- /dev/null
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/GetCommitFileProducer.java
@@ -0,0 +1,82 @@
+/**
+ * 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.github.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.github.GitHubEndpoint;
+import org.apache.camel.spi.Registry;
+import org.apache.commons.codec.binary.Base64;
+import org.eclipse.egit.github.core.Blob;
+import org.eclipse.egit.github.core.CommitFile;
+import org.eclipse.egit.github.core.service.DataService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Producer endpoint that gets the file associated with a CommitFile object.
+ *
+ */
+public class GetCommitFileProducer extends AbstractGitHubProducer {
+ private static final transient Logger LOG = LoggerFactory.getLogger(GetCommitFileProducer.class);
+
+ private DataService dataService;
+
+ private String encoding=Blob.ENCODING_UTF8;
+
+ public GetCommitFileProducer(GitHubEndpoint endpoint) throws Exception {
+ super(endpoint);
+
+ Registry registry = endpoint.getCamelContext().getRegistry();
+ Object service = registry.lookupByName("githubDataService");
+ if (service != null) {
+ LOG.debug("Using DataService found in registry " + service.getClass().getCanonicalName());
+ dataService = (DataService) service;
+ } else {
+ dataService = new DataService();
+ }
+ initService(dataService);
+
+ if (endpoint.getEncoding() != null) {
+ encoding = endpoint.getEncoding();
+
+ if (!encoding.equalsIgnoreCase(Blob.ENCODING_BASE64)
+ && !encoding.equalsIgnoreCase(Blob.ENCODING_UTF8)) {
+ throw new IllegalArgumentException("Unknown encoding '"+encoding+"'");
+ }
+ }
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ CommitFile file=exchange.getIn().getBody(CommitFile.class);
+
+ Blob response=dataService.getBlob(getRepository(), file.getSha());
+
+ String text=response.getContent();
+
+ // By default, if blob encoding is base64 then we convert to UTF-8. If
+ // base64 encoding is required, then must be explicitly requested
+ if (response.getEncoding().equals(Blob.ENCODING_BASE64) &&
+ encoding != null && encoding.equalsIgnoreCase(Blob.ENCODING_UTF8)) {
+ text = new String(Base64.decodeBase64(text));
+ }
+
+ // copy the header of in message to the out message
+ exchange.getOut().copyFrom(exchange.getIn());
+ exchange.getOut().setBody(text);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestFilesProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestFilesProducer.java b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestFilesProducer.java
new file mode 100644
index 0000000..f69bd3f
--- /dev/null
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestFilesProducer.java
@@ -0,0 +1,61 @@
+/**
+ * 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.github.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.github.GitHubEndpoint;
+import org.apache.camel.spi.Registry;
+import org.eclipse.egit.github.core.CommitFile;
+import org.eclipse.egit.github.core.service.PullRequestService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Producer endpoint that gets the files associated with a pull request.
+ *
+ * The endpoint requires the "GitHubPullRequest" header, identifying the pull request number (integer).
+ */
+public class PullRequestFilesProducer extends AbstractGitHubProducer {
+ private static final transient Logger LOG = LoggerFactory.getLogger(PullRequestFilesProducer.class);
+
+ private PullRequestService pullRequestService;
+
+ public PullRequestFilesProducer(GitHubEndpoint endpoint) throws Exception {
+ super(endpoint);
+
+ Registry registry = endpoint.getCamelContext().getRegistry();
+ Object service = registry.lookupByName("githubPullRequestService");
+ if (service != null) {
+ LOG.debug("Using PullRequestService found in registry " + service.getClass().getCanonicalName());
+ pullRequestService = (PullRequestService) service;
+ } else {
+ pullRequestService = new PullRequestService();
+ }
+ initService(pullRequestService);
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ Integer pullRequestNumber = exchange.getIn().getHeader("GitHubPullRequest", Integer.class);
+
+ java.util.List<CommitFile> response=pullRequestService.getFiles(getRepository(), pullRequestNumber);
+
+ // copy the header of in message to the out message
+ exchange.getOut().copyFrom(exchange.getIn());
+ exchange.getOut().setBody(response);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestStateProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestStateProducer.java b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestStateProducer.java
new file mode 100644
index 0000000..b9218b6
--- /dev/null
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestStateProducer.java
@@ -0,0 +1,83 @@
+/**
+ * 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.github.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.github.GitHubEndpoint;
+import org.apache.camel.spi.Registry;
+import org.eclipse.egit.github.core.CommitStatus;
+import org.eclipse.egit.github.core.service.CommitService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Producer endpoint that sets the commit status.
+ *
+ * The endpoint requires the "GitHubPullRequest" header, identifying the pull request number (integer),
+ * and the "GitHubPullRequestHeadCommitSHA" header, identifying the commit SHA on which the state will be recorded.
+ */
+public class PullRequestStateProducer extends AbstractGitHubProducer {
+ private static final transient Logger LOG = LoggerFactory.getLogger(PullRequestStateProducer.class);
+
+ private CommitService commitService;
+
+ private String state;
+ private String targetUrl;
+
+ public PullRequestStateProducer(GitHubEndpoint endpoint) throws Exception {
+ super(endpoint);
+
+ Registry registry = endpoint.getCamelContext().getRegistry();
+ Object service = registry.lookupByName("githubCommitService");
+ if (service != null) {
+ LOG.debug("Using CommitService found in registry " + service.getClass().getCanonicalName());
+ commitService = (CommitService) service;
+ } else {
+ commitService = new CommitService();
+ }
+ initService(commitService);
+
+ state = endpoint.getState();
+ targetUrl = endpoint.getTargetUrl();
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ String pullRequestNumberSHA = exchange.getIn().getHeader("GitHubPullRequestHeadCommitSHA", String.class);
+ String text = exchange.getIn().getBody(String.class);
+
+ CommitStatus status=new CommitStatus();
+
+ if (state != null) {
+ status.setState(state);
+ }
+
+ if (targetUrl != null) {
+ status.setTargetUrl(targetUrl);
+ }
+
+ if (text != null) {
+ status.setDescription(text);
+ }
+
+ CommitStatus response=commitService.createStatus(getRepository(), pullRequestNumberSHA, status);
+
+ // copy the header of in message to the out message
+ exchange.getOut().copyFrom(exchange.getIn());
+ exchange.getOut().setBody(response);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/ClosePullRequestProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/ClosePullRequestProducerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/ClosePullRequestProducerTest.java
deleted file mode 100755
index 6b5a1a8..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/ClosePullRequestProducerTest.java
+++ /dev/null
@@ -1,95 +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.component.github;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.eclipse.egit.github.core.PullRequest;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ClosePullRequestProducerTest extends GitHubComponentTestBase {
- public static final String PULL_REQUEST_PRODUCER_ENDPOINT = "direct:validPullRequest";
- protected static final Logger LOG = LoggerFactory.getLogger(ClosePullRequestProducerTest.class);
- private long latestPullRequestId;
-
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- context.addComponent("github", new GitHubComponent());
- from(PULL_REQUEST_PRODUCER_ENDPOINT)
- .process(new ClosePullRequestProducerProcessor())
- .to("github://closePullRequest?" + GITHUB_CREDENTIALS_STRING);
- } // end of configure
-
-
- };
- }
-
-
- @Test
- public void testPullRequestCommentProducer() throws Exception {
- // Create a pull request
- PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestCommentProducer");
- latestPullRequestId = pullRequest.getId();
-
-
- // Close it
- Endpoint closePullRequestEndpoint = getMandatoryEndpoint(PULL_REQUEST_PRODUCER_ENDPOINT);
- Exchange exchange = closePullRequestEndpoint.createExchange();
- template.send(closePullRequestEndpoint, exchange);
-
- Thread.sleep(1 * 1000);
-
- // Verify that it was closed
-
- List<PullRequest> closedPullRequests = pullRequestService.getPullRequests(null, "closed");
- assertNotNull(closedPullRequests);
- boolean found = false;
- for (PullRequest pr : closedPullRequests) {
- if (pr.getId() == latestPullRequestId) {
- found = true;
- break;
- }
- }
-
- assertTrue("Didn't find pull request " + latestPullRequestId, found);
- }
-
-
- public class ClosePullRequestProducerProcessor implements Processor {
- @Override
- public void process(Exchange exchange) throws Exception {
- Message in = exchange.getIn();
- Map<String, Object> headers = in.getHeaders();
- headers.put("GitHubPullRequest", latestPullRequestId);
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/CommitConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/CommitConsumerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/CommitConsumerTest.java
deleted file mode 100644
index c9bd8b5..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/CommitConsumerTest.java
+++ /dev/null
@@ -1,64 +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.component.github;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.eclipse.egit.github.core.RepositoryCommit;
-import org.eclipse.egit.github.core.User;
-import org.junit.Test;
-
-public class CommitConsumerTest extends GitHubComponentTestBase {
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- context.addComponent("github", new GitHubComponent());
- from("github://commit/master?" + GITHUB_CREDENTIALS_STRING).
- process(new GitHubCommitProcessor())
- .to(mockResultEndpoint);
- }
- };
- }
-
-
- @Test
- public void commitConsumerTest() throws Exception {
- mockResultEndpoint.expectedMessageCount(2);
- RepositoryCommit commit1 = commitService.addRepositoryCommit();
- RepositoryCommit commit2 = commitService.addRepositoryCommit();
- mockResultEndpoint.expectedBodiesReceivedInAnyOrder(commit1, commit2);
-
- Thread.sleep(1 * 1000);
-
- mockResultEndpoint.assertIsSatisfied();
- }
-
- public class GitHubCommitProcessor implements Processor {
- @Override
- public void process(Exchange exchange) throws Exception {
- Message in = exchange.getIn();
- RepositoryCommit commit = (RepositoryCommit) in.getBody();
- User author = commit.getAuthor();
- log.debug("Got commit with author: " + author.getLogin() + ": " + author.getHtmlUrl() + " SHA " + commit.getSha());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/GitHubComponentTestBase.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/GitHubComponentTestBase.java b/components/camel-github/src/test/java/org/apache/camel/component/github/GitHubComponentTestBase.java
index ac93fb5..d0cba8c 100644
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/GitHubComponentTestBase.java
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/GitHubComponentTestBase.java
@@ -17,10 +17,10 @@
package org.apache.camel.component.github;
import org.apache.camel.EndpointInject;
-import org.apache.camel.component.github.consumer.MockCommitService;
-import org.apache.camel.component.github.consumer.MockIssueService;
-import org.apache.camel.component.github.consumer.MockPullRequestService;
-import org.apache.camel.component.github.consumer.MockRepositoryService;
+import org.apache.camel.component.github.services.MockCommitService;
+import org.apache.camel.component.github.services.MockIssueService;
+import org.apache.camel.component.github.services.MockPullRequestService;
+import org.apache.camel.component.github.services.MockRepositoryService;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.test.junit4.CamelTestSupport;
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestCommentConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestCommentConsumerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestCommentConsumerTest.java
deleted file mode 100644
index ad489f6..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestCommentConsumerTest.java
+++ /dev/null
@@ -1,69 +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.component.github;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.eclipse.egit.github.core.Comment;
-import org.eclipse.egit.github.core.CommitComment;
-import org.eclipse.egit.github.core.PullRequest;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PullRequestCommentConsumerTest extends GitHubComponentTestBase {
- protected static final Logger LOG = LoggerFactory.getLogger(PullRequestCommentConsumerTest.class);
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- context.addComponent("github", new GitHubComponent());
- from("github://pullRequestComment?" + GITHUB_CREDENTIALS_STRING)
- .process(new PullRequestCommentProcessor())
- .to(mockResultEndpoint);
- }
- };
- }
-
- @Test
- public void pullRequestCommentTest() throws Exception {
- PullRequest pr1 = pullRequestService.addPullRequest("First add");
- PullRequest pr2 = pullRequestService.addPullRequest("Second");
- CommitComment commitComment1 = pullRequestService.addComment(pr1.getId(), "First comment");
- CommitComment commitComment2 = pullRequestService.addComment(pr2.getId(), "Second comment");
- mockResultEndpoint.expectedBodiesReceivedInAnyOrder(commitComment1, commitComment2);
-
- Thread.sleep(1 * 1000); // TODO do I need this?
-
- mockResultEndpoint.assertIsSatisfied();
- }
-
-
- public class PullRequestCommentProcessor implements Processor {
- @Override
- public void process(Exchange exchange) throws Exception {
- Message in = exchange.getIn();
- Comment comment = (Comment) in.getBody();
- LOG.debug("Got Comment " + comment.getId() + " [" + comment.getBody() + "] from User [" + comment.getUser().getLogin() + "]");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestCommentProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestCommentProducerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestCommentProducerTest.java
deleted file mode 100644
index ef70c5e..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestCommentProducerTest.java
+++ /dev/null
@@ -1,87 +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.component.github;
-
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.eclipse.egit.github.core.CommitComment;
-import org.eclipse.egit.github.core.PullRequest;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PullRequestCommentProducerTest extends GitHubComponentTestBase {
- protected static final Logger LOG = LoggerFactory.getLogger(PullRequestCommentProducerTest.class);
- private long latestPullRequestId;
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- context.addComponent("github", new GitHubComponent());
- from("direct:validPullRequest")
- .process(new MockPullRequestCommentProducerProcessor())
- .to("github://pullRequestComment?" + GITHUB_CREDENTIALS_STRING);
- } // end of configure
-
-
- };
- }
-
-
- @Test
- public void testPullRequestCommentProducer() throws Exception {
- PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestCommentProducer");
- latestPullRequestId = pullRequest.getId();
-
- Endpoint commentProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
- Exchange exchange = commentProducerEndpoint.createExchange();
- String commentText = "Pushed this comment at " + new Date();
- exchange.getIn().setBody(commentText);
- template.send(commentProducerEndpoint, exchange);
-
- Thread.sleep(1 * 1000);
-
- // Verify that the mock pull request service received this comment.
- List<CommitComment> commitComments = pullRequestService.getComments(null, (int) pullRequest.getId());
- assertEquals(1, commitComments.size());
- CommitComment commitComment = commitComments.get(0);
- assertEquals("Commit IDs did not match ", Long.toString(pullRequest.getId()), commitComment.getCommitId());
- assertEquals("Comment text did not match ", commentText, commitComment.getBodyText());
- }
-
-
- public class MockPullRequestCommentProducerProcessor implements Processor {
- @Override
- public void process(Exchange exchange) throws Exception {
- Message in = exchange.getIn();
- Map<String, Object> headers = in.getHeaders();
- headers.put("GitHubPullRequest", latestPullRequestId);
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestConsumerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestConsumerTest.java
deleted file mode 100644
index a2df1d3..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/PullRequestConsumerTest.java
+++ /dev/null
@@ -1,72 +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.component.github;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.eclipse.egit.github.core.PullRequest;
-import org.eclipse.egit.github.core.User;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PullRequestConsumerTest extends GitHubComponentTestBase {
- protected static final Logger LOG = LoggerFactory.getLogger(PullRequestConsumerTest.class);
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- context.addComponent("github", new GitHubComponent());
- from("github://pullRequest?" + GITHUB_CREDENTIALS_STRING)
- .process(new MockPullRequestProcessor())
- .to(mockResultEndpoint);
- }
- };
- }
-
-
- @Test
- public void pullRequestTest() throws Exception {
- PullRequest pr1 = pullRequestService.addPullRequest("First add");
- PullRequest pr2 = pullRequestService.addPullRequest("Second");
- mockResultEndpoint.expectedMessageCount(2);
- mockResultEndpoint.expectedBodiesReceivedInAnyOrder(pr1, pr2);
- Thread.sleep(1 * 1000);
-
- mockResultEndpoint.assertIsSatisfied();
- }
-
- public class MockPullRequestProcessor implements Processor {
- @Override
- public void process(Exchange exchange) throws Exception {
- Message in = exchange.getIn();
- PullRequest pullRequest = (PullRequest) in.getBody();
- User pullRequestUser = pullRequest.getUser();
-
- pullRequest.getTitle();
- pullRequest.getHtmlUrl();
- pullRequest.getUser().getLogin();
- pullRequest.getUser().getHtmlUrl();
- LOG.debug("Got PullRequest " + pullRequest.getHtmlUrl() + " [" + pullRequest.getTitle() + "] From " + pullRequestUser.getLogin());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/TagConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/TagConsumerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/TagConsumerTest.java
deleted file mode 100644
index 6d69954..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/TagConsumerTest.java
+++ /dev/null
@@ -1,62 +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.component.github;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.eclipse.egit.github.core.RepositoryTag;
-import org.junit.Test;
-
-public class TagConsumerTest extends GitHubComponentTestBase {
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
-
- @Override
- public void configure() throws Exception {
- context.addComponent("github", new GitHubComponent());
- from("github://tag?" + GITHUB_CREDENTIALS_STRING)
- .process(new RepositoryTagProcessor())
- .to(mockResultEndpoint);
- }
- };
- }
-
-
- @Test
- public void tagConsumerTest() throws Exception {
- RepositoryTag tag1 = repositoryService.addTag("TAG1");
- RepositoryTag tag2 = repositoryService.addTag("TAG2");
- RepositoryTag tag3 = repositoryService.addTag("TAG3");
- mockResultEndpoint.expectedBodiesReceivedInAnyOrder(tag1, tag2, tag3);
- Thread.sleep(1 * 1000);
-
- mockResultEndpoint.assertIsSatisfied();
- }
-
- public class RepositoryTagProcessor implements Processor {
- @Override
- public void process(Exchange exchange) throws Exception {
- Message in = exchange.getIn();
- RepositoryTag tag = (RepositoryTag) in.getBody();
- log.debug("Got TAG [" + tag.getName() + "]");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/CommitConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/CommitConsumerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/CommitConsumerTest.java
new file mode 100644
index 0000000..196231c
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/CommitConsumerTest.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.github.consumer;
+
+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.github.GitHubComponent;
+import org.apache.camel.component.github.GitHubComponentTestBase;
+import org.eclipse.egit.github.core.RepositoryCommit;
+import org.eclipse.egit.github.core.User;
+import org.junit.Test;
+
+public class CommitConsumerTest extends GitHubComponentTestBase {
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ context.addComponent("github", new GitHubComponent());
+ from("github://commit/master?" + GITHUB_CREDENTIALS_STRING).
+ process(new GitHubCommitProcessor())
+ .to(mockResultEndpoint);
+ }
+ };
+ }
+
+
+ @Test
+ public void commitConsumerTest() throws Exception {
+ mockResultEndpoint.expectedMessageCount(2);
+ RepositoryCommit commit1 = commitService.addRepositoryCommit();
+ RepositoryCommit commit2 = commitService.addRepositoryCommit();
+ mockResultEndpoint.expectedBodiesReceivedInAnyOrder(commit1, commit2);
+
+ Thread.sleep(1 * 1000);
+
+ mockResultEndpoint.assertIsSatisfied();
+ }
+
+ public class GitHubCommitProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ RepositoryCommit commit = (RepositoryCommit) in.getBody();
+ User author = commit.getAuthor();
+ log.debug("Got commit with author: " + author.getLogin() + ": " + author.getHtmlUrl() + " SHA " + commit.getSha());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockCommitService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockCommitService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockCommitService.java
deleted file mode 100644
index a7bc45a..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockCommitService.java
+++ /dev/null
@@ -1,57 +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.component.github.consumer;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.eclipse.egit.github.core.IRepositoryIdProvider;
-import org.eclipse.egit.github.core.RepositoryCommit;
-import org.eclipse.egit.github.core.User;
-import org.eclipse.egit.github.core.service.CommitService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MockCommitService extends CommitService {
- protected static final Logger LOG = LoggerFactory.getLogger(MockCommitService.class);
-
- private List<RepositoryCommit> commitsList = new ArrayList<RepositoryCommit>();
- private AtomicLong fakeSha = new AtomicLong(System.currentTimeMillis());
-
- public synchronized RepositoryCommit addRepositoryCommit() {
- User author = new User();
- author.setEmail("someguy@gmail.com"); // TODO change
- author.setHtmlUrl("http://github/someguy");
- author.setLogin("someguy");
-
- RepositoryCommit rc = new RepositoryCommit();
- rc.setAuthor(author);
- rc.setSha(fakeSha.incrementAndGet() + "");
- LOG.debug("In MockCommitService added commit with sha " + rc.getSha());
- commitsList.add(rc);
-
- return rc;
- }
-
- @Override
- public synchronized List<RepositoryCommit> getCommits(IRepositoryIdProvider repository, String sha, String path) throws IOException {
- LOG.debug("Returning list of size " + commitsList.size());
- return commitsList;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockIssueService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockIssueService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockIssueService.java
deleted file mode 100644
index 4106a8a..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockIssueService.java
+++ /dev/null
@@ -1,47 +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.component.github.consumer;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.egit.github.core.Comment;
-import org.eclipse.egit.github.core.IRepositoryIdProvider;
-import org.eclipse.egit.github.core.service.IssueService;
-
-public class MockIssueService extends IssueService {
-
- private List<Comment> comments = new ArrayList<Comment>();
- private MockPullRequestService mockPullRequestService;
-
- public MockIssueService(MockPullRequestService mockPullRequestService) {
- this.mockPullRequestService = mockPullRequestService;
-
- }
-
- @Override
- public List<Comment> getComments(IRepositoryIdProvider repository, int issueNumber) {
- return comments;
- }
-
- @Override
- public Comment createComment(IRepositoryIdProvider repository, int issueNumber, String commentText) throws IOException {
- Comment addedComment = mockPullRequestService.addComment((long) issueNumber, commentText);
- return addedComment;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockPullRequestService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockPullRequestService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockPullRequestService.java
deleted file mode 100755
index b171e4a..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockPullRequestService.java
+++ /dev/null
@@ -1,126 +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.component.github.consumer;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.eclipse.egit.github.core.CommitComment;
-import org.eclipse.egit.github.core.IRepositoryIdProvider;
-import org.eclipse.egit.github.core.PullRequest;
-import org.eclipse.egit.github.core.User;
-import org.eclipse.egit.github.core.service.PullRequestService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MockPullRequestService extends PullRequestService {
- protected static final Logger LOG = LoggerFactory.getLogger(MockPullRequestService.class);
-
- private Map<Long, PullRequest> pullRequests = new HashMap<Long, PullRequest>();
- private List<CommitComment> emptyComments = new ArrayList<CommitComment>();
- private AtomicInteger pullRequestNumber = new AtomicInteger(101);
- private AtomicInteger commentId = new AtomicInteger(500);
- private Map<Long, List<CommitComment>> allComments = new HashMap<Long, List<CommitComment>>();
-
- public List<CommitComment> getComments(IRepositoryIdProvider repository, int pullRequestId) {
- Long id = new Long(pullRequestId);
- if (allComments.containsKey(id)) {
- List<CommitComment> comments = allComments.get(id);
- return comments;
- } else {
- return emptyComments;
- }
- }
-
- private User createAuthor() {
- User author = new User();
- author.setEmail("someguy@gmail.com");
- author.setHtmlUrl("http://github/someguy");
- author.setLogin("someguy");
-
- return author;
- }
-
- public CommitComment addComment(Long pullRequestId, String bodyText) {
- CommitComment commitComment = new CommitComment();
-
- User author = createAuthor();
- commitComment.setUser(author);
- commitComment.setCommitId("" + pullRequestId);
- commitComment.setId(commentId.getAndIncrement());
- commitComment.setBody(bodyText);
- commitComment.setBodyText(bodyText);
-
- List<CommitComment> comments;
- if (allComments.containsKey(pullRequestId)) {
- comments = allComments.get(pullRequestId);
- } else {
- comments = new ArrayList<CommitComment>();
- }
- comments.add(commitComment);
- allComments.put(pullRequestId, comments);
-
- return commitComment;
- }
-
- public PullRequest addPullRequest(String title) {
- User author = createAuthor();
-
- PullRequest pullRequest = new PullRequest();
- pullRequest.setUser(author);
- pullRequest.setHtmlUrl("https://github.com/someguy/somerepo/pull" + pullRequestNumber);
- pullRequest.setTitle(title);
- pullRequest.setNumber(pullRequestNumber.get());
- pullRequest.setId(pullRequestNumber.get());
- pullRequest.setState("open");
- pullRequests.put(pullRequest.getId(), pullRequest);
-
- pullRequestNumber.incrementAndGet();
- return pullRequest;
- }
-
- @Override
- public PullRequest getPullRequest(IRepositoryIdProvider repository, int id) throws IOException {
- PullRequest pullRequest = pullRequests.get((long) id);
- return pullRequest;
- }
-
- @Override
- public PullRequest editPullRequest(IRepositoryIdProvider repository, PullRequest request) throws IOException {
- pullRequests.put(request.getId(), request);
- return request;
- }
-
- @Override
- public synchronized List<PullRequest> getPullRequests(IRepositoryIdProvider repository, String state) {
- List<PullRequest> result = new ArrayList<PullRequest>();
-
- for (Long id : pullRequests.keySet()) {
- PullRequest pr = pullRequests.get(id);
- if (pr.getState().equals(state)) {
- result.add(pr);
- }
- }
-
- LOG.debug("Returning list of " + result.size() + " pull requests with state " + state);
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockRepositoryService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockRepositoryService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockRepositoryService.java
deleted file mode 100644
index d42bcd4..0000000
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/MockRepositoryService.java
+++ /dev/null
@@ -1,55 +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.component.github.consumer;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.egit.github.core.IRepositoryIdProvider;
-import org.eclipse.egit.github.core.Repository;
-import org.eclipse.egit.github.core.RepositoryTag;
-import org.eclipse.egit.github.core.service.RepositoryService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MockRepositoryService extends RepositoryService {
- protected static final Logger LOG = LoggerFactory.getLogger(MockRepositoryService.class);
-
- private List<RepositoryTag> tags = new ArrayList<RepositoryTag>();
-
- public RepositoryTag addTag(String tagName) {
- RepositoryTag tag = new RepositoryTag();
- tag.setName(tagName);
- tags.add(tag);
-
- return tag;
- }
-
- @Override
- public Repository getRepository(final String owner, final String name) throws IOException {
- Repository repository = new Repository();
- repository.setName(name);
- return repository;
- }
-
- @Override
- public List<RepositoryTag> getTags(IRepositoryIdProvider repository) throws IOException {
- LOG.debug("in MockRepositoryService returning " + tags.size() + " tags");
- return tags;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/PullRequestCommentConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/PullRequestCommentConsumerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/PullRequestCommentConsumerTest.java
new file mode 100644
index 0000000..e20bd1a
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/PullRequestCommentConsumerTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.github.consumer;
+
+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.github.GitHubComponent;
+import org.apache.camel.component.github.GitHubComponentTestBase;
+import org.eclipse.egit.github.core.Comment;
+import org.eclipse.egit.github.core.CommitComment;
+import org.eclipse.egit.github.core.PullRequest;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PullRequestCommentConsumerTest extends GitHubComponentTestBase {
+ protected static final Logger LOG = LoggerFactory.getLogger(PullRequestCommentConsumerTest.class);
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ context.addComponent("github", new GitHubComponent());
+ from("github://pullRequestComment?" + GITHUB_CREDENTIALS_STRING)
+ .process(new PullRequestCommentProcessor())
+ .to(mockResultEndpoint);
+ }
+ };
+ }
+
+ @Test
+ public void pullRequestCommentTest() throws Exception {
+ PullRequest pr1 = pullRequestService.addPullRequest("First add");
+ PullRequest pr2 = pullRequestService.addPullRequest("Second");
+ CommitComment commitComment1 = pullRequestService.addComment(pr1.getId(), "First comment");
+ CommitComment commitComment2 = pullRequestService.addComment(pr2.getId(), "Second comment");
+ mockResultEndpoint.expectedBodiesReceivedInAnyOrder(commitComment1, commitComment2);
+
+ Thread.sleep(1 * 1000); // TODO do I need this?
+
+ mockResultEndpoint.assertIsSatisfied();
+ }
+
+
+ public class PullRequestCommentProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ Comment comment = (Comment) in.getBody();
+ LOG.debug("Got Comment " + comment.getId() + " [" + comment.getBody() + "] from User [" + comment.getUser().getLogin() + "]");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/PullRequestConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/PullRequestConsumerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/PullRequestConsumerTest.java
new file mode 100644
index 0000000..c197085
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/PullRequestConsumerTest.java
@@ -0,0 +1,74 @@
+/**
+ * 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.github.consumer;
+
+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.github.GitHubComponent;
+import org.apache.camel.component.github.GitHubComponentTestBase;
+import org.eclipse.egit.github.core.PullRequest;
+import org.eclipse.egit.github.core.User;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PullRequestConsumerTest extends GitHubComponentTestBase {
+ protected static final Logger LOG = LoggerFactory.getLogger(PullRequestConsumerTest.class);
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ context.addComponent("github", new GitHubComponent());
+ from("github://pullRequest?" + GITHUB_CREDENTIALS_STRING)
+ .process(new MockPullRequestProcessor())
+ .to(mockResultEndpoint);
+ }
+ };
+ }
+
+
+ @Test
+ public void pullRequestTest() throws Exception {
+ PullRequest pr1 = pullRequestService.addPullRequest("First add");
+ PullRequest pr2 = pullRequestService.addPullRequest("Second");
+ mockResultEndpoint.expectedMessageCount(2);
+ mockResultEndpoint.expectedBodiesReceivedInAnyOrder(pr1, pr2);
+ Thread.sleep(1 * 1000);
+
+ mockResultEndpoint.assertIsSatisfied();
+ }
+
+ public class MockPullRequestProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ PullRequest pullRequest = (PullRequest) in.getBody();
+ User pullRequestUser = pullRequest.getUser();
+
+ pullRequest.getTitle();
+ pullRequest.getHtmlUrl();
+ pullRequest.getUser().getLogin();
+ pullRequest.getUser().getHtmlUrl();
+ LOG.debug("Got PullRequest " + pullRequest.getHtmlUrl() + " [" + pullRequest.getTitle() + "] From " + pullRequestUser.getLogin());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/TagConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/TagConsumerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/TagConsumerTest.java
new file mode 100644
index 0000000..4b0ffab
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/consumer/TagConsumerTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.github.consumer;
+
+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.github.GitHubComponent;
+import org.apache.camel.component.github.GitHubComponentTestBase;
+import org.eclipse.egit.github.core.RepositoryTag;
+import org.junit.Test;
+
+public class TagConsumerTest extends GitHubComponentTestBase {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ context.addComponent("github", new GitHubComponent());
+ from("github://tag?" + GITHUB_CREDENTIALS_STRING)
+ .process(new RepositoryTagProcessor())
+ .to(mockResultEndpoint);
+ }
+ };
+ }
+
+
+ @Test
+ public void tagConsumerTest() throws Exception {
+ RepositoryTag tag1 = repositoryService.addTag("TAG1");
+ RepositoryTag tag2 = repositoryService.addTag("TAG2");
+ RepositoryTag tag3 = repositoryService.addTag("TAG3");
+ mockResultEndpoint.expectedBodiesReceivedInAnyOrder(tag1, tag2, tag3);
+ Thread.sleep(1 * 1000);
+
+ mockResultEndpoint.assertIsSatisfied();
+ }
+
+ public class RepositoryTagProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ RepositoryTag tag = (RepositoryTag) in.getBody();
+ log.debug("Got TAG [" + tag.getName() + "]");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/producer/ClosePullRequestProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/producer/ClosePullRequestProducerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/ClosePullRequestProducerTest.java
new file mode 100755
index 0000000..c9a8a94
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/ClosePullRequestProducerTest.java
@@ -0,0 +1,97 @@
+/**
+ * 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.github.producer;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+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.github.GitHubComponent;
+import org.apache.camel.component.github.GitHubComponentTestBase;
+import org.eclipse.egit.github.core.PullRequest;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ClosePullRequestProducerTest extends GitHubComponentTestBase {
+ public static final String PULL_REQUEST_PRODUCER_ENDPOINT = "direct:validPullRequest";
+ protected static final Logger LOG = LoggerFactory.getLogger(ClosePullRequestProducerTest.class);
+ private long latestPullRequestId;
+
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ context.addComponent("github", new GitHubComponent());
+ from(PULL_REQUEST_PRODUCER_ENDPOINT)
+ .process(new ClosePullRequestProducerProcessor())
+ .to("github://closePullRequest?" + GITHUB_CREDENTIALS_STRING);
+ } // end of configure
+
+
+ };
+ }
+
+
+ @Test
+ public void testPullRequestCommentProducer() throws Exception {
+ // Create a pull request
+ PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestCommentProducer");
+ latestPullRequestId = pullRequest.getId();
+
+
+ // Close it
+ Endpoint closePullRequestEndpoint = getMandatoryEndpoint(PULL_REQUEST_PRODUCER_ENDPOINT);
+ Exchange exchange = closePullRequestEndpoint.createExchange();
+ template.send(closePullRequestEndpoint, exchange);
+
+ Thread.sleep(1 * 1000);
+
+ // Verify that it was closed
+
+ List<PullRequest> closedPullRequests = pullRequestService.getPullRequests(null, "closed");
+ assertNotNull(closedPullRequests);
+ boolean found = false;
+ for (PullRequest pr : closedPullRequests) {
+ if (pr.getId() == latestPullRequestId) {
+ found = true;
+ break;
+ }
+ }
+
+ assertTrue("Didn't find pull request " + latestPullRequestId, found);
+ }
+
+
+ public class ClosePullRequestProducerProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ Map<String, Object> headers = in.getHeaders();
+ headers.put("GitHubPullRequest", latestPullRequestId);
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestCommentProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestCommentProducerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestCommentProducerTest.java
new file mode 100644
index 0000000..9396b3e
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestCommentProducerTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.github.producer;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+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.github.GitHubComponent;
+import org.apache.camel.component.github.GitHubComponentTestBase;
+import org.eclipse.egit.github.core.CommitComment;
+import org.eclipse.egit.github.core.PullRequest;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PullRequestCommentProducerTest extends GitHubComponentTestBase {
+ protected static final Logger LOG = LoggerFactory.getLogger(PullRequestCommentProducerTest.class);
+ private long latestPullRequestId;
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ context.addComponent("github", new GitHubComponent());
+ from("direct:validPullRequest")
+ .process(new MockPullRequestCommentProducerProcessor())
+ .to("github://pullRequestComment?" + GITHUB_CREDENTIALS_STRING);
+ } // end of configure
+
+
+ };
+ }
+
+
+ @Test
+ public void testPullRequestCommentProducer() throws Exception {
+ PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestCommentProducer");
+ latestPullRequestId = pullRequest.getId();
+
+ Endpoint commentProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
+ Exchange exchange = commentProducerEndpoint.createExchange();
+ String commentText = "Pushed this comment at " + new Date();
+ exchange.getIn().setBody(commentText);
+ template.send(commentProducerEndpoint, exchange);
+
+ Thread.sleep(1 * 1000);
+
+ // Verify that the mock pull request service received this comment.
+ List<CommitComment> commitComments = pullRequestService.getComments(null, (int) pullRequest.getId());
+ assertEquals(1, commitComments.size());
+ CommitComment commitComment = commitComments.get(0);
+ assertEquals("Commit IDs did not match ", Long.toString(pullRequest.getId()), commitComment.getCommitId());
+ assertEquals("Comment text did not match ", commentText, commitComment.getBodyText());
+ }
+
+
+ public class MockPullRequestCommentProducerProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ Map<String, Object> headers = in.getHeaders();
+ headers.put("GitHubPullRequest", latestPullRequestId);
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestFilesProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestFilesProducerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestFilesProducerTest.java
new file mode 100644
index 0000000..d975532
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestFilesProducerTest.java
@@ -0,0 +1,88 @@
+/**
+ * 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.github.producer;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+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.github.GitHubComponent;
+import org.apache.camel.component.github.GitHubComponentTestBase;
+import org.eclipse.egit.github.core.CommitFile;
+import org.eclipse.egit.github.core.PullRequest;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PullRequestFilesProducerTest extends GitHubComponentTestBase {
+ protected static final Logger LOG = LoggerFactory.getLogger(PullRequestFilesProducerTest.class);
+ private int latestPullRequestNumber;
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ context.addComponent("github", new GitHubComponent());
+ from("direct:validPullRequest")
+ .process(new MockPullFilesProducerProcessor())
+ .to("github://pullRequestFiles?" + GITHUB_CREDENTIALS_STRING);
+ } // end of configure
+
+
+ };
+ }
+
+
+ @Test
+ public void testPullRequestFilesProducer() throws Exception {
+ PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestFilesProducer");
+ latestPullRequestNumber = pullRequest.getNumber();
+
+ CommitFile file=new CommitFile();
+ file.setFilename("testfile");
+
+ List<CommitFile> commitFiles=new ArrayList<CommitFile>();
+ commitFiles.add(file);
+ pullRequestService.setFiles(latestPullRequestNumber, commitFiles);
+
+ Endpoint filesProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
+ Exchange exchange = filesProducerEndpoint.createExchange();
+
+ Exchange resp = template.send(filesProducerEndpoint, exchange);
+
+ assertEquals(resp.getOut().getBody(), commitFiles);
+ }
+
+
+ public class MockPullFilesProducerProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ Map<String, Object> headers = in.getHeaders();
+ headers.put("GitHubPullRequest", latestPullRequestNumber);
+ }
+ }
+
+
+}
[2/5] camel git commit: CAMEL-8497 Add support for setting a commit
status,
getting list of files associated with PR and retrieving a specific file
content.
Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestStateProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestStateProducerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestStateProducerTest.java
new file mode 100644
index 0000000..1aabe95
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestStateProducerTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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.github.producer;
+
+import java.util.Date;
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+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.github.GitHubComponent;
+import org.apache.camel.component.github.GitHubComponentTestBase;
+import org.eclipse.egit.github.core.CommitStatus;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PullRequestStateProducerTest extends GitHubComponentTestBase {
+ protected static final Logger LOG = LoggerFactory.getLogger(PullRequestStateProducerTest.class);
+ private String commitsha;
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ context.addComponent("github", new GitHubComponent());
+ from("direct:validPullRequest")
+ .process(new MockPullRequestStateProducerProcessor())
+ .to("github://pullRequestState?state=success&" + GITHUB_CREDENTIALS_STRING);
+ } // end of configure
+
+
+ };
+ }
+
+
+ @Test
+ public void testPullRequestStateProducer() throws Exception {
+ commitsha = commitService.getNextSha();
+
+ Endpoint stateProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest");
+ Exchange exchange = stateProducerEndpoint.createExchange();
+ String text = "Message sent at " + new Date();
+ exchange.getIn().setBody(text);
+ Exchange response=template.send(stateProducerEndpoint, exchange);
+
+ assertNotNull(response.getOut().getBody());
+
+ if (!(response.getOut().getBody() instanceof CommitStatus)) {
+ fail("Expecting CommitStatus");
+ }
+
+ CommitStatus status=response.getOut().getBody(CommitStatus.class);
+
+ // Check status set on commit service
+ if (commitService.getCommitStatus(commitsha) != status) {
+ fail("Commit status sent to service is different from response");
+ }
+
+ assertEquals(status.getState(), "success");
+
+ assertEquals(status.getDescription(), text);
+ }
+
+
+ public class MockPullRequestStateProducerProcessor implements Processor {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ Map<String, Object> headers = in.getHeaders();
+ headers.put("GitHubPullRequestHeadCommitSHA", commitsha);
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockCommitService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockCommitService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockCommitService.java
new file mode 100644
index 0000000..4759170
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockCommitService.java
@@ -0,0 +1,77 @@
+/**
+ * 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.github.services;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.eclipse.egit.github.core.CommitStatus;
+import org.eclipse.egit.github.core.IRepositoryIdProvider;
+import org.eclipse.egit.github.core.RepositoryCommit;
+import org.eclipse.egit.github.core.User;
+import org.eclipse.egit.github.core.service.CommitService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockCommitService extends CommitService {
+ protected static final Logger LOG = LoggerFactory.getLogger(MockCommitService.class);
+
+ private List<RepositoryCommit> commitsList = new ArrayList<RepositoryCommit>();
+ private AtomicLong fakeSha = new AtomicLong(System.currentTimeMillis());
+ private Map<String,CommitStatus> commitStatus = new HashMap<String,CommitStatus>();
+
+ public synchronized RepositoryCommit addRepositoryCommit() {
+ User author = new User();
+ author.setEmail("someguy@gmail.com"); // TODO change
+ author.setHtmlUrl("http://github/someguy");
+ author.setLogin("someguy");
+
+ RepositoryCommit rc = new RepositoryCommit();
+ rc.setAuthor(author);
+ rc.setSha(fakeSha.incrementAndGet() + "");
+ LOG.debug("In MockCommitService added commit with sha " + rc.getSha());
+ commitsList.add(rc);
+
+ return rc;
+ }
+
+ @Override
+ public synchronized List<RepositoryCommit> getCommits(IRepositoryIdProvider repository, String sha, String path) throws IOException {
+ LOG.debug("Returning list of size " + commitsList.size());
+ return commitsList;
+ }
+
+ @Override
+ public CommitStatus createStatus(IRepositoryIdProvider repository,
+ String sha, CommitStatus status) throws IOException {
+ commitStatus.put(sha, status);
+
+ return status;
+ }
+
+ public String getNextSha() {
+ return (fakeSha.incrementAndGet()+"");
+ }
+
+ public CommitStatus getCommitStatus(String sha) {
+ return commitStatus.get(sha);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockIssueService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockIssueService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockIssueService.java
new file mode 100644
index 0000000..dd7b376
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockIssueService.java
@@ -0,0 +1,47 @@
+/**
+ * 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.github.services;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.egit.github.core.Comment;
+import org.eclipse.egit.github.core.IRepositoryIdProvider;
+import org.eclipse.egit.github.core.service.IssueService;
+
+public class MockIssueService extends IssueService {
+
+ private List<Comment> comments = new ArrayList<Comment>();
+ private MockPullRequestService mockPullRequestService;
+
+ public MockIssueService(MockPullRequestService mockPullRequestService) {
+ this.mockPullRequestService = mockPullRequestService;
+
+ }
+
+ @Override
+ public List<Comment> getComments(IRepositoryIdProvider repository, int issueNumber) {
+ return comments;
+ }
+
+ @Override
+ public Comment createComment(IRepositoryIdProvider repository, int issueNumber, String commentText) throws IOException {
+ Comment addedComment = mockPullRequestService.addComment((long) issueNumber, commentText);
+ return addedComment;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockPullRequestService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockPullRequestService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockPullRequestService.java
new file mode 100755
index 0000000..2619c8b
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockPullRequestService.java
@@ -0,0 +1,138 @@
+/**
+ * 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.github.services;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.egit.github.core.CommitComment;
+import org.eclipse.egit.github.core.CommitFile;
+import org.eclipse.egit.github.core.IRepositoryIdProvider;
+import org.eclipse.egit.github.core.PullRequest;
+import org.eclipse.egit.github.core.User;
+import org.eclipse.egit.github.core.service.PullRequestService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockPullRequestService extends PullRequestService {
+ protected static final Logger LOG = LoggerFactory.getLogger(MockPullRequestService.class);
+
+ private Map<Long, PullRequest> pullRequests = new HashMap<Long, PullRequest>();
+ private List<CommitComment> emptyComments = new ArrayList<CommitComment>();
+ private AtomicInteger pullRequestNumber = new AtomicInteger(101);
+ private AtomicInteger commentId = new AtomicInteger(500);
+ private Map<Long, List<CommitComment>> allComments = new HashMap<Long, List<CommitComment>>();
+ private Map<Integer,List<CommitFile>> files = new HashMap<Integer,List<CommitFile>>();
+
+ public List<CommitComment> getComments(IRepositoryIdProvider repository, int pullRequestId) {
+ Long id = new Long(pullRequestId);
+ if (allComments.containsKey(id)) {
+ List<CommitComment> comments = allComments.get(id);
+ return comments;
+ } else {
+ return emptyComments;
+ }
+ }
+
+ private User createAuthor() {
+ User author = new User();
+ author.setEmail("someguy@gmail.com");
+ author.setHtmlUrl("http://github/someguy");
+ author.setLogin("someguy");
+
+ return author;
+ }
+
+ public CommitComment addComment(Long pullRequestId, String bodyText) {
+ CommitComment commitComment = new CommitComment();
+
+ User author = createAuthor();
+ commitComment.setUser(author);
+ commitComment.setCommitId("" + pullRequestId);
+ commitComment.setId(commentId.getAndIncrement());
+ commitComment.setBody(bodyText);
+ commitComment.setBodyText(bodyText);
+
+ List<CommitComment> comments;
+ if (allComments.containsKey(pullRequestId)) {
+ comments = allComments.get(pullRequestId);
+ } else {
+ comments = new ArrayList<CommitComment>();
+ }
+ comments.add(commitComment);
+ allComments.put(pullRequestId, comments);
+
+ return commitComment;
+ }
+
+ public PullRequest addPullRequest(String title) {
+ User author = createAuthor();
+
+ PullRequest pullRequest = new PullRequest();
+ pullRequest.setUser(author);
+ pullRequest.setHtmlUrl("https://github.com/someguy/somerepo/pull" + pullRequestNumber);
+ pullRequest.setTitle(title);
+ pullRequest.setNumber(pullRequestNumber.get());
+ pullRequest.setId(pullRequestNumber.get());
+ pullRequest.setState("open");
+ pullRequests.put(pullRequest.getId(), pullRequest);
+
+ pullRequestNumber.incrementAndGet();
+ return pullRequest;
+ }
+
+ @Override
+ public PullRequest getPullRequest(IRepositoryIdProvider repository, int id) throws IOException {
+ PullRequest pullRequest = pullRequests.get((long) id);
+ return pullRequest;
+ }
+
+ @Override
+ public PullRequest editPullRequest(IRepositoryIdProvider repository, PullRequest request) throws IOException {
+ pullRequests.put(request.getId(), request);
+ return request;
+ }
+
+ @Override
+ public synchronized List<PullRequest> getPullRequests(IRepositoryIdProvider repository, String state) {
+ List<PullRequest> result = new ArrayList<PullRequest>();
+
+ for (Long id : pullRequests.keySet()) {
+ PullRequest pr = pullRequests.get(id);
+ if (pr.getState().equals(state)) {
+ result.add(pr);
+ }
+ }
+
+ LOG.debug("Returning list of " + result.size() + " pull requests with state " + state);
+ return result;
+ }
+
+ public void setFiles(int id, List<CommitFile> commitFiles) {
+ files.put(id, commitFiles);
+ }
+
+ @Override
+ public List<CommitFile> getFiles(IRepositoryIdProvider repository, int id)
+ throws IOException {
+ return (files.get(id));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1cb3c092/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockRepositoryService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockRepositoryService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockRepositoryService.java
new file mode 100644
index 0000000..9c93273
--- /dev/null
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockRepositoryService.java
@@ -0,0 +1,55 @@
+/**
+ * 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.github.services;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.egit.github.core.IRepositoryIdProvider;
+import org.eclipse.egit.github.core.Repository;
+import org.eclipse.egit.github.core.RepositoryTag;
+import org.eclipse.egit.github.core.service.RepositoryService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MockRepositoryService extends RepositoryService {
+ protected static final Logger LOG = LoggerFactory.getLogger(MockRepositoryService.class);
+
+ private List<RepositoryTag> tags = new ArrayList<RepositoryTag>();
+
+ public RepositoryTag addTag(String tagName) {
+ RepositoryTag tag = new RepositoryTag();
+ tag.setName(tagName);
+ tags.add(tag);
+
+ return tag;
+ }
+
+ @Override
+ public Repository getRepository(final String owner, final String name) throws IOException {
+ Repository repository = new Repository();
+ repository.setName(name);
+ return repository;
+ }
+
+ @Override
+ public List<RepositoryTag> getTags(IRepositoryIdProvider repository) throws IOException {
+ LOG.debug("in MockRepositoryService returning " + tags.size() + " tags");
+ return tags;
+ }
+}
[4/5] camel git commit: CAMEL-8497 Fixed bunch of CS errors
Posted by ni...@apache.org.
CAMEL-8497 Fixed bunch of CS errors
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bd8ff746
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bd8ff746
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bd8ff746
Branch: refs/heads/camel-2.15.x
Commit: bd8ff74605e3c4c10143ae5948bd18bbfa681fa8
Parents: 1cb3c09
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Mar 19 14:54:44 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Mar 19 15:01:45 2015 +0800
----------------------------------------------------------------------
.../github/producer/GetCommitFileProducer.java | 14 +++++++-------
.../github/producer/PullRequestFilesProducer.java | 2 +-
.../github/producer/PullRequestStateProducer.java | 4 ++--
.../github/producer/PullRequestFilesProducerTest.java | 4 ++--
.../github/producer/PullRequestStateProducerTest.java | 4 ++--
.../component/github/services/MockCommitService.java | 4 ++--
.../github/services/MockPullRequestService.java | 7 +++----
7 files changed, 19 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/bd8ff746/components/camel-github/src/main/java/org/apache/camel/component/github/producer/GetCommitFileProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/GetCommitFileProducer.java b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/GetCommitFileProducer.java
index 92375b9..04dd6bd 100644
--- a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/GetCommitFileProducer.java
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/GetCommitFileProducer.java
@@ -35,7 +35,7 @@ public class GetCommitFileProducer extends AbstractGitHubProducer {
private DataService dataService;
- private String encoding=Blob.ENCODING_UTF8;
+ private String encoding = Blob.ENCODING_UTF8;
public GetCommitFileProducer(GitHubEndpoint endpoint) throws Exception {
super(endpoint);
@@ -55,22 +55,22 @@ public class GetCommitFileProducer extends AbstractGitHubProducer {
if (!encoding.equalsIgnoreCase(Blob.ENCODING_BASE64)
&& !encoding.equalsIgnoreCase(Blob.ENCODING_UTF8)) {
- throw new IllegalArgumentException("Unknown encoding '"+encoding+"'");
+ throw new IllegalArgumentException("Unknown encoding '" + encoding + "'");
}
}
}
public void process(Exchange exchange) throws Exception {
- CommitFile file=exchange.getIn().getBody(CommitFile.class);
+ CommitFile file = exchange.getIn().getBody(CommitFile.class);
- Blob response=dataService.getBlob(getRepository(), file.getSha());
+ Blob response = dataService.getBlob(getRepository(), file.getSha());
- String text=response.getContent();
+ String text = response.getContent();
// By default, if blob encoding is base64 then we convert to UTF-8. If
// base64 encoding is required, then must be explicitly requested
- if (response.getEncoding().equals(Blob.ENCODING_BASE64) &&
- encoding != null && encoding.equalsIgnoreCase(Blob.ENCODING_UTF8)) {
+ if (response.getEncoding().equals(Blob.ENCODING_BASE64)
+ && encoding != null && encoding.equalsIgnoreCase(Blob.ENCODING_UTF8)) {
text = new String(Base64.decodeBase64(text));
}
http://git-wip-us.apache.org/repos/asf/camel/blob/bd8ff746/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestFilesProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestFilesProducer.java b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestFilesProducer.java
index f69bd3f..a44a0c5 100644
--- a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestFilesProducer.java
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestFilesProducer.java
@@ -51,7 +51,7 @@ public class PullRequestFilesProducer extends AbstractGitHubProducer {
public void process(Exchange exchange) throws Exception {
Integer pullRequestNumber = exchange.getIn().getHeader("GitHubPullRequest", Integer.class);
- java.util.List<CommitFile> response=pullRequestService.getFiles(getRepository(), pullRequestNumber);
+ java.util.List<CommitFile> response = pullRequestService.getFiles(getRepository(), pullRequestNumber);
// copy the header of in message to the out message
exchange.getOut().copyFrom(exchange.getIn());
http://git-wip-us.apache.org/repos/asf/camel/blob/bd8ff746/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestStateProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestStateProducer.java b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestStateProducer.java
index b9218b6..ab84fd1 100644
--- a/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestStateProducer.java
+++ b/components/camel-github/src/main/java/org/apache/camel/component/github/producer/PullRequestStateProducer.java
@@ -59,7 +59,7 @@ public class PullRequestStateProducer extends AbstractGitHubProducer {
String pullRequestNumberSHA = exchange.getIn().getHeader("GitHubPullRequestHeadCommitSHA", String.class);
String text = exchange.getIn().getBody(String.class);
- CommitStatus status=new CommitStatus();
+ CommitStatus status = new CommitStatus();
if (state != null) {
status.setState(state);
@@ -73,7 +73,7 @@ public class PullRequestStateProducer extends AbstractGitHubProducer {
status.setDescription(text);
}
- CommitStatus response=commitService.createStatus(getRepository(), pullRequestNumberSHA, status);
+ CommitStatus response = commitService.createStatus(getRepository(), pullRequestNumberSHA, status);
// copy the header of in message to the out message
exchange.getOut().copyFrom(exchange.getIn());
http://git-wip-us.apache.org/repos/asf/camel/blob/bd8ff746/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestFilesProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestFilesProducerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestFilesProducerTest.java
index d975532..fc4e97d 100644
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestFilesProducerTest.java
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestFilesProducerTest.java
@@ -59,10 +59,10 @@ public class PullRequestFilesProducerTest extends GitHubComponentTestBase {
PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestFilesProducer");
latestPullRequestNumber = pullRequest.getNumber();
- CommitFile file=new CommitFile();
+ CommitFile file = new CommitFile();
file.setFilename("testfile");
- List<CommitFile> commitFiles=new ArrayList<CommitFile>();
+ List<CommitFile> commitFiles = new ArrayList<CommitFile>();
commitFiles.add(file);
pullRequestService.setFiles(latestPullRequestNumber, commitFiles);
http://git-wip-us.apache.org/repos/asf/camel/blob/bd8ff746/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestStateProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestStateProducerTest.java b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestStateProducerTest.java
index 1aabe95..c6a6a93 100644
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestStateProducerTest.java
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/producer/PullRequestStateProducerTest.java
@@ -60,7 +60,7 @@ public class PullRequestStateProducerTest extends GitHubComponentTestBase {
Exchange exchange = stateProducerEndpoint.createExchange();
String text = "Message sent at " + new Date();
exchange.getIn().setBody(text);
- Exchange response=template.send(stateProducerEndpoint, exchange);
+ Exchange response = template.send(stateProducerEndpoint, exchange);
assertNotNull(response.getOut().getBody());
@@ -68,7 +68,7 @@ public class PullRequestStateProducerTest extends GitHubComponentTestBase {
fail("Expecting CommitStatus");
}
- CommitStatus status=response.getOut().getBody(CommitStatus.class);
+ CommitStatus status = response.getOut().getBody(CommitStatus.class);
// Check status set on commit service
if (commitService.getCommitStatus(commitsha) != status) {
http://git-wip-us.apache.org/repos/asf/camel/blob/bd8ff746/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockCommitService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockCommitService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockCommitService.java
index 4759170..c3f8f51 100644
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockCommitService.java
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockCommitService.java
@@ -36,7 +36,7 @@ public class MockCommitService extends CommitService {
private List<RepositoryCommit> commitsList = new ArrayList<RepositoryCommit>();
private AtomicLong fakeSha = new AtomicLong(System.currentTimeMillis());
- private Map<String,CommitStatus> commitStatus = new HashMap<String,CommitStatus>();
+ private Map<String, CommitStatus> commitStatus = new HashMap<String, CommitStatus>();
public synchronized RepositoryCommit addRepositoryCommit() {
User author = new User();
@@ -68,7 +68,7 @@ public class MockCommitService extends CommitService {
}
public String getNextSha() {
- return (fakeSha.incrementAndGet()+"");
+ return fakeSha.incrementAndGet() + "";
}
public CommitStatus getCommitStatus(String sha) {
http://git-wip-us.apache.org/repos/asf/camel/blob/bd8ff746/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockPullRequestService.java
----------------------------------------------------------------------
diff --git a/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockPullRequestService.java b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockPullRequestService.java
index 2619c8b..09a7d63 100755
--- a/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockPullRequestService.java
+++ b/components/camel-github/src/test/java/org/apache/camel/component/github/services/MockPullRequestService.java
@@ -40,7 +40,7 @@ public class MockPullRequestService extends PullRequestService {
private AtomicInteger pullRequestNumber = new AtomicInteger(101);
private AtomicInteger commentId = new AtomicInteger(500);
private Map<Long, List<CommitComment>> allComments = new HashMap<Long, List<CommitComment>>();
- private Map<Integer,List<CommitFile>> files = new HashMap<Integer,List<CommitFile>>();
+ private Map<Integer, List<CommitFile>> files = new HashMap<Integer, List<CommitFile>>();
public List<CommitComment> getComments(IRepositoryIdProvider repository, int pullRequestId) {
Long id = new Long(pullRequestId);
@@ -131,8 +131,7 @@ public class MockPullRequestService extends PullRequestService {
}
@Override
- public List<CommitFile> getFiles(IRepositoryIdProvider repository, int id)
- throws IOException {
- return (files.get(id));
+ public List<CommitFile> getFiles(IRepositoryIdProvider repository, int id) throws IOException {
+ return files.get(id);
}
}
[5/5] camel git commit: CAMEL-8497 Added the dependency bundle of
common-codec in the camel-github feature
Posted by ni...@apache.org.
CAMEL-8497 Added the dependency bundle of common-codec in the camel-github feature
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2eaeaee2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2eaeaee2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2eaeaee2
Branch: refs/heads/camel-2.15.x
Commit: 2eaeaee258a31f205c482b9e9b3da8dccb430342
Parents: bd8ff74
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Mar 19 14:56:43 2015 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Mar 19 15:01:59 2015 +0800
----------------------------------------------------------------------
platforms/karaf/features/src/main/resources/features.xml | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2eaeaee2/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index a3832fd..4947447 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -435,6 +435,7 @@
<bundle dependency='true'>mvn:com.google.code.gson/gson/2.2</bundle>
<!--TODO use the servicesmix wrapped bundle -->
<bundle dependency='true'>mvn:org.eclipse.mylyn.github/org.eclipse.egit.github.core/${egit-github-core-version}</bundle>
+ <bundle dependency='true'>mvn:commons-codec/commons-codec/${commons-codec-version}</bundle>
<bundle>mvn:org.apache.camel/camel-github/${project.version}</bundle>
</feature>
<feature name='camel-google-calendar' version='${project.version}' resolver='(obr)' start-level='50'>
@@ -977,7 +978,7 @@
<bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.isorelax/${isorelax-bundle-version}</bundle>
<feature version='${project.version}'>camel-core</feature>
<bundle>mvn:org.apache.camel/camel-msv/${project.version}</bundle>
- </feature>
+ </feature>
<feature name='camel-mustache' version='${project.version}' resolver='(obr)' start-level='50'>
<bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.mustache-compiler/${mustache-bundle-version}</bundle>
<bundle dependency='true'>mvn:com.google.guava/guava/${mustache-guava-version}</bundle>
@@ -1127,7 +1128,7 @@
<feature name='camel-rabbitmq' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<bundle dependency='true'>mvn:com.rabbitmq/amqp-client/${rabbitmq-amqp-client-version}</bundle>
- <bundle dependency='true'>mvn:commons-pool/commons-pool/${commons-pool-version}</bundle>
+ <bundle dependency='true'>mvn:commons-pool/commons-pool/${commons-pool-version}</bundle>
<bundle>mvn:org.apache.camel/camel-rabbitmq/${project.version}</bundle>
</feature>
<feature name='camel-restlet' version='${project.version}' resolver='(obr)' start-level='50'>
@@ -1439,7 +1440,7 @@
<bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.json4s/${json4s-bundle-version}</bundle>
<bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.reflections/${reflections-bundle-version}</bundle>
<bundle>mvn:org.apache.camel/camel-swagger/${project.version}</bundle>
- </feature>
+ </feature>
<feature name='camel-syslog' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<feature version='${project.version}'>camel-netty</feature>