org.apache.camel.Exchange

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

1. HawtDBGetNotFoundTest#testPutAndGetNotFound()

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

2. 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);
}

3. LevelDBGetNotFoundTest#testPutAndGetNotFound()

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

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

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

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

7. DefaultConsumerTemplateTest#testReceiveException()

View license
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());
    }
}

8. DefaultProducerTemplateAsyncTest#testAsyncCallbackExchangeInOutGetResult()

View license
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());
}

9. CircuitBreakerLoadBalancerTest#failedMessagesOpenCircuitToPreventMessageThree()

View license
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);
}

10. CryptoDataFormatTest#testKeySuppliedAsHeader()

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

11. CsvMarshalCharsetTest#testMarshal()

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

12. DefaultCxfBindingTest#testPopupalteExchangeFromCxfRequestWithHeaderMerged()

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

13. 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());
}

14. EndpointMessageListener#createExchange()

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

15. 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());
}

16. MinaTransferExchangeOptionTest#sendExchange()

View license
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;
}

17. MinaVMTransferExchangeOptionTest#sendExchange()

View license
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;
}

18. Mina2TransferExchangeOptionTest#sendExchange()

View license
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;
}

19. Mina2VMTransferExchangeOptionTest#sendExchange()

View license
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;
}

20. NettyTransferExchangeOptionTest#sendExchange()

View license
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;
}

21. NettyTransferExchangeOptionTest#sendExchange()

View license
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;
}

22. 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());
}

23. ZooKeeperElection#createCandidateNode()

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

24. ManagedBrowsableEndpoint#browseExchange()

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

25. ManagedBrowsableEndpoint#browseMessageBody()

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

26. Enricher#createResourceExchange()

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

27. RoutingSlip#prepareExchangeForRoutingSlip()

Project: camel
Source File: RoutingSlip.java
View license
protected 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;
}

28. BeanInfoAMoreComplexOverloadedTest#testRequestA()

View license
public 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]);
}

29. BeanInfoAMoreComplexOverloadedTest#testRequestB()

View license
public 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]);
}

30. BeanInfoAMoreComplexOverloadedTest#testAmbigious()

View license
public 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());
    }
}

31. BeanInfoOverloadedTest#testBeanInfoOverloaded()

Project: camel
Source File: BeanInfoOverloadedTest.java
View license
public 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]);
}

32. FileConsumeTemplateTest#testConsumeFileWithTemplate()

Project: camel
Source File: FileConsumeTemplateTest.java
View license
public 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);
}

33. CollectionProducerTest#testCollectionProducer()

Project: camel
Source File: CollectionProducerTest.java
View license
public 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());
}

34. ValidatorRouteTest#testNullHeader()

Project: camel
Source File: ValidatorRouteTest.java
View license
public 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"));
}

35. IOConverterTest#testToInputStreamStringBufferAndBuilderExchange()

Project: camel
Source File: IOConverterTest.java
View license
public 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));
}

36. StAX2SAXSourceTest#testDefaultPrefixInRootElementWithCopyTransformer()

Project: camel
Source File: StAX2SAXSourceTest.java
View license
public 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));
}

37. DefaultExchangeHolderTest#testCaughtException()

View license
public 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());
}

38. DefaultInflightRepositoryTest#testDefaultInflightRepository()

View license
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());
}

39. DefaultProducerTemplateAsyncTest#testRequestAsync()

View license
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();
}

40. DefaultProducerTemplateAsyncTest#testAsyncCallbackExchangeInOut()

View license
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());
}

41. DefaultProducerTemplateAsyncTest#testAsyncCallbackExchangeInOnlyGetResult()

View license
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);
}

42. DefaultProducerTemplateAsyncTest#testAsyncCallbackExchangeInOutWithFailure()

View license
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());
}

43. DefaultProducerTemplateTest#testExceptionUsingExchange()

View license
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();
}

44. DefaultProducerTemplateTest#testRequestExceptionUsingExchange()

View license
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();
}

45. MulticastParallelFailureEndpointTest#runTest()

View license
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;
}

46. PipelineMEPTest#testInOnly()

Project: camel
Source File: PipelineMEPTest.java
View license
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());
}

47. PipelineMEPTest#testInOut()

Project: camel
Source File: PipelineMEPTest.java
View license
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());
}

48. RemoveHeaderTest#testSetHeaderMidRouteThenRemove()

Project: camel
Source File: RemoveHeaderTest.java
View license
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));
}

49. RemovePropertiesWithoutExclusionTest#testSetExchangePropertiesMidRouteThenRemoveWithPattern()

View license
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));
}

50. RemovePropertyTest#testSetExchangePropertyMidRouteThenRemove()

Project: camel
Source File: RemovePropertyTest.java
View license
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));
}

51. UnmarshalProcessorTest#testDataFormatReturnsAnotherExchange()

Project: camel
Source File: UnmarshalProcessorTest.java
View license
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());
}

52. ExpressionListComparatorTest#testExpressionListComparator()

View license
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);
}

53. IOHelperTest#testCharsetName()

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

54. 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));
}

55. 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));
}

56. SqsComponentSpringTest#sendInOnly()

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

57. SqsComponentSpringTest#sendInOut()

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

58. SqsComponentTest#sendInOnly()

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

59. SqsComponentTest#sendInOut()

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

60. 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());
}

61. 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);
}

62. 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());
}

63. 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);
}

64. SignatureTests#testProvideAliasInHeader()

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

65. SignatureTests#testProvideKeysInHeader()

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

66. SignatureTests#testProvideCertificateInHeader()

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

67. CxfProducerRouterTest#testInvokingSimpleServerWithParams()

Project: camel
Source File: CxfProducerRouterTest.java
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
}

68. CxfProducerRouterTest#testInvokingSimpleServerWithMessageDataFormat()

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

69. CxfProducerRouterTest#testInvokingSimpleServerWithPayLoadDataFormat()

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

70. DefaultCxfBindingTest#testPopupalteExchangeFromCxfResponseOfNullBody()

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

71. CxfMessageHeadersRelayTest#doTestOutOutOfBandHeaderCamelTemplate()

View license
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);
}

72. CxfHeaderHelperTest#testPropagateCxfToCamelWithMerged()

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

73. 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());
}

74. 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);
}

75. 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);
}

76. HawtDBGetNotFoundTest#testGetNotFound()

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

77. 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());
}

78. InfinispanLocalAggregationRepositoryOperationsTest#testRecover()

View license
@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);
}

79. 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));
}

80. 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));
}

81. IronMQComponentTest#sendInOnly()

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

82. IronMQComponentTest#sendInOut()

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

83. 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);
}

84. 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) {
    }
}

85. JcrAuthLoginTest#testCreateNodeWithAuthentication()

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

86. JcrNodePathCreationTest#testJcrNodePathCreation()

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

87. JcrNodePathCreationTest#testJcrNodePathCreationMultiValued()

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

88. 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();
        }
    }
}

89. JcrProducerTest#testJcrProducer()

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

90. JcrProducerTest#testNodeTypeIsSpecified()

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

91. JdbcRSMetaDataTest#testJdbcRSMetaData()

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

92. HttpTwoEndpointTest#testTwoEndpoints()

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

93. 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());
}

94. Jt400DataQueueConsumer#receive()

Project: camel
Source File: Jt400DataQueueConsumer.java
View license
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;
}

95. LdapRouteTest#testLdapRouteStandard()

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

96. LdapRouteTest#testLdapRouteWithPaging()

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

97. LevelDBGetNotFoundTest#testGetNotFound()

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

98. MinaConverterTest#testToStringTwoTimes()

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

99. Mina2ConverterTest#testToStringTwoTimes()

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

100. NettyHttpEndpoint#createExchange()

Project: camel
Source File: NettyHttpEndpoint.java
View license
@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;
}