camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CAMEL-11687) Camel-spring-boot documentation should also cover testing
Date Mon, 21 Aug 2017 23:54:00 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-11687?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16136039#comment-16136039
] 

Claus Ibsen commented on CAMEL-11687:
-------------------------------------

You are welcome to work on the docs - its now in ascii docs at
https://github.com/apache/camel/tree/master/components/camel-spring-boot/src/main/docs

> Camel-spring-boot documentation should also cover testing
> ---------------------------------------------------------
>
>                 Key: CAMEL-11687
>                 URL: https://issues.apache.org/jira/browse/CAMEL-11687
>             Project: Camel
>          Issue Type: Improvement
>          Components: documentation
>            Reporter: Kamil
>
> The [Documentation|http://camel.apache.org/spring-boot.html] helps a lot with configuring
Camel with SpringBoot but says nothing about how to configure tests, which is not trivial...
> First of all I noticed, that when you don't Autowire CamelContext and return it in:
> {code}
> @Override
> protected CamelContext createCamelContext() throws Exception {
> 	return camelContext;
> }
> {code}
> you end up in having two contexts, which causes for example that exception:
> {code}
> org.apache.camel.CamelExecutionException: Exception occurred during execution on the
exchange: Exchange[ID-TEST-19340-1101151111626-1-2]
> 	at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1790)
> 	at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:695)
> 	at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:515)
> 	at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:511)
> 	at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:189)
> 	at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:382)
> 	at hello.MyRouteTest.testSomething(MyRouteTest.java:72)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> 	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> 	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
> 	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
> 	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
> 	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
> 	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
> 	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
> 	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
> 	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> 	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
> 	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> 	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
> 	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
> 	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> 	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
> Caused by: org.apache.camel.component.direct.DirectConsumerNotAvailableException: No
consumers available on endpoint: direct://someEndpoin. Exchange[ID-TEST-19340-1101151111626-1-2]
> 	at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:55)
> 	at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
> 	at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
> 	at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:529)
> 	at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:497)
> 	at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:365)
> 	at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:497)
> 	at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:225)
> 	at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:144)
> 	at org.apache.camel.impl.DefaultProducerTemplate.sendBodyAndHeader(DefaultProducerTemplate.java:187)
> 	... 37 more
> {code}
> Also "CamelSpringTestSupport" requires you to implement "createApplicationContext()"
which is weird.
> To sum it up - I found this configuration working fine with Camel-spring-boot:
> {code}
> @ActiveProfiles("test")
> @RunWith(CamelSpringBootRunner.class)
> @SpringBootTest
> @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
> @DisableJmx(true)
> public class MyRouteTest extends CamelTestSupport {
> 	@Autowired
> 	private CamelContext camelContext;
> 	@Override
> 	protected CamelContext createCamelContext() throws Exception {
> 		return camelContext;
> 	}
> 	@EndpointInject(uri = "direct:myEndpoint")
> 	private ProducerTemplate endpoint;
> 	@Override
> 	public void setUp() throws Exception {
> 		super.setUp();
> 		RouteDefinition definition = context().getRouteDefinitions().get(0);
> 		definition.adviceWith(context(), new RouteBuilder() {
> 			@Override
> 			public void configure() throws Exception {
> 				onException(Exception.class).maximumRedeliveries(0);
> 			}
> 		});
> 	}
> 	@Override
> 	public String isMockEndpointsAndSkip() {
>         	return "myEndpoint:put*";
> 	}
> 	@Test
> 	public void shouldSucceed() throws Exception {
> 		assertNotNull(camelContext);
> 		assertNotNull(endpoint);
> 		
> 		String expectedValue = "expectedValue";
> 		MockEndpoint mock = getMockEndpoint("mock:myEndpoint:put");
> 		mock.expectedMessageCount(1);
> 		mock.allMessages().body().isEqualTo(expectedValue);
> 		mock.allMessages().header(MY_HEADER).isEqualTo("testHeader");
> 		endpoint.sendBodyAndHeader("test", MY_HEADER, "testHeader");
> 		
> 		mock.assertIsSatisfied();
> 	}
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message