org.apache.camel.Exchange

Here are the examples of the java api class org.apache.camel.Exchange taken from open source projects.

1. LevelDBGetNotFoundTest#testPutAndGetNotFound()

Project: camel
File: LevelDBGetNotFoundTest.java
@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);
}

2. HawtDBGetNotFoundTest#testPutAndGetNotFound()

Project: camel
File: HawtDBGetNotFoundTest.java
@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. CamelJaxbFallbackConverterTest#testFilteringConverter()

Project: camel
File: CamelJaxbFallbackConverterTest.java
@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);
}

4. JdbcGetNotFoundTest#testPutAndGetNotFound()

Project: camel
File: JdbcGetNotFoundTest.java
@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. ZooKeeperElection#createCandidateNode()

Project: camel
File: ZooKeeperElection.java
private 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;
}

6. DefaultCxfBindingTest#testPopupalteExchangeFromCxfRequestWithHeaderMerged()

Project: camel
File: DefaultCxfBindingTest.java
@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"));
}

7. CsvMarshalCharsetTest#testMarshal()

Project: camel
File: CsvMarshalCharsetTest.java
@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"));
}

8. CryptoDataFormatTest#testKeySuppliedAsHeader()

Project: camel
File: CryptoDataFormatTest.java
@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);
}

9. HawtDBAggregationRepositoryMultipleRepoTest#testMultipeRepoSameKeyDifferentContent()

Project: camel
File: HawtDBAggregationRepositoryMultipleRepoTest.java
@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());
}

10. JdbcAggregationRepositoryMultipleRepoTest#testMultipeRepoSameKeyDifferentContent()

Project: camel
File: JdbcAggregationRepositoryMultipleRepoTest.java
@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());
}

11. CircuitBreakerLoadBalancerTest#failedMessagesOpenCircuitToPreventMessageThree()

Project: camel
File: CircuitBreakerLoadBalancerTest.java
private 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);
}

12. DefaultProducerTemplateAsyncTest#testAsyncCallbackExchangeInOutGetResult()

Project: camel
File: DefaultProducerTemplateAsyncTest.java
public 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());
}

13. EndpointMessageListener#createExchange()

Project: camel
File: EndpointMessageListener.java
public 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;
}

14. NettyTransferExchangeOptionTest#sendExchange()

Project: camel
File: NettyTransferExchangeOptionTest.java
private 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. NettyTransferExchangeOptionTest#sendExchange()

Project: camel
File: NettyTransferExchangeOptionTest.java
private 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;
}

16. Mina2VMTransferExchangeOptionTest#sendExchange()

Project: camel
File: Mina2VMTransferExchangeOptionTest.java
private 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;
}

17. Mina2TransferExchangeOptionTest#sendExchange()

Project: camel
File: Mina2TransferExchangeOptionTest.java
private 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;
}

18. MinaVMTransferExchangeOptionTest#sendExchange()

Project: camel
File: MinaVMTransferExchangeOptionTest.java
private 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;
}

19. MinaTransferExchangeOptionTest#sendExchange()

Project: camel
File: MinaTransferExchangeOptionTest.java
private 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;
}

20. LevelDBAggregationRepositoryMultipleRepoTest#testMultipeRepoSameKeyDifferentContent()

Project: camel
File: LevelDBAggregationRepositoryMultipleRepoTest.java
@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());
}

21. DefaultConsumerTemplateTest#testReceiveException()

Project: camel
File: DefaultConsumerTemplateTest.java
public 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());
    }
}

22. SedaAsyncProducerTest#testAsyncProducerWait()

Project: camel
File: SedaAsyncProducerTest.java
public 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);
}

23. ExchangeHelper#createCorrelatedCopy()

Project: camel
File: ExchangeHelper.java
/**
     * 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;
}

24. HawtDBGetNotFoundTest#testGetNotFound()

Project: camel
File: HawtDBGetNotFoundTest.java
@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);
}

25. PullRequestFilesProducerTest#testPullRequestFilesProducer()

Project: camel
File: PullRequestFilesProducerTest.java
@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);
}

26. EhcacheAggregationRepositoryOperationTest#testRecover()

Project: camel
File: EhcacheAggregationRepositoryOperationTest.java
@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);
}

27. EhcacheAggregationRepositoryOperationTest#testGetExists()

Project: camel
File: EhcacheAggregationRepositoryOperationTest.java
@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());
}

28. SqlGeneratedKeysTest#testNoKeysForSelect()

Project: camel
File: SqlGeneratedKeysTest.java
@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));
}

29. SpringWireTapUsingFireAndForgetTest#testFireAndForgetUsingProcessor()

Project: camel
File: SpringWireTapUsingFireAndForgetTest.java
public 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());
}

30. SpringWireTapUsingFireAndForgetTest#testFireAndForgetUsingExpression()

Project: camel
File: SpringWireTapUsingFireAndForgetTest.java
public 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());
}

31. SpringWireTapUsingFireAndForgetCopyTest#testFireAndForgetUsingProcessor()

Project: camel
File: SpringWireTapUsingFireAndForgetCopyTest.java
public 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());
}

32. SpringWireTapUsingFireAndForgetCopyTest#testFireAndForgetUsingExpression()

Project: camel
File: SpringWireTapUsingFireAndForgetCopyTest.java
public 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());
}

33. SmppComponentSpringIntegrationTest#sendSubmitSMInOnly()

Project: camel
File: SmppComponentSpringIntegrationTest.java
@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));
}

34. SmppComponentSpringIntegrationTest#sendSubmitSMInOut()

Project: camel
File: SmppComponentSpringIntegrationTest.java
@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));
}

35. SmppComponentIntegrationTest#sendSubmitSMInOnly()

Project: camel
File: SmppComponentIntegrationTest.java
@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));
}

36. SmppComponentIntegrationTest#sendSubmitSMInOut()

Project: camel
File: SmppComponentIntegrationTest.java
@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));
}

37. CxfHeaderHelperTest#testPropagateCxfToCamelWithMerged()

Project: camel
File: CxfHeaderHelperTest.java
@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"));
}

38. CxfMessageHeadersRelayTest#doTestOutOutOfBandHeaderCamelTemplate()

Project: camel
File: CxfMessageHeadersRelayTest.java
protected 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);
}

39. DefaultCxfBindingTest#testPopupalteExchangeFromCxfResponseOfNullBody()

Project: camel
File: DefaultCxfBindingTest.java
@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());
}

40. CxfProducerRouterTest#testInvokingSimpleServerWithPayLoadDataFormat()

Project: camel
File: CxfProducerRouterTest.java
@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()

Project: camel
File: CxfProducerRouterTest.java
@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()

Project: camel
File: CxfProducerRouterTest.java
@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()

Project: camel
File: SignatureTests.java
@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()

Project: camel
File: SignatureTests.java
@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()

Project: camel
File: SignatureTests.java
@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()

Project: camel
File: NamedCassandraAggregationRepositoryTest.java
@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()

Project: camel
File: NamedCassandraAggregationRepositoryTest.java
@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()

Project: camel
File: CassandraAggregationRepositoryTest.java
@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()

Project: camel
File: CassandraAggregationRepositoryTest.java
@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()

Project: camel
File: SqsComponentTest.java
@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()

Project: camel
File: SqsComponentTest.java
@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()

Project: camel
File: SqsComponentSpringTest.java
@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()

Project: camel
File: SqsComponentSpringTest.java
@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()

Project: camel
File: SqsComponentIntegrationTest.java
@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()

Project: camel
File: SqsComponentIntegrationTest.java
@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()

Project: camel
File: Jt400DataQueueConsumer.java
private 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()

Project: camel
File: HttpJettyProducerTwoEndpointTest.java
@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()

Project: camel
File: HttpTwoEndpointTest.java
@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()

Project: camel
File: JdbcRSMetaDataTest.java
@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()

Project: camel
File: JcrProducerTest.java
@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()

Project: camel
File: JcrProducerTest.java
@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()

Project: camel
File: JcrProducerDifferentWorkspaceTest.java
@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()

Project: camel
File: JcrNodePathCreationTest.java
@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()

Project: camel
File: JcrNodePathCreationTest.java
@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()

Project: camel
File: JcrAuthLoginTest.java
@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()

Project: camel
File: CamelJaxbFallbackConverterTest.java
@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()

Project: camel
File: CamelJaxbFallbackConverterTest.java
@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()

Project: camel
File: IronMQComponentTest.java
@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()

Project: camel
File: IronMQComponentTest.java
@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#sendInOut()

Project: camel
File: IronMQComponentSpringTest.java
@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));
}

71. IronMQComponentSpringTest#sendInOnly()

Project: camel
File: IronMQComponentSpringTest.java
@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));
}

72. InfinispanLocalAggregationRepositoryOperationsTest#testRecover()

Project: camel
File: InfinispanLocalAggregationRepositoryOperationsTest.java
@Test
public void testRecover() {
    // Given
    String[] keys = { "Recover1", "Recover2" };
    addExchanges(keys);
    // When
    Exchange exchange2 = aggregationRepository.recover(camelContext, "Recover2");
    Exchange exchange3 = aggregationRepository.recover(camelContext, "Recover3");
    // Then
    assertNotNull(exchange2);
    assertNull(exchange3);
}

73. InfinispanLocalAggregationRepositoryOperationsTest#testGetExists()

Project: camel
File: InfinispanLocalAggregationRepositoryOperationsTest.java
@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());
}

74. NettyHttpEndpoint#createExchange()

Project: camel
File: NettyHttpEndpoint.java
@Override
public Exchange createExchange(ChannelHandlerContext ctx, Object message) throws Exception {
    Exchange exchange = createExchange();
    FullHttpRequest request = (FullHttpRequest) message;
    Message in = getNettyHttpBinding().toCamelMessage(request, exchange, getConfiguration());
    exchange.setIn(in);
    // setup the common message headers 
    updateMessageHeader(in, ctx);
    // honor the character encoding
    String contentType = in.getHeader(Exchange.CONTENT_TYPE, String.class);
    String charset = NettyHttpHelper.getCharsetFromContentType(contentType);
    if (charset != null) {
        exchange.setProperty(Exchange.CHARSET_NAME, charset);
        in.setHeader(Exchange.HTTP_CHARACTER_ENCODING, charset);
    }
    return exchange;
}

75. NettyHttpEndpoint#createExchange()

Project: camel
File: NettyHttpEndpoint.java
@Override
public Exchange createExchange(ChannelHandlerContext ctx, MessageEvent messageEvent) throws Exception {
    Exchange exchange = createExchange();
    // use the http binding
    HttpRequest request = (HttpRequest) messageEvent.getMessage();
    Message in = getNettyHttpBinding().toCamelMessage(request, exchange, getConfiguration());
    exchange.setIn(in);
    // setup the common message headers 
    updateMessageHeader(in, ctx, messageEvent);
    // honor the character encoding
    String contentType = in.getHeader(Exchange.CONTENT_TYPE, String.class);
    String charset = NettyHttpHelper.getCharsetFromContentType(contentType);
    if (charset != null) {
        exchange.setProperty(Exchange.CHARSET_NAME, charset);
        in.setHeader(Exchange.HTTP_CHARACTER_ENCODING, charset);
    }
    return exchange;
}

76. Mina2ConverterTest#testToStringTwoTimes()

Project: camel
File: Mina2ConverterTest.java
public 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);
}

77. MinaConverterTest#testToStringTwoTimes()

Project: camel
File: MinaConverterTest.java
public 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);
}

78. LevelDBGetNotFoundTest#testGetNotFound()

Project: camel
File: LevelDBGetNotFoundTest.java
@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);
}

79. LdapRouteTest#testLdapRouteWithPaging()

Project: camel
File: LdapRouteTest.java
@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());
}

80. LdapRouteTest#testLdapRouteStandard()

Project: camel
File: LdapRouteTest.java
@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
}

81. IOHelperTest#testCharsetName()

Project: camel
File: IOHelperTest.java
public 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));
}

82. ExpressionListComparatorTest#testExpressionListComparator()

Project: camel
File: ExpressionListComparatorTest.java
public void testExpressionListComparator() {
    List<Expression> list = new ArrayList<Expression>();
    list.add(new MyFooExpression());
    list.add(new MyBarExpression());
    ExpressionListComparator comp = new ExpressionListComparator(list);
    Exchange e1 = new DefaultExchange(context);
    Exchange e2 = new DefaultExchange(context);
    int out = comp.compare(e1, e2);
    assertEquals(0, out);
}

83. UnmarshalProcessorTest#testDataFormatReturnsAnotherExchange()

Project: camel
File: UnmarshalProcessorTest.java
public void testDataFormatReturnsAnotherExchange() throws Exception {
    CamelContext context = new DefaultCamelContext();
    Exchange exchange = createExchangeWithBody(context, "body");
    Exchange exchange2 = createExchangeWithBody(context, "body2");
    Processor processor = new UnmarshalProcessor(new MyDataFormat(exchange2));
    processor.process(exchange);
    Exception e = exchange.getException();
    assertNotNull(e);
    assertEquals("The returned exchange " + exchange2 + " is not the same as " + exchange + " provided to the DataFormat", e.getMessage());
}

84. RemovePropertyTest#testSetExchangePropertyMidRouteThenRemove()

Project: camel
File: RemovePropertyTest.java
public void testSetExchangePropertyMidRouteThenRemove() throws Exception {
    mid.expectedMessageCount(1);
    end.expectedMessageCount(1);
    template.sendBody("direct:start", "<blah/>");
    // make sure we got the message
    assertMockEndpointsSatisfied();
    List<Exchange> midExchanges = mid.getExchanges();
    Exchange midExchange = midExchanges.get(0);
    String actualPropertyValue = midExchange.getProperty(propertyName, String.class);
    assertEquals(expectedPropertyValue, actualPropertyValue);
    List<Exchange> endExchanges = end.getExchanges();
    Exchange endExchange = endExchanges.get(0);
    // property should be removed
    assertNull(endExchange.getProperty(propertyName, String.class));
}

85. RemovePropertiesWithoutExclusionTest#testSetExchangePropertiesMidRouteThenRemoveWithPattern()

Project: camel
File: RemovePropertiesWithoutExclusionTest.java
public void testSetExchangePropertiesMidRouteThenRemoveWithPattern() throws Exception {
    mid.expectedMessageCount(1);
    end.expectedMessageCount(1);
    template.sendBody("direct:start", "message");
    // make sure we got the message
    assertMockEndpointsSatisfied();
    List<Exchange> midExchanges = mid.getExchanges();
    Exchange midExchange = midExchanges.get(0);
    String actualPropertyValue = midExchange.getProperty(propertyName, String.class);
    String actualPropertyValue1 = midExchange.getProperty(propertyName1, String.class);
    assertEquals(expectedPropertyValue, actualPropertyValue);
    assertEquals(expectedPropertyValue1, actualPropertyValue1);
    List<Exchange> endExchanges = end.getExchanges();
    Exchange endExchange = endExchanges.get(0);
    // properties should be removed
    assertNull(endExchange.getProperty(propertyName, String.class));
    assertNull(endExchange.getProperty(propertyName1, String.class));
}

86. RemoveHeaderTest#testSetHeaderMidRouteThenRemove()

Project: camel
File: RemoveHeaderTest.java
public void testSetHeaderMidRouteThenRemove() throws Exception {
    mid.expectedMessageCount(1);
    end.expectedMessageCount(1);
    template.sendBody("direct:start", "<blah/>");
    // make sure we got the message
    assertMockEndpointsSatisfied();
    List<Exchange> midExchanges = mid.getExchanges();
    Exchange midExchange = midExchanges.get(0);
    String actualHeaderValue = midExchange.getIn().getHeader(headerName, String.class);
    assertEquals(expectedHeaderValue, actualHeaderValue);
    List<Exchange> endExchanges = end.getExchanges();
    Exchange endExchange = endExchanges.get(0);
    // header should be removed
    assertNull(endExchange.getIn().getHeader(headerName, String.class));
}

87. PipelineMEPTest#testInOut()

Project: camel
File: PipelineMEPTest.java
public void testInOut() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived(3);
    Exchange exchange = context.getEndpoint("direct:a").createExchange(ExchangePattern.InOut);
    exchange.getIn().setBody(1);
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    assertEquals(ExchangePattern.InOut, out.getPattern());
    assertMockEndpointsSatisfied();
    // should keep MEP as InOut
    assertEquals(ExchangePattern.InOut, mock.getExchanges().get(0).getPattern());
}

88. PipelineMEPTest#testInOnly()

Project: camel
File: PipelineMEPTest.java
public void testInOnly() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived(3);
    Exchange exchange = context.getEndpoint("direct:a").createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody(1);
    Exchange out = template.send("direct:a", exchange);
    assertNotNull(out);
    assertEquals(ExchangePattern.InOnly, out.getPattern());
    assertMockEndpointsSatisfied();
    // should keep MEP as InOnly
    assertEquals(ExchangePattern.InOnly, mock.getExchanges().get(0).getPattern());
}

89. MulticastParallelFailureEndpointTest#runTest()

Project: camel
File: MulticastParallelFailureEndpointTest.java
public Exchange runTest(String uri) throws Exception {
    MockEndpoint mr = getMockEndpoint("mock:run");
    MockEndpoint ma = getMockEndpoint("mock:a");
    MockEndpoint mb = getMockEndpoint("mock:b");
    mr.expectedMessageCount(0);
    ma.expectedMessageCount(0);
    mb.expectedMessageCount(1);
    Exchange request = new DefaultExchange(context, ExchangePattern.InOut);
    request.getIn().setBody("Hello World");
    Exchange result = template.send(uri, request);
    assertMockEndpointsSatisfied();
    return result;
}

90. DefaultProducerTemplateTest#testRequestExceptionUsingExchange()

Project: camel
File: DefaultProducerTemplateTest.java
public void testRequestExceptionUsingExchange() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    Exchange exchange = context.getEndpoint("direct:exception").createExchange(ExchangePattern.InOut);
    exchange.getIn().setBody("Hello World");
    Exchange out = template.send("direct:exception", exchange);
    assertTrue(out.isFailed());
    assertEquals("Forced exception by unit test", out.getException().getMessage());
    assertMockEndpointsSatisfied();
}

91. DefaultProducerTemplateTest#testExceptionUsingExchange()

Project: camel
File: DefaultProducerTemplateTest.java
public void testExceptionUsingExchange() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(0);
    Exchange exchange = context.getEndpoint("direct:exception").createExchange();
    exchange.getIn().setBody("Hello World");
    Exchange out = template.send("direct:exception", exchange);
    assertTrue(out.isFailed());
    assertEquals("Forced exception by unit test", out.getException().getMessage());
    assertMockEndpointsSatisfied();
}

92. DefaultProducerTemplateAsyncTest#testAsyncCallbackExchangeInOutWithFailure()

Project: camel
File: DefaultProducerTemplateAsyncTest.java
public void testAsyncCallbackExchangeInOutWithFailure() throws Exception {
    ORDER.set(0);
    final CountDownLatch latch = new CountDownLatch(1);
    Exchange exchange = context.getEndpoint("direct:error").createExchange();
    exchange.getIn().setBody("Hello");
    exchange.setPattern(ExchangePattern.InOut);
    template.asyncCallback("direct:error", exchange, new SynchronizationAdapter() {

        @Override
        public void onFailure(Exchange exchange) {
            assertEquals("Damn forced by unit test", exchange.getException().getMessage());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertEquals(7, ORDER.get());
}

93. DefaultProducerTemplateAsyncTest#testAsyncCallbackExchangeInOnlyGetResult()

Project: camel
File: DefaultProducerTemplateAsyncTest.java
public void testAsyncCallbackExchangeInOnlyGetResult() throws Exception {
    ORDER.set(0);
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    Exchange exchange = context.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody("Hello");
    Future<Exchange> future = template.asyncCallback("direct:start", exchange, new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("Hello World", exchange.getIn().getBody());
            ORDER.addAndGet(2);
        }
    });
    ORDER.addAndGet(1);
    Exchange reply = future.get(10, TimeUnit.SECONDS);
    ORDER.addAndGet(4);
    assertMockEndpointsSatisfied();
    assertEquals(7, ORDER.get());
    assertNotNull(reply);
}

94. DefaultProducerTemplateAsyncTest#testAsyncCallbackExchangeInOut()

Project: camel
File: DefaultProducerTemplateAsyncTest.java
public void testAsyncCallbackExchangeInOut() throws Exception {
    ORDER.set(0);
    final CountDownLatch latch = new CountDownLatch(1);
    Exchange exchange = context.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody("Hello");
    exchange.setPattern(ExchangePattern.InOut);
    template.asyncCallback("direct:echo", exchange, new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("HelloHello", exchange.getOut().getBody());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertEquals(7, ORDER.get());
}

95. DefaultProducerTemplateAsyncTest#testRequestAsync()

Project: camel
File: DefaultProducerTemplateAsyncTest.java
public 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();
}

96. DefaultInflightRepositoryTest#testDefaultInflightRepository()

Project: camel
File: DefaultInflightRepositoryTest.java
public 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());
}

97. AbstractCamelProvisioningManager#sendMessage()

Project: syncope
File: AbstractCamelProvisioningManager.java
protected 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);
}

98. ContentBasedRouterTest#testWhen()

Project: camel-cookbook-examples
File: ContentBasedRouterTest.java
@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"));
}

99. ZooKeeperProducerTest#setAndGetListing()

Project: camel
File: ZooKeeperProducerTest.java
@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));
}

100. ZooKeeperProducerTest#deleteNode()

Project: camel
File: ZooKeeperProducerTest.java
@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));
}