use of java.util.Map in project camel by apache.
the class BindySimpleFixedLengthHeaderFooterTest method testMarshallMessageWithIndirectHeaderAndFooterInput.
/**
* Verifies that header & footer provided via message headers are marshalled successfully
*/
@Test
public void testMarshallMessageWithIndirectHeaderAndFooterInput() throws Exception {
Order order = new Order();
order.setOrderNr(10);
order.setOrderType("BUY");
order.setClientNr("A9");
order.setFirstName("Pauline");
order.setLastName("M");
order.setAmount(new BigDecimal("2500.45"));
order.setInstrumentCode("ISIN");
order.setInstrumentNumber("XD12345678");
order.setInstrumentType("Share");
order.setCurrency("USD");
Calendar calendar = new GregorianCalendar();
calendar.set(2009, 7, 1, 0, 0, 0);
order.setOrderDate(calendar.getTime());
List<Map<String, Object>> input = new ArrayList<Map<String, Object>>();
Map<String, Object> bodyRow = new HashMap<String, Object>();
bodyRow.put(Order.class.getName(), order);
input.add(bodyRow);
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_HEADER, createHeaderRow());
headers.put(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_FOOTER, createFooterRow());
marshallResult.reset();
marshallResult.expectedMessageCount(1);
StringBuffer buff = new StringBuffer();
buff.append(TEST_HEADER).append(TEST_RECORD).append(TEST_FOOTER);
marshallResult.expectedBodiesReceived(Arrays.asList(new String[] { buff.toString() }));
template.sendBodyAndHeaders(URI_DIRECT_MARSHALL, input, headers);
marshallResult.assertIsSatisfied();
}
use of java.util.Map in project camel by apache.
the class BindyFixedLengthHeaderFooterSkipHeaderTest method testUnmarshallMessage.
// *************************************************************************
// TESTS
// *************************************************************************
@SuppressWarnings("unchecked")
@Test
public void testUnmarshallMessage() throws Exception {
StringBuffer buff = new StringBuffer();
buff.append(TEST_HEADER).append(TEST_RECORD).append(TEST_FOOTER);
unmarshallResult.expectedMessageCount(1);
template.sendBody(URI_DIRECT_UNMARSHALL, buff.toString());
unmarshallResult.assertIsSatisfied();
// check the model
Exchange exchange = unmarshallResult.getReceivedExchanges().get(0);
Order order = (Order) exchange.getIn().getBody();
assertEquals(10, order.getOrderNr());
// the field is not trimmed
assertEquals(" Pauline", order.getFirstName());
assertEquals("M ", order.getLastName());
Map<String, Object> receivedHeaderMap = (Map<String, Object>) exchange.getIn().getHeader(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_HEADER);
Map<String, Object> receivedFooterMap = (Map<String, Object>) exchange.getIn().getHeader(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_FOOTER);
assertNull(receivedHeaderMap);
assertNotNull(receivedFooterMap);
}
use of java.util.Map in project camel by apache.
the class AbstractBraintreeTestSupport method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
final CamelContext context = super.createCamelContext();
// read Braintree component configuration from TEST_OPTIONS_PROPERTIES
final Properties properties = new Properties();
try {
properties.load(getClass().getResourceAsStream(TEST_OPTIONS_PROPERTIES));
} catch (Exception e) {
throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()), e);
}
Map<String, Object> options = new HashMap<>();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
options.put(entry.getKey().toString(), entry.getValue());
}
addOptionIfMissing(options, "environment", "CAMEL_BRAINTREE_ENVIRONMENT");
addOptionIfMissing(options, "merchantId", "CAMEL_BRAINTREE_MERCHANT_ID");
addOptionIfMissing(options, "publicKey", "CAMEL_BRAINTREE_PUBLIC_KEY");
addOptionIfMissing(options, "privateKey", "CAMEL_BRAINTREE_PRIVATE_KEY");
final BraintreeConfiguration configuration = new BraintreeConfiguration();
configuration.setHttpLogLevel(BraintreeLogHandler.DEFAULT_LOGGER_VERSION);
configuration.setHttpLogName(BraintreeLogHandler.DEFAULT_LOGGER_NAME);
IntrospectionSupport.setProperties(configuration, options);
// add BraintreeComponent to Camel context
final BraintreeComponent component = new BraintreeComponent(context);
component.setConfiguration(configuration);
context.addComponent("braintree", component);
return context;
}
use of java.util.Map in project camel by apache.
the class GooglePubsubProducer method sendMessages.
private void sendMessages(List<Exchange> exchanges) throws Exception {
GooglePubsubEndpoint endpoint = (GooglePubsubEndpoint) getEndpoint();
String topicName = String.format("projects/%s/topics/%s", endpoint.getProjectId(), endpoint.getDestinationName());
List<PubsubMessage> messages = new ArrayList<>();
for (Exchange exchange : exchanges) {
PubsubMessage message = new PubsubMessage();
Object body = exchange.getIn().getBody();
if (body instanceof String) {
message.encodeData(((String) body).getBytes("UTF-8"));
} else if (body instanceof byte[]) {
message.encodeData((byte[]) body);
} else {
message.encodeData(serialize(body));
}
Object attributes = exchange.getIn().getHeader(GooglePubsubConstants.ATTRIBUTES);
if (attributes != null && attributes instanceof Map && ((Map) attributes).size() > 0) {
message.setAttributes((Map) attributes);
}
messages.add(message);
}
PublishRequest publishRequest = new PublishRequest().setMessages(messages);
PublishResponse response = endpoint.getPubsub().projects().topics().publish(topicName, publishRequest).execute();
List<String> sentMessageIds = response.getMessageIds();
int i = 0;
for (Exchange entry : exchanges) {
entry.getIn().setHeader(GooglePubsubConstants.MESSAGE_ID, sentMessageIds.get(i));
i++;
}
}
use of java.util.Map in project camel by apache.
the class AbstractGoogleDriveTestSupport method createCamelContext.
@Override
protected CamelContext createCamelContext() throws Exception {
final InputStream in = getClass().getResourceAsStream(TEST_OPTIONS_PROPERTIES);
if (in == null) {
throw new IOException(TEST_OPTIONS_PROPERTIES + " could not be found");
}
final StringBuilder builder = new StringBuilder();
final BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line).append(LINE_SEPARATOR);
}
propertyText = builder.toString();
final Properties properties = new Properties();
try {
properties.load(new StringReader(propertyText));
} catch (IOException e) {
throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()), e);
}
//
// // cache test properties
// refreshToken = properties.getProperty(REFRESH_TOKEN_PROPERTY);
// testFolderId = properties.getProperty("testFolderId");
// testFileId = properties.getProperty("testFileId");
// testUserId = properties.getProperty("testUserId");
//
Map<String, Object> options = new HashMap<String, Object>();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
options.put(entry.getKey().toString(), entry.getValue());
}
final GoogleDriveConfiguration configuration = new GoogleDriveConfiguration();
IntrospectionSupport.setProperties(configuration, options);
// add GoogleDriveComponent to Camel context
final CamelContext context = super.createCamelContext();
final GoogleDriveComponent component = new GoogleDriveComponent(context);
component.setConfiguration(configuration);
context.addComponent("google-drive", component);
return context;
}
Aggregations