package de.fred4jupiter.springbootcamel;

import static org.junit.Assert.assertNotNull;

import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringBootRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@ActiveProfiles("test")
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
public class SimpleRouteTest {

	@Autowired
	private CamelContext camelContext;

	@EndpointInject(uri = "{{simpleRoute.start}}")
	private ProducerTemplate simpleRouteStartEndpoint;

	@EndpointInject(uri = "{{simpleRoute.end}}")
	private MockEndpoint resultEndpoint;

	@Test
	public void shouldSucceed() throws Exception {
		assertNotNull(camelContext);
		assertNotNull(simpleRouteStartEndpoint);

		simpleRouteStartEndpoint.sendBody("");

		resultEndpoint.expectedMessageCount(1);
		resultEndpoint.allMessages().body().isEqualTo("Hello World");
		resultEndpoint.assertIsSatisfied();
	}
}

@@ -33,17 +33,19 @@
 otcamel;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -86,47 +86,11 @@
 ull;
-%0A%0Aimport org.apache.camel.CamelContext;
+%0D%0A%0D
 %0Aimp
@@ -125,16 +125,17 @@
 tInject;
+%0D
 %0Aimport 
@@ -168,16 +168,17 @@
 emplate;
+%0D
 %0Aimport 
@@ -222,16 +222,17 @@
 ndpoint;
+%0D
 %0Aimport 
@@ -282,16 +282,43 @@
 tRunner;
+%0D%0Aimport org.junit.Before;%0D
 %0Aimport 
@@ -328,24 +328,25 @@
 .junit.Test;
+%0D
 %0Aimport org.
@@ -366,16 +366,17 @@
 RunWith;
+%0D
 %0Aimport 
@@ -400,103 +400,101 @@
 rk.b
-eans.factory.annotation.Autowired;%0Aimport org.springframework.boot.test.context.SpringBootTes
+oot.test.context.SpringBootTest;%0D%0Aimport org.springframework.test.annotation.DirtiesContex
 t;
+%0D
 %0Aimp
@@ -545,17 +545,19 @@
 rofiles;
-%0A
+%0D%0A%0D
 %0A@Active
@@ -572,16 +572,17 @@
 (%22test%22)
+%0D
 %0A@RunWit
@@ -611,16 +611,17 @@
 r.class)
+%0D
 %0A@Spring
@@ -632,89 +632,121 @@
 Test
-%0Apublic class SimpleRouteTest %7B%0A%0A%09@Autowired%0A%09private CamelContext camelContext;%0A
+%0D%0A@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)%0D%0Apublic class SimpleRouteTest %7B%0D%0A%0D
 %0A%09@E
@@ -785,24 +785,25 @@
 te.start%7D%7D%22)
+%0D
 %0A%09private Pr
@@ -842,17 +842,19 @@
 ndpoint;
-%0A
+%0D%0A%0D
 %0A%09@Endpo
@@ -891,16 +891,17 @@
 .end%7D%7D%22)
+%0D
 %0A%09privat
@@ -934,16 +934,21 @@
 int;
-%0A%0A%09@Test
+%0D%0A%0D%0A%09@Before%0D
 %0A%09pu
@@ -961,21 +961,124 @@
 oid 
-shouldSucceed
+checkInjection() %7B%0D%0A%09%09assertNotNull(simpleRouteStartEndpoint);%0D%0A%09%7D%0D%0A%0D%0A%09@Test%0D%0A%09public void triggerRouteWithoutHeader
 () t
@@ -1098,125 +1098,344 @@
 on %7B
+%0D
 %0A%09%09
-assertNotNull(camel
+simpleRouteStartEndpoint.sendBody(%22%22);%0D%0A%0D%0A%09%09resultEndpoint.expectedMessage
 Co
+u
 nt
-ext
+(1);%0D%0A%09%09resultEndpoint.allMessages().body().isEqualTo(%22Hello World%22
 );
+%0D
 %0A%09%09
-assertNotNull(simpleRouteStartEndpoint);%0A%0A%09%09simpleRouteStartEndpoint.sendBody(%22%22);%0A
+resultEndpoint.assertIsSatisfied();%0D%0A%09%7D%0D%0A%0D%0A%09@Test%0D%0A%09public void triggerRouteWithHeader() throws Exception %7B%0D%0A%09%09simpleRouteStartEndpoint.sendBodyAndHeader(%22%22, %22name%22, %22Michael%22);%0D%0A%0D
 %0A%09%09r
@@ -1472,16 +1472,17 @@
 ount(1);
+%0D
 %0A%09%09resul
@@ -1529,24 +1529,27 @@
 (%22Hello 
-World
+Michael
 %22);
+%0D
 %0A%09%09resul
@@ -1582,10 +1582,13 @@
 d();
+%0D
 %0A%09%7D
+%0D
 %0A%7D
+%0D
 %0A

update test