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