Search in sources :

Example 81 with HashMap

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

the class ManagedRouteAddRemoveTest method testRouteAddRemoteRouteWithRecipientListAndRouteScopedOnException.

public void testRouteAddRemoteRouteWithRecipientListAndRouteScopedOnException() throws Exception {
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    result.assertIsSatisfied();
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=services,*");
    // number of services
    Set<ObjectName> names = mbeanServer.queryNames(on, null);
    assertEquals(services, names.size());
    log.info("Adding 2nd route");
    // add a 2nd route
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:bar").routeId("bar").onException(Exception.class).handled(true).recipientList(header("error")).end().end().recipientList(header("bar")).throwException(new IllegalArgumentException("Forced"));
        }
    });
    // and send a message to it
    getMockEndpoint("mock:bar").expectedMessageCount(1);
    getMockEndpoint("mock:error").expectedMessageCount(1);
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("error", "mock:error");
    headers.put("bar", "mock:bar");
    template.sendBodyAndHeaders("direct:bar", "Hello World", headers);
    assertMockEndpointsSatisfied();
    // there should still be the same number of services
    names = mbeanServer.queryNames(on, null);
    assertEquals(services, names.size());
    // now stop and remove the 2nd route
    log.info("Stopping 2nd route");
    context.stopRoute("bar");
    log.info("Removing 2nd route");
    boolean removed = context.removeRoute("bar");
    assertTrue(removed);
    // there should still be the same number of services
    names = mbeanServer.queryNames(on, null);
    assertEquals(services, names.size());
    log.info("Shutting down...");
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 82 with HashMap

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

the class ApiMethodPropertiesHelperTest method testGetExchangeProperties.

@Test
public void testGetExchangeProperties() throws Exception {
    final HashMap<String, Object> properties = new HashMap<String, Object>();
    final DefaultExchange exchange = new DefaultExchange(new MockEndpoint());
    exchange.getIn().setHeader(PROPERTY_1, VALUE_1);
    exchange.getIn().setHeader(PROPERTY_2, VALUE_2);
    exchange.getIn().setHeader(PROPERTY_3, VALUE_3);
    exchange.getIn().setHeader(PROPERTY_4, VALUE_4);
    exchange.getIn().setHeader(PROPERTY_5, VALUE_5);
    propertiesHelper.getExchangeProperties(exchange, properties);
    assertEquals(5, properties.size());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) HashMap(java.util.HashMap) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 83 with HashMap

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

the class IntrospectionSupportTest method testGetPropertiesSkipNull.

public void testGetPropertiesSkipNull() throws Exception {
    ExampleBean bean = new ExampleBean();
    bean.setName("Claus");
    bean.setPrice(10.0);
    bean.setId(null);
    Map<String, Object> map = new HashMap<String, Object>();
    IntrospectionSupport.getProperties(bean, map, null, false);
    assertEquals(2, map.size());
    assertEquals("Claus", map.get("name"));
    String price = map.get("price").toString();
    assertTrue(price.startsWith("10"));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ExampleBean(org.apache.camel.util.jndi.ExampleBean)

Example 84 with HashMap

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

the class IntrospectionSupportTest method testGetPropertiesOptionPrefix.

public void testGetPropertiesOptionPrefix() throws Exception {
    ExampleBean bean = new ExampleBean();
    bean.setName("Claus");
    bean.setPrice(10.0);
    bean.setId("123");
    Map<String, Object> map = new HashMap<String, Object>();
    IntrospectionSupport.getProperties(bean, map, "bean.");
    assertEquals(3, map.size());
    assertEquals("Claus", map.get("bean.name"));
    String price = map.get("bean.price").toString();
    assertTrue(price.startsWith("10"));
    assertEquals("123", map.get("bean.id"));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ExampleBean(org.apache.camel.util.jndi.ExampleBean)

Example 85 with HashMap

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

the class IntrospectionSupportTest method testGetProperties.

public void testGetProperties() throws Exception {
    ExampleBean bean = new ExampleBean();
    bean.setName("Claus");
    bean.setPrice(10.0);
    Map<String, Object> map = new HashMap<String, Object>();
    IntrospectionSupport.getProperties(bean, map, null);
    assertEquals(3, map.size());
    assertEquals("Claus", map.get("name"));
    String price = map.get("price").toString();
    assertTrue(price.startsWith("10"));
    assertEquals(null, map.get("id"));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ExampleBean(org.apache.camel.util.jndi.ExampleBean)

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