forked from apache/camel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAMEL-7902 New test for camel-github
- Loading branch information
1 parent
2275e28
commit f1d4afe
Showing
16 changed files
with
781 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ents/camel-github/src/test/java/org/apache/camel/component/github/CommitConsumerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.github; | ||
|
||
import org.apache.camel.Exchange; | ||
import org.apache.camel.Message; | ||
import org.apache.camel.Processor; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.eclipse.egit.github.core.RepositoryCommit; | ||
import org.eclipse.egit.github.core.User; | ||
import org.junit.Test; | ||
|
||
public class CommitConsumerTest extends GitHubComponentTestBase { | ||
@Override | ||
protected RouteBuilder createRouteBuilder() throws Exception { | ||
return new RouteBuilder() { | ||
|
||
@Override | ||
public void configure() throws Exception { | ||
context.addComponent("github", new GitHubComponent()); | ||
from("github://commit/master?" + GITHUB_CREDENTIALS_STRING). | ||
process(new GitHubCommitProcessor()) | ||
.to(mockResultEndpoint); | ||
} | ||
}; | ||
} | ||
|
||
|
||
@Test | ||
public void commitConsumerTest() throws Exception { | ||
mockResultEndpoint.expectedMessageCount(2); | ||
RepositoryCommit commit1 = commitService.addRepositoryCommit(); | ||
RepositoryCommit commit2 = commitService.addRepositoryCommit(); | ||
mockResultEndpoint.expectedBodiesReceivedInAnyOrder(commit1, commit2); | ||
|
||
Thread.sleep(1 * 1000); | ||
|
||
mockResultEndpoint.assertIsSatisfied(); | ||
} | ||
|
||
public class GitHubCommitProcessor implements Processor { | ||
@Override | ||
public void process(Exchange exchange) throws Exception { | ||
Message in = exchange.getIn(); | ||
RepositoryCommit commit = (RepositoryCommit) in.getBody(); | ||
User author = commit.getAuthor(); | ||
log.debug("Got commit with author: " + author.getLogin() + ": " + author.getHtmlUrl() + " SHA " + commit.getSha()); | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...camel-github/src/test/java/org/apache/camel/component/github/GitHubComponentTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.github; | ||
|
||
import org.apache.camel.EndpointInject; | ||
import org.apache.camel.component.github.consumer.MockCommitService; | ||
import org.apache.camel.component.github.consumer.MockIssueService; | ||
import org.apache.camel.component.github.consumer.MockPullRequestService; | ||
import org.apache.camel.component.github.consumer.MockRepositoryService; | ||
import org.apache.camel.component.mock.MockEndpoint; | ||
import org.apache.camel.impl.JndiRegistry; | ||
import org.apache.camel.test.junit4.CamelTestSupport; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestName; | ||
|
||
public abstract class GitHubComponentTestBase extends CamelTestSupport { | ||
public String USERNAME = "someguy"; | ||
public String PASSWORD = "apassword"; | ||
public String REPO_OWNER = "anotherguy"; | ||
public String REPO_NAME = "somerepo"; | ||
public String GITHUB_CREDENTIALS_STRING = "username=" + USERNAME + "&password=" + PASSWORD + "&repoOwner=" + REPO_OWNER + "&repoName=" + REPO_NAME; | ||
|
||
@Rule | ||
public TestName testName = new TestName(); | ||
|
||
protected MockCommitService commitService; | ||
protected MockRepositoryService repositoryService; | ||
protected MockPullRequestService pullRequestService; | ||
protected MockIssueService issueService; | ||
|
||
@EndpointInject(uri = "mock:result") | ||
protected MockEndpoint mockResultEndpoint; | ||
|
||
@Override | ||
protected JndiRegistry createRegistry() throws Exception { | ||
JndiRegistry registry = super.createRegistry(); | ||
commitService = new MockCommitService(); | ||
registry.bind("githubCommitService", commitService); | ||
|
||
repositoryService = new MockRepositoryService(); | ||
registry.bind("githubRepositoryService", repositoryService); | ||
|
||
pullRequestService = new MockPullRequestService(); | ||
registry.bind("githubPullRequestService", pullRequestService); | ||
|
||
issueService = new MockIssueService(pullRequestService); | ||
registry.bind("githbIssueService", issueService); | ||
|
||
return registry; | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
log.debug("Starting test " + testName.getMethodName()); | ||
} | ||
|
||
@Test | ||
public void emptyAtStartupTest() throws Exception { | ||
mockResultEndpoint.expectedMessageCount(0); | ||
mockResultEndpoint.assertIsSatisfied(); | ||
} | ||
|
||
} |
Oops, something went wrong.