camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/4] camel git commit: Capitalize on validateLogs
Date Tue, 22 Nov 2016 10:00:28 GMT
Repository: camel
Updated Branches:
  refs/heads/master 0be70c532 -> 22f30a300


Capitalize on validateLogs


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

Branch: refs/heads/master
Commit: 1a8b2c4bd662edd8b2769b91daca0814d4d88b4f
Parents: e396f77
Author: Olivier Antibi <olivier.antibi@crossing-tech.com>
Authored: Tue Nov 22 10:34:25 2016 +0100
Committer: Olivier Antibi <olivier.antibi@crossing-tech.com>
Committed: Tue Nov 22 10:34:41 2016 +0100

----------------------------------------------------------------------
 .../camel/component/git/GitTestSupport.java     |  12 ++
 .../component/git/consumer/GitConsumerTest.java |  26 +---
 .../component/git/producer/GitProducerTest.java | 152 ++-----------------
 3 files changed, 35 insertions(+), 155 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1a8b2c4b/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
b/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
index 15bd8ce..65c1f12 100644
--- a/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
+++ b/components/camel-git/src/test/java/org/apache/camel/component/git/GitTestSupport.java
@@ -23,6 +23,7 @@ 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.revwalk.RevCommit;
 import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
 
 public class GitTestSupport extends CamelTestSupport {
@@ -78,4 +79,15 @@ public class GitTestSupport extends CamelTestSupport {
     protected Git getGitTestRepository() throws IOException, IllegalStateException, GitAPIException
{
         return new Git(getTestRepository());
     }
+
+    protected void validateGitLogs(Git git, String... messages) throws GitAPIException {
+        Iterable<RevCommit> logs = git.log().call();
+        int count = 0;
+        for (RevCommit rev : logs) {
+            assertEquals(messages[count], rev.getShortMessage());
+            count++;
+        }
+        assertEquals(messages.length, count);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1a8b2c4b/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
index f2b5db1..bb3d594 100644
--- 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
@@ -5,9 +5,9 @@
  * 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
  * 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.
@@ -16,26 +16,20 @@
  */
 package org.apache.camel.component.git.consumer;
 
-import java.io.File;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
 import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.builder.NotifyBuilder;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.git.GitConstants;
 import org.apache.camel.component.git.GitTestSupport;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.Status;
-import org.eclipse.jgit.internal.storage.file.RefDirectory;
 import org.eclipse.jgit.lib.ObjectIdRef;
 import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.junit.Test;
 
+import java.io.File;
+import java.util.List;
+
 public class GitConsumerTest extends GitTestSupport {
 
     @Test
@@ -59,12 +53,7 @@ public class GitConsumerTest extends GitTestSupport {
         assertTrue(status.getAdded().contains(filenameBranchToAdd));
         git.commit().setMessage("Test test Commit").call();
         Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        for (RevCommit rev : logs) {
-            count++;
-        }
-        assertEquals(count, 2);
-
+        validateGitLogs(git, "Test test Commit", commitMessage);
         // Test
         mockResultCommit.assertIsSatisfied();
 
@@ -134,7 +123,6 @@ public class GitConsumerTest extends GitTestSupport {
         }
         assertEquals(branchCreated, true);
 
-
         // Test
         mockResultBranch.assertIsSatisfied();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/1a8b2c4b/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 94edb9c..c0fa799 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
@@ -108,13 +108,7 @@ public class GitProducerTest extends GitTestSupport {
         gitDir = new File(gitLocalRepo, ".git");
         assertEquals(gitDir.exists(), true);
         git.commit().setMessage(commitMessage).call();
-        Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        for (RevCommit rev : logs) {
-            assertEquals(rev.getShortMessage(), commitMessage);
-            count++;
-        }
-        assertEquals(count, 1);
+        validateGitLogs(git, commitMessage);
         status = git.status().call();
         assertFalse(status.getAdded().contains(filenameToAdd));
         git.close();
@@ -134,13 +128,7 @@ public class GitProducerTest extends GitTestSupport {
         template.sendBodyAndHeader("direct:commit", "", GitConstants.GIT_COMMIT_MESSAGE,
commitMessage);
 
         // Check
-        Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        for (RevCommit rev : logs) {
-            assertEquals(rev.getShortMessage(), commitMessage);
-            count++;
-        }
-        assertEquals(count, 1);
+        validateGitLogs(git, commitMessage);
         git.close();
     }
 
@@ -161,13 +149,7 @@ public class GitProducerTest extends GitTestSupport {
         template.requestBodyAndHeader("direct:commit", "", GitConstants.GIT_COMMIT_MESSAGE,
commitMessage);
 
         // Check that it has been commited twice
-        Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        for (RevCommit rev : logs) {
-            assertEquals(rev.getShortMessage(), commitMessage);
-            count++;
-        }
-        assertEquals(count, 2);
+        validateGitLogs(git, commitMessage, commitMessage);
         git.close();
     }
 
@@ -222,13 +204,7 @@ public class GitProducerTest extends GitTestSupport {
         Status status = git.status().call();
         assertTrue(status.getAdded().contains(filenameToAdd));
         git.commit().setMessage(commitMessage).call();
-        Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        for (RevCommit rev : logs) {
-            assertEquals(rev.getShortMessage(), commitMessage);
-            count++;
-        }
-        assertEquals(count, 1);
+        validateGitLogs(git, commitMessage);
         git.checkout().setCreateBranch(true).setName(branchTest).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
 
         // Test camel-git commit (with branch)
@@ -238,18 +214,7 @@ public class GitProducerTest extends GitTestSupport {
                 exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessageBranch);
             }
         });
-        logs = git.log().call();
-        count = 0;
-        for (RevCommit rev : logs) {
-            if (count == 0) {
-                assertEquals(rev.getShortMessage(), commitMessageBranch);
-            }
-            if (count == 1) {
-                assertEquals(rev.getShortMessage(), commitMessage);
-            }
-            count++;
-        }
-        assertEquals(count, 2);
+        validateGitLogs(git, commitMessageBranch, commitMessage);
         git.close();
     }
 
@@ -266,13 +231,7 @@ public class GitProducerTest extends GitTestSupport {
                 exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessageAll);
             }
         });
-        Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        for (RevCommit rev : logs) {
-            assertEquals(rev.getShortMessage(), commitMessageAll);
-            count++;
-        }
-        assertEquals(count, 1);
+        validateGitLogs(git, commitMessageAll);
         git.close();
     }
 
@@ -288,16 +247,8 @@ public class GitProducerTest extends GitTestSupport {
         Status status = git.status().call();
         assertTrue(status.getAdded().contains(filenameToAdd));
         git.commit().setMessage(commitMessage).call();
-        Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        for (RevCommit rev : logs) {
-            assertEquals(rev.getShortMessage(), commitMessage);
-            count++;
-        }
-        assertEquals(count, 1);
-
+        validateGitLogs(git, commitMessage);
         git.checkout().setCreateBranch(true).setName(branchTest).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
-
         File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
         fileToAdd1.createNewFile();
 
@@ -317,18 +268,7 @@ public class GitProducerTest extends GitTestSupport {
         });
 
         // Check
-        logs = git.log().call();
-        count = 0;
-        for (RevCommit rev : logs) {
-            if (count == 0) {
-                assertEquals(rev.getShortMessage(), commitMessageAll);
-            }
-            if (count == 1) {
-                assertEquals(rev.getShortMessage(), commitMessage);
-            }
-            count++;
-        }
-        assertEquals(count, 2);
+        validateGitLogs(git, commitMessageAll, commitMessage);
         git.close();
     }
 
@@ -344,30 +284,13 @@ public class GitProducerTest extends GitTestSupport {
         Status status = git.status().call();
         assertTrue(status.getAdded().contains(filenameToAdd));
         git.commit().setMessage(commitMessage).call();
-        Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        for (RevCommit rev : logs) {
-            assertEquals(rev.getShortMessage(), commitMessage);
-            count++;
-        }
-        assertEquals(count, 1);
+        validateGitLogs(git, commitMessage);
         git.checkout().setCreateBranch(true).setName(branchTest).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
         File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
         fileToAdd1.createNewFile();
         git.add().addFilepattern(filenameBranchToAdd).call();
         git.commit().setMessage(commitMessageAll).call();
-        logs = git.log().call();
-        count = 0;
-        for (RevCommit rev : logs) {
-            if (count == 0) {
-                assertEquals(rev.getShortMessage(), commitMessageAll);
-            }
-            if (count == 1) {
-                assertEquals(rev.getShortMessage(), commitMessage);
-            }
-            count++;
-        }
-        assertEquals(count, 2);
+        validateGitLogs(git, commitMessageAll, commitMessage);
 
         // Test camel-git remove
         template.send("direct:remove-on-branch", new Processor() {
@@ -691,31 +614,14 @@ public class GitProducerTest extends GitTestSupport {
         assertTrue(status.getAdded().contains(fileToAdd1Name));
         git.commit().setMessage("Test second commit").call();
         Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        String id = "";
-        for (RevCommit rev : logs) {
-            if (count == 0) {
-                id = rev.getName();
-                assertEquals(rev.getShortMessage(), "Test second commit");
-            }
-            count++;
-        }
-        assertEquals(count, 2);
+        validateGitLogs(git, "Test second commit", commitMessage);
+        String id = logs.iterator().next().getName();
 
         // Test camel-git cherry-pick
         template.sendBodyAndHeader("direct:cherrypick", "", GitConstants.GIT_COMMIT_ID, id);
 
         // Check
-        git.checkout().setCreateBranch(false).setName(branchTest).call();
-        logs = git.log().call();
-        count = 0;
-        for (RevCommit rev : logs) {
-            if (count == 0) {
-                assertEquals(rev.getShortMessage(), "Test second commit");
-            }
-            count++;
-        }
-        assertEquals(count, 2);
+        validateGitLogs(git, "Test second commit", commitMessage);
         git.close();
     }
 
@@ -748,31 +654,15 @@ public class GitProducerTest extends GitTestSupport {
         assertTrue(status.getAdded().contains(fileToAdd1Name));
         git.commit().setMessage("Test second commit").call();
         Iterable<RevCommit> logs = git.log().call();
-        int count = 0;
-        String id = "";
-        for (RevCommit rev : logs) {
-            if (count == 0) {
-                id = rev.getName();
-                assertEquals(rev.getShortMessage(), "Test second commit");
-            }
-            count++;
-        }
-        assertEquals(count, 2);
+        validateGitLogs(git, "Test second commit", commitMessage);
+        String id = logs.iterator().next().getName();
 
         // Test camel-git cherry-pick (on master)
         template.sendBodyAndHeader("direct:cherrypick-master", "", GitConstants.GIT_COMMIT_ID,
id);
 
         // Check
         git.checkout().setCreateBranch(false).setName("refs/heads/master").call();
-        logs = git.log().call();
-        count = 0;
-        for (RevCommit rev : logs) {
-            if (count == 0) {
-                assertEquals(rev.getShortMessage(), "Test second commit");
-            }
-            count++;
-        }
-        assertEquals(count, 2);
+        validateGitLogs(git, "Test second commit", commitMessage);
         git.close();
     }
 
@@ -814,16 +704,6 @@ public class GitProducerTest extends GitTestSupport {
         git.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() {


Mime
View raw message