use of java.math.BigDecimal in project camel by apache.
the class PurchaseOrderConverter method toPurchaseOrder.
@Converter
public PurchaseOrder toPurchaseOrder(byte[] data) {
String s = converter.convertTo(String.class, data);
if (s == null || s.length() < 30) {
throw new IllegalArgumentException("data is invalid");
}
s = s.replaceAll("##START##", "");
s = s.replaceAll("##END##", "");
String name = s.substring(0, 9).trim();
String s2 = s.substring(10, 19).trim();
String s3 = s.substring(20).trim();
BigDecimal price = new BigDecimal(s2);
price = price.setScale(2);
Integer amount = converter.convertTo(Integer.class, s3);
PurchaseOrder order = new PurchaseOrder(name, price, amount);
return order;
}
use of java.math.BigDecimal in project camel by apache.
the class BindyFixedLengthDynamicFieldTest method testMarshallMessage.
@Test
public void testMarshallMessage() throws Exception {
BindyFixedLengthDynamicFieldTest.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.setInstrumentNumberLen(10);
order.setInstrumentNumber("XD12345678");
order.setInstrumentType("Share");
order.setCurrency("USD");
Calendar calendar = new GregorianCalendar();
calendar.set(2009, 7, 1);
order.setOrderDate(calendar.getTime());
marshallResult.expectedMessageCount(1);
marshallResult.expectedBodiesReceived(Arrays.asList(new String[] { TEST_RECORD }));
template.sendBody(URI_DIRECT_MARSHALL, order);
marshallResult.assertIsSatisfied();
}
use of java.math.BigDecimal 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.math.BigDecimal in project camel by apache.
the class BindyPojoSimpleCsvMarshallTest method generateModel.
public Object generateModel() {
// just use the order POJO directly
Order order = new Order();
order.setOrderNr(1);
order.setOrderType("BUY");
order.setClientNr("B2");
order.setFirstName("Keira");
order.setLastName("Knightley");
order.setAmount(new BigDecimal("400.25"));
order.setInstrumentCode("ISIN");
order.setInstrumentNumber("XX23456789");
order.setInstrumentType("Share");
order.setCurrency("EUR");
Calendar calendar = new GregorianCalendar();
calendar.set(2009, 0, 14);
order.setOrderDate(calendar.getTime());
calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
// 4 hour shift
// 16-02-2010 23:21:59 by GMT+4
calendar.set(2010, 1, 17, 19, 27, 59);
calendar.set(Calendar.MILLISECOND, 0);
order.setOrderDateTime(calendar.getTime());
return order;
}
use of java.math.BigDecimal in project camel by apache.
the class BindySimpleCsvIntegerMarshallTest method testMarshallMessage.
@Test
@DirtiesContext
public void testMarshallMessage() throws Exception {
MyOrder order = new MyOrder();
order.setInstrument("XX23456789");
order.setQuantity(12345678);
order.setPrice(new BigDecimal("400.25"));
result.expectedBodiesReceived("XX23456789,12345678,400.25\r\n");
template.sendBody(order);
result.assertIsSatisfied();
}
Aggregations