Search in sources :

Example 16 with Money

use of com.dexels.navajo.document.types.Money in project navajo by Dexels.

the class ToMoneyInternal method main.

public static void main(String[] args) throws Exception {
    java.util.Locale.setDefault(new java.util.Locale("nl", "NL"));
    // Tests.
    ToMoneyInternal tm = new ToMoneyInternal();
    tm.reset();
    tm.insertMoneyOperand(new Money(3.4));
    System.out.println("result = " + tm.evaluate());
}
Also used : Money(com.dexels.navajo.document.types.Money)

Example 17 with Money

use of com.dexels.navajo.document.types.Money in project navajo by Dexels.

the class TestTMLJson method testMoney.

@Test
public void testMoney() throws Exception {
    Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message2.xml"));
    JSONTML json = JSONTMLFactory.getInstance();
    Property moneyProp = NavajoFactory.getInstance().createProperty(n, "moneyProp", "", "", "");
    moneyProp.setAnyValue(new Money("32.22"));
    n.getMessage("SimpleMessage").addProperty(moneyProp);
    Writer sw = new StringWriter();
    json.format(n, sw, true);
    String result = sw.toString();
    Assert.assertEquals("{\n  \"moneyProp\" : 3222.0\n}", result);
}
Also used : Money(com.dexels.navajo.document.types.Money) StringWriter(java.io.StringWriter) JSONTML(com.dexels.navajo.document.json.JSONTML) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 18 with Money

use of com.dexels.navajo.document.types.Money in project navajo by Dexels.

the class TestProperty method tesMoneyFormat.

@Test
public void tesMoneyFormat() {
    Money m = new Money(10);
    logger.info("Country: {}", Locale.getDefault().getCountry());
    logger.info("m: {} :: {}", m.toTmlString(), m.editingString());
    Assert.assertEquals(m.toTmlString(), "10.00");
    Assert.assertEquals(m.editingString(), "10");
    m = new Money("10.000");
    Assert.assertEquals(m.doubleValue(), 10000d, 0.1);
    m = new Money("10.000,00");
    Assert.assertEquals(m.doubleValue(), 10000d, 0.1);
    m = new Money("5,00");
    Assert.assertEquals(m.doubleValue(), 5d, 0.1);
}
Also used : Money(com.dexels.navajo.document.types.Money) Test(org.junit.Test)

Example 19 with Money

use of com.dexels.navajo.document.types.Money in project navajo by Dexels.

the class TestProperty method tesSetAnyValue.

@Test
public void tesSetAnyValue() {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Property p1 = NavajoFactory.getInstance().createProperty(n, "Aap", "", "", "");
    // String
    p1.setAnyValue("Apenoot");
    assertEquals("string", p1.getType());
    assertEquals("Apenoot", p1.getValue());
    assertTrue(p1.getTypedValue().equals("Apenoot"));
    // Integer
    p1.setAnyValue(Integer.valueOf(50));
    assertEquals("integer", p1.getType());
    assertEquals("50", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Integer.valueOf(50)));
    // Double
    p1.setAnyValue(Double.valueOf(50));
    assertEquals("float", p1.getType());
    assertEquals("50.0", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Double.valueOf(50)));
    // Float
    p1.setAnyValue(Float.valueOf(50));
    assertEquals("float", p1.getType());
    assertEquals("50.0", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Double.valueOf(50)));
    // Date
    Date d = new java.util.Date();
    p1.setAnyValue(d);
    String expectedFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS").format(d);
    assertEquals("date", p1.getType());
    assertEquals(expectedFormat, p1.getValue());
    assertTrue(p1.getTypedValue().equals(d));
    // Long
    p1.setAnyValue(Long.valueOf(10));
    assertEquals("long", p1.getType());
    assertEquals("10", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Long.valueOf(10)));
    // Boolean
    p1.setAnyValue(Boolean.TRUE);
    assertEquals("boolean", p1.getType());
    assertEquals("true", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Boolean.TRUE));
    // Binary
    Binary b = new Binary("Mooie array".getBytes());
    p1.setAnyValue(b);
    assertEquals("binary", p1.getType());
    Binary b1 = (Binary) p1.getTypedValue();
    String expected = new String(b1.getData());
    assertEquals("Mooie array", expected);
    // Money
    p1.setAnyValue(new Money(5000));
    assertEquals("money", p1.getType());
    assertEquals("5000.00", p1.getValue());
    assertTrue(p1.getTypedValue().equals(new Money(5000)));
    // ClockTime
    Date d1 = new java.util.Date();
    ClockTime ct = new ClockTime(d1);
    String expectedFormat2 = ct.toString();
    p1.setAnyValue(ct);
    assertEquals("clocktime", p1.getType());
    assertEquals(expectedFormat2, p1.getValue());
    assertTrue(p1.getTypedValue().equals(new ClockTime(d1)));
    // StopwatchTime
    Date d2 = new java.util.Date();
    String format = new SimpleDateFormat("HH:mm:ss:SSS").format(d2);
    StopwatchTime swt = new StopwatchTime(format);
    p1.setAnyValue(swt);
    assertEquals("stopwatchtime", p1.getType());
    logger.info("FORM: {} val: {}", format, p1.getValue());
    assertEquals(format, p1.getValue());
    assertTrue(p1.getTypedValue().equals(new StopwatchTime(format)));
    // Percentage
    Percentage p = new Percentage(50);
    p1.setAnyValue(p);
    assertEquals("percentage", p1.getType());
    assertEquals("50.0", p1.getValue());
    assertTrue(p1.getTypedValue().equals(new Percentage(50)));
}
Also used : StopwatchTime(com.dexels.navajo.document.types.StopwatchTime) Money(com.dexels.navajo.document.types.Money) Percentage(com.dexels.navajo.document.types.Percentage) Navajo(com.dexels.navajo.document.Navajo) Binary(com.dexels.navajo.document.types.Binary) ClockTime(com.dexels.navajo.document.types.ClockTime) Property(com.dexels.navajo.document.Property) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 20 with Money

use of com.dexels.navajo.document.types.Money in project navajo by Dexels.

the class ComparisonNode method compare.

private static final Boolean compare(ComparisonOperator compOp, Operand ao, Operand bo, String expression) {
    Object a = ao.value;
    Object b = bo.value;
    if (a == null || b == null) {
        throw new TMLExpressionException("Illegal arguement for " + compOp.getDescription() + ";. Cannot compare " + a + " " + compOp.getOperator() + " " + b + ". No null values are allowed. Expression: " + expression);
    }
    if (a instanceof Integer && b instanceof Integer)
        return Utils.compare((Integer) a, (Integer) b, compOp.getOperator());
    else if (a instanceof Integer && b instanceof Double)
        return Utils.compare(((Integer) a).doubleValue(), (Double) b, compOp.getOperator());
    else if (a instanceof Double && b instanceof Integer)
        return Utils.compare((Double) a, ((Integer) b).doubleValue(), compOp.getOperator());
    else if (a instanceof Double && b instanceof Double)
        return Utils.compare((Double) a, (Double) b, compOp.getOperator());
    else if (a instanceof Date)
        return Boolean.valueOf(Utils.compareDates(a, b, compOp.getOperator()));
    else if (a instanceof Money || b instanceof Money)
        return Utils.compare(Utils.getDoubleValue(a), Utils.getDoubleValue(b), compOp.getOperator());
    else if (a instanceof Percentage || b instanceof Percentage)
        return Utils.compare(Utils.getDoubleValue(a), Utils.getDoubleValue(b), compOp.getOperator());
    else if (a instanceof ClockTime && b instanceof ClockTime)
        return Boolean.valueOf(Utils.compareDates(a, b, compOp.getOperator()));
    else if (a instanceof String && b instanceof String)
        return Utils.compare((String) a, (String) b, compOp.getOperator());
    else
        throw new TMLExpressionException("Illegal comparison for " + compOp.getDescription() + "; " + a.getClass().getName() + " " + b.getClass().getName());
}
Also used : Money(com.dexels.navajo.document.types.Money) Percentage(com.dexels.navajo.document.types.Percentage) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) ClockTime(com.dexels.navajo.document.types.ClockTime) Date(java.util.Date)

Aggregations

Money (com.dexels.navajo.document.types.Money)39 Test (org.junit.Test)25 Percentage (com.dexels.navajo.document.types.Percentage)10 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)8 ClockTime (com.dexels.navajo.document.types.ClockTime)6 Navajo (com.dexels.navajo.document.Navajo)5 Property (com.dexels.navajo.document.Property)5 Date (java.util.Date)5 Operand (com.dexels.navajo.document.Operand)4 Message (com.dexels.navajo.document.Message)3 NavajoException (com.dexels.navajo.document.NavajoException)3 Binary (com.dexels.navajo.document.types.Binary)3 StopwatchTime (com.dexels.navajo.document.types.StopwatchTime)3 StringWriter (java.io.StringWriter)3 DatePattern (com.dexels.navajo.document.types.DatePattern)2 SystemException (com.dexels.navajo.script.api.SystemException)2 StringReader (java.io.StringReader)2 ExpressionChangedException (com.dexels.navajo.document.ExpressionChangedException)1 PropertyTypeException (com.dexels.navajo.document.PropertyTypeException)1 BaseMessageImpl (com.dexels.navajo.document.base.BaseMessageImpl)1