Skip to content

Instantly share code, notes, and snippets.

@cmoulliard
Created October 18, 2013 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmoulliard/7039502 to your computer and use it in GitHub Desktop.
Save cmoulliard/7039502 to your computer and use it in GitHub Desktop.
package org.fusesource.workshop.spring;
import org.apache.camel.*;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
@ContextConfiguration
public class RouteTest extends AbstractJUnit4SpringContextTests {
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:result")
public MockEndpoint result;
@Produce(uri = "direct:start")
private ProducerTemplate template;
@Test
public void testMocksAreValid() throws Exception {
MockEndpoint.assertIsSatisfied(camelContext);
}
@Test
@DirtiesContext
public void testWebService() throws Exception {
result.expectedBodiesReceived(response);
template.sendBody(payload);
result.assertIsSatisfied();
}
private final static String payload = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.workshop.fusesource.org\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <ser:documentId>\n" +
" <id>123</id>\n" +
" </ser:documentId>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
private final static String response = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns2:documentResponse xmlns:ns2=\"http://service.workshop.fusesource.org\"><incidentId>123</incidentId><givenName>Charles</givenName><familyName>Moulliard</familyName><details>&lt;html>&lt;body>Message received !!&lt;/body>&lt;/html></details><email>cmoulliard@gmail.com</email><phone>111 222 333</phone></ns2:documentResponse></soap:Body></soap:Envelope>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment