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