Search in sources :

Example 6 with JSONTML

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==");
}
Also used : StringWriter(java.io.StringWriter) JSONTML(com.dexels.navajo.document.json.JSONTML) StringReader(java.io.StringReader) Navajo(com.dexels.navajo.document.Navajo) Binary(com.dexels.navajo.document.types.Binary) Property(com.dexels.navajo.document.Property) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 7 with JSONTML

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);
}
Also used : StringWriter(java.io.StringWriter) JSONTML(com.dexels.navajo.document.json.JSONTML) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Memo(com.dexels.navajo.document.types.Memo) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 8 with JSONTML

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));
}
Also used : StringWriter(java.io.StringWriter) JSONTML(com.dexels.navajo.document.json.JSONTML) StringReader(java.io.StringReader) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Date(java.util.Date) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with JSONTML

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);
}
Also used : StringWriter(java.io.StringWriter) JSONTML(com.dexels.navajo.document.json.JSONTML) Navajo(com.dexels.navajo.document.Navajo) ClockTime(com.dexels.navajo.document.types.ClockTime) Property(com.dexels.navajo.document.Property) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Aggregations

Navajo (com.dexels.navajo.document.Navajo)9 JSONTML (com.dexels.navajo.document.json.JSONTML)9 StringWriter (java.io.StringWriter)9 Writer (java.io.Writer)9 Test (org.junit.Test)9 Property (com.dexels.navajo.document.Property)8 StringReader (java.io.StringReader)4 Message (com.dexels.navajo.document.Message)1 Binary (com.dexels.navajo.document.types.Binary)1 ClockTime (com.dexels.navajo.document.types.ClockTime)1 Coordinate (com.dexels.navajo.document.types.Coordinate)1 Memo (com.dexels.navajo.document.types.Memo)1 Money (com.dexels.navajo.document.types.Money)1 Percentage (com.dexels.navajo.document.types.Percentage)1 Date (java.util.Date)1 Ignore (org.junit.Ignore)1