Search in sources :

Example 76 with HashMap

use of java.util.HashMap in project camel by apache.

the class DefaultProducerTemplateTest method testRequestBody.

public void testRequestBody() throws Exception {
    // with endpoint as string uri
    Integer out = template.requestBody("direct:inout", "Hello", Integer.class);
    assertEquals(new Integer(123), out);
    out = template.requestBodyAndHeader("direct:inout", "Hello", "foo", "bar", Integer.class);
    assertEquals(new Integer(123), out);
    Map<String, Object> headers = new HashMap<String, Object>();
    out = template.requestBodyAndHeaders("direct:inout", "Hello", headers, Integer.class);
    assertEquals(new Integer(123), out);
    // with endpoint object
    Endpoint endpoint = context.getEndpoint("direct:inout");
    out = template.requestBody(endpoint, "Hello", Integer.class);
    assertEquals(new Integer(123), out);
    out = template.requestBodyAndHeader(endpoint, "Hello", "foo", "bar", Integer.class);
    assertEquals(new Integer(123), out);
    headers = new HashMap<String, Object>();
    out = template.requestBodyAndHeaders(endpoint, "Hello", headers, Integer.class);
    assertEquals(new Integer(123), out);
}
Also used : Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap)

Example 77 with HashMap

use of java.util.HashMap in project camel by apache.

the class DefaultProducerTemplateTest method testSendUsingDefaultEndpoint.

public void testSendUsingDefaultEndpoint() throws Exception {
    ProducerTemplate producer = new DefaultProducerTemplate(context, context.getEndpoint("direct:in"));
    producer.start();
    getMockEndpoint("mock:result").expectedMessageCount(3);
    producer.sendBody("Hello");
    producer.sendBodyAndHeader("Hello", "foo", 123);
    Map<String, Object> headers = new HashMap<String, Object>();
    producer.sendBodyAndHeaders("Hello", headers);
    assertMockEndpointsSatisfied();
    producer.stop();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) HashMap(java.util.HashMap)

Example 78 with HashMap

use of java.util.HashMap in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testRequestAsyncBodyAndHeadersType.

public void testRequestAsyncBodyAndHeadersType() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    mock.expectedHeaderReceived("foo", 123);
    mock.expectedHeaderReceived("bar", "cheese");
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("foo", 123);
    headers.put("bar", "cheese");
    Future<String> future = template.asyncRequestBodyAndHeaders("direct:start", "Hello", headers, String.class);
    long start = System.currentTimeMillis();
    // you can do other stuff
    String echo = template.requestBody("direct:echo", "Hi", String.class);
    assertEquals("HiHi", echo);
    // or we can use parameter type in the requestBody method so the future handle know its type
    String result = future.get();
    assertMockEndpointsSatisfied();
    long delta = System.currentTimeMillis() - start;
    assertEquals("Hello World", result);
    assertTrue("Should take longer than: " + delta, delta > 250);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap)

Example 79 with HashMap

use of java.util.HashMap in project camel by apache.

the class SimpleParserPredicateTest method testSimpleMap.

public void testSimpleMap() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("foo", "123");
    map.put("foo bar", "456");
    exchange.getIn().setBody(map);
    SimplePredicateParser parser = new SimplePredicateParser("${body[foo]} == 123", true);
    Predicate pre = parser.parsePredicate();
    assertTrue("Should match", pre.matches(exchange));
    parser = new SimplePredicateParser("${body['foo bar']} == 456", true);
    pre = parser.parsePredicate();
    assertTrue("Should match", pre.matches(exchange));
    // the predicate has whitespace in the function
    parser = new SimplePredicateParser("${body[foo bar]} == 456", true);
    pre = parser.parsePredicate();
    assertTrue("Should match", pre.matches(exchange));
    // no header with that name
    parser = new SimplePredicateParser("${body[unknown]} == 456", true);
    pre = parser.parsePredicate();
    assertFalse("Should not match", pre.matches(exchange));
}
Also used : HashMap(java.util.HashMap) Predicate(org.apache.camel.Predicate)

Example 80 with HashMap

use of java.util.HashMap in project camel by apache.

the class SimpleParserPredicateTest method testSimpleIn.

public void testSimpleIn() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("key", "foo");
    map.put("key2", "bar");
    map.put("key3", "none");
    exchange.getIn().setBody(map);
    SimplePredicateParser parser = new SimplePredicateParser("${body[key]} in ${ref:myList}", true);
    Predicate pre = parser.parsePredicate();
    assertTrue("Should match", pre.matches(exchange));
    parser = new SimplePredicateParser("${body[key2]} in ${ref:myList}", true);
    pre = parser.parsePredicate();
    assertTrue("Should match", pre.matches(exchange));
    parser = new SimplePredicateParser("${body[key3]} in ${ref:myList}", true);
    pre = parser.parsePredicate();
    assertFalse("Should not match", pre.matches(exchange));
}
Also used : HashMap(java.util.HashMap) Predicate(org.apache.camel.Predicate)

Aggregations

HashMap (java.util.HashMap)24090 ArrayList (java.util.ArrayList)5632 Map (java.util.Map)5586 Test (org.junit.Test)5079 List (java.util.List)2721 HashSet (java.util.HashSet)2103 IOException (java.io.IOException)1780 Set (java.util.Set)1465 File (java.io.File)1206 Iterator (java.util.Iterator)1198 LinkedHashMap (java.util.LinkedHashMap)1138 Test (org.testng.annotations.Test)884 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)680 Date (java.util.Date)545 LinkedList (java.util.LinkedList)494 URI (java.net.URI)415 Properties (java.util.Properties)381 InputStream (java.io.InputStream)343 Collection (java.util.Collection)342 TreeMap (java.util.TreeMap)333