// This file was generated from org.apache.camel.archetypes/camel-archetype-scr/2.15-SNAPSHOT
package example;
import java.util.List;
import org.apache.camel.scr.internal.ScrHelper;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.component.mock.MockComponent;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class CamelScrExampleTest {
Logger log = LoggerFactory.getLogger(getClass());
@Rule
public TestName testName = new TestName();
CamelScrExample integration;
ModelCamelContext context;
@Before
public void setUp() throws Exception {
log.info("*******************************************************************");
log.info("Test: " + testName.getMethodName());
log.info("*******************************************************************");
// Set property prefix for unit testing
System.setProperty(CamelScrExample.PROPERTY_PREFIX, "unit");
// Prepare the integration
integration = new CamelScrExample();
integration.prepare(null, ScrHelper.getScrProperties(integration.getClass().getName()));
context = integration.getContext();
// Disable JMX for test
context.disableJMX();
// Fake a component for test
context.addComponent("amq", new MockComponent());
}
@After
public void tearDown() throws Exception {
integration.stop();
}
@Test
public void testRoutes() throws Exception {
// Adjust routes
List<RouteDefinition> routes = context.getRouteDefinitions();
routes.get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// Replace "from" endpoint with direct:start
replaceFromWith("direct:start");
// Mock and skip result endpoint
mockEndpoints("log:*");
}
});
MockEndpoint resultEndpoint = context.getEndpoint("mock:log:foo", MockEndpoint.class);
// resultEndpoint.expectedMessageCount(1); // If you want to just check the number of messages
resultEndpoint.expectedBodiesReceived("hello"); // If you want to check the contents
// Start the integration
integration.run();
// Send the test message
context.createProducerTemplate().sendBody("direct:start", "hello");
resultEndpoint.assertIsSatisfied();
}
}
// This file was generated from org.apache.camel.archetypes/camel-archetype-scr/2.15-SNAPSHOT
package example;
import java.util.List;
import org.apache.camel.scr.internal.ScrHelper;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.component.mock.MockComponent;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class CamelScrExampleTest {
Logger log = LoggerFactory.getLogger(getClass());
@Rule
public TestName testName = new TestName();
CamelScrExample integration;
ModelCamelContext context;
@Before
public void setUp() throws Exception {
log.info("*******************************************************************");
log.info("Test: " + testName.getMethodName());
log.info("*******************************************************************");
// Set property prefix for unit testing
System.setProperty(CamelScrExample.PROPERTY_PREFIX, "unit");
// Prepare the integration
integration = new CamelScrExample();
integration.prepare(null, ScrHelper.getScrProperties(integration.getClass().getName()));
context = integration.getContext();
// Disable JMX for test
context.disableJMX();
// Fake a component for test
context.addComponent("amq", new MockComponent());
}
@After
public void tearDown() throws Exception {
integration.stop();
}
@Test
public void testRoutes() throws Exception {
// Adjust routes
List<RouteDefinition> routes = context.getRouteDefinitions();
routes.get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// Replace "from" endpoint with direct:start
replaceFromWith("direct:start");
// Mock and skip result endpoint
mockEndpoints("log:*");
}
});
MockEndpoint resultEndpoint = context.getEndpoint("mock:log:foo", MockEndpoint.class);
// resultEndpoint.expectedMessageCount(1); // If you want to just check the number of messages
resultEndpoint.expectedBodiesReceived("hello"); // If you want to check the contents
// Start the integration
integration.run();
// Send the test message
context.createProducerTemplate().sendBody("direct:start", "hello");
resultEndpoint.assertIsSatisfied();
}
}
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
// Set property prefix for unit testing
System.setProperty(CamelScrExample.PROPERTY_PREFIX, "unit");
// Set property prefix for unit testing
System.setProperty(CamelScrExample.PROPERTY_PREFIX, "unit");
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
integration.prepare(null, ScrHelper.getScrProperties(integration.getClass().getName()));
integration.prepare(null, ScrHelper.getScrProperties(integration.getClass().getName()));
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
// Fake a component for test
context.addComponent("amq", new MockComponent());
// Fake a component for test
context.addComponent("amq", new MockComponent());
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
// Adjust routes
List<RouteDefinition> routes = context.getRouteDefinitions();
routes.get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// Replace "from" endpoint with direct:start
replaceFromWith("direct:start");
// Mock and skip result endpoint
mockEndpoints("log:*");
}
});
// Adjust routes
List<RouteDefinition> routes = context.getRouteDefinitions();
routes.get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// Replace "from" endpoint with direct:start
replaceFromWith("direct:start");
// Mock and skip result endpoint
mockEndpoints("log:*");
}
});
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
// Start the integration
integration.run();
// Start the integration
integration.run();
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
// Send the test message
context.createProducerTemplate().sendBody("direct:start", "hello");
// Send the test message
context.createProducerTemplate().sendBody("direct:start", "hello");
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow