This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 83ab5f1536c CAMEL-19665: camel-git should be batch poll consumer 83ab5f1536c is described below commit 83ab5f1536c587728d2a2db852119c420d886b5a Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Jan 21 07:40:11 2025 +0100 CAMEL-19665: camel-git should be batch poll consumer --- .../component/git/consumer/GitCommitConsumer.java | 1 - .../git/consumer/GitConsumerCommitTest.java | 83 ++++++++++++++++++++++ .../component/git/consumer/GitConsumerTest.java | 41 ----------- 3 files changed, 83 insertions(+), 42 deletions(-) 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 1b559b9d161..4eed8c29832 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 @@ -65,7 +65,6 @@ public class GitCommitConsumer extends AbstractGitConsumer { e.getMessage().setHeader(GitConstants.GIT_COMMIT_AUTHOR_NAME, commit.getAuthorIdent().getName()); e.getMessage().setHeader(GitConstants.GIT_COMMIT_COMMITTER_NAME, commit.getCommitterIdent().getName()); e.getMessage().setHeader(GitConstants.GIT_COMMIT_TIME, commit.getCommitTime()); - getProcessor().process(e); exchanges.add(e); } } diff --git a/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerCommitTest.java b/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerCommitTest.java new file mode 100644 index 00000000000..c7996e9af10 --- /dev/null +++ b/components/camel-git/src/test/java/org/apache/camel/component/git/consumer/GitConsumerCommitTest.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.git.consumer; + +import java.io.File; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +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.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class GitConsumerCommitTest extends GitTestSupport { + + @Test + public void commitConsumerTest() throws Exception { + // Init + MockEndpoint mockResultCommit = getMockEndpoint("mock:result-commit"); + mockResultCommit.expectedMessageCount(2); + + Git git = getGitTestRepository(); + File gitDir = new File(getGitDir(), ".git"); + assertEquals(true, gitDir.exists()); + File fileToAdd = new File(getGitDir(), filenameToAdd); + fileToAdd.createNewFile(); + git.add().addFilepattern(filenameToAdd).call(); + Status status = git.status().call(); + assertTrue(status.getAdded().contains(filenameToAdd)); + git.commit().setMessage(commitMessage).call(); + File fileToAdd1 = new File(getGitDir(), filenameBranchToAdd); + fileToAdd1.createNewFile(); + git.add().addFilepattern(filenameBranchToAdd).call(); + status = git.status().call(); + assertTrue(status.getAdded().contains(filenameBranchToAdd)); + git.commit().setMessage("Test test Commit").call(); + validateGitLogs(git, "Test test Commit", commitMessage); + // Test + mockResultCommit.assertIsSatisfied(); + + // Check + Exchange ex1 = mockResultCommit.getExchanges().get(0); + Exchange ex2 = mockResultCommit.getExchanges().get(1); + assertEquals(commitMessage, ex2.getMessage().getBody(String.class)); + assertEquals("Test test Commit", ex1.getMessage().getBody(String.class)); + git.close(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + // force create git repo before routes + getTestRepository(); + final String dir = getGitDir().getPath(); + + return new RouteBuilder() { + @Override + public void configure() { + from("git://" + dir + "?type=commit&branchName=master") + .to("log:all?showAll=true") + .to("mock:result-commit"); + } + }; + } + +} 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 9d63615fa51..c722a8bfa17 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 @@ -34,39 +34,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class GitConsumerTest extends GitTestSupport { - @Test - public void commitConsumerTest() throws Exception { - // Init - MockEndpoint mockResultCommit = getMockEndpoint("mock:result-commit"); - mockResultCommit.expectedMessageCount(2); - - Git git = getGitTestRepository(); - File gitDir = new File(getGitDir(), ".git"); - assertEquals(true, gitDir.exists()); - File fileToAdd = new File(getGitDir(), filenameToAdd); - fileToAdd.createNewFile(); - git.add().addFilepattern(filenameToAdd).call(); - Status status = git.status().call(); - assertTrue(status.getAdded().contains(filenameToAdd)); - git.commit().setMessage(commitMessage).call(); - File fileToAdd1 = new File(getGitDir(), filenameBranchToAdd); - fileToAdd1.createNewFile(); - git.add().addFilepattern(filenameBranchToAdd).call(); - status = git.status().call(); - assertTrue(status.getAdded().contains(filenameBranchToAdd)); - git.commit().setMessage("Test test Commit").call(); - validateGitLogs(git, "Test test Commit", commitMessage); - // Test - mockResultCommit.assertIsSatisfied(); - - // Check - Exchange ex1 = mockResultCommit.getExchanges().get(0); - Exchange ex2 = mockResultCommit.getExchanges().get(1); - assertEquals(commitMessage, ex2.getMessage().getBody(String.class)); - assertEquals("Test test Commit", ex1.getMessage().getBody(String.class)); - git.close(); - } - @Test public void commitConsumerNotExistingBranchTest() throws Exception { // Init @@ -185,14 +152,6 @@ public class GitConsumerTest extends GitTestSupport { return new RouteBuilder() { @Override public void configure() { - from("direct:clone").to("git://" + dir - + "?remotePath=https://github.com/oscerd/json-webserver-example.git&operation=clone"); - from("direct:init").to("git://" + dir + "?operation=init"); - from("direct:add").to("git://" + dir + "?operation=add"); - from("direct:commit").to("git://" + dir + "?operation=commit"); - from("direct:create-branch").to("git://" + dir + "?operation=createBranch&branchName=" + branchTest); - from("direct:create-tag").to("git://" + dir + "?operation=createTag&tagName=" + tagTest); - from("git://" + dir + "?type=commit&branchName=master").to("mock:result-commit"); from("git://" + dir + "?type=commit&branchName=notexisting").to("mock:result-commit-notexistent"); from("git://" + dir + "?type=tag").to("mock:result-tag"); from("git://" + dir + "?type=branch&gitConfigFile=classpath:git.config")