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