camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-10502 - Camel-git : Copy headers from in to out
Date Tue, 22 Nov 2016 08:33:10 GMT
Repository: camel
Updated Branches:
  refs/heads/master 0bb63d5ba -> 8ab374b1e


CAMEL-10502 - Camel-git : Copy headers from in to out


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

Branch: refs/heads/master
Commit: 8ab374b1ea3074d64bbde4cfca25a6751572f622
Parents: 0bb63d5
Author: Olivier Antibi <olivier.antibi@crossing-tech.com>
Authored: Mon Nov 21 18:09:36 2016 +0100
Committer: Olivier Antibi <olivier.antibi@crossing-tech.com>
Committed: Mon Nov 21 22:44:44 2016 +0100

----------------------------------------------------------------------
 .../component/git/producer/GitProducer.java     | 18 ++++++---
 .../component/git/producer/GitProducerTest.java | 42 ++++++++++++++++----
 2 files changed, 46 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8ab374b1/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
index f6eae4f..b6bedd2 100644
--- a/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
+++ b/components/camel-git/src/main/java/org/apache/camel/component/git/producer/GitProducer.java
@@ -23,6 +23,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.component.git.GitConstants;
 import org.apache.camel.component.git.GitEndpoint;
 import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.MessageHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.eclipse.jgit.api.CherryPickResult;
 import org.eclipse.jgit.api.Git;
@@ -335,7 +336,7 @@ public class GitProducer extends DefaultProducer {
             LOG.error("There was an error in Git " + operation + " operation");
             throw e;
         }
-        exchange.getOut().setBody(status);
+        updateExchange(exchange, status);
     }
 
     protected void doLog(Exchange exchange, String operation) throws Exception {
@@ -349,7 +350,7 @@ public class GitProducer extends DefaultProducer {
             LOG.error("There was an error in Git " + operation + " operation");
             throw e;
         }
-        exchange.getOut().setBody(revCommit);
+        updateExchange(exchange, revCommit);
     }
 
     protected void doPush(Exchange exchange, String operation) throws Exception {
@@ -371,7 +372,7 @@ public class GitProducer extends DefaultProducer {
             LOG.error("There was an error in Git " + operation + " operation");
             throw e;
         }
-        exchange.getOut().setBody(result);
+        updateExchange(exchange, result);
     }
 
     protected void doPull(Exchange exchange, String operation) throws Exception {
@@ -393,7 +394,7 @@ public class GitProducer extends DefaultProducer {
             LOG.error("There was an error in Git " + operation + " operation");
             throw e;
         }
-        exchange.getOut().setBody(result);
+        updateExchange(exchange, result);
     }
 
     protected void doCreateTag(Exchange exchange, String operation) throws Exception {
@@ -428,7 +429,7 @@ public class GitProducer extends DefaultProducer {
             LOG.error("There was an error in Git " + operation + " operation");
             throw e;
         }
-        exchange.getOut().setBody(result);
+        updateExchange(exchange, result);
     }
 
     protected void doCherryPick(Exchange exchange, String operation) throws Exception {
@@ -452,7 +453,7 @@ public class GitProducer extends DefaultProducer {
             LOG.error("There was an error in Git " + operation + " operation");
             throw e;
         }
-        exchange.getOut().setBody(result);
+        updateExchange(exchange, result);
     }
 
     private Repository getLocalRepository() throws IOException {
@@ -471,4 +472,9 @@ public class GitProducer extends DefaultProducer {
         }
         return repo;
     }
+
+    private void updateExchange(Exchange exchange, Object body) {
+        exchange.getOut().setBody(body);
+        MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8ab374b1/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
index 920e2ec..35507b5 100755
--- 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
@@ -30,6 +30,7 @@ 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;
@@ -144,7 +145,7 @@ public class GitProducerTest extends GitTestSupport {
     public void commitTest() throws Exception {
 
         Repository repository = getTestRepository();
-
+        Git git = new Git(repository);
         File fileToAdd = new File(gitLocalRepo, filenameToAdd);
         fileToAdd.createNewFile();
 
@@ -166,13 +167,7 @@ public class GitProducerTest extends GitTestSupport {
                 exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
             }
         });
-        Iterable<RevCommit> logs = new Git(repository).log().call();
-        int count = 0;
-        for (RevCommit rev : logs) {
-            assertEquals(rev.getShortMessage(), commitMessage);
-            count++;
-        }
-        assertEquals(count, 1);
+        validateGitLogs(git, commitMessage);
         repository.close();
     }
 
@@ -212,6 +207,24 @@ public class GitProducerTest extends GitTestSupport {
     }
 
     @Test
+    public void addAndStatusAndCommitTest() throws Exception {
+        // Initialize repository using JGit
+        Repository repository = getTestRepository();
+        File gitDir = new File(gitLocalRepo, ".git");
+        assertEquals(gitDir.exists(), true);
+        Git git = new Git(repository);
+        File fileToAdd = new File(gitLocalRepo, filenameToAdd);
+        fileToAdd.createNewFile();
+        // Checking camel route
+        Map<String, Object> headers = new HashMap<>();
+        headers.put(GitConstants.GIT_FILE_NAME, filenameToAdd);
+        headers.put(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
+        template.requestBodyAndHeaders("direct:add-status-commit", "", headers);
+        validateGitLogs(git, commitMessage);
+        git.close();
+    }
+
+    @Test
     public void commitBranchTest() throws Exception {
 
         Repository repository = getTestRepository();
@@ -1076,6 +1089,16 @@ public class GitProducerTest extends GitTestSupport {
         repository.close();
     }
 
+    private void validateGitLogs(Git git, String... messages) throws GitAPIException {
+        Iterable<RevCommit> logs = git.log().call();
+        int count = 0;
+        for (RevCommit rev : logs) {
+            assertEquals(rev.getShortMessage(), messages[count]);
+            count++;
+        }
+        assertEquals(messages.length, count);
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
@@ -1092,6 +1115,9 @@ public class GitProducerTest extends GitTestSupport {
                 from("direct:commit-branch").to("git://" + gitLocalRepo + "?operation=commit&branchName="
+ branchTest);
                 from("direct:commit-all").to("git://" + gitLocalRepo + "?operation=commit");
                 from("direct:commit-all-branch").to("git://" + gitLocalRepo + "?operation=commit&branchName="
+ branchTest);
+                from("direct:add-status-commit").to("git://" + gitLocalRepo + "?operation=add").to("git://"
+ gitLocalRepo + "?operation=status").choice()
+                    .when(simple("${body.hasUncommittedChanges()}")).log("Commiting changes...").to("git://"
+ gitLocalRepo + "?operation=commit").otherwise()
+                    .log("Nothing to commit").end();
                 from("direct:create-branch").to("git://" + gitLocalRepo + "?operation=createBranch&branchName="
+ branchTest);
                 from("direct:delete-branch").to("git://" + gitLocalRepo + "?operation=deleteBranch&branchName="
+ branchTest);
                 from("direct:status").to("git://" + gitLocalRepo + "?operation=status");


Mime
View raw message