Search in sources :

Example 1 with BigDecimal

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;
}
Also used : PurchaseOrder(org.apache.camel.converter.PurchaseOrder) BigDecimal(java.math.BigDecimal) TypeConverter(org.apache.camel.TypeConverter) Converter(org.apache.camel.Converter)

Example 2 with BigDecimal

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();
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with BigDecimal

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();
}
Also used : HashMap(java.util.HashMap) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with BigDecimal

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;
}
Also used : Order(org.apache.camel.dataformat.bindy.model.simple.oneclass.Order) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) BigDecimal(java.math.BigDecimal)

Example 5 with BigDecimal

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();
}
Also used : BigDecimal(java.math.BigDecimal) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

BigDecimal (java.math.BigDecimal)4643 Test (org.junit.Test)634 BigInteger (java.math.BigInteger)624 Test (org.testng.annotations.Test)573 LocalDate (org.joda.time.LocalDate)409 ArrayList (java.util.ArrayList)351 ResultSet (java.sql.ResultSet)222 Timestamp (java.sql.Timestamp)205 PreparedStatement (java.sql.PreparedStatement)201 SQLException (java.sql.SQLException)159 Invoice (org.killbill.billing.invoice.api.Invoice)148 Date (java.util.Date)146 UUID (java.util.UUID)144 MathContext (java.math.MathContext)140 DateTime (org.joda.time.DateTime)132 HashMap (java.util.HashMap)130 RoundingMode (java.math.RoundingMode)128 List (java.util.List)113 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)104 Session (org.hibernate.Session)96