@Test public void testFileToFile() throws Exception { // Body contains two CDs, one DVD and one BOOK. String bodyOfMessage = "eminem / cd,harry potter and the deathly hollows / dvd," + "Claus Ibsen - Camel in Action / book," + "Xzibit / cd"; // The TemplateProducer is part of CamelTestSupport. It is used to send messages to Camel // endpoints. template.sendBodyAndHeader( "file://orders/inbox", bodyOfMessage, Exchange.FILE_NAME, "order.csv"); // Mock is included implicitly. MockEndpoint mock = context.getEndpoint("mock:others", MockEndpoint.class); // The Mock expects only one message, because it only receives the BOOK order: mock.expectedMessageCount(1); mock.setResultWaitTime(1000); Thread.sleep(3000); String dvdBody = " harry potter and the deathly hollows / dvd"; File target = new File("orders/outbox/dvd/order.csv"); String content = context.getTypeConverter().convertTo(String.class, target); // Assertions mock.assertIsSatisfied(); assertEquals(dvdBody.toUpperCase(), content); }
@Test public void testStartDelayed() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.setMinimumResultWaitTime(1900); mock.setResultWaitTime(3000); mock.expectedMessageCount(2); assertMockEndpointsSatisfied(); }
public void testSendLotsOfMessagesButOnly3GetThrough() throws Exception { MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class); resultEndpoint.expectedMessageCount(3); resultEndpoint.setResultWaitTime(5000); for (int i = 0; i < messageCount; i++) { template.sendBody("seda:a", "<message>" + i + "</message>"); } // lets pause to give the requests time to be processed // to check that the throttle really does kick in resultEndpoint.assertIsSatisfied(); }
public void testCustomPolicy() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedBodiesReceived("Hello World"); mock.setResultWaitTime(2000); template.sendBody("seda:foo", "Hello World"); // wait 2 sec but the route is not started mock.assertIsNotSatisfied(); // now start it using our policy policy.startRoute(); // now the message should be routed mock.assertIsSatisfied(); }
@Test public void testShutdownCompleteCurrentTaskOnly() throws Exception { MockEndpoint bar = getMockEndpoint("mock:bar"); bar.expectedMinimumMessageCount(1); bar.setResultWaitTime(3000); assertMockEndpointsSatisfied(); // shutdown during processing context.stop(); // should NOT route all 8 assertTrue( "Should NOT complete all messages, was: " + bar.getReceivedCounter(), bar.getReceivedCounter() < 8); }
@Test public void testDiscovery() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMinimumMessageCount(1); mock.setResultWaitTime(5000); // force shutdown after 5 seconds as otherwise the bean will keep generating a new input context.getShutdownStrategy().setTimeout(5); assertMockEndpointsSatisfied(); // sleep a little Thread.sleep(1000); Map<String, Map> map = new HashMap<String, Map>(registry.getServices()); assertTrue("There should be 1 or more, was: " + map.size(), map.size() >= 1); }
@Test public void testMaxMessagesPerPoll() throws Exception { // start route context.startRoute("foo"); MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedBodiesReceived("Bye World", "Godday World"); mock.setResultWaitTime(4000); mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 2); assertMockEndpointsSatisfied(); mock.reset(); mock.expectedBodiesReceived("Hello World"); mock.expectedPropertyReceived(Exchange.BATCH_SIZE, 1); assertMockEndpointsSatisfied(); }