use of com.dexels.navajo.document.json.JSONTML in project navajo by Dexels.
the class TestTMLJson method testJsonBinary.
@Test
public void testJsonBinary() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message.xml"));
JSONTML json = JSONTMLFactory.getInstance();
Binary binary1 = new Binary(getClass().getResourceAsStream("binary1.txt"));
Property binProp = NavajoFactory.getInstance().createProperty(n, "Bin", "", "", "");
binProp.setAnyValue(binary1);
n.getMessage("SimpleMessage").addProperty(binProp);
Property testprop = NavajoFactory.getInstance().createProperty(n, "TestProp", "", "", "");
testprop.setAnyValue("100a");
n.getMessage("SimpleMessage").addProperty(testprop);
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
logger.info(result);
// Length should be 113, right?
Assert.assertEquals(113, result.length());
// Turn back into a Navajo and compare
Navajo n2 = json.parse(new StringReader(result), "SimpleMessage");
Assert.assertEquals(n2.getMessage("SimpleMessage").getProperty("Bin").getTypedValue(), "YWJjZGVmZw==");
}
use of com.dexels.navajo.document.json.JSONTML in project navajo by Dexels.
the class TestTMLJson method testMemo.
@Test
public void testMemo() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message2.xml"));
JSONTML json = JSONTMLFactory.getInstance();
Property prop = NavajoFactory.getInstance().createProperty(n, "memoProp", "", "", "");
prop.setAnyValue(new Memo("This is a memo value"));
n.getMessage("SimpleMessage").addProperty(prop);
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
logger.info(result);
Assert.assertEquals("{\n \"memoProp\" : \"This is a memo value\"\n}", result);
}
use of com.dexels.navajo.document.json.JSONTML in project navajo by Dexels.
the class TestTMLJson method testDates.
// TODO fix time zone issue
@Test
@Ignore
public void testDates() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message.xml"));
JSONTML json = JSONTMLFactory.getInstance();
// Add date property
Property dateprop = NavajoFactory.getInstance().createProperty(n, "date", "", "", "");
dateprop.setAnyValue(new Date(1477393027000L));
n.getMessage("SimpleMessage").addProperty(dateprop);
// Add date property
Property tsprop = NavajoFactory.getInstance().createProperty(n, "timestamp", "", "", "");
tsprop.setType(Property.TIMESTAMP_PROPERTY);
tsprop.setAnyValue(new Date(1477393027000L));
n.getMessage("SimpleMessage").addProperty(tsprop);
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
logger.info(result);
// Length should be 133... Right?
Assert.assertEquals(133, result.length());
// Turn back into a Navajo and compare
Navajo n2 = json.parse(new StringReader(result), "SimpleMessage");
Assert.assertEquals("2016-10-25", n2.getMessage("SimpleMessage").getProperty("date").getValue());
String resultValue = n2.getMessage("SimpleMessage").getProperty("timestamp").getValue();
Assert.assertEquals("2016-10-25T12:57:07", resultValue.substring(0, resultValue.length() - 5));
}
use of com.dexels.navajo.document.json.JSONTML in project navajo by Dexels.
the class TestTMLJson method testClockTime.
@Test
public void testClockTime() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message2.xml"));
JSONTML json = JSONTMLFactory.getInstance();
Property prop = NavajoFactory.getInstance().createProperty(n, "clockTimeProp", "", "", "");
prop.setAnyValue(new ClockTime("11:12:12"));
n.getMessage("SimpleMessage").addProperty(prop);
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
Assert.assertEquals("{\n \"clockTimeProp\" : \"11:12:00\"\n}", result);
}
Aggregations