Here are the examples of the java api class org.apache.camel.Exchange taken from open source projects.
1. CamelJaxbFallbackConverterTest#testFilteringConverter()
View license@Test public void testFilteringConverter() throws Exception { byte[] buffers = "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>".getBytes("UTF-8"); InputStream is = new ByteArrayInputStream(buffers); Exchange exchange = new DefaultExchange(context); exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8"); exchange.setProperty(Exchange.FILTER_NON_XML_CHARS, true); TypeConverter converter = context.getTypeConverter(); PersonType person = converter.convertTo(PersonType.class, exchange, is); assertNotNull("Person should not be null ", person); assertEquals("Get the wrong first name ", "FOO", person.getFirstName()); assertEquals("Get the wrong second name ", "BAR ", person.getLastName()); person.setLastName("BAR?"); String value = converter.convertTo(String.class, exchange, person); assertTrue("Didn't filter the non-xml chars", value.indexOf("<lastName>BAR </lastName>") > 0); exchange.setProperty(Exchange.FILTER_NON_XML_CHARS, false); value = converter.convertTo(String.class, exchange, person); assertTrue("Should not filter the non-xml chars", value.indexOf("<lastName>BAR?</lastName>") > 0); }
2. HawtDBGetNotFoundTest#testPutAndGetNotFound()
View license@Test public void testPutAndGetNotFound() { HawtDBAggregationRepository repo = new HawtDBAggregationRepository(); repo.setHawtDBFile(hawtDBFile); repo.setRepositoryName("repo1"); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); log.info("Created " + exchange.getExchangeId()); repo.add(context, exchange.getExchangeId(), exchange); Exchange out = repo.get(context, exchange.getExchangeId()); assertNotNull("Should find exchange", out); Exchange exchange2 = new DefaultExchange(context); exchange2.getIn().setBody("Bye World"); log.info("Created " + exchange2.getExchangeId()); Exchange out2 = repo.get(context, exchange2.getExchangeId()); assertNull("Should not find exchange", out2); }
3. LevelDBGetNotFoundTest#testPutAndGetNotFound()
View license@Test public void testPutAndGetNotFound() { LevelDBAggregationRepository repo = new LevelDBAggregationRepository(); repo.setLevelDBFile(levelDBFile); repo.setRepositoryName("repo1"); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); log.info("Created " + exchange.getExchangeId()); repo.add(context, exchange.getExchangeId(), exchange); Exchange out = repo.get(context, exchange.getExchangeId()); assertNotNull("Should find exchange", out); Exchange exchange2 = new DefaultExchange(context); exchange2.getIn().setBody("Bye World"); log.info("Created " + exchange2.getExchangeId()); Exchange out2 = repo.get(context, exchange2.getExchangeId()); assertNull("Should not find exchange", out2); }
4. JdbcGetNotFoundTest#testPutAndGetNotFound()
View license@Test public void testPutAndGetNotFound() { Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); log.info("Created " + exchange.getExchangeId()); repo.add(context, exchange.getExchangeId(), exchange); Exchange out = repo.get(context, exchange.getExchangeId()); assertNotNull("Should find exchange", out); Exchange exchange2 = new DefaultExchange(context); exchange2.getIn().setBody("Bye World"); log.info("Created " + exchange2.getExchangeId()); Exchange out2 = repo.get(context, exchange2.getExchangeId()); assertNull("Should not find exchange", out2); }
5. ExchangeHelper#createCorrelatedCopy()
View license/** * Creates a new instance and copies from the current message exchange so that it can be * forwarded to another destination as a new instance. Unlike regular copy this operation * will not share the same {@link org.apache.camel.spi.UnitOfWork} so its should be used * for async messaging, where the original and copied exchange are independent. * * @param exchange original copy of the exchange * @param handover whether the on completion callbacks should be handed over to the new copy. * @param useSameMessageId whether to use same message id on the copy message. */ public static Exchange createCorrelatedCopy(Exchange exchange, boolean handover, boolean useSameMessageId) { String id = exchange.getExchangeId(); // make sure to do a safe copy as the correlated copy can be routed independently of the source. Exchange copy = exchange.copy(true); // do not reuse message id on copy if (!useSameMessageId) { if (copy.hasOut()) { copy.getOut().setMessageId(null); } copy.getIn().setMessageId(null); } // do not share the unit of work copy.setUnitOfWork(null); // do not reuse the message id // hand over on completion to the copy if we got any UnitOfWork uow = exchange.getUnitOfWork(); if (handover && uow != null) { uow.handoverSynchronization(copy); } // set a correlation id so we can track back the original exchange copy.setProperty(Exchange.CORRELATION_ID, id); return copy; }
6. SedaAsyncProducerTest#testAsyncProducerWait()
View licensepublic void testAsyncProducerWait() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); // using the new async API we can fire a real async message Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); exchange.setPattern(ExchangePattern.InOut); exchange.setProperty(Exchange.ASYNC_WAIT, WaitForTaskToComplete.IfReplyExpected); template.send("direct:start", exchange); // I should not happen before mock route = route + "send"; assertMockEndpointsSatisfied(); assertEquals("Send should occur before processor", "processsend", route); String response = exchange.getOut().getBody(String.class); assertEquals("Bye World", response); }
7. DefaultConsumerTemplateTest#testReceiveException()
View licensepublic void testReceiveException() throws Exception { Exchange exchange = new DefaultExchange(context); exchange.setException(new IllegalArgumentException("Damn")); Exchange out = template.send("seda:foo", exchange); assertTrue(out.isFailed()); assertNotNull(out.getException()); try { consumer.receiveBody("seda:foo", String.class); fail("Should have thrown an exception"); } catch (RuntimeCamelException e) { assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); assertEquals("Damn", e.getCause().getMessage()); } }
8. LevelDBAggregationRepositoryMultipleRepoTest#testMultipeRepoSameKeyDifferentContent()
View license@Test public void testMultipeRepoSameKeyDifferentContent() { LevelDBAggregationRepository repo1 = new LevelDBAggregationRepository(); repo1.setLevelDBFile(levelDBFile); repo1.setRepositoryName("repo1"); LevelDBAggregationRepository repo2 = new LevelDBAggregationRepository(); repo2.setLevelDBFile(levelDBFile); repo2.setRepositoryName("repo2"); Exchange exchange1 = new DefaultExchange(context); exchange1.getIn().setBody("Hello World"); repo1.add(context, "foo", exchange1); Exchange exchange2 = new DefaultExchange(context); exchange2.getIn().setBody("Bye World"); repo2.add(context, "foo", exchange2); Exchange actual = repo1.get(context, "foo"); assertEquals("Hello World", actual.getIn().getBody()); actual = repo2.get(context, "foo"); assertEquals("Bye World", actual.getIn().getBody()); }
9. MinaTransferExchangeOptionTest#sendExchange()
View licenseprivate Exchange sendExchange(boolean setException) throws Exception { Endpoint endpoint = context.getEndpoint("mina:tcp://localhost:{{port}}?sync=true&encoding=UTF-8&transferExchange=true"); Exchange exchange = endpoint.createExchange(); Message message = exchange.getIn(); message.setBody("Hello!"); message.setHeader("cheese", "feta"); exchange.setProperty("ham", "old"); exchange.setProperty("setException", setException); Producer producer = endpoint.createProducer(); producer.start(); producer.process(exchange); return exchange; }
10. MinaVMTransferExchangeOptionTest#sendExchange()
View licenseprivate Exchange sendExchange(boolean setException) throws Exception { Endpoint endpoint = context.getEndpoint("mina:vm://localhost:{{port}}?sync=true&encoding=UTF-8&transferExchange=true"); Exchange exchange = endpoint.createExchange(); Message message = exchange.getIn(); message.setBody("Hello!"); message.setHeader("cheese", "feta"); exchange.setProperty("ham", "old"); exchange.setProperty("setException", setException); Producer producer = endpoint.createProducer(); producer.start(); producer.process(exchange); return exchange; }
11. Mina2TransferExchangeOptionTest#sendExchange()
View licenseprivate Exchange sendExchange(boolean setException) throws Exception { Endpoint endpoint = context.getEndpoint(String.format("mina2:tcp://localhost:%1$s?sync=true&encoding=UTF-8&transferExchange=true", getPort())); Producer producer = endpoint.createProducer(); Exchange exchange = endpoint.createExchange(); //Exchange exchange = endpoint.createExchange(); Message message = exchange.getIn(); message.setBody("Hello!"); message.setHeader("cheese", "feta"); exchange.setProperty("ham", "old"); exchange.setProperty("setException", setException); producer.start(); producer.process(exchange); return exchange; }
12. Mina2VMTransferExchangeOptionTest#sendExchange()
View licenseprivate Exchange sendExchange(boolean setException) throws Exception { Endpoint endpoint = context.getEndpoint(String.format("mina2:vm://localhost:%1$s?sync=true&encoding=UTF-8&transferExchange=true", getPort())); Exchange exchange = endpoint.createExchange(); Message message = exchange.getIn(); message.setBody("Hello!"); message.setHeader("cheese", "feta"); exchange.setProperty("ham", "old"); exchange.setProperty("setException", setException); Producer producer = endpoint.createProducer(); producer.start(); producer.process(exchange); return exchange; }
13. NettyTransferExchangeOptionTest#sendExchange()
View licenseprivate Exchange sendExchange(boolean setException) throws Exception { Endpoint endpoint = context.getEndpoint("netty:tcp://localhost:{{port}}?transferExchange=true"); Exchange exchange = endpoint.createExchange(); Message message = exchange.getIn(); message.setBody("Hello!"); message.setHeader("cheese", "feta"); exchange.setProperty("ham", "old"); exchange.setProperty("setException", setException); Producer producer = endpoint.createProducer(); producer.start(); // ensure to stop producer after usage try { producer.process(exchange); } finally { producer.stop(); } return exchange; }
14. NettyTransferExchangeOptionTest#sendExchange()
View licenseprivate Exchange sendExchange(boolean setException) throws Exception { Endpoint endpoint = context.getEndpoint("netty4:tcp://localhost:{{port}}?transferExchange=true"); Exchange exchange = endpoint.createExchange(); Message message = exchange.getIn(); message.setBody("Hello!"); message.setHeader("cheese", "feta"); exchange.setProperty("ham", "old"); exchange.setProperty("setException", setException); Producer producer = endpoint.createProducer(); producer.start(); // ensure to stop producer after usage try { producer.process(exchange); } finally { producer.stop(); } return exchange; }
15. EndpointMessageListener#createExchange()
View licensepublic Exchange createExchange(Message message, Session session, Object replyDestination) { Exchange exchange = endpoint.createExchange(); JmsBinding binding = getBinding(); exchange.setProperty(Exchange.BINDING, binding); exchange.setIn(new JmsMessage(message, session, binding)); // lets set to an InOut if we have some kind of reply-to destination if (replyDestination != null && !disableReplyTo) { // only change pattern if not already out capable if (!exchange.getPattern().isOutCapable()) { exchange.setPattern(ExchangePattern.InOut); } } return exchange; }
16. DefaultProducerTemplateAsyncTest#testAsyncCallbackExchangeInOutGetResult()
View licensepublic void testAsyncCallbackExchangeInOutGetResult() throws Exception { ORDER.set(0); Exchange exchange = context.getEndpoint("direct:start").createExchange(); exchange.getIn().setBody("Hello"); exchange.setPattern(ExchangePattern.InOut); Future<Exchange> future = template.asyncCallback("direct:echo", exchange, new SynchronizationAdapter() { @Override public void onDone(Exchange exchange) { assertEquals("HelloHello", exchange.getOut().getBody()); ORDER.addAndGet(2); } }); ORDER.addAndGet(1); Exchange reply = future.get(10, TimeUnit.SECONDS); ORDER.addAndGet(4); assertEquals(7, ORDER.get()); assertNotNull(reply); assertEquals("HelloHello", reply.getOut().getBody()); }
17. CircuitBreakerLoadBalancerTest#failedMessagesOpenCircuitToPreventMessageThree()
View licenseprivate void failedMessagesOpenCircuitToPreventMessageThree(String endpoint) throws InterruptedException, Exception { expectsMessageCount(2, result); result.whenAnyExchangeReceived(new Processor() { @Override public void process(Exchange exchange) throws Exception { exchange.setException(new MyCustomException()); } }); Exchange exchangeOne = sendMessage(endpoint, "message one"); Exchange exchangeTwo = sendMessage(endpoint, "message two"); Exchange exchangeThree = sendMessage(endpoint, "message three"); assertMockEndpointsSatisfied(); assertTrue(exchangeOne.getException() instanceof MyCustomException); assertTrue(exchangeTwo.getException() instanceof MyCustomException); assertTrue(exchangeThree.getException() instanceof RejectedExecutionException); }
18. JdbcAggregationRepositoryMultipleRepoTest#testMultipeRepoSameKeyDifferentContent()
View license@Test public void testMultipeRepoSameKeyDifferentContent() { JdbcAggregationRepository repo1 = applicationContext.getBean("repo1", JdbcAggregationRepository.class); JdbcAggregationRepository repo2 = applicationContext.getBean("repo2", JdbcAggregationRepository.class); Exchange exchange1 = new DefaultExchange(context); exchange1.getIn().setBody("Hello World"); repo1.add(context, "foo", exchange1); Exchange exchange2 = new DefaultExchange(context); exchange2.getIn().setBody("Bye World"); repo2.add(context, "foo", exchange2); Exchange actual = repo1.get(context, "foo"); assertEquals("Hello World", actual.getIn().getBody()); actual = repo2.get(context, "foo"); assertEquals("Bye World", actual.getIn().getBody()); }
19. HawtDBAggregationRepositoryMultipleRepoTest#testMultipeRepoSameKeyDifferentContent()
View license@Test public void testMultipeRepoSameKeyDifferentContent() { HawtDBAggregationRepository repo1 = new HawtDBAggregationRepository(); repo1.setHawtDBFile(hawtDBFile); repo1.setRepositoryName("repo1"); HawtDBAggregationRepository repo2 = new HawtDBAggregationRepository(); repo2.setHawtDBFile(hawtDBFile); repo2.setRepositoryName("repo2"); Exchange exchange1 = new DefaultExchange(context); exchange1.getIn().setBody("Hello World"); repo1.add(context, "foo", exchange1); Exchange exchange2 = new DefaultExchange(context); exchange2.getIn().setBody("Bye World"); repo2.add(context, "foo", exchange2); Exchange actual = repo1.get(context, "foo"); assertEquals("Hello World", actual.getIn().getBody()); actual = repo2.get(context, "foo"); assertEquals("Bye World", actual.getIn().getBody()); }
20. CryptoDataFormatTest#testKeySuppliedAsHeader()
View license@Test public void testKeySuppliedAsHeader() throws Exception { KeyGenerator generator = KeyGenerator.getInstance("DES"); Key key = generator.generateKey(); Exchange unecrypted = getMandatoryEndpoint("direct:key-in-header-encrypt").createExchange(); unecrypted.getIn().setBody("Hi Alice, Be careful Eve is listening, signed Bob"); unecrypted.getIn().setHeader(CryptoDataFormat.KEY, key); unecrypted = template.send("direct:key-in-header-encrypt", unecrypted); validateHeaderIsCleared(unecrypted); MockEndpoint mock = setupExpectations(context, 1, "mock:unencrypted"); Exchange encrypted = getMandatoryEndpoint("direct:key-in-header-decrypt").createExchange(); encrypted.getIn().copyFrom(unecrypted.getIn()); encrypted.getIn().setHeader(CryptoDataFormat.KEY, key); template.send("direct:key-in-header-decrypt", encrypted); assertMockEndpointsSatisfied(); Exchange received = mock.getReceivedExchanges().get(0); validateHeaderIsCleared(received); }
21. CsvMarshalCharsetTest#testMarshal()
View license@Test public void testMarshal() throws Exception { MockEndpoint endpoint = getMockEndpoint("mock:daltons"); endpoint.expectedMessageCount(1); List<List<String>> data = new ArrayList<List<String>>(); data.add(0, new ArrayList<String>()); data.get(0).add(0, "Lücky Luke"); Exchange in = createExchangeWithBody(data); in.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1"); template.send("direct:start", in); endpoint.assertIsSatisfied(); Exchange exchange = endpoint.getExchanges().get(0); String body = exchange.getIn().getBody(String.class); assertThat(body, startsWith("Lücky Luke")); }
22. DefaultCxfBindingTest#testPopupalteExchangeFromCxfRequestWithHeaderMerged()
View license@Test public void testPopupalteExchangeFromCxfRequestWithHeaderMerged() { DefaultCxfBinding cxfBinding = new DefaultCxfBinding(); cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy()); Exchange exchange = new DefaultExchange(context); exchange.setProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.TRUE); org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl(); exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD); org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl(); Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); headers.put("myfruitheader", Arrays.asList("peach")); headers.put("mybrewheader", Arrays.asList("cappuccino", "espresso")); cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers); cxfExchange.setInMessage(cxfMessage); cxfBinding.populateExchangeFromCxfRequest(cxfExchange, exchange); Map<String, Object> camelHeaders = exchange.getIn().getHeaders(); assertNotNull(camelHeaders); assertEquals("peach", camelHeaders.get("MyFruitHeader")); assertEquals("cappuccino, espresso", camelHeaders.get("MyBrewHeader")); }
23. ZooKeeperElection#createCandidateNode()
View licenseprivate ZooKeeperEndpoint createCandidateNode(CamelContext camelContext) { LOG.info("Initializing ZookeeperElection with uri '{}'", uri); ZooKeeperEndpoint zep = camelContext.getEndpoint(uri, ZooKeeperEndpoint.class); zep.getConfiguration().setCreate(true); String fullpath = createFullPathToCandidate(zep); Exchange e = zep.createExchange(); e.setPattern(ExchangePattern.InOut); e.getIn().setHeader(ZooKeeperMessage.ZOOKEEPER_NODE, fullpath); e.getIn().setHeader(ZooKeeperMessage.ZOOKEEPER_CREATE_MODE, CreateMode.EPHEMERAL_SEQUENTIAL); producerTemplate.send(zep, e); if (e.isFailed()) { LOG.warn("Error setting up election node " + fullpath, e.getException()); } else { LOG.info("Candidate node '{}' has been created", fullpath); try { camelContext.addRoutes(new ElectoralMonitorRoute(zep)); } catch (Exception ex) { LOG.warn("Error configuring ZookeeperElection", ex); } } return zep; }
24. DefaultCxfBindingTest#testPopupalteExchangeFromCxfResponseOfNullBody()
View license@Test public void testPopupalteExchangeFromCxfResponseOfNullBody() { DefaultCxfBinding cxfBinding = new DefaultCxfBinding(); cxfBinding.setHeaderFilterStrategy(new DefaultHeaderFilterStrategy()); Exchange exchange = new DefaultExchange(context); org.apache.cxf.message.Exchange cxfExchange = new org.apache.cxf.message.ExchangeImpl(); exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD); Map<String, Object> responseContext = new HashMap<String, Object>(); responseContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, Integer.valueOf(200)); Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); responseContext.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers); org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl(); cxfExchange.setInMessage(cxfMessage); cxfBinding.populateExchangeFromCxfResponse(exchange, cxfExchange, responseContext); CxfPayload<?> cxfPayload = exchange.getOut().getBody(CxfPayload.class); assertNotNull(cxfPayload); List<?> body = cxfPayload.getBody(); assertNotNull(body); assertEquals(0, body.size()); }
25. HawtDBGetNotFoundTest#testGetNotFound()
View license@Test public void testGetNotFound() { HawtDBAggregationRepository repo = new HawtDBAggregationRepository(); repo.setHawtDBFile(hawtDBFile); repo.setRepositoryName("repo1"); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); Exchange out = repo.get(context, exchange.getExchangeId()); assertNull("Should not find exchange", out); }
26. PullRequestFilesProducerTest#testPullRequestFilesProducer()
View license@Test public void testPullRequestFilesProducer() throws Exception { PullRequest pullRequest = pullRequestService.addPullRequest("testPullRequestFilesProducer"); latestPullRequestNumber = pullRequest.getNumber(); CommitFile file = new CommitFile(); file.setFilename("testfile"); List<CommitFile> commitFiles = new ArrayList<CommitFile>(); commitFiles.add(file); pullRequestService.setFiles(latestPullRequestNumber, commitFiles); Endpoint filesProducerEndpoint = getMandatoryEndpoint("direct:validPullRequest"); Exchange exchange = filesProducerEndpoint.createExchange(); Exchange resp = template.send(filesProducerEndpoint, exchange); assertEquals(resp.getOut().getBody(), commitFiles); }
27. EhcacheAggregationRepositoryOperationTest#testRecover()
View license@Test public void testRecover() { // Given String[] keys = { "Recover1", "Recover2" }; addExchanges(keys); // When Exchange exchange2 = aggregationRepository.recover(context(), "Recover2"); Exchange exchange3 = aggregationRepository.recover(context(), "Recover3"); // Then assertNotNull(exchange2); assertNull(exchange3); }
28. EhcacheAggregationRepositoryOperationTest#testGetExists()
View license@Test public void testGetExists() { // Given String key = "Get_Exists"; Exchange exchange = new DefaultExchange(context()); aggregationRepository.add(context(), key, exchange); assertTrue(exists(key)); // When Exchange exchange2 = aggregationRepository.get(context(), key); // Then assertNotNull(exchange2); assertEquals(exchange.getExchangeId(), exchange2.getExchangeId()); }
29. SqlGeneratedKeysTest#testNoKeysForSelect()
View license@Test @SuppressWarnings("unchecked") public void testNoKeysForSelect() throws Exception { // first we create our exchange using the endpoint Endpoint endpoint = context.getEndpoint("direct:select"); Exchange exchange = endpoint.createExchange(); // then we set the SQL on the in body exchange.getIn().setHeader(SqlConstants.SQL_RETRIEVE_GENERATED_KEYS, true); // now we send the exchange to the endpoint, and receives the response from Camel Exchange out = template.send(endpoint, exchange); List<Map<String, Object>> result = out.getOut().getBody(List.class); assertEquals("We should get 3 projects", 3, result.size()); List<Map<String, Object>> generatedKeys = out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA, List.class); assertEquals("We should not get any keys", 0, generatedKeys.size()); assertEquals("We should not get any keys", 0, out.getOut().getHeader(SqlConstants.SQL_GENERATED_KEYS_ROW_COUNT)); }
30. SpringWireTapUsingFireAndForgetTest#testFireAndForgetUsingProcessor()
View licensepublic void testFireAndForgetUsingProcessor() throws Exception { MockEndpoint result = getMockEndpoint("mock:result"); result.expectedBodiesReceived("Hello World"); MockEndpoint foo = getMockEndpoint("mock:foo"); foo.expectedBodiesReceived("Bye World"); foo.expectedHeaderReceived("foo", "bar"); template.sendBody("direct:start2", "Hello World"); assertMockEndpointsSatisfied(); // should be different exchange instances Exchange e1 = result.getReceivedExchanges().get(0); Exchange e2 = foo.getReceivedExchanges().get(0); assertNotSame("Should not be same Exchange", e1, e2); // should have same from endpoint assertEquals("direct://start2", e1.getFromEndpoint().getEndpointUri()); assertEquals("direct://start2", e2.getFromEndpoint().getEndpointUri()); }
31. SpringWireTapUsingFireAndForgetTest#testFireAndForgetUsingExpression()
View licensepublic void testFireAndForgetUsingExpression() throws Exception { MockEndpoint result = getMockEndpoint("mock:result"); result.expectedBodiesReceived("Hello World"); MockEndpoint foo = getMockEndpoint("mock:foo"); foo.expectedBodiesReceived("Bye World"); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); // should be different exchange instances Exchange e1 = result.getReceivedExchanges().get(0); Exchange e2 = foo.getReceivedExchanges().get(0); assertNotSame("Should not be same Exchange", e1, e2); // should have same from endpoint assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); }
32. SpringWireTapUsingFireAndForgetCopyTest#testFireAndForgetUsingProcessor()
View licensepublic void testFireAndForgetUsingProcessor() throws Exception { MockEndpoint result = getMockEndpoint("mock:result"); result.expectedBodiesReceived("World"); MockEndpoint foo = getMockEndpoint("mock:foo"); foo.expectedBodiesReceived("Bye World"); foo.expectedHeaderReceived("foo", "bar"); template.sendBody("direct:start2", "World"); assertMockEndpointsSatisfied(); // should be different exchange instances Exchange e1 = result.getReceivedExchanges().get(0); Exchange e2 = foo.getReceivedExchanges().get(0); assertNotSame("Should not be same Exchange", e1, e2); // should have same from endpoint assertEquals("direct://start2", e1.getFromEndpoint().getEndpointUri()); assertEquals("direct://start2", e2.getFromEndpoint().getEndpointUri()); }
33. SpringWireTapUsingFireAndForgetCopyTest#testFireAndForgetUsingExpression()
View licensepublic void testFireAndForgetUsingExpression() throws Exception { MockEndpoint result = getMockEndpoint("mock:result"); result.expectedBodiesReceived("World"); MockEndpoint foo = getMockEndpoint("mock:foo"); foo.expectedBodiesReceived("Bye World"); template.sendBody("direct:start", "World"); assertMockEndpointsSatisfied(); // should be different exchange instances Exchange e1 = result.getReceivedExchanges().get(0); Exchange e2 = foo.getReceivedExchanges().get(0); assertNotSame("Should not be same Exchange", e1, e2); // should have same from endpoint assertEquals("direct://start", e1.getFromEndpoint().getEndpointUri()); assertEquals("direct://start", e2.getFromEndpoint().getEndpointUri()); }
34. SmppComponentSpringIntegrationTest#sendSubmitSMInOnly()
View license@Test public void sendSubmitSMInOnly() throws Exception { result.expectedMessageCount(1); Exchange exchange = start.createExchange(ExchangePattern.InOnly); exchange.getIn().setBody("Hello SMPP World!"); template.send(start, exchange); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals(SmppMessageType.DeliveryReceipt.toString(), resultExchange.getIn().getHeader(SmppConstants.MESSAGE_TYPE)); assertEquals("Hello SMPP World!", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.ID)); assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.SUBMITTED)); assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.DELIVERED)); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.DONE_DATE)); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.SUBMIT_DATE)); assertNull(resultExchange.getIn().getHeader(SmppConstants.ERROR)); assertNotNull(exchange.getIn().getHeader(SmppConstants.ID)); assertEquals(1, exchange.getIn().getHeader(SmppConstants.SENT_MESSAGE_COUNT)); }
35. SmppComponentSpringIntegrationTest#sendSubmitSMInOut()
View license@Test public void sendSubmitSMInOut() throws Exception { result.expectedMessageCount(1); Exchange exchange = start.createExchange(ExchangePattern.InOut); exchange.getIn().setBody("Hello SMPP World!"); template.send(start, exchange); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals(SmppMessageType.DeliveryReceipt.toString(), resultExchange.getIn().getHeader(SmppConstants.MESSAGE_TYPE)); assertEquals("Hello SMPP World!", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.ID)); assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.SUBMITTED)); assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.DELIVERED)); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.DONE_DATE)); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.SUBMIT_DATE)); assertNull(resultExchange.getIn().getHeader(SmppConstants.ERROR)); assertNotNull(exchange.getOut().getHeader(SmppConstants.ID)); assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT)); }
36. SmppComponentIntegrationTest#sendSubmitSMInOnly()
View license@Test public void sendSubmitSMInOnly() throws Exception { result.expectedMessageCount(1); Exchange exchange = start.createExchange(ExchangePattern.InOnly); exchange.getIn().setBody("Hello SMPP World!"); template.send(start, exchange); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals(SmppMessageType.DeliveryReceipt.toString(), resultExchange.getIn().getHeader(SmppConstants.MESSAGE_TYPE)); assertEquals("Hello SMPP World!", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.ID)); assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.SUBMITTED)); assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.DELIVERED)); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.DONE_DATE)); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.SUBMIT_DATE)); assertNull(resultExchange.getIn().getHeader(SmppConstants.ERROR)); assertNotNull(exchange.getIn().getHeader(SmppConstants.ID)); assertEquals(1, exchange.getIn().getHeader(SmppConstants.SENT_MESSAGE_COUNT)); }
37. SmppComponentIntegrationTest#sendSubmitSMInOut()
View license@Test public void sendSubmitSMInOut() throws Exception { result.expectedMessageCount(1); Exchange exchange = start.createExchange(ExchangePattern.InOut); exchange.getIn().setBody("Hello SMPP World!"); template.send(start, exchange); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals(SmppMessageType.DeliveryReceipt.toString(), resultExchange.getIn().getHeader(SmppConstants.MESSAGE_TYPE)); assertEquals("Hello SMPP World!", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.ID)); assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.SUBMITTED)); assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.DELIVERED)); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.DONE_DATE)); assertNotNull(resultExchange.getIn().getHeader(SmppConstants.SUBMIT_DATE)); assertNull(resultExchange.getIn().getHeader(SmppConstants.ERROR)); assertNotNull(exchange.getOut().getHeader(SmppConstants.ID)); assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT)); }
38. CxfHeaderHelperTest#testPropagateCxfToCamelWithMerged()
View license@Test public void testPropagateCxfToCamelWithMerged() { Exchange exchange = new DefaultExchange(context); exchange.setProperty(CxfConstants.CAMEL_CXF_PROTOCOL_HEADERS_MERGED, Boolean.TRUE); org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl(); Map<String, List<String>> cxfHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); cxfHeaders.put("myfruitheader", Arrays.asList("peach")); cxfHeaders.put("mybrewheader", Arrays.asList("cappuccino", "espresso")); cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, cxfHeaders); Map<String, Object> camelHeaders = exchange.getIn().getHeaders(); CxfHeaderHelper.propagateCxfToCamel(new DefaultHeaderFilterStrategy(), cxfMessage, camelHeaders, exchange); assertEquals("peach", camelHeaders.get("MyFruitHeader")); assertEquals("cappuccino, espresso", camelHeaders.get("MyBrewHeader")); }
39. CxfMessageHeadersRelayTest#doTestOutOutOfBandHeaderCamelTemplate()
View licenseprotected void doTestOutOutOfBandHeaderCamelTemplate(String producerUri) throws Exception { // START SNIPPET: sending Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut); final List<Object> params = new ArrayList<Object>(); Me me = new Me(); me.setFirstName("john"); me.setLastName("Doh"); params.add(me); senderExchange.getIn().setBody(params); senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "outOutOfBandHeader"); Exchange exchange = template.send(producerUri, senderExchange); org.apache.camel.Message out = exchange.getOut(); MessageContentsList result = (MessageContentsList) out.getBody(); assertTrue("Expected the out of band header to propagate but it didn't", result.get(0) != null && ((Me) result.get(0)).getFirstName().equals("pass")); Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>) out.getHeader(Client.RESPONSE_CONTEXT)); assertNotNull(responseContext); validateReturnedOutOfBandHeader(responseContext); }
40. CxfProducerRouterTest#testInvokingSimpleServerWithPayLoadDataFormat()
View license@Test public void testInvokingSimpleServerWithPayLoadDataFormat() throws Exception { Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut); senderExchange.getIn().setBody(REQUEST_PAYLOAD); // We need to specify the operation name to help CxfProducer to look up the BindingOperationInfo senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "echo"); Exchange exchange = template.send("direct:EndpointC", senderExchange); org.apache.camel.Message out = exchange.getOut(); String response = out.getBody(String.class); assertTrue("It should has the echo message", response.indexOf("echo " + TEST_MESSAGE) > 0); assertTrue("It should has the echoResponse tag", response.indexOf("echoResponse") > 0); senderExchange = new DefaultExchange(context, ExchangePattern.InOut); senderExchange.getIn().setBody(REQUEST_PAYLOAD); // Don't specify operation information here exchange = template.send("direct:EndpointC", senderExchange); assertNotNull("Expect exception here.", exchange.getException()); assertTrue(exchange.getException() instanceof IllegalArgumentException); }
41. CxfProducerRouterTest#testInvokingSimpleServerWithMessageDataFormat()
View license@Test public void testInvokingSimpleServerWithMessageDataFormat() throws Exception { Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut); senderExchange.getIn().setBody(REQUEST_MESSAGE); Exchange exchange = template.send("direct:EndpointB", senderExchange); org.apache.camel.Message out = exchange.getOut(); String response = out.getBody(String.class); assertTrue("It should has the echo message", response.indexOf("echo " + TEST_MESSAGE) > 0); assertTrue("It should has the echoResponse tag", response.indexOf("echoResponse") > 0); }
42. CxfProducerRouterTest#testInvokingSimpleServerWithParams()
View license@Test public void testInvokingSimpleServerWithParams() throws Exception { // START SNIPPET: sending Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut); final List<String> params = new ArrayList<String>(); // Prepare the request message for the camel-cxf procedure params.add(TEST_MESSAGE); senderExchange.getIn().setBody(params); senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION); Exchange exchange = template.send("direct:EndpointA", senderExchange); org.apache.camel.Message out = exchange.getOut(); // The response message's body is an MessageContentsList which first element is the return value of the operation, // If there are some holder parameters, the holder parameter will be filled in the reset of List. // The result will be extract from the MessageContentsList with the String class type MessageContentsList result = (MessageContentsList) out.getBody(); LOG.info("Received output text: " + result.get(0)); Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>) out.getHeader(Client.RESPONSE_CONTEXT)); assertNotNull(responseContext); assertEquals("We should get the response context here", "UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING)); assertEquals("Reply body on Camel is wrong", "echo " + TEST_MESSAGE, result.get(0)); // END SNIPPET: sending }
43. SignatureTests#testProvideCertificateInHeader()
View license@Test public void testProvideCertificateInHeader() throws Exception { setupMock(); Exchange unsigned = getMandatoryEndpoint("direct:signature-property").createExchange(); unsigned.getIn().setBody(payload); // create a keypair KeyStore keystore = loadKeystore(); Certificate certificate = keystore.getCertificate("bob"); PrivateKey pk = (PrivateKey) keystore.getKey("bob", "letmein".toCharArray()); // sign with the private key unsigned.getIn().setHeader(SIGNATURE_PRIVATE_KEY, pk); template.send("direct:headerkey-sign", unsigned); // verify with the public key Exchange signed = getMandatoryEndpoint("direct:alias-sign").createExchange(); signed.getIn().copyFrom(unsigned.getOut()); signed.getIn().setHeader(SIGNATURE_PUBLIC_KEY_OR_CERT, certificate); template.send("direct:headerkey-verify", signed); assertMockEndpointsSatisfied(); }
44. SignatureTests#testProvideKeysInHeader()
View license@Test public void testProvideKeysInHeader() throws Exception { setupMock(); Exchange unsigned = getMandatoryEndpoint("direct:headerkey-sign").createExchange(); unsigned.getIn().setBody(payload); // create a keypair KeyPair pair = getKeyPair("DSA"); // sign with the private key unsigned.getIn().setHeader(SIGNATURE_PRIVATE_KEY, pair.getPrivate()); template.send("direct:headerkey-sign", unsigned); // verify with the public key Exchange signed = getMandatoryEndpoint("direct:alias-sign").createExchange(); signed.getIn().copyFrom(unsigned.getOut()); signed.getIn().setHeader(SIGNATURE_PUBLIC_KEY_OR_CERT, pair.getPublic()); template.send("direct:headerkey-verify", signed); assertMockEndpointsSatisfied(); }
45. SignatureTests#testProvideAliasInHeader()
View license@Test public void testProvideAliasInHeader() throws Exception { setupMock(); // START SNIPPET: alias-send Exchange unsigned = getMandatoryEndpoint("direct:alias-sign").createExchange(); unsigned.getIn().setBody(payload); unsigned.getIn().setHeader(DigitalSignatureConstants.KEYSTORE_ALIAS, "bob"); unsigned.getIn().setHeader(DigitalSignatureConstants.KEYSTORE_PASSWORD, "letmein".toCharArray()); template.send("direct:alias-sign", unsigned); Exchange signed = getMandatoryEndpoint("direct:alias-sign").createExchange(); signed.getIn().copyFrom(unsigned.getOut()); signed.getIn().setHeader(KEYSTORE_ALIAS, "bob"); template.send("direct:alias-verify", signed); // START SNIPPET: alias-send assertMockEndpointsSatisfied(); }
46. NamedCassandraAggregationRepositoryTest#testRecover()
View license@Test public void testRecover() { // Given String[] keys = { "Recover1", "Recover2" }; addExchanges(keys); // When Exchange exchange2 = aggregationRepository.recover(camelContext, "Exchange-Recover2"); Exchange exchange3 = aggregationRepository.recover(camelContext, "Exchange-Recover3"); // Then assertNotNull(exchange2); assertNull(exchange3); }
47. NamedCassandraAggregationRepositoryTest#testGetExists()
View license@Test public void testGetExists() { // Given String key = "Get_Exists"; Exchange exchange = new DefaultExchange(camelContext); aggregationRepository.add(camelContext, key, exchange); assertTrue(exists(key)); // When Exchange exchange2 = aggregationRepository.get(camelContext, key); // Then assertNotNull(exchange2); assertEquals(exchange.getExchangeId(), exchange2.getExchangeId()); }
48. CassandraAggregationRepositoryTest#testRecover()
View license@Test public void testRecover() { // Given String[] keys = { "Recover1", "Recover2" }; addExchanges(keys); // When Exchange exchange2 = aggregationRepository.recover(camelContext, "Exchange-Recover2"); Exchange exchange3 = aggregationRepository.recover(camelContext, "Exchange-Recover3"); // Then assertNotNull(exchange2); assertNull(exchange3); }
49. CassandraAggregationRepositoryTest#testGetExists()
View license@Test public void testGetExists() { // Given String key = "Get_Exists"; Exchange exchange = new DefaultExchange(camelContext); aggregationRepository.add(camelContext, key, exchange); assertTrue(exists(key)); // When Exchange exchange2 = aggregationRepository.get(camelContext, key); // Then assertNotNull(exchange2); assertEquals(exchange.getExchangeId(), exchange2.getExchangeId()); }
50. SqsComponentTest#sendInOut()
View license@Test public void sendInOut() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOut, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); assertEquals("This is my message text.", exchange.getOut().getBody()); assertNotNull(exchange.getOut().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getOut().getHeader(SqsConstants.MD5_OF_BODY)); }
51. SqsComponentTest#sendInOnly()
View license@Test public void sendInOnly() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); assertEquals("This is my message text.", exchange.getIn().getBody()); assertNotNull(exchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); }
52. SqsComponentSpringTest#sendInOut()
View license@Test public void sendInOut() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOut, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); assertNotNull(exchange.getOut().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getOut().getHeader(SqsConstants.MD5_OF_BODY)); }
53. SqsComponentSpringTest#sendInOnly()
View license@Test public void sendInOnly() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); assertNotNull(exchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); }
54. SqsComponentIntegrationTest#sendInOut()
View license@Test public void sendInOut() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOut, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); assertNotNull(exchange.getOut().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getOut().getHeader(SqsConstants.MD5_OF_BODY)); }
55. SqsComponentIntegrationTest#sendInOnly()
View license@Test public void sendInOnly() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", resultExchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.ATTRIBUTES)); assertNotNull(resultExchange.getIn().getHeader(SqsConstants.MESSAGE_ATTRIBUTES)); assertNotNull(exchange.getIn().getHeader(SqsConstants.MESSAGE_ID)); assertEquals("6a1559560f67c5e7a7d5d838bf0272ee", exchange.getIn().getHeader(SqsConstants.MD5_OF_BODY)); }
56. Jt400DataQueueConsumer#receive()
View licenseprivate Exchange receive(DataQueue queue, long timeout) throws Exception { DataQueueEntry entry; if (timeout >= 0) { int seconds = (int) timeout / 1000; log.trace("Reading from data queue: {} with {} seconds timeout", queue.getName(), seconds); entry = queue.read(seconds); } else { log.trace("Reading from data queue: {} with no timeout", queue.getName()); entry = queue.read(-1); } Exchange exchange = new DefaultExchange(endpoint.getCamelContext()); exchange.setFromEndpoint(endpoint); if (entry != null) { exchange.getIn().setHeader(Jt400Endpoint.SENDER_INFORMATION, entry.getSenderInformation()); if (endpoint.getFormat() == Jt400Configuration.Format.binary) { exchange.getIn().setBody(entry.getData()); } else { exchange.getIn().setBody(entry.getString()); } return exchange; } return null; }
57. HttpJettyProducerTwoEndpointTest#testTwoEndpoints()
View license@Test public void testTwoEndpoints() throws Exception { // these tests does not run well on Windows if (isPlatform("windows")) { return; } // give Jetty time to startup properly Thread.sleep(1000); Exchange a = template.request("direct:a", null); assertNotNull(a); Exchange b = template.request("direct:b", null); assertNotNull(b); assertEquals("Bye cheese", a.getOut().getBody(String.class)); assertEquals(246, a.getOut().getHeader("foo", Integer.class).intValue()); assertEquals("Bye cake", b.getOut().getBody(String.class)); assertEquals(912, b.getOut().getHeader("foo", Integer.class).intValue()); assertEquals(5, context.getEndpoints().size()); }
58. HttpTwoEndpointTest#testTwoEndpoints()
View license@Test public void testTwoEndpoints() throws Exception { Exchange a = template.request("direct:a", null); assertNotNull(a); Exchange b = template.request("direct:b", null); assertNotNull(b); assertEquals("Bye cheese", a.getOut().getBody(String.class)); assertEquals(246, a.getOut().getHeader("foo", Integer.class).intValue()); assertEquals("Bye cake", b.getOut().getBody(String.class)); assertEquals(912, b.getOut().getHeader("foo", Integer.class).intValue()); assertEquals(5, context.getEndpoints().size()); }
59. JdbcRSMetaDataTest#testJdbcRSMetaData()
View license@Test @SuppressWarnings("unchecked") public void testJdbcRSMetaData() { Endpoint directHelloEndpoint = context.getEndpoint("direct:hello"); Exchange directHelloExchange = directHelloEndpoint.createExchange(); directHelloExchange.getIn().setBody("select * from customer order by ID"); Exchange out = template.send(directHelloEndpoint, directHelloExchange); assertNotNull(out); assertNotNull(out.getOut()); List<Map<String, Object>> returnValues = out.getOut().getBody(List.class); assertNotNull(returnValues); assertEquals(3, returnValues.size()); Map<String, Object> row = returnValues.get(0); assertEquals("cust1", row.get("ID")); assertEquals("jstrachan", row.get("NAME")); Set<String> columnNames = (Set<String>) out.getOut().getHeader(JdbcConstants.JDBC_COLUMN_NAMES); assertNotNull(columnNames); assertEquals(2, columnNames.size()); assertTrue(columnNames.contains("ID")); assertTrue(columnNames.contains("NAME")); }
60. JcrProducerTest#testNodeTypeIsSpecified()
View license@Test public void testNodeTypeIsSpecified() throws Exception { Exchange exchange = createExchangeWithBody("Test"); //there is no definition of such property in nt:resource exchange.getIn().removeHeader("testClass"); exchange.getIn().setHeader(JcrConstants.JCR_NODE_NAME, "typedNode"); exchange.getIn().setHeader(JcrConstants.JCR_NODE_TYPE, "nt:folder"); Exchange out = template.send("direct:a", exchange); assertNotNull(out); String uuid = out.getOut().getBody(String.class); Session session = openSession(); try { Node node = session.getNodeByIdentifier(uuid); assertNotNull(node); assertEquals("/home/test/typedNode", node.getPath()); assertEquals("nt:folder", node.getPrimaryNodeType().getName()); } finally { if (session != null && session.isLive()) { session.logout(); } } }
61. JcrProducerTest#testJcrProducer()
View license@Test public void testJcrProducer() throws Exception { Exchange exchange = createExchangeWithBody("<hello>world!</hello>"); exchange.getIn().setHeader(JcrConstants.JCR_NODE_NAME, "node"); exchange.getIn().setHeader("my.contents.property", exchange.getIn().getBody()); Exchange out = template.send("direct:a", exchange); assertNotNull(out); String uuid = out.getOut().getBody(String.class); Session session = openSession(); try { Node node = session.getNodeByIdentifier(uuid); assertNotNull(node); assertEquals("/home/test/node", node.getPath()); assertEquals("<hello>world!</hello>", node.getProperty("my.contents.property").getString()); } finally { if (session != null && session.isLive()) { session.logout(); } } }
62. JcrProducerDifferentWorkspaceTest#testJcrProducer()
View license@Test public void testJcrProducer() throws Exception { Exchange exchange = createExchangeWithBody("<hello>world!</hello>"); Exchange out = template.send("direct:a", exchange); assertNotNull(out); String uuid = out.getOut().getBody(String.class); Session session = openSession(CUSTOM_WORKSPACE_NAME); try { Node node = session.getNodeByIdentifier(uuid); Workspace workspace = session.getWorkspace(); assertEquals(CUSTOM_WORKSPACE_NAME, workspace.getName()); assertNotNull(node); assertEquals("/home/test/node", node.getPath()); assertEquals("<hello>world!</hello>", node.getProperty("my.contents.property").getString()); } finally { if (session != null && session.isLive()) { session.logout(); } } }
63. JcrNodePathCreationTest#testJcrNodePathCreationMultiValued()
View license@Test public void testJcrNodePathCreationMultiValued() throws Exception { Exchange exchange = createExchangeWithBody(multiValued); Exchange out = template.send("direct:a", exchange); assertNotNull(out); String uuid = out.getOut().getBody(String.class); assertNotNull("Out body was null; expected JCR node UUID", uuid); Session session = openSession(); try { Node node = session.getNodeByIdentifier(uuid); assertNotNull(node); assertEquals("/home/test/node/with/path", node.getPath()); assertTrue(node.getProperty("my.contents.property").isMultiple()); assertArrayEquals(multiValued, node.getProperty("my.contents.property").getValues()); } finally { if (session != null && session.isLive()) { session.logout(); } } }
64. JcrNodePathCreationTest#testJcrNodePathCreation()
View license@Test public void testJcrNodePathCreation() throws Exception { Exchange exchange = createExchangeWithBody("<body/>"); Exchange out = template.send("direct:a", exchange); assertNotNull(out); String uuid = out.getOut().getBody(String.class); assertNotNull("Out body was null; expected JCR node UUID", uuid); Session session = openSession(); try { Node node = session.getNodeByIdentifier(uuid); assertNotNull(node); assertEquals("/home/test/node/with/path", node.getPath()); } finally { if (session != null && session.isLive()) { session.logout(); } } }
65. JcrAuthLoginTest#testCreateNodeWithAuthentication()
View license@Test public void testCreateNodeWithAuthentication() throws Exception { Exchange exchange = createExchangeWithBody("<message>hello!</message>"); Exchange out = template.send("direct:a", exchange); assertNotNull(out); String uuid = out.getOut().getBody(String.class); assertNotNull("Out body was null; expected JCR node UUID", uuid); Session session = getRepository().login(new SimpleCredentials("admin", "admin".toCharArray())); try { Node node = session.getNodeByIdentifier(uuid); assertNotNull(node); assertEquals(BASE_REPO_PATH + "/node", node.getPath()); } finally { if (session != null && session.isLive()) { session.logout(); } } }
66. CamelJaxbFallbackConverterTest#testConverter()
View license@Test public void testConverter() throws Exception { TypeConverter converter = context.getTypeConverter(); PersonType person = converter.convertTo(PersonType.class, "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>"); assertNotNull("Person should not be null ", person); assertEquals("Get the wrong first name ", "FOO", person.getFirstName()); assertEquals("Get the wrong second name ", "BAR", person.getLastName()); Exchange exchange = new DefaultExchange(context); exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8"); String value = converter.convertTo(String.class, exchange, person); assertTrue("Should get a right marshalled string", value.indexOf("<lastName>BAR</lastName>") > 0); byte[] buffers = "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>".getBytes("UTF-8"); InputStream is = new ByteArrayInputStream(buffers); try { converter.convertTo(PersonType.class, exchange, is); fail("Should have thrown exception"); } catch (TypeConversionException e) { } }
67. CamelJaxbFallbackConverterTest#testFallbackConverterWithoutObjectFactory()
View license@Test public void testFallbackConverterWithoutObjectFactory() throws Exception { TypeConverter converter = context.getTypeConverter(); Foo foo = converter.convertTo(Foo.class, "<foo><zot name=\"bar1\" value=\"value\" otherValue=\"otherValue\"/></foo>"); assertNotNull("foo should not be null", foo); assertEquals("value", foo.getBarRefs().get(0).getValue()); foo.getBarRefs().clear(); Bar bar = new Bar(); bar.setName("myName"); bar.setValue("myValue"); foo.getBarRefs().add(bar); Exchange exchange = new DefaultExchange(context); exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8"); String value = converter.convertTo(String.class, exchange, foo); assertTrue("Should get a right marshalled string", value.indexOf("<bar name=\"myName\" value=\"myValue\"/>") > 0); }
68. IronMQComponentTest#sendInOut()
View license@Test public void sendInOut() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOut, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(IronMQConstants.MESSAGE_ID)); assertEquals("This is my message text.", exchange.getOut().getBody()); assertNotNull(exchange.getOut().getHeader(IronMQConstants.MESSAGE_ID)); }
69. IronMQComponentTest#sendInOnly()
View license@Test public void sendInOnly() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(IronMQConstants.MESSAGE_ID)); assertEquals("This is my message text.", exchange.getIn().getBody()); assertNotNull(exchange.getIn().getHeader(IronMQConstants.MESSAGE_ID)); }
70. IronMQComponentSpringTest#sendInOnly()
View license@Test public void sendInOnly() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(IronMQConstants.MESSAGE_ID)); assertNotNull(exchange.getIn().getHeader(IronMQConstants.MESSAGE_ID)); }
71. ManagedBrowsableEndpoint#browseExchange()
View license@Override public String browseExchange(Integer index) { List<Exchange> exchanges = getEndpoint().getExchanges(); if (index >= exchanges.size()) { return null; } Exchange exchange = exchanges.get(index); if (exchange == null) { return null; } // must use java type with JMX such as java.lang.String return exchange.toString(); }
72. ManagedBrowsableEndpoint#browseMessageBody()
View license@Override public String browseMessageBody(Integer index) { List<Exchange> exchanges = getEndpoint().getExchanges(); if (index >= exchanges.size()) { return null; } Exchange exchange = exchanges.get(index); if (exchange == null) { return null; } // must use java type with JMX such as java.lang.String String body; if (exchange.hasOut()) { body = exchange.getOut().getBody(String.class); } else { body = exchange.getIn().getBody(String.class); } return body; }
73. Enricher#createResourceExchange()
View license/** * Creates a new {@link DefaultExchange} instance from the given * <code>exchange</code>. The resulting exchange's pattern is defined by * <code>pattern</code>. * * @param source exchange to copy from. * @param pattern exchange pattern to set. * @return created exchange. */ protected Exchange createResourceExchange(Exchange source, ExchangePattern pattern) { // copy exchange, and do not share the unit of work Exchange target = ExchangeHelper.createCorrelatedCopy(source, false); target.setPattern(pattern); // if we share unit of work, we need to prepare the resource exchange if (isShareUnitOfWork()) { target.setProperty(Exchange.PARENT_UNIT_OF_WORK, source.getUnitOfWork()); // and then share the unit of work target.setUnitOfWork(source.getUnitOfWork()); } return target; }
74. RoutingSlip#prepareExchangeForRoutingSlip()
View licenseprotected Exchange prepareExchangeForRoutingSlip(Exchange current, Endpoint endpoint) { Exchange copy = new DefaultExchange(current); // we must use the same id as this is a snapshot strategy where Camel copies a snapshot // before processing the next step in the pipeline, so we have a snapshot of the exchange // just before. This snapshot is used if Camel should do redeliveries (re try) using // DeadLetterChannel. That is why it's important the id is the same, as it is the *same* // exchange being routed. copy.setExchangeId(current.getExchangeId()); copyOutToIn(copy, current); // ensure stream caching is reset MessageHelper.resetStreamCache(copy.getIn()); return copy; }
75. BeanInfoAMoreComplexOverloadedTest#testRequestA()
View licensepublic void testRequestA() throws Exception { BeanInfo beanInfo = new BeanInfo(context, Bean.class); Message message = new DefaultMessage(); message.setBody(new RequestA()); Exchange exchange = new DefaultExchange(context); exchange.setIn(message); MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange); Method method = methodInvocation.getMethod(); assertEquals("doSomething", method.getName()); assertEquals(RequestA.class, method.getGenericParameterTypes()[0]); }
76. BeanInfoAMoreComplexOverloadedTest#testRequestB()
View licensepublic void testRequestB() throws Exception { BeanInfo beanInfo = new BeanInfo(context, Bean.class); Message message = new DefaultMessage(); message.setBody(new RequestB()); Exchange exchange = new DefaultExchange(context); exchange.setIn(message); MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange); Method method = methodInvocation.getMethod(); assertEquals("doSomething", method.getName()); assertEquals(RequestB.class, method.getGenericParameterTypes()[0]); }
77. BeanInfoAMoreComplexOverloadedTest#testAmbigious()
View licensepublic void testAmbigious() throws Exception { BeanInfo beanInfo = new BeanInfo(context, Bean.class); Message message = new DefaultMessage(); message.setBody("Hello World"); Exchange exchange = new DefaultExchange(context); exchange.setIn(message); try { beanInfo.createInvocation(new Bean(), exchange); fail("Should have thrown an exception"); } catch (AmbiguousMethodCallException e) { assertEquals(2, e.getMethods().size()); } }
78. BeanInfoOverloadedTest#testBeanInfoOverloaded()
View licensepublic void testBeanInfoOverloaded() throws Exception { BeanInfo beanInfo = new BeanInfo(context, Bean.class); Message message = new DefaultMessage(); message.setBody(new RequestB()); Exchange exchange = new DefaultExchange(context); exchange.setIn(message); MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange); Method method = methodInvocation.getMethod(); assertEquals("doSomething", method.getName()); assertEquals(RequestB.class, method.getGenericParameterTypes()[0]); }
79. FileConsumeTemplateTest#testConsumeFileWithTemplate()
View licensepublic void testConsumeFileWithTemplate() throws Exception { template.sendBodyAndHeader("file://target/template", "Hello World", Exchange.FILE_NAME, "hello.txt"); template.sendBodyAndHeader("file://target/template", "Bye World", Exchange.FILE_NAME, "bye.txt"); Exchange out = consumer.receive("file://target/template?sortBy=file:name"); assertNotNull(out); Exchange out2 = consumer.receive("file://target/template?sortBy=file:name"); assertNotNull(out2); String body = out.getIn().getBody(String.class); String body2 = out2.getIn().getBody(String.class); assertEquals("Bye World", body); assertEquals("Hello World", body2); }
80. CollectionProducerTest#testCollectionProducer()
View licensepublic void testCollectionProducer() throws Exception { Queue<Exchange> queue = new ArrayBlockingQueue<Exchange>(10); Endpoint endpoint = context.getEndpoint("seda://foo"); MyProducer my = new MyProducer(endpoint, queue); my.start(); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); my.process(exchange); Exchange top = queue.poll(); assertNotNull(top); assertEquals("Hello World", top.getIn().getBody()); }
81. ValidatorRouteTest#testNullHeader()
View licensepublic void testNullHeader() throws Exception { validEndpoint.setExpectedMessageCount(0); Exchange in = resolveMandatoryEndpoint("direct:startNoHeaderException").createExchange(ExchangePattern.InOut); in.getIn().setBody(null); in.getIn().setHeader("headerToValidate", null); Exchange out = template.send("direct:startNoHeaderException", in); MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint); Exception exception = out.getException(); assertTrue("Should be failed", out.isFailed()); assertTrue("Exception should be correct type", exception instanceof NoXmlHeaderValidationException); assertTrue("Exception should mention missing header", exception.getMessage().contains("headerToValidate")); }
82. IOConverterTest#testToInputStreamStringBufferAndBuilderExchange()
View licensepublic void testToInputStreamStringBufferAndBuilderExchange() throws Exception { Exchange exchange = new DefaultExchange(context); exchange.setProperty(Exchange.CHARSET_NAME, ObjectHelper.getDefaultCharacterSet()); StringBuffer buffer = new StringBuffer(); buffer.append("Hello World"); InputStream is = IOConverter.toInputStream(buffer, exchange); assertNotNull(is); assertEquals("Hello World", IOConverter.toString(is, exchange)); StringBuilder builder = new StringBuilder(); builder.append("Hello World"); is = IOConverter.toInputStream(builder, exchange); assertNotNull(is); assertEquals("Hello World", IOConverter.toString(is, exchange)); }
83. StAX2SAXSourceTest#testDefaultPrefixInRootElementWithCopyTransformer()
View licensepublic void testDefaultPrefixInRootElementWithCopyTransformer() throws Exception { TransformerFactory trf = TransformerFactory.newInstance(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLStreamReader reader = context.getTypeConverter().mandatoryConvertTo(XMLStreamReader.class, new StringReader(TEST_XML)); // ensure UTF-8 encoding Exchange exchange = new DefaultExchange(context); exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.toString()); XMLStreamWriter writer = context.getTypeConverter().mandatoryConvertTo(XMLStreamWriter.class, exchange, baos); StAX2SAXSource staxSource = new StAX2SAXSource(reader); StreamSource templateSource = new StreamSource(getClass().getResourceAsStream("/xslt/common/copy.xsl")); Transformer transformer = trf.newTransformer(templateSource); log.info("Used transformer: {}", transformer.getClass().getName()); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(staxSource, new StreamResult(baos)); writer.flush(); baos.flush(); assertThat(new String(baos.toByteArray()), equalTo(TEST_XML)); }
84. DefaultExchangeHolderTest#testCaughtException()
View licensepublic void testCaughtException() throws Exception { // use a mixed list, the MyFoo is not serializable so the entire list should be skipped List<Object> list = new ArrayList<Object>(); list.add("I am okay"); list.add(new MyFoo("Tiger")); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); exchange.getIn().setHeader("Foo", list); exchange.getIn().setHeader("Bar", 123); exchange.setProperty(Exchange.EXCEPTION_CAUGHT, new IllegalArgumentException("Forced")); DefaultExchangeHolder holder = DefaultExchangeHolder.marshal(exchange); exchange = new DefaultExchange(context); DefaultExchangeHolder.unmarshal(exchange, holder); // the caught exception should be included assertEquals("Hello World", exchange.getIn().getBody()); assertEquals(123, exchange.getIn().getHeader("Bar")); assertNull(exchange.getIn().getHeader("Foo")); assertNotNull(exchange.getProperty(Exchange.EXCEPTION_CAUGHT)); assertEquals("Forced", exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class).getMessage()); }
85. ZooKeeperProducerTest#testRoundtripOfDataToAndFromZnode()
View license@Test public void testRoundtripOfDataToAndFromZnode() throws Exception { MockEndpoint mock = getMockEndpoint("mock:consumed-from-node"); MockEndpoint pipeline = getMockEndpoint("mock:producer-out"); mock.expectedMessageCount(1); pipeline.expectedMessageCount(1); Exchange e = createExchangeWithBody(testPayload); e.setPattern(ExchangePattern.InOut); template.send("direct:roundtrip", e); assertMockEndpointsSatisfied(); }
86. ZooKeeperProducerTest#createWithOtherCreateMode()
View license@Test public void createWithOtherCreateMode() throws Exception { MockEndpoint mock = getMockEndpoint("mock:create-mode"); mock.expectedMessageCount(1); Exchange e = createExchangeWithBody(testPayload); e.setPattern(ExchangePattern.InOut); template.send("direct:create-mode", e); assertMockEndpointsSatisfied(); Stat s = mock.getReceivedExchanges().get(0).getIn().getHeader(ZooKeeperMessage.ZOOKEEPER_STATISTICS, Stat.class); assertEquals(s.getEphemeralOwner(), 0); }
87. IronMQComponentSpringTest#sendInOut()
View license@Test public void sendInOut() throws Exception { result.expectedMessageCount(1); Exchange exchange = template.send("direct:start", ExchangePattern.InOut, new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody("This is my message text."); } }); assertMockEndpointsSatisfied(); Exchange resultExchange = result.getExchanges().get(0); assertEquals("This is my message text.", resultExchange.getIn().getBody()); assertNotNull(resultExchange.getIn().getHeader(IronMQConstants.MESSAGE_ID)); assertNotNull(exchange.getOut().getHeader(IronMQConstants.MESSAGE_ID)); }
88. ZooKeeperProducerTest#deleteNode()
View license@Test public void deleteNode() throws Exception { MockEndpoint mock = getMockEndpoint("mock:delete"); mock.expectedMessageCount(1); client.createPersistent("/to-be-deleted", "to be deleted"); Exchange e = createExchangeWithBody(null); e.setPattern(ExchangePattern.InOut); e.getIn().setHeader(ZOOKEEPER_OPERATION, "DELETE"); template.send("direct:delete", e); assertMockEndpointsSatisfied(); assertNull(client.getConnection().exists("/to-be-deleted", false)); }
89. ZooKeeperProducerTest#setAndGetListing()
View license@Test public void setAndGetListing() throws Exception { client.createPersistent("/set-listing", "parent for set and list test"); Exchange exchange = createExchangeWithBody(testPayload); exchange.getIn().setHeader(ZOOKEEPER_NODE, "/set-listing/firstborn"); exchange.setPattern(ExchangePattern.InOut); template.send("zookeeper://localhost:" + getServerPort() + "/set-listing?create=true&listChildren=true", exchange); List<?> children = exchange.getOut().getMandatoryBody(List.class); assertEquals(1, children.size()); assertEquals("firstborn", children.get(0)); }
90. ContentBasedRouterTest#testWhen()
View license@Test public void testWhen() throws Exception { MockEndpoint mockCamel = getMockEndpoint("mock:camel"); mockCamel.expectedMessageCount(2); mockCamel.message(0).body().isEqualTo("Camel Rocks"); mockCamel.message(0).header("verified").isEqualTo(true); mockCamel.message(0).arrives().noLaterThan(50).millis().beforeNext(); mockCamel.message(0).simple("${header[verified]} == true"); MockEndpoint mockOther = getMockEndpoint("mock:other"); mockOther.expectedMessageCount(0); template.sendBody("direct:start", "Camel Rocks"); template.sendBody("direct:start", "Loving the Camel"); mockCamel.assertIsSatisfied(); mockOther.assertIsSatisfied(); Exchange exchange0 = mockCamel.assertExchangeReceived(0); Exchange exchange1 = mockCamel.assertExchangeReceived(1); assertEquals(exchange0.getIn().getHeader("verified"), exchange1.getIn().getHeader("verified")); }
91. AbstractCamelProvisioningManager#sendMessage()
View licenseprotected void sendMessage(final String uri, final Object body, final Map<String, Object> properties) { Exchange exchange = new DefaultExchange(getContext()); for (Map.Entry<String, Object> property : properties.entrySet()) { exchange.setProperty(property.getKey(), property.getValue()); LOG.debug("Added property {}", property.getKey()); } DefaultMessage message = new DefaultMessage(); message.setBody(body); exchange.setIn(message); ProducerTemplate template = getContext().createProducerTemplate(); template.send(uri, exchange); }
92. DefaultInflightRepositoryTest#testDefaultInflightRepository()
View licensepublic void testDefaultInflightRepository() throws Exception { InflightRepository repo = new DefaultInflightRepository(); assertEquals(0, repo.size()); Exchange e1 = new DefaultExchange(context); repo.add(e1); assertEquals(1, repo.size()); Exchange e2 = new DefaultExchange(context); repo.add(e2); assertEquals(2, repo.size()); repo.remove(e2); assertEquals(1, repo.size()); repo.remove(e1); assertEquals(0, repo.size()); }
93. DefaultProducerTemplateAsyncTest#testRequestAsync()
View licensepublic void testRequestAsync() throws Exception { Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello"); Future<Exchange> future = template.asyncSend("direct:start", exchange); long start = System.currentTimeMillis(); // you can do other stuff String echo = template.requestBody("direct:echo", "Hi", String.class); assertEquals("HiHi", echo); Exchange result = future.get(); long delta = System.currentTimeMillis() - start; assertEquals("Hello World", result.getIn().getBody()); assertTrue("Should take longer than: " + delta, delta > 250); assertMockEndpointsSatisfied(); }
94. Mina2ConverterTest#testToStringTwoTimes()
View licensepublic void testToStringTwoTimes() throws UnsupportedEncodingException { String in = "Hello World ??"; IoBuffer bb = IoBuffer.wrap(in.getBytes("UTF-8")); Exchange exchange = new DefaultExchange(new DefaultCamelContext()); exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8"); String out = Mina2Converter.toString(bb, exchange); assertEquals("Hello World ??", out); // should NOT be possible to convert to string without affecting the ByteBuffer out = Mina2Converter.toString(bb, exchange); assertEquals("", out); }
95. IOHelperTest#testCharsetName()
View licensepublic void testCharsetName() throws Exception { Exchange exchange = new DefaultExchange((CamelContext) null); assertNull(IOHelper.getCharsetName(exchange, false)); exchange.getIn().setHeader(Exchange.CHARSET_NAME, "iso-8859-1"); assertEquals("iso-8859-1", IOHelper.getCharsetName(exchange, false)); exchange.getIn().removeHeader(Exchange.CHARSET_NAME); exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1"); assertEquals("iso-8859-1", IOHelper.getCharsetName(exchange, false)); }
96. LdapRouteTest#testLdapRouteStandard()
View license@Test public void testLdapRouteStandard() throws Exception { camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system")); camel.start(); // START SNIPPET: invoke Endpoint endpoint = camel.getEndpoint("direct:start"); Exchange exchange = endpoint.createExchange(); // then we set the LDAP filter on the in body exchange.getIn().setBody("(!(ou=test1))"); // now we send the exchange to the endpoint, and receives the response from Camel Exchange out = template.send(endpoint, exchange); Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out); assertFalse(contains("uid=test1,ou=test,ou=system", searchResults)); assertTrue(contains("uid=test2,ou=test,ou=system", searchResults)); assertTrue(contains("uid=testNoOU,ou=test,ou=system", searchResults)); assertTrue(contains("uid=tcruise,ou=actors,ou=system", searchResults)); // START SNIPPET: invoke }
97. LdapRouteTest#testLdapRouteWithPaging()
View license@Test public void testLdapRouteWithPaging() throws Exception { camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system&pageSize=5")); camel.start(); Endpoint endpoint = camel.getEndpoint("direct:start"); Exchange exchange = endpoint.createExchange(); // then we set the LDAP filter on the in body exchange.getIn().setBody("(objectClass=*)"); // now we send the exchange to the endpoint, and receives the response from Camel Exchange out = template.send(endpoint, exchange); Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out); assertEquals(16, searchResults.size()); }
98. LevelDBGetNotFoundTest#testGetNotFound()
View license@Test public void testGetNotFound() { LevelDBAggregationRepository repo = new LevelDBAggregationRepository(); repo.setLevelDBFile(levelDBFile); repo.setRepositoryName("repo1"); Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody("Hello World"); Exchange out = repo.get(context, exchange.getExchangeId()); assertNull("Should not find exchange", out); }
99. MinaConverterTest#testToStringTwoTimes()
View licensepublic void testToStringTwoTimes() throws UnsupportedEncodingException { String in = "Hello World ??"; ByteBuffer bb = ByteBuffer.wrap(in.getBytes("UTF-8")); Exchange exchange = new DefaultExchange(new DefaultCamelContext()); exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8"); String out = MinaConverter.toString(bb, exchange); assertEquals("Hello World ??", out); // should be possible to convert to string without affecting the ByteBuffer out = MinaConverter.toString(bb, exchange); assertEquals("Hello World ??", out); }
100. InfinispanLocalAggregationRepositoryOperationsTest#testGetExists()
View license@Test public void testGetExists() { // Given String key = "Get_Exists"; Exchange exchange = new DefaultExchange(camelContext); aggregationRepository.add(camelContext, key, exchange); assertTrue(exists(key)); // When Exchange exchange2 = aggregationRepository.get(camelContext, key); // Then assertNotNull(exchange2); assertEquals(exchange.getExchangeId(), exchange2.getExchangeId()); }