You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2015/07/18 11:09:30 UTC
[13/23] camel git commit: CAMEL-7982: camel-git - A generic git
component, add tag consumer
CAMEL-7982: camel-git - A generic git component, add tag consumer
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/828dc8b3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/828dc8b3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/828dc8b3
Branch: refs/heads/master
Commit: 828dc8b3bd49352398310fa8a42c9420e28102cf
Parents: 8239d6f
Author: Andrea Cosentino <an...@gmail.com>
Authored: Sat Jul 18 11:06:56 2015 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sat Jul 18 11:08:15 2015 +0200
----------------------------------------------------------------------
.../apache/camel/component/git/GitEndpoint.java | 2 +
.../git/consumer/AbstractGitConsumer.java | 16 +
.../git/consumer/GitCommitConsumer.java | 21 +-
.../component/git/consumer/GitTagConsumer.java | 52 ++
.../camel/component/git/consumer/GitType.java | 2 +-
.../component/git/consumer/GitConsumerTest.java | 140 ++++
.../component/git/producer/GitProducerTest.java | 724 +++++++++++++++++++
.../git/producer/GitRemoteProducerTest.java | 91 +++
.../component/git/producer/GitTestSupport.java | 88 +++
.../github/consumer/GitConsumerTest.java | 126 ----
.../github/producer/GitProducerTest.java | 724 -------------------
.../github/producer/GitRemoteProducerTest.java | 91 ---
.../github/producer/GitTestSupport.java | 88 ---
13 files changed, 1132 insertions(+), 1033 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java b/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java
index 247b60d..1b06092 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/GitEndpoint.java
@@ -20,6 +20,7 @@ import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.component.git.consumer.GitCommitConsumer;
+import org.apache.camel.component.git.consumer.GitTagConsumer;
import org.apache.camel.component.git.consumer.GitType;
import org.apache.camel.component.git.producer.GitProducer;
import org.apache.camel.impl.DefaultEndpoint;
@@ -58,6 +59,7 @@ public class GitEndpoint extends DefaultEndpoint {
@Override
public Consumer createConsumer(Processor processor) throws Exception {
if (type == GitType.COMMIT) return new GitCommitConsumer(this, processor);
+ else if (type == GitType.TAG) return new GitTagConsumer(this, processor);
else throw new IllegalArgumentException("Cannot create producer with type " + type);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
index 5ceec5d..6e93849 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/AbstractGitConsumer.java
@@ -1,3 +1,19 @@
+/**
+ * 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.git.consumer;
import java.io.File;
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java
index d289c26..c837adc 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitCommitConsumer.java
@@ -1,3 +1,19 @@
+/**
+ * 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.git.consumer;
import java.util.ArrayList;
@@ -10,11 +26,10 @@ import org.eclipse.jgit.revwalk.RevCommit;
public class GitCommitConsumer extends AbstractGitConsumer {
- private List used;
+ private List used = new ArrayList();
public GitCommitConsumer(GitEndpoint endpoint, Processor processor) {
super(endpoint, processor);
- this.used = new ArrayList();
}
@Override
@@ -24,7 +39,7 @@ public class GitCommitConsumer extends AbstractGitConsumer {
for (RevCommit commit : commits) {
if (!used.contains(commit.getId())) {
Exchange e = getEndpoint().createExchange();
- e.getOut().setBody(commit.getShortMessage());
+ e.getOut().setBody(commit);
getProcessor().process(e);
used.add(commit.getId());
count++;
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitTagConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitTagConsumer.java b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitTagConsumer.java
new file mode 100644
index 0000000..ca063f3
--- /dev/null
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitTagConsumer.java
@@ -0,0 +1,52 @@
+/**
+ * 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.git.consumer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.git.GitEndpoint;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.revwalk.RevCommit;
+
+public class GitTagConsumer extends AbstractGitConsumer {
+
+ private List used = new ArrayList();
+
+ public GitTagConsumer(GitEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ }
+
+ @Override
+ protected int poll() throws Exception {
+ int count = 0;
+ List<Ref> call = getGit().tagList().call();
+ for (Ref ref : call) {
+ if (!used.contains(ref.getName())) {
+ Exchange e = getEndpoint().createExchange();
+ e.getOut().setBody(ref);
+ getProcessor().process(e);
+ used.add(ref.getName());
+ count++;
+ }
+ }
+ return count;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitType.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitType.java b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitType.java
index af3729e..4015445 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitType.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/consumer/GitType.java
@@ -18,6 +18,6 @@ package org.apache.camel.component.git.consumer;
public enum GitType {
- COMMIT
+ COMMIT, TAG
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerTest.java b/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerTest.java
new file mode 100644
index 0000000..21273e2
--- /dev/null
+++ b/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerTest.java
@@ -0,0 +1,140 @@
+/**
+ * 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.git.consumer;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.git.GitConstants;
+import org.apache.camel.component.git.producer.GitTestSupport;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.Status;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.junit.Test;
+
+public class GitConsumerTest extends GitTestSupport {
+
+ @Test
+ public void commitConsumerTest() throws Exception {
+
+ Repository repository = getTestRepository();
+ MockEndpoint added = getMockEndpoint("mock:result");
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+ Iterable<RevCommit> logs = new Git(repository).log()
+ .call();
+ int count = 0;
+ for (RevCommit rev : logs) {
+ assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+ assertEquals(count, 1);
+
+ File fileToAdd1 = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
+ fileToAdd1.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
+ }
+ });
+
+ status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_BRANCH_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, "Test test Commit");
+ }
+ });
+ logs = new Git(repository).log()
+ .call();
+ count = 0;
+ for (RevCommit rev : logs) {
+ count++;
+ }
+ assertEquals(count, 2);
+
+ Thread.sleep(1 * 5000);
+ Exchange ex1 = added.getExchanges().get(0);
+ Exchange ex2 = added.getExchanges().get(1);
+ assertEquals(COMMIT_MESSAGE, ex2.getOut().getBody(RevCommit.class).getShortMessage());
+ assertEquals("Test test Commit", ex1.getOut().getBody(RevCommit.class).getShortMessage());
+ repository.close();
+ }
+
+ @Test
+ public void tagConsumerTest() throws Exception {
+
+ Repository repository = getTestRepository();
+ MockEndpoint added = getMockEndpoint("mock:result");
+
+ Thread.sleep(1 * 5000);
+ assertEquals(added.getExchanges().size(), 0);
+ repository.close();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:clone")
+ .to("git://" + GIT_LOCAL_REPO + "?remotePath=https://github.com/oscerd/json-webserver-example.git&operation=clone");
+ from("direct:init")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=init");
+ from("direct:add")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=add");
+ from("direct:commit")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=commit");
+ from("git://" + GIT_LOCAL_REPO + "?type=commit")
+ .to("mock:result");
+ from("git://" + GIT_LOCAL_REPO + "?type=tag")
+ .to("mock:result");
+ }
+ };
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java
new file mode 100755
index 0000000..5a9c7f3
--- /dev/null
+++ b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitProducerTest.java
@@ -0,0 +1,724 @@
+/**
+ * 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.git.producer;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.git.GitConstants;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.Status;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+import org.eclipse.jgit.transport.PushResult;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class GitProducerTest extends GitTestSupport {
+
+ @Test
+ public void cloneTest() throws Exception {
+ template.sendBody("direct:clone","");
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+ }
+
+ @Test
+ public void initTest() throws Exception {
+ template.sendBody("direct:init","");
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+ }
+
+ @Test
+ public void addTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+ repository.close();
+ }
+
+ @Test
+ public void removeTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:remove", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+ Iterable<RevCommit> logs = new Git(repository).log()
+ .call();
+ int count = 0;
+ for (RevCommit rev : logs) {
+ assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+ assertEquals(count, 1);
+
+ status = new Git(repository).status().call();
+
+ assertFalse(status.getAdded().contains(FILENAME_TO_ADD));
+
+ repository.close();
+ }
+
+ @Test
+ public void commitTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+ Iterable<RevCommit> logs = new Git(repository).log()
+ .call();
+ int count = 0;
+ for (RevCommit rev : logs) {
+ assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+ assertEquals(count, 1);
+ repository.close();
+ }
+
+ @Test
+ public void commitBranchTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+ Iterable<RevCommit> logs = new Git(repository).log()
+ .call();
+ int count = 0;
+ for (RevCommit rev : logs) {
+ assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+ assertEquals(count, 1);
+
+ Git git = new Git(repository);
+ git.checkout().setCreateBranch(true).setName(BRANCH_TEST).
+ setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
+
+ template.send("direct:commit-branch", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_BRANCH);
+ }
+ });
+ logs = git.log().call();
+ count = 0;
+ for (RevCommit rev : logs) {
+ if (count == 0) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_BRANCH);
+ if (count == 1) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+ assertEquals(count, 2);
+ repository.close();
+ }
+
+
+
+ @Test
+ public void commitAllTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+
+ template.send("direct:commit-all", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_ALL);
+ }
+ });
+ Iterable<RevCommit> logs = new Git(repository).log()
+ .call();
+ int count = 0;
+ for (RevCommit rev : logs) {
+ assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_ALL);
+ count++;
+ }
+ assertEquals(count, 1);
+ repository.close();
+ }
+
+ @Test
+ public void commitAllDifferentBranchTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+ Iterable<RevCommit> logs = new Git(repository).log()
+ .call();
+ int count = 0;
+ for (RevCommit rev : logs) {
+ assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+ assertEquals(count, 1);
+
+ Git git = new Git(repository);
+ git.checkout().setCreateBranch(true).setName(BRANCH_TEST).
+ setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
+
+ File fileToAdd1 = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
+ fileToAdd1.createNewFile();
+
+ template.send("direct:add-on-branch", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
+ }
+ });
+
+ template.send("direct:commit-all-branch", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_ALL);
+ }
+ });
+ logs = git.log().call();
+ count = 0;
+ for (RevCommit rev : logs) {
+ if (count == 0) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_ALL);
+ if (count == 1) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+ assertEquals(count, 2);
+ repository.close();
+ }
+
+ @Test
+ public void removeFileBranchTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+ Iterable<RevCommit> logs = new Git(repository).log()
+ .call();
+ int count = 0;
+ for (RevCommit rev : logs) {
+ assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+ assertEquals(count, 1);
+
+ Git git = new Git(repository);
+ git.checkout().setCreateBranch(true).setName(BRANCH_TEST).
+ setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
+
+ File fileToAdd1 = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
+ fileToAdd1.createNewFile();
+
+ template.send("direct:add-on-branch", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
+ }
+ });
+
+ template.send("direct:commit-all-branch", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_ALL);
+ }
+ });
+ logs = git.log().call();
+ count = 0;
+ for (RevCommit rev : logs) {
+ if (count == 0) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_ALL);
+ if (count == 1) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+ assertEquals(count, 2);
+
+ template.send("direct:remove-on-branch", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+
+ git = new Git(repository);
+ git.checkout().setCreateBranch(false).setName(BRANCH_TEST).call();
+
+ status = git.status().call();
+ assertFalse(status.getAdded().contains(FILENAME_TO_ADD));
+
+ repository.close();
+ }
+
+ @Test
+ public void createBranchTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+
+ Git git = new Git(repository);
+
+ template.sendBody("direct:create-branch", "");
+
+ List<Ref> ref = git.branchList().call();
+ boolean branchCreated = false;
+ for (Ref refInternal : ref) {
+ if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
+ branchCreated = true;
+ }
+ }
+ assertEquals(branchCreated, true);
+ repository.close();
+ }
+
+ @Test
+ public void deleteBranchTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+
+ Git git = new Git(repository);
+
+ template.sendBody("direct:create-branch", "");
+
+ List<Ref> ref = git.branchList().call();
+ boolean branchCreated = false;
+ for (Ref refInternal : ref) {
+ if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
+ branchCreated = true;
+ }
+ }
+ assertEquals(branchCreated, true);
+
+ template.sendBody("direct:delete-branch", "");
+
+ ref = git.branchList().call();
+ branchCreated = false;
+ for (Ref refInternal : ref) {
+ if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
+ branchCreated = true;
+ }
+ }
+ assertEquals(branchCreated, false);
+ repository.close();
+ }
+
+ @Test
+ public void statusTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = template.requestBody("direct:status", "", Status.class);
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ repository.close();
+ }
+
+ @Test
+ public void statusBranchTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = template.requestBody("direct:status", "", Status.class);
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+
+ template.sendBody("direct:create-branch", "");
+
+ Git git = new Git(repository);
+
+ List<Ref> ref = git.branchList().call();
+ boolean branchCreated = false;
+ for (Ref refInternal : ref) {
+ if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
+ branchCreated = true;
+ }
+ }
+ assertEquals(branchCreated, true);
+
+ File fileToAddDifferent = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
+ fileToAddDifferent.createNewFile();
+
+ template.send("direct:add-on-branch", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
+ }
+ });
+
+ status = template.requestBody("direct:status-branch", "", Status.class);
+ assertTrue(status.getAdded().contains(FILENAME_BRANCH_TO_ADD));
+
+ repository.close();
+ }
+
+ @Test
+ public void logTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = template.requestBody("direct:status", "", Status.class);
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+
+ Iterable<RevCommit> revCommits = template.requestBody("direct:log", "", Iterable.class);
+ for (RevCommit rev : revCommits) {
+ assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ }
+ repository.close();
+ }
+
+ @Test
+ public void logBranchTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = template.requestBody("direct:status", "", Status.class);
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+
+ Iterable<RevCommit> revCommits = template.requestBody("direct:log", "", Iterable.class);
+ for (RevCommit rev : revCommits) {
+ assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ }
+
+ template.sendBody("direct:create-branch", "");
+
+ Git git = new Git(repository);
+
+ List<Ref> ref = git.branchList().call();
+ boolean branchCreated = false;
+ for (Ref refInternal : ref) {
+ if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
+ branchCreated = true;
+ }
+ }
+ assertEquals(branchCreated, true);
+
+ File fileToAddDifferent = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
+ fileToAddDifferent.createNewFile();
+
+ template.send("direct:add-on-branch", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
+ }
+ });
+
+ template.send("direct:commit-all-branch", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_ALL);
+ }
+ });
+
+ revCommits = template.requestBody("direct:log-branch", "", Iterable.class);
+ int count = 0;
+ for (RevCommit rev : revCommits) {
+ if (count == 0) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_ALL);
+ if (count == 1) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
+ count++;
+ }
+
+ repository.close();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:clone")
+ .to("git://" + GIT_LOCAL_REPO + "?remotePath=https://github.com/oscerd/json-webserver-example.git&operation=clone");
+ from("direct:init")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=init");
+ from("direct:add")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=add");
+ from("direct:remove")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=rm");
+ from("direct:add-on-branch")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=add&branchName=" + BRANCH_TEST);
+ from("direct:remove-on-branch")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=add&branchName=" + BRANCH_TEST);
+ from("direct:commit")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=commit");
+ from("direct:commit-branch")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=commit&branchName=" + BRANCH_TEST);
+ from("direct:commit-all")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=commit");
+ from("direct:commit-all-branch")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=commit&branchName=" + BRANCH_TEST);
+ from("direct:create-branch")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=createBranch&branchName=" + BRANCH_TEST);
+ from("direct:delete-branch")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=deleteBranch&branchName=" + BRANCH_TEST);
+ from("direct:status")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=status");
+ from("direct:status-branch")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=status&branchName=" + BRANCH_TEST);
+ from("direct:log")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=log");
+ from("direct:log-branch")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=log&branchName=" + BRANCH_TEST);
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitRemoteProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitRemoteProducerTest.java b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitRemoteProducerTest.java
new file mode 100644
index 0000000..a82eba7
--- /dev/null
+++ b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitRemoteProducerTest.java
@@ -0,0 +1,91 @@
+/**
+ * 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.git.producer;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.git.GitConstants;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.PullResult;
+import org.eclipse.jgit.api.Status;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+import org.eclipse.jgit.transport.PushResult;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class GitRemoteProducerTest extends GitTestSupport {
+
+ @Ignore("Require a remote git repository")
+ @Test
+ public void pushTest() throws Exception {
+
+ Repository repository = getTestRepository();
+
+ File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
+ fileToAdd.createNewFile();
+
+ template.send("direct:add", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
+ }
+ });
+ File gitDir = new File(GIT_LOCAL_REPO, ".git");
+ assertEquals(gitDir.exists(), true);
+
+ Status status = new Git(repository).status().call();
+ assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
+
+ template.send("direct:commit", new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
+ }
+ });
+
+ Iterable<PushResult> result = template.requestBody("direct:push", "", Iterable.class);
+
+ repository.close();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:add")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=add");
+ from("direct:commit")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=commit");
+ from("direct:push")
+ .to("git://" + GIT_LOCAL_REPO + "?operation=push&remotePath=remoteURL&username=xxx&password=xxx" );
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitTestSupport.java b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitTestSupport.java
new file mode 100644
index 0000000..f0cfacb
--- /dev/null
+++ b/components/camel-git/src/test/java/org/apache/camel/component/git/producer/GitTestSupport.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.git.producer;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+
+public class GitTestSupport extends CamelTestSupport {
+
+ public final static String GIT_LOCAL_REPO = "testRepo";
+
+ public final static String FILENAME_TO_ADD = "filetest.txt";
+
+ public final static String FILENAME_BRANCH_TO_ADD = "filetest1.txt";
+
+ public final static String COMMIT_MESSAGE = "Test commit";
+
+ public final static String COMMIT_MESSAGE_ALL = "Test commit all";
+
+ public final static String COMMIT_MESSAGE_BRANCH = "Test commit on a branch";
+
+ public final static String BRANCH_TEST = "testBranch";
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ File localPath = File.createTempFile(GIT_LOCAL_REPO, "");
+ localPath.delete();
+ File path = new File(GIT_LOCAL_REPO);
+ path.deleteOnExit();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ File path = new File(GIT_LOCAL_REPO);
+ deleteDirectory(path);
+ }
+
+ protected Repository getTestRepository() throws IOException, IllegalStateException, GitAPIException {
+ File gitRepo = new File(GIT_LOCAL_REPO, ".git");
+ Git.init().setDirectory(new File(GIT_LOCAL_REPO,"")).setBare(false).call();
+ // now open the resulting repository with a FileRepositoryBuilder
+ FileRepositoryBuilder builder = new FileRepositoryBuilder();
+ Repository repo = builder.setGitDir(gitRepo)
+ .readEnvironment() // scan environment GIT_* variables
+ .findGitDir() // scan up the file system tree
+ .build();
+ return repo;
+ }
+
+ static public boolean deleteDirectory(File path) {
+ if( path.exists() ) {
+ File[] files = path.listFiles();
+ for(int i=0; i<files.length; i++) {
+ if(files[i].isDirectory()) {
+ deleteDirectory(files[i]);
+ }
+ else {
+ files[i].delete();
+ }
+ }
+ }
+ return( path.delete() );
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/test/java/org/apache/camel/component/github/consumer/GitConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/github/consumer/GitConsumerTest.java b/components/camel-git/src/test/java/org/apache/camel/component/github/consumer/GitConsumerTest.java
deleted file mode 100644
index d45591b..0000000
--- a/components/camel-git/src/test/java/org/apache/camel/component/github/consumer/GitConsumerTest.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.File;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.git.GitConstants;
-import org.apache.camel.component.github.producer.GitTestSupport;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.Status;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.junit.Test;
-
-public class GitConsumerTest extends GitTestSupport {
-
- @Test
- public void commitConsumerTest() throws Exception {
-
- Repository repository = getTestRepository();
- MockEndpoint added = getMockEndpoint("mock:result");
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
- int count = 0;
- for (RevCommit rev : logs) {
- assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
- assertEquals(count, 1);
-
- File fileToAdd1 = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
- fileToAdd1.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
- }
- });
-
- status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_BRANCH_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, "Test test Commit");
- }
- });
- logs = new Git(repository).log()
- .call();
- count = 0;
- for (RevCommit rev : logs) {
- count++;
- }
- assertEquals(count, 2);
-
- Thread.sleep(1 * 5000);
- Exchange ex1 = added.getExchanges().get(0);
- Exchange ex2 = added.getExchanges().get(1);
- assertEquals(COMMIT_MESSAGE, ex2.getOut().getBody());
- assertEquals("Test test Commit", ex1.getOut().getBody());
- repository.close();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:clone")
- .to("git://" + GIT_LOCAL_REPO + "?remotePath=https://github.com/oscerd/json-webserver-example.git&operation=clone");
- from("direct:init")
- .to("git://" + GIT_LOCAL_REPO + "?operation=init");
- from("direct:add")
- .to("git://" + GIT_LOCAL_REPO + "?operation=add");
- from("direct:commit")
- .to("git://" + GIT_LOCAL_REPO + "?operation=commit");
- from("git://" + GIT_LOCAL_REPO + "?type=commit")
- .to("mock:result");
- }
- };
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/camel/blob/828dc8b3/components/camel-git/src/test/java/org/apache/camel/component/github/producer/GitProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/github/producer/GitProducerTest.java b/components/camel-git/src/test/java/org/apache/camel/component/github/producer/GitProducerTest.java
deleted file mode 100755
index cee4011..0000000
--- a/components/camel-git/src/test/java/org/apache/camel/component/github/producer/GitProducerTest.java
+++ /dev/null
@@ -1,724 +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.producer;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.git.GitConstants;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.Status;
-import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
-import org.eclipse.jgit.transport.PushResult;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class GitProducerTest extends GitTestSupport {
-
- @Test
- public void cloneTest() throws Exception {
- template.sendBody("direct:clone","");
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
- }
-
- @Test
- public void initTest() throws Exception {
- template.sendBody("direct:init","");
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
- }
-
- @Test
- public void addTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
- repository.close();
- }
-
- @Test
- public void removeTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:remove", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
- int count = 0;
- for (RevCommit rev : logs) {
- assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
- assertEquals(count, 1);
-
- status = new Git(repository).status().call();
-
- assertFalse(status.getAdded().contains(FILENAME_TO_ADD));
-
- repository.close();
- }
-
- @Test
- public void commitTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
- int count = 0;
- for (RevCommit rev : logs) {
- assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
- assertEquals(count, 1);
- repository.close();
- }
-
- @Test
- public void commitBranchTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
- int count = 0;
- for (RevCommit rev : logs) {
- assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
- assertEquals(count, 1);
-
- Git git = new Git(repository);
- git.checkout().setCreateBranch(true).setName(BRANCH_TEST).
- setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
-
- template.send("direct:commit-branch", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_BRANCH);
- }
- });
- logs = git.log().call();
- count = 0;
- for (RevCommit rev : logs) {
- if (count == 0) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_BRANCH);
- if (count == 1) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
- assertEquals(count, 2);
- repository.close();
- }
-
-
-
- @Test
- public void commitAllTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
-
- template.send("direct:commit-all", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_ALL);
- }
- });
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
- int count = 0;
- for (RevCommit rev : logs) {
- assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_ALL);
- count++;
- }
- assertEquals(count, 1);
- repository.close();
- }
-
- @Test
- public void commitAllDifferentBranchTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
- int count = 0;
- for (RevCommit rev : logs) {
- assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
- assertEquals(count, 1);
-
- Git git = new Git(repository);
- git.checkout().setCreateBranch(true).setName(BRANCH_TEST).
- setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
-
- File fileToAdd1 = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
- fileToAdd1.createNewFile();
-
- template.send("direct:add-on-branch", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
- }
- });
-
- template.send("direct:commit-all-branch", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_ALL);
- }
- });
- logs = git.log().call();
- count = 0;
- for (RevCommit rev : logs) {
- if (count == 0) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_ALL);
- if (count == 1) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
- assertEquals(count, 2);
- repository.close();
- }
-
- @Test
- public void removeFileBranchTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
- Iterable<RevCommit> logs = new Git(repository).log()
- .call();
- int count = 0;
- for (RevCommit rev : logs) {
- assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
- assertEquals(count, 1);
-
- Git git = new Git(repository);
- git.checkout().setCreateBranch(true).setName(BRANCH_TEST).
- setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
-
- File fileToAdd1 = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
- fileToAdd1.createNewFile();
-
- template.send("direct:add-on-branch", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
- }
- });
-
- template.send("direct:commit-all-branch", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_ALL);
- }
- });
- logs = git.log().call();
- count = 0;
- for (RevCommit rev : logs) {
- if (count == 0) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_ALL);
- if (count == 1) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
- assertEquals(count, 2);
-
- template.send("direct:remove-on-branch", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
-
- git = new Git(repository);
- git.checkout().setCreateBranch(false).setName(BRANCH_TEST).call();
-
- status = git.status().call();
- assertFalse(status.getAdded().contains(FILENAME_TO_ADD));
-
- repository.close();
- }
-
- @Test
- public void createBranchTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
-
- Git git = new Git(repository);
-
- template.sendBody("direct:create-branch", "");
-
- List<Ref> ref = git.branchList().call();
- boolean branchCreated = false;
- for (Ref refInternal : ref) {
- if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
- branchCreated = true;
- }
- }
- assertEquals(branchCreated, true);
- repository.close();
- }
-
- @Test
- public void deleteBranchTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = new Git(repository).status().call();
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
-
- Git git = new Git(repository);
-
- template.sendBody("direct:create-branch", "");
-
- List<Ref> ref = git.branchList().call();
- boolean branchCreated = false;
- for (Ref refInternal : ref) {
- if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
- branchCreated = true;
- }
- }
- assertEquals(branchCreated, true);
-
- template.sendBody("direct:delete-branch", "");
-
- ref = git.branchList().call();
- branchCreated = false;
- for (Ref refInternal : ref) {
- if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
- branchCreated = true;
- }
- }
- assertEquals(branchCreated, false);
- repository.close();
- }
-
- @Test
- public void statusTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = template.requestBody("direct:status", "", Status.class);
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- repository.close();
- }
-
- @Test
- public void statusBranchTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = template.requestBody("direct:status", "", Status.class);
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
-
- template.sendBody("direct:create-branch", "");
-
- Git git = new Git(repository);
-
- List<Ref> ref = git.branchList().call();
- boolean branchCreated = false;
- for (Ref refInternal : ref) {
- if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
- branchCreated = true;
- }
- }
- assertEquals(branchCreated, true);
-
- File fileToAddDifferent = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
- fileToAddDifferent.createNewFile();
-
- template.send("direct:add-on-branch", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
- }
- });
-
- status = template.requestBody("direct:status-branch", "", Status.class);
- assertTrue(status.getAdded().contains(FILENAME_BRANCH_TO_ADD));
-
- repository.close();
- }
-
- @Test
- public void logTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = template.requestBody("direct:status", "", Status.class);
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
-
- Iterable<RevCommit> revCommits = template.requestBody("direct:log", "", Iterable.class);
- for (RevCommit rev : revCommits) {
- assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- }
- repository.close();
- }
-
- @Test
- public void logBranchTest() throws Exception {
-
- Repository repository = getTestRepository();
-
- File fileToAdd = new File(GIT_LOCAL_REPO, FILENAME_TO_ADD);
- fileToAdd.createNewFile();
-
- template.send("direct:add", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_TO_ADD);
- }
- });
- File gitDir = new File(GIT_LOCAL_REPO, ".git");
- assertEquals(gitDir.exists(), true);
-
- Status status = template.requestBody("direct:status", "", Status.class);
- assertTrue(status.getAdded().contains(FILENAME_TO_ADD));
-
- template.send("direct:commit", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE);
- }
- });
-
- Iterable<RevCommit> revCommits = template.requestBody("direct:log", "", Iterable.class);
- for (RevCommit rev : revCommits) {
- assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- }
-
- template.sendBody("direct:create-branch", "");
-
- Git git = new Git(repository);
-
- List<Ref> ref = git.branchList().call();
- boolean branchCreated = false;
- for (Ref refInternal : ref) {
- if (refInternal.getName().equals("refs/heads/" + BRANCH_TEST)) {
- branchCreated = true;
- }
- }
- assertEquals(branchCreated, true);
-
- File fileToAddDifferent = new File(GIT_LOCAL_REPO, FILENAME_BRANCH_TO_ADD);
- fileToAddDifferent.createNewFile();
-
- template.send("direct:add-on-branch", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, FILENAME_BRANCH_TO_ADD);
- }
- });
-
- template.send("direct:commit-all-branch", new Processor() {
- @Override
- public void process(Exchange exchange) throws Exception {
- exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, COMMIT_MESSAGE_ALL);
- }
- });
-
- revCommits = template.requestBody("direct:log-branch", "", Iterable.class);
- int count = 0;
- for (RevCommit rev : revCommits) {
- if (count == 0) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE_ALL);
- if (count == 1) assertEquals(rev.getShortMessage(), COMMIT_MESSAGE);
- count++;
- }
-
- repository.close();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:clone")
- .to("git://" + GIT_LOCAL_REPO + "?remotePath=https://github.com/oscerd/json-webserver-example.git&operation=clone");
- from("direct:init")
- .to("git://" + GIT_LOCAL_REPO + "?operation=init");
- from("direct:add")
- .to("git://" + GIT_LOCAL_REPO + "?operation=add");
- from("direct:remove")
- .to("git://" + GIT_LOCAL_REPO + "?operation=rm");
- from("direct:add-on-branch")
- .to("git://" + GIT_LOCAL_REPO + "?operation=add&branchName=" + BRANCH_TEST);
- from("direct:remove-on-branch")
- .to("git://" + GIT_LOCAL_REPO + "?operation=add&branchName=" + BRANCH_TEST);
- from("direct:commit")
- .to("git://" + GIT_LOCAL_REPO + "?operation=commit");
- from("direct:commit-branch")
- .to("git://" + GIT_LOCAL_REPO + "?operation=commit&branchName=" + BRANCH_TEST);
- from("direct:commit-all")
- .to("git://" + GIT_LOCAL_REPO + "?operation=commit");
- from("direct:commit-all-branch")
- .to("git://" + GIT_LOCAL_REPO + "?operation=commit&branchName=" + BRANCH_TEST);
- from("direct:create-branch")
- .to("git://" + GIT_LOCAL_REPO + "?operation=createBranch&branchName=" + BRANCH_TEST);
- from("direct:delete-branch")
- .to("git://" + GIT_LOCAL_REPO + "?operation=deleteBranch&branchName=" + BRANCH_TEST);
- from("direct:status")
- .to("git://" + GIT_LOCAL_REPO + "?operation=status");
- from("direct:status-branch")
- .to("git://" + GIT_LOCAL_REPO + "?operation=status&branchName=" + BRANCH_TEST);
- from("direct:log")
- .to("git://" + GIT_LOCAL_REPO + "?operation=log");
- from("direct:log-branch")
- .to("git://" + GIT_LOCAL_REPO + "?operation=log&branchName=" + BRANCH_TEST);
- }
- };
- }
-
-}