use of com.dexels.navajo.document.json.JSONTML 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.json.JSONTML in project navajo by Dexels.
the class TestTMLJson method testPercentage.
@Test
public void testPercentage() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message2.xml"));
JSONTML json = JSONTMLFactory.getInstance();
Property prop = NavajoFactory.getInstance().createProperty(n, "percentageProp", "", "", "");
prop.setAnyValue(new Percentage("43"));
n.getMessage("SimpleMessage").addProperty(prop);
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
Assert.assertEquals("{\n \"percentageProp\" : 43.0\n}", result);
}
use of com.dexels.navajo.document.json.JSONTML in project navajo by Dexels.
the class TestTMLJson method testJson.
@Test
public void testJson() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message.xml"));
JSONTML json = JSONTMLFactory.getInstance();
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
logger.info(result);
// Length should be... 64! right?
Assert.assertEquals(64, result.length());
// Turn back into a Navajo and compare
Navajo n2 = json.parse(new StringReader(result), "SimpleMessage");
Assert.assertTrue(n.getMessage("SimpleMessage").isEqual(n2.getMessage("SimpleMessage")));
}
use of com.dexels.navajo.document.json.JSONTML in project navajo by Dexels.
the class TestTMLJson method testJsonIgnoreMessage.
@Test
public void testJsonIgnoreMessage() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message.xml"));
JSONTML json = JSONTMLFactory.getInstance();
Message ignoreMessage = NavajoFactory.getInstance().createMessage(n, "ignoreme");
n.addMessage(ignoreMessage);
ignoreMessage.setMode(Message.MSG_MODE_IGNORE);
Property testprop = NavajoFactory.getInstance().createProperty(n, "TestProp", "", "", "");
testprop.setAnyValue("100a");
ignoreMessage.addProperty(testprop);
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
logger.info(result);
// Length should be... 64! right?
Assert.assertEquals(64, result.length());
// Ignore message shouldnt be present
Assert.assertFalse(result.contains("ignoreme"));
// Turn back into a Navajo and compare
Navajo n2 = json.parse(new StringReader(result), "SimpleMessage");
Assert.assertTrue(n.getMessage("SimpleMessage").isEqual(n2.getMessage("SimpleMessage")));
}
use of com.dexels.navajo.document.json.JSONTML in project navajo by Dexels.
the class TestTMLJson method testCoordinate.
@Test
public void testCoordinate() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message2.xml"));
JSONTML json = JSONTMLFactory.getInstance();
Property prop = NavajoFactory.getInstance().createProperty(n, "coordinateProp", "", "", "");
prop.setAnyValue(new Coordinate(-12.65342223, 13.12323425));
n.getMessage("SimpleMessage").addProperty(prop);
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
Assert.assertEquals("{\n \"coordinateProp\" : \"[-12.65342223,13.12323425]\"\n}", result);
}
Aggregations