package com.mzimecki.camel.spring.route;

import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.builder.ExchangeBuilder;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;

import com.mzimecki.camel.spring.constants.ServiceConstants;

public class HelloRouteTest extends CamelSpringTestSupport {
	
	private static final String TEST_MESSAGE_PAYLOAD = "my message";

	@Override
	protected AbstractApplicationContext createApplicationContext() {
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
		ctx.scan("com.mzimecki.camel.spring");
		ctx.refresh();
		return ctx;
	}
	
	@Test
	public void should_hello_route_be_running() throws Exception {
		assertTrue(context().getRouteStatus(ServiceConstants.HELLO_ROUTE_ID).isStarted());
	}
	
	@Test
	public void should_hello_route_process_the_message() throws Exception {
		Endpoint endpoint = getMandatoryEndpoint(ServiceConstants.HELLO_SERVICE_ENDPOINT);
		Exchange requestExchange = ExchangeBuilder.anExchange(context()).withBody(TEST_MESSAGE_PAYLOAD).build();
		Exchange resultExchange = context().createProducerTemplate().send(endpoint, requestExchange);
		String resultBody = resultExchange.getOut().getBody(String.class);
		assertTrue(resultBody.contains(TEST_MESSAGE_PAYLOAD));
	}

}

@@ -1095,16 +1095,22 @@
 on %7B%0D%0A%09%09
+final 
 Endpoint
@@ -1183,24 +1183,30 @@
 DPOINT);%0D%0A%09%09
+final 
 Exchange req
@@ -1301,16 +1301,22 @@
 d();%0D%0A%09%09
+final 
 Exchange
@@ -1404,16 +1404,22 @@
 ge);%0D%0A%09%09
+final 
 String r

test corrected