Java Code Examples for org.apache.camel.CamelContext#getEndpoint()
The following examples show how to use
org.apache.camel.CamelContext#getEndpoint() .
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: CouchDBIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testCouchDBConsumer() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { fromF("couchdb:http://%s:5984/%s?username=%s&password=%s", TestUtils.getDockerHost(), COUCHDB_NAME, COUCHDB_USERNAME, COUCHDB_PASSWORD) .to("mock:result"); } }); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedHeaderReceived(CouchDbConstants.HEADER_METHOD, "UPDATE"); mockEndpoint.expectedMessageCount(1); camelctx.start(); try { JsonElement element = new Gson().fromJson(getJSONString(), JsonElement.class); client.save(element); mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 2
Source File: JingIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testJingRncSchemaValidationFailure() throws Exception { CamelContext camelctx = createCamelContext(true); MockEndpoint mockEndpointValid = camelctx.getEndpoint("mock:valid", MockEndpoint.class); mockEndpointValid.expectedMessageCount(0); MockEndpoint mockEndpointInvalid = camelctx.getEndpoint("mock:invalid", MockEndpoint.class); mockEndpointInvalid.expectedMessageCount(1); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:start", ORDER_XML_INVALID); mockEndpointValid.assertIsSatisfied(); mockEndpointInvalid.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 3
Source File: WordpressIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testUserSingleRequest() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { configureComponent(getContext()); from("wordpress:user?id=114913").to("mock:resultSingle"); } }); camelctx.start(); try { MockEndpoint mock = camelctx.getEndpoint("mock:resultSingle", MockEndpoint.class); mock.expectedMinimumMessageCount(1); mock.allMessages().body().isInstanceOf(User.class); mock.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 4
Source File: SipIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testPresenceAgentBasedPubSub() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(createRouteBuilder()); MockEndpoint mockNeverland = camelctx.getEndpoint("mock:neverland", MockEndpoint.class); mockNeverland.expectedMessageCount(0); MockEndpoint mockNotification = camelctx.getEndpoint("mock:notification", MockEndpoint.class); mockNotification.expectedMinimumMessageCount(1); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader( "sip://agent@localhost:" + port1 + "?stackName=client&eventHeaderName=evtHdrName&eventId=evtid&fromUser=user2&fromHost=localhost&fromPort=" + port3, "EVENT_A", "REQUEST_METHOD", Request.PUBLISH); mockNeverland.assertIsSatisfied(); mockNotification.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 5
Source File: SimpleProcessTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "process/example.bpmn20.xml" }) public void testRunProcessByKey() throws Exception { CamelContext ctx = applicationContext.getBean(CamelContext.class); ProducerTemplate tpl = ctx.createProducerTemplate(); MockEndpoint me = (MockEndpoint) ctx.getEndpoint("mock:service1"); me.expectedBodiesReceived("ala"); tpl.sendBodyAndProperty("direct:start", Collections.singletonMap("var1", "ala"), FlowableProducer.PROCESS_KEY_PROPERTY, "key1"); String instanceId = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey("key1").singleResult().getProcessInstanceId(); tpl.sendBodyAndProperty("direct:receive", null, FlowableProducer.PROCESS_KEY_PROPERTY, "key1"); assertProcessEnded(instanceId); me.assertIsSatisfied(); }
Example 6
Source File: MicrometerCounterIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testUsingScriptEvaluation() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.start(); try { MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:out", MockEndpoint.class); mockEndpoint.expectedMessageCount(1); String message = "Hello from Camel Metrics!"; ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("direct:in-4", message, HEADER_COUNTER_DECREMENT, 7.0D); Counter counter = metricsRegistry.find("D").counter(); Assert.assertEquals(message.length(), counter.count(), 0.01D); Assert.assertEquals(Integer.toString(message.length()), counter.getId().getTag("a")); mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 7
Source File: SimpleProcessTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Deployment(resources = { "process/example.bpmn20.xml" }) public void testRunProcessByKey() throws Exception { CamelContext ctx = applicationContext.getBean(CamelContext.class); ProducerTemplate tpl = ctx.createProducerTemplate(); MockEndpoint me = (MockEndpoint) ctx.getEndpoint("mock:service1"); me.expectedBodiesReceived("ala"); tpl.sendBodyAndProperty("direct:start", Collections.singletonMap("var1", "ala"), ActivitiProducer.PROCESS_KEY_PROPERTY, "key1"); String instanceId = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey("key1").singleResult().getProcessInstanceId(); tpl.sendBodyAndProperty("direct:receive", null, ActivitiProducer.PROCESS_KEY_PROPERTY, "key1"); assertProcessEnded(instanceId); me.assertIsSatisfied(); }
Example 8
Source File: UndertowIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testUndertowConsumerPrefixPath() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("undertow:http://localhost/foo/bar?matchOnUriPrefix=true") .to("mock:result"); } }); try { camelctx.start(); MockEndpoint endpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); endpoint.setExpectedMessageCount(3); HttpRequest.get("http://localhost:8080/foo").throwExceptionOnFailure(false).getResponse(); HttpRequest.get("http://localhost:8080/foo/bar").getResponse(); HttpRequest.get("http://localhost:8080/foo/bar/hello").getResponse(); HttpRequest.get("http://localhost:8080/foo/bar/hello/world").getResponse(); endpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 9
Source File: LevelDBIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testLevelDBAggregate() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { LevelDBAggregationRepository repo = new LevelDBAggregationRepository("repo1", "target/leveldb/leveldb.dat"); from("direct:start") .aggregate(header("id"), new MyAggregationStrategy()) .completionSize(5).aggregationRepository(repo) .to("mock:aggregated"); } }); MockEndpoint mockAggregated = camelctx.getEndpoint("mock:aggregated", MockEndpoint.class); mockAggregated.expectedBodiesReceived("ABCDE"); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("direct:start", "A", "id", 123); template.sendBodyAndHeader("direct:start", "B", "id", 123); template.sendBodyAndHeader("direct:start", "C", "id", 123); template.sendBodyAndHeader("direct:start", "D", "id", 123); template.sendBodyAndHeader("direct:start", "E", "id", 123); MockEndpoint.assertIsSatisfied(camelctx, 30, TimeUnit.SECONDS); } finally { camelctx.close(); } }
Example 10
Source File: CryptoComponentIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testBasicSignatureRoute() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:sign") .to("crypto:sign://basic?privateKey=#myPrivateKey&algorithm=SHA1withDSA&provider=SUN") .to("direct:verify"); from("direct:verify") .to("crypto:verify://basic?publicKey=#myPublicKey&algorithm=SHA1withDSA&provider=SUN") .to("mock:result"); } }); camelctx.start(); try { camelctx.createProducerTemplate().sendBody("direct:sign", PAYLOAD); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); Exchange e = mockEndpoint.getExchanges().get(0); Message result = e == null ? null : e.hasOut() ? e.getOut() : e.getIn(); Assert.assertNull(result.getHeader(DigitalSignatureConstants.SIGNATURE)); } finally { camelctx.close(); } }
Example 11
Source File: TikaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void detectGif() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("tika:detect").to("mock:result"); } }); MockEndpoint resultEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); try { camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); File document = new File("src/test/resources/tika/testGIF.gif"); template.sendBody("direct:start", document); resultEndpoint.setExpectedMessageCount(1); resultEndpoint.expectedMessagesMatches(new Predicate() { @Override public boolean matches(Exchange exchange) { Object body = exchange.getIn().getBody(String.class); Assert.assertThat(body, instanceOf(String.class)); Assert.assertThat((String) body, containsString("image/gif")); return true; } }); resultEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 12
Source File: CryptoCmsIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testCryptoCmsDecryptVerifyBinary() 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: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"); context.bind("keyStoreParameters", keyStoreParameters); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedBodiesReceived("Testmessage"); camelctx.start(); try { InputStream input = CryptoCmsIntegrationTest.class.getResourceAsStream("/signed.bin"); ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:start", input); mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); context.unbind("keyStoreParameters"); } }
Example 13
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testEndpoints() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { public void configure() throws Exception { from("direct:start").to("openstack-swift:localhost"); from("direct:start").to("openstack-nova:localhost"); from("direct:start").to("openstack-neutron:localhost"); from("direct:start").to("openstack-keystone:localhost"); from("direct:start").to("openstack-glance:localhost"); from("direct:start").to("openstack-cinder:localhost"); } }); SwiftEndpoint swiftEndpoint = camelctx.getEndpoint("openstack-swift:localhost", SwiftEndpoint.class); Assert.assertNotNull("SwiftEndpoint not null", swiftEndpoint); NovaEndpoint novaEndpoint = camelctx.getEndpoint("openstack-nova:localhost", NovaEndpoint.class); Assert.assertNotNull("NovaEndpoint not null", novaEndpoint); NeutronEndpoint neutronEndpoint = camelctx.getEndpoint("openstack-neutron:localhost", NeutronEndpoint.class); Assert.assertNotNull("NeutronEndpoint not null", neutronEndpoint); KeystoneEndpoint keystoneEndpoint = camelctx.getEndpoint("openstack-keystone:localhost", KeystoneEndpoint.class); Assert.assertNotNull("KeystoneEndpoint not null", keystoneEndpoint); GlanceEndpoint glanceEndpoint = camelctx.getEndpoint("openstack-glance:localhost", GlanceEndpoint.class); Assert.assertNotNull("GlanceEndpoint not null", glanceEndpoint); CinderEndpoint cinderEndpoint = camelctx.getEndpoint("openstack-cinder:localhost", CinderEndpoint.class); Assert.assertNotNull("cinderEndpoint not null", cinderEndpoint); }
Example 14
Source File: EhCacheIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testEhCacheIdempotentRepository() throws Exception { EhcacheIdempotentRepository repository = new EhcacheIdempotentRepository(cacheManager, "idempotent"); CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .idempotentConsumer(header("messageId"), repository) .to("mock:result"); } }); camelctx.start(); try { MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedMessageCount(1); // Send 5 messages with the same messageId header. Only 1 should be forwarded to the mock:result endpoint ProducerTemplate template = camelctx.createProducerTemplate(); for (int i = 0; i < 5; i++) { template.requestBodyAndHeader("direct:start", null, "messageId", "12345"); } mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 15
Source File: SJMS2IntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testSJMS2Consumer() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("sjms2:queue:" + QUEUE_NAME + "?connectionFactory=#ConnectionFactory") .setBody(simple("Hello ${body}")) .to("mock:result"); } }); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedBodiesReceived("Hello Kermit"); camelctx.start(); try { // Send a message to the queue ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory"); Connection connection = cfactory.createConnection(); try { sendMessage(connection, QUEUE_JNDI_NAME, "Kermit"); mockEndpoint.assertIsSatisfied(); } finally { connection.close(); } } finally { camelctx.close(); } }
Example 16
Source File: Iec60870IntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testIec60870ClientServer() throws Exception { int port = AvailablePortFinder.getNextAvailable(); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .toF("iec60870-client:localhost:%d/0-1-2-3-4", port); fromF("iec60870-server:localhost:%d/0-1-2-3-4", port) .setBody(simple("Received command ${body.value}")) .to("mock:result"); } }); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.expectedBodiesReceived("Received command 12345"); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:start", 12345); mockEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }
Example 17
Source File: GangliaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void sendDefaultConfigurationShouldSucceed() throws Exception { CamelContext camelctx = assertSingleCamelContext(); ProducerTemplate template = camelctx.createProducerTemplate(); Integer port = template.requestBody("direct:getPort", null, Integer.class); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.setMinimumExpectedMessageCount(0); mockEndpoint.setAssertPeriod(100L); mockEndpoint.whenAnyExchangeReceived(new Processor() { @Override public void process(Exchange exchange) throws Exception { Ganglia_metadata_msg metadataMessage = exchange.getIn().getBody(Ganglia_metadata_msg.class); if (metadataMessage != null) { Assert.assertEquals(DEFAULT_METRIC_NAME, metadataMessage.gfull.metric.name); Assert.assertEquals(DEFAULT_TYPE.getGangliaType(), metadataMessage.gfull.metric.type); Assert.assertEquals(DEFAULT_SLOPE.getGangliaSlope(), metadataMessage.gfull.metric.slope); Assert.assertEquals(DEFAULT_UNITS, metadataMessage.gfull.metric.units); Assert.assertEquals(DEFAULT_TMAX, metadataMessage.gfull.metric.tmax); Assert.assertEquals(DEFAULT_DMAX, metadataMessage.gfull.metric.dmax); } else { Ganglia_value_msg valueMessage = exchange.getIn().getBody(Ganglia_value_msg.class); if (valueMessage != null) { Assert.assertEquals("28.0", valueMessage.gstr.str); Assert.assertEquals("%s", valueMessage.gstr.fmt); } else { Assert.fail("Mock endpoint should only receive non-null metadata or value messages"); } } } }); template.sendBody(String.format("ganglia:localhost:%d?mode=UNICAST", port), "28.0"); mockEndpoint.assertIsSatisfied(); }
Example 18
Source File: ReactorIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testSubscriber() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:reactor") .to("mock:result"); } }); camelctx.start(); try { CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx); Flux.just(1, 2, 3) .subscribe(crs.subscriber("direct:reactor", Integer.class)); MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedMessageCount(3); mock.assertIsSatisfied(); int idx = 1; for (Exchange ex : mock.getExchanges()) { Assert.assertEquals(new Integer(idx++), ex.getIn().getBody(Integer.class)); } } finally { camelctx.close(); } }
Example 19
Source File: LuceneIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testComponentLoads() throws Exception { CamelContext ctx = new DefaultCamelContext(); Endpoint endpoint = ctx.getEndpoint("lucene:searchIndex:query?maxHits=20"); Assert.assertNotNull(endpoint); Assert.assertEquals(endpoint.getClass().getName(), "org.apache.camel.component.lucene.LuceneEndpoint"); }
Example 20
Source File: TikaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void parseOdtWithEncoding() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("tika:parse?tikaParseOutputEncoding=" + StandardCharsets.UTF_16.name()) .to("mock:result"); } }); MockEndpoint resultEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); try { camelctx.start(); ProducerTemplate template = camelctx.createProducerTemplate(); File document = new File("src/test/resources/tika/testOpenOffice2.odt"); template.sendBody("direct:start", document); resultEndpoint.setExpectedMessageCount(1); resultEndpoint.expectedMessagesMatches(new Predicate() { @Override public boolean matches(Exchange exchange) { Object body = exchange.getIn().getBody(String.class); Map<String, Object> headerMap = exchange.getIn().getHeaders(); Assert.assertThat(body, instanceOf(String.class)); Charset detectedCharset = null; try { InputStream bodyIs = new ByteArrayInputStream( ((String) body).getBytes(StandardCharsets.UTF_16)); UniversalEncodingDetector encodingDetector = new UniversalEncodingDetector(); detectedCharset = encodingDetector.detect(bodyIs, new Metadata()); } catch (IOException e1) { throw new RuntimeException(e1); } Assert.assertThat(detectedCharset.name(), startsWith(StandardCharsets.UTF_16.name())); Assert.assertThat(headerMap.get(Exchange.CONTENT_TYPE), equalTo("application/vnd.oasis.opendocument.text")); return true; } }); resultEndpoint.assertIsSatisfied(); } finally { camelctx.close(); } }