Java Code Examples for org.apache.camel.component.mock.MockEndpoint#assertIsSatisfied()
The following examples show how to use
org.apache.camel.component.mock.MockEndpoint#assertIsSatisfied() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NagiosIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSendToNagios() throws Exception { CamelContext camelctx = createCamelContext(); MessagePayload expectedPayload = new MessagePayload("localhost", Level.OK, camelctx.getName(), "Hello Nagios"); MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(1); mock.allMessages().body().isInstanceOf(String.class); mock.expectedBodiesReceived("Hello Nagios"); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:start", "Hello Nagios"); mock.assertIsSatisfied(); Mockito.verify(nagiosPassiveCheckSender, Mockito.times(1)).send(expectedPayload); } finally { camelctx.close(); } }
Example 2
Source File: ODataReadRouteSplitResultsTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testODataRouteWithSimpleQuery() throws Exception { String queryParams = "$filter=ID eq 1"; Connector odataConnector = createODataConnector(new PropertyBuilder<String>() .property(SERVICE_URI, defaultTestServer.servicePlainUri()) .property(QUERY_PARAMS, queryParams)); Step odataStep = createODataStep(odataConnector, defaultTestServer.resourcePath()); Integration odataIntegration = createIntegration(odataStep, mockStep); RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration); context.addRoutes(routes); MockEndpoint result = initMockEndpoint(); result.setMinimumExpectedMessageCount(1); context.start(); result.assertIsSatisfied(); testResult(result, 0, TEST_SERVER_DATA_1); }
Example 3
Source File: ActivityLoggingTest.java From syndesis with Apache License 2.0 | 6 votes |
@Test public void testLoggingWithSuccessStep() throws Exception { final MockEndpoint result = context.getEndpoint("mock:end", MockEndpoint.class); result.expectedBodiesReceived("Hello World"); context.createProducerTemplate().sendBody("direct:start", "Hello World"); result.assertIsSatisfied(); // There should be 1 exchanges logged assertEquals(1, findExchangesLogged().size()); // There should be 1 "status":"begin" assertEquals(1, findActivityEvents(x -> "begin".equals(x.status)).size()); // There should be 1 "status":"done" assertEquals(1, findActivityEvents(x -> "done".equals(x.status)).size()); // There should be no failed flag on activity with "status":"done" assertEquals("false", findActivityEvent(x -> "done".equals(x.status)).failed); // There should be 1 log activity assertEquals(1, findActivityEvents(x -> "log".equals(x.step) && ObjectHelper.isEmpty(x.duration)).size()); assertEquals(1, findActivityEvents(x -> "log".equals(x.step) && ObjectHelper.isNotEmpty(x.duration)).size()); assertEquals("hi", findActivityEvent(x -> "log".equals(x.step)).message); // There should be step activity tracking events assertEquals(3, findActivityEvents(x -> ObjectHelper.isNotEmpty(x.duration)).size()); }
Example 4
Source File: CaffeineLoadCacheIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testCacheClear() throws Exception { camelctx.addRoutes(createRouteBuilder()); camelctx.start(); try { MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMinimumMessageCount(1); mock.expectedBodiesReceived((Object)null); mock.expectedHeaderReceived(CaffeineConstants.ACTION_HAS_RESULT, false); mock.expectedHeaderReceived(CaffeineConstants.ACTION_SUCCEEDED, true); camelctx.createFluentProducerTemplate().to("direct://start") .withHeader(CaffeineConstants.ACTION, CaffeineConstants.ACTION_CLEANUP) .send(); mock.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 5
Source File: HazelcastMapConsumerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testEvict() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.start(); try { MockEndpoint mock = camelctx.getEndpoint("mock:evicted", MockEndpoint.class); mock.expectedMessageCount(1); EntryEvent<Object, Object> event = new EntryEvent<Object, Object>("foo", null, EntryEventType.EVICTED.getType(), "4711", "my-foo"); argument.getValue().entryEvicted(event); mock.assertIsSatisfied(3000); } finally { camelctx.close(); } }
Example 6
Source File: HipchatConsumerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void sendInOnlyNoResponse() throws Exception { CamelContext camelctx = createCamelContext(); MockEndpoint result = camelctx.getEndpoint("mock:result", MockEndpoint.class); result.expectedMessageCount(0); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); HttpEntity mockHttpEntity = mock(HttpEntity.class); when(mockHttpEntity.getContent()).thenReturn(null); when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity); when(closeableHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "")); result.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 7
Source File: LumberjackComponentTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void shouldListenToMessages() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { public void configure() { from("lumberjack:0.0.0.0:" + port).to("mock:output"); } }); // We're expecting 25 messages with Maps MockEndpoint mock = camelctx.getEndpoint("mock:output", MockEndpoint.class); mock.expectedMessageCount(25); mock.allMessages().body().isInstanceOf(Map.class); camelctx.start(); try { sendMessages(port, null); // Then we should have the messages we're expecting mock.assertIsSatisfied(); // And the first map should contains valid data (we're assuming it's also valid for the other ones) Map<?, ?> first = mock.getExchanges().get(0).getIn().getBody(Map.class); Assert.assertEquals("log", first.get("input_type")); Assert.assertEquals("/home/qatest/collectNetwork/log/data-integration/00000000-f000-0000-1541-8da26f200001/absorption.log", first.get("source")); } finally { camelctx.close(); } }
Example 8
Source File: SpringFirstMockTest.java From camelinaction2 with Apache License 2.0 | 5 votes |
@Test public void testQuote() throws Exception { // get the mock endpoint MockEndpoint quote = getMockEndpoint("mock:quote"); // set expectations such as 1 message should arrive quote.expectedMessageCount(1); // fire in a message to Camel template.sendBody("stub:jms:topic:quote", "Camel rocks"); // verify the result quote.assertIsSatisfied(); }
Example 9
Source File: RxJava2IntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testMultipleConsumers() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("reactive-streams:multipleConsumers?concurrentConsumers=3") .process() .message(m -> m.setHeader("thread", Thread.currentThread().getId())) .to("mock:multipleBucket"); } }); CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx); camelctx.start(); try { Flowable.range(0, 1000).subscribe( crs.streamSubscriber("multipleConsumers", Number.class) ); MockEndpoint endpoint = camelctx.getEndpoint("mock:multipleBucket", MockEndpoint.class); endpoint.expectedMessageCount(1000); endpoint.assertIsSatisfied(); Assert.assertEquals( 3, endpoint.getExchanges().stream() .map(x -> x.getIn().getHeader("thread", String.class)) .distinct() .count() ); } finally { camelctx.close(); } }
Example 10
Source File: UndertowWsIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void wsClientSingleText() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { final int port = getPort(); from("undertow:ws://localhost:" + port + "/app1") .log(">>> Message received from WebSocket Client : ${body}").to("mock:result1"); } }); camelctx.start(); try { TestClient websocket = new TestClient("ws://localhost:" + getPort() + "/app1").connect(); MockEndpoint result = camelctx.getEndpoint("mock:result1", MockEndpoint.class); result.expectedBodiesReceived("Test"); websocket.sendTextMessage("Test"); result.await(60, TimeUnit.SECONDS); result.assertIsSatisfied(); websocket.close(); } finally { camelctx.close(); } }
Example 11
Source File: ProducerTemplateInOnlyTest.java From camelinaction with Apache License 2.0 | 5 votes |
@Test public void testProducerTemplateInOnly() throws Exception { MockEndpoint result = getMockEndpoint("mock:result"); result.expectedBodiesReceived("My order"); AuditOrderBean auditOrderBean = getMandatoryBean(AuditOrderBean.class, "auditOrderBean"); auditOrderBean.auditOrder("My order"); result.assertIsSatisfied(); }
Example 12
Source File: CamelEventNotifierTest.java From camel-spring-boot with Apache License 2.0 | 5 votes |
@Test public void testEventNotifier() throws InterruptedException { MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedMessageCount(1); producerTemplate.sendBody("direct:start", "Hello World"); mockEndpoint.assertIsSatisfied(); MyEventNotifier notifier = (MyEventNotifier) camelContext.getManagementStrategy().getEventNotifiers().get(0); assertNotNull(notifier); assertTrue(notifier.getCount() > 0); }
Example 13
Source File: SMPPIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testSMPPComponent() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("smpp://smppuser@" + TestUtils.getDockerHost() + ":2775?password=password&systemType=producer"); from("smpp://smppuser@" + TestUtils.getDockerHost() + ":2775?password=password&systemType=consumer") .setBody(simple("Hello ${body}")) .to("mock:result"); } }); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedBodiesReceived("Hello Kermit"); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:start", "Kermit"); mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 14
Source File: MqttOnCamelMqttToLinkIntegrationTest.java From Ardulink-2 with Apache License 2.0 | 5 votes |
@Test public void canEnableAnalogListening() throws Exception { context = camelContext(topics.withControlChannelEnabled()); int anyPinNumber = anyPinNumber(); mqttClient.startListenig(analogPin(anyPinNumber)); MockEndpoint out = getMockEndpoint(); out.expectedBodiesReceived(alpProtocolMessage(START_LISTENING_ANALOG).forPin(anyPinNumber).withoutValue()); out.assertIsSatisfied(); }
Example 15
Source File: FileCharsetTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testCharset() throws Exception { Path dirPath = Paths.get("target/test-classes/file"); Assert.assertTrue(dirPath.toFile().isDirectory()); Path filePath = dirPath.resolve("charset-test.xml"); Assert.assertTrue(filePath.toFile().isFile()); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("file://" + dirPath + "?charset=iso-8859-1&fileName=charset-test.xml") .split().xpath("/foo/bar").log(body().toString()).to("mock:result"); } }); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedBodiesReceived("<bar>abc</bar>", "<bar>xyz</bar>", "<bar>åäö</bar>"); camelctx.start(); try { mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 16
Source File: ThreadingIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testContainerManagedExecutorService() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .log("Starting to process big file: ${header.CamelFileName}") .split(body().tokenize("\n")).streaming().parallelProcessing().executorService(executorService) .bean(InventoryService.class, "csvToObject") .to("direct:update") .end() .log("Done processing big file: ${header.CamelFileName}"); from("direct:update") .bean(InventoryService.class, "updateInventory") .to("mock:end"); } }); camelctx.start(); try { MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:end", MockEndpoint.class); mockEndpoint.expectedMessageCount(10); ProducerTemplate producerTemplate = camelctx.createProducerTemplate(); producerTemplate.requestBody("direct:start", getClass().getResource("/smallfile.csv")); mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 17
Source File: RxJava2IntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testOnCompleteHeaderForwarded() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("reactive-streams:numbers?forwardOnComplete=true") .to("mock:endpoint"); } }); CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx); Subscriber<Integer> numbers = crs.streamSubscriber("numbers", Integer.class); camelctx.start(); try { Flowable.<Integer>empty().subscribe(numbers); MockEndpoint endpoint = camelctx.getEndpoint("mock:endpoint", MockEndpoint.class); endpoint.expectedMessageCount(1); endpoint.expectedHeaderReceived(ReactiveStreamsConstants.REACTIVE_STREAMS_EVENT_TYPE, "onComplete"); endpoint.expectedBodiesReceived(new Object[]{null}); endpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 18
Source File: IRCIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testIRCComponent() throws Exception { try (CamelContext camelctx = new DefaultCamelContext()) { String uri = "irc:kermit@" + TestUtils.getDockerHost() + ":6667?channels=#wfctest"; camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from(uri) .to("mock:messages"); } }); // Expect a JOIN message for each user connection, followed by the actual IRC message MockEndpoint endpoint = camelctx.getEndpoint("mock:messages", MockEndpoint.class); endpoint.expectedMessageCount(3); CountDownLatch latch = new CountDownLatch(1); IrcComponent component = camelctx.getComponent("irc", IrcComponent.class); IrcEndpoint ircEndpoint = camelctx.getEndpoint(uri, IrcEndpoint.class); IRCConnection ircConnection = component.getIRCConnection(ircEndpoint.getConfiguration()); ircConnection.addIRCEventListener(new ChannelJoinListener(latch)); camelctx.start(); Assert.assertTrue("Gave up waiting for user to join IRC channel", latch.await(15, TimeUnit.SECONDS)); ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("irc:piggy@" + TestUtils.getDockerHost() + ":6667?channels=#wfctest", "Hello Kermit!"); endpoint.assertIsSatisfied(10000); System.out.println(endpoint); endpoint.getExchanges().forEach(ex -> System.out.println(ex.getMessage())); Exchange ex3 = endpoint.getExchanges().get(2); Assert.assertEquals("Hello Kermit!", ex3.getMessage().getBody(String.class)); } }
Example 19
Source File: FilterStepHandlerTest.java From syndesis with Apache License 2.0 | 4 votes |
@Test public void testPlaintextFilterStep() throws Exception { final DefaultCamelContext context = new DefaultCamelContext(); try { final RouteBuilder routes = newIntegrationRouteBuilder(activityTracker, new Step.Builder() .id(START_STEP) .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("direct") .putConfiguredProperty("name", "start") .build()) .build()) .build(), new Step.Builder() .id(FILTER_STEP) .stepKind(StepKind.expressionFilter) .putConfiguredProperty("filter", "${body} contains 'number'") .build(), new Step.Builder() .id(MOCK_STEP) .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .componentScheme("mock") .putConfiguredProperty("name", "result") .build()) .build()) .build() ); // Set up the camel context context.setUuidGenerator(KeyGenerator::createKey); context.addLogListener(new IntegrationLoggingListener(activityTracker)); context.addInterceptStrategy(new ActivityTrackingInterceptStrategy(activityTracker)); context.addRoutes(routes); context.start(); // Dump routes as XML for troubleshooting dumpRoutes(context); final List<String> matchingMessages = Collections.singletonList("Body: [number:9436] Log zo syndesisu"); final List<String> notMatchingMessages = Collections.singletonList("something else"); final ProducerTemplate template = context.createProducerTemplate(); final MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class); List<String> allMessages = new ArrayList<>(); allMessages.addAll(matchingMessages); allMessages.addAll(notMatchingMessages); result.expectedBodiesReceived(matchingMessages); for (Object body : allMessages) { template.sendBody("direct:start", body); } result.assertIsSatisfied(); verify(activityTracker, times(allMessages.size())).startTracking(any(Exchange.class)); verifyActivityStepTracking(MOCK_STEP, matchingMessages.size()); verifyActivityStepTracking(FILTER_STEP, allMessages.size()); verify(activityTracker, times(allMessages.size())).finishTracking(any(Exchange.class)); } finally { context.stop(); } }
Example 20
Source File: CryptoCmsIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testCryptoCmsSignEncryptDecryptVerify() throws Exception { Assume.assumeFalse("[#2241] CryptoCmsIntegrationTest fails on IBM JDK", EnvironmentUtils.isIbmJDK() || EnvironmentUtils.isOpenJDK()); CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("crypto-cms:sign://testsign?signer=#signer1,signer=#signer2&includeContent=true") .to("crypto-cms:encrypt://testencrpyt?toBase64=true&recipient=#recipient1&contentEncryptionAlgorithm=DESede/CBC/PKCS5Padding&secretKeyLength=128") .to("crypto-cms:decrypt://testdecrypt?fromBase64=true&keyStoreParameters=#keyStoreParameters") .to("crypto-cms:verify://testverify?keyStoreParameters=#keyStoreParameters") .to("mock:result"); } }); KeyStoreParameters keyStoreParameters = new KeyStoreParameters(); keyStoreParameters.setType("JCEKS"); keyStoreParameters.setResource("/crypto.keystore"); keyStoreParameters.setPassword("Abcd1234"); DefaultKeyTransRecipientInfo recipient = new DefaultKeyTransRecipientInfo(); recipient.setCertificateAlias("rsa"); recipient.setKeyStoreParameters(keyStoreParameters); DefaultSignerInfo signerInfo = new DefaultSignerInfo(); signerInfo.setIncludeCertificates(true); signerInfo.setSignatureAlgorithm("SHA256withRSA"); signerInfo.setPrivateKeyAlias("rsa"); signerInfo.setKeyStoreParameters(keyStoreParameters); DefaultSignerInfo signerInfo2 = new DefaultSignerInfo(); signerInfo2.setSignatureAlgorithm("SHA256withDSA"); signerInfo2.setPrivateKeyAlias("dsa"); signerInfo2.setKeyStoreParameters(keyStoreParameters); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedBodiesReceived("Testmessage"); context.bind("keyStoreParameters", keyStoreParameters); context.bind("signer1", signerInfo); context.bind("signer2", signerInfo2); context.bind("recipient1", recipient); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:start", "Testmessage"); mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); context.unbind("keyStoreParameters"); context.unbind("signer1"); context.unbind("signer2"); context.unbind("recipient1"); } }