Search in sources :

Example 1 with LinkedHashMap

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

the class CsvRouteTest method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(1);
    // START SNIPPET: marshalInput
    Map<String, Object> body = new LinkedHashMap<String, Object>();
    body.put("foo", "abc");
    body.put("bar", 123);
    // END SNIPPET: marshalInput
    template.sendBody("direct:start", body);
    resultEndpoint.assertIsSatisfied();
    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    for (Exchange exchange : list) {
        Message in = exchange.getIn();
        String text = in.getBody(String.class);
        log.debug("Received " + text);
        assertNotNull("Should be able to convert received body to a string", text);
        // order is not guaranteed with a Map (which was passed in before)
        // so we need to check for both combinations
        assertTrue("Text body has wrong value.", "abc,123".equals(text.trim()) || "123,abc".equals(text.trim()));
    }
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with LinkedHashMap

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

the class CsvRouteTest method testMultipleMessages.

@Test
public void testMultipleMessages() throws Exception {
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:resultMulti", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(2);
    Map<String, Object> body1 = new LinkedHashMap<String, Object>();
    body1.put("foo", "abc");
    body1.put("bar", 123);
    Map<String, Object> body2 = new LinkedHashMap<String, Object>();
    body2.put("foo", "def");
    body2.put("bar", 456);
    body2.put("baz", 789);
    template.sendBody("direct:startMulti", body1);
    template.sendBody("direct:startMulti", body2);
    resultEndpoint.assertIsSatisfied();
    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    Message in1 = list.get(0).getIn();
    String text1 = in1.getBody(String.class);
    log.debug("Received " + text1);
    assertTrue("First CSV body has wrong value", Pattern.matches("(abc,123)|(123,abc)", text1.trim()));
    Message in2 = list.get(1).getIn();
    String text2 = in2.getBody(String.class);
    log.debug("Received " + text2);
    // fields should keep the same order from one call to the other
    if (text1.trim().equals("abc,123")) {
        assertEquals("Second CSV body has wrong value", "def,456,789", text2.trim());
    } else {
        assertEquals("Second CSV body has wrong value", "456,def,789", text2.trim());
    }
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with LinkedHashMap

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

the class CsvRouteTest method testPresetConfig.

@Test
public void testPresetConfig() throws Exception {
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:resultMultiCustom", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(2);
    Map<String, Object> body1 = new LinkedHashMap<String, Object>();
    body1.put("foo", "abc");
    body1.put("bar", 123);
    Map<String, Object> body2 = new LinkedHashMap<String, Object>();
    body2.put("foo", "def");
    body2.put("bar", 456);
    body2.put("baz", 789);
    body2.put("buz", "000");
    template.sendBody("direct:startMultiCustom", body1);
    template.sendBody("direct:startMultiCustom", body2);
    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    Message in1 = list.get(0).getIn();
    String text1 = in1.getBody(String.class);
    log.debug("Received " + text1);
    assertEquals("First CSV body has wrong value", "abc;;123", text1.trim());
    Message in2 = list.get(1).getIn();
    String text2 = in2.getBody(String.class);
    log.debug("Received " + text2);
    assertEquals("Second CSV body has wrong value", "def;789;456", text2.trim());
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with LinkedHashMap

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

the class CxfRsAsyncProducerTest method testProducerWithQueryParametersHeader.

@Test
public void testProducerWithQueryParametersHeader() {
    Exchange exchange = template.send("cxfrs://http://localhost:" + getPort2() + "/" + getClass().getSimpleName() + "/testQuery?httpClientAPI=true&q1=12&q2=13", newExchange -> {
        newExchange.setPattern(ExchangePattern.InOut);
        Message inMessage = newExchange.getIn();
        inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, InputStream.class);
        Map<String, String> queryMap = new LinkedHashMap<>();
        queryMap.put("q1", "new");
        queryMap.put("q2", "world");
        inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP, queryMap);
        inMessage.setBody(null);
    });
    // get the response message 
    String response = exchange.getOut().getBody(String.class);
    assertNotNull("The response should not be null ", response);
    assertEquals("The response value is wrong", "q1=new&q2=world", response);
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with LinkedHashMap

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

the class ReadingBuilder method copy.

public static Reading copy(Reading reading, boolean skipSinceUtil) throws NoSuchFieldException, IllegalAccessException {
    // use private field access to make a copy
    Field field = Reading.class.getDeclaredField("parameterMap");
    field.setAccessible(true);
    final LinkedHashMap<String, String> source = (LinkedHashMap<String, String>) field.get(reading);
    // create another reading, and add all fields from source
    Reading copy = new Reading();
    final LinkedHashMap<String, String> copyMap = new LinkedHashMap<String, String>();
    copyMap.putAll(source);
    if (skipSinceUtil) {
        copyMap.remove("since");
        copyMap.remove("until");
    }
    field.set(copy, copyMap);
    field.setAccessible(false);
    return copy;
}
Also used : Field(java.lang.reflect.Field) Reading(facebook4j.Reading) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1944 ArrayList (java.util.ArrayList)575 Map (java.util.Map)561 HashMap (java.util.HashMap)373 Test (org.junit.Test)275 List (java.util.List)255 IOException (java.io.IOException)122 HashSet (java.util.HashSet)91 Set (java.util.Set)79 File (java.io.File)76 LinkedHashSet (java.util.LinkedHashSet)68 TreeMap (java.util.TreeMap)68 Node (org.apache.hadoop.hive.ql.lib.Node)59 NodeProcessor (org.apache.hadoop.hive.ql.lib.NodeProcessor)58 Rule (org.apache.hadoop.hive.ql.lib.Rule)58 Date (java.util.Date)57 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)56 Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)55 Iterator (java.util.Iterator)54 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)54