PageRenderTime 33ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/components/camel-jira/src/test/java/org/apache/camel/component/jira/IssueConsumerTest.java

https://gitlab.com/matticala/apache-camel
Java | 115 lines | 77 code | 19 blank | 19 comment | 0 complexity | 8a05f6d6ed231ad334d01515187b1432 MD5 | raw file
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.apache.camel.component.jira;
  18. import com.atlassian.jira.rest.client.domain.BasicIssue;
  19. import org.apache.camel.Exchange;
  20. import org.apache.camel.Message;
  21. import org.apache.camel.Processor;
  22. import org.apache.camel.builder.RouteBuilder;
  23. import org.apache.camel.component.jira.mocks.MockJerseyJiraRestClientFactory;
  24. import org.apache.camel.component.jira.mocks.MockJiraRestClient;
  25. import org.apache.camel.component.jira.mocks.MockSearchRestClient;
  26. import org.apache.camel.component.mock.MockEndpoint;
  27. import org.apache.camel.impl.JndiRegistry;
  28. import org.apache.camel.test.junit4.CamelTestSupport;
  29. import org.junit.Test;
  30. import org.slf4j.Logger;
  31. import org.slf4j.LoggerFactory;
  32. public class IssueConsumerTest extends CamelTestSupport {
  33. public static final Logger LOG = LoggerFactory.getLogger(IssueConsumerTest.class);
  34. private static final String URL = "https://somerepo.atlassian.net";
  35. private static final String USERNAME = "someguy";
  36. private static final String PASSWORD = "xU3xjhay9yjEaZq";
  37. private static final String JIRA_CREDENTIALS = URL + "&username=" + USERNAME + "&password=" + PASSWORD;
  38. private static final String PROJECT = "camel-jira-component";
  39. protected MockJerseyJiraRestClientFactory factory;
  40. @Override
  41. protected JndiRegistry createRegistry() throws Exception {
  42. JndiRegistry registry = super.createRegistry();
  43. factory = new MockJerseyJiraRestClientFactory();
  44. registry.bind("JerseyJiraRestClientFactory", factory);
  45. return registry;
  46. }
  47. @Override
  48. protected RouteBuilder createRouteBuilder() throws Exception {
  49. return new RouteBuilder() {
  50. @Override
  51. public void configure() throws Exception {
  52. context.addComponent("jira", new JIRAComponent());
  53. from("jira://newIssue?serverUrl=" + JIRA_CREDENTIALS + "&jql=project=" + PROJECT + "&delay=500")
  54. .process(new NewIssueProcessor())
  55. .to("mock:result");
  56. }
  57. };
  58. }
  59. @Test
  60. public void emptyAtStartupTest() throws Exception {
  61. MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");
  62. mockResultEndpoint.expectedMessageCount(0);
  63. mockResultEndpoint.assertIsSatisfied();
  64. }
  65. @Test
  66. public void singleIssueTest() throws Exception {
  67. MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");
  68. MockJiraRestClient client = factory.getClient();
  69. MockSearchRestClient restClient = (MockSearchRestClient) client.getSearchClient();
  70. BasicIssue issue1 = restClient.addIssue();
  71. mockResultEndpoint.expectedBodiesReceived(issue1);
  72. mockResultEndpoint.assertIsSatisfied();
  73. }
  74. @Test
  75. public void multipleIssuesTest() throws Exception {
  76. MockEndpoint mockResultEndpoint = getMockEndpoint("mock:result");
  77. MockJiraRestClient client = factory.getClient();
  78. MockSearchRestClient restClient = (MockSearchRestClient) client.getSearchClient();
  79. BasicIssue issue1 = restClient.addIssue();
  80. BasicIssue issue2 = restClient.addIssue();
  81. BasicIssue issue3 = restClient.addIssue();
  82. mockResultEndpoint.expectedBodiesReceived(issue3, issue2, issue1);
  83. mockResultEndpoint.assertIsSatisfied();
  84. }
  85. /**
  86. * Log new issues. Not really needed for this test, but useful for debugging.
  87. */
  88. public class NewIssueProcessor implements Processor {
  89. @Override
  90. public void process(Exchange exchange) throws Exception {
  91. Message in = exchange.getIn();
  92. BasicIssue issue = in.getBody(BasicIssue.class);
  93. LOG.debug("Got issue with id " + issue.getId() + " key " + issue.getKey());
  94. }
  95. }
  96. }