Search in sources :

Example 1 with JSONTML

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);
}
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 2 with JSONTML

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);
}
Also used : StringWriter(java.io.StringWriter) Percentage(com.dexels.navajo.document.types.Percentage) 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 3 with JSONTML

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

Example 4 with JSONTML

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")));
}
Also used : Message(com.dexels.navajo.document.Message) 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) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 5 with JSONTML

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);
}
Also used : StringWriter(java.io.StringWriter) Coordinate(com.dexels.navajo.document.types.Coordinate) 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)

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