Search in sources :

Example 66 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class TestProperty method testDateTime.

@Test
public void testDateTime() {
    Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("iphone.xml"));
    Property ios = n.getMessage("NewMatchEvent").getProperty("Ios");
    Property correct = n.getMessage("NewMatchEvent").getProperty("Correct");
    Object correctValue = correct.getTypedValue();
    Object iosValue = ios.getTypedValue();
    assertTrue(correctValue != null);
    assertTrue(iosValue != null);
    assertEquals(Date.class, correctValue.getClass());
    assertEquals(Date.class, iosValue.getClass());
    Date correctDate = (Date) correctValue;
    Date iosDate = (Date) iosValue;
    Calendar c = Calendar.getInstance();
    c.setTime(correctDate);
    assertFalse(c.get(Calendar.HOUR_OF_DAY) == 0);
    Calendar iosCalendar = Calendar.getInstance();
    iosCalendar.setTime(iosDate);
    assertFalse(iosCalendar.get(Calendar.HOUR_OF_DAY) == 0);
}
Also used : Calendar(java.util.Calendar) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Date(java.util.Date) Test(org.junit.Test)

Example 67 with Navajo

use of com.dexels.navajo.document.Navajo 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 68 with Navajo

use of com.dexels.navajo.document.Navajo 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 69 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class TestMessage method testMaskMessage.

@Test
public void testMaskMessage() {
    Message myMessage = NavajoFactory.getInstance().createMessage(testDoc, "MyTop");
    testDoc.addMessage(myMessage);
    Property p1 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp1", "string", "AAP", 0, "", "in", "");
    myMessage.addProperty(p1);
    Property p2 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp2", "string", "NOOT", 0, "", "in", "");
    myMessage.addProperty(p2);
    Message arrayMsg = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage");
    arrayMsg.setType(Message.MSG_TYPE_ARRAY);
    myMessage.addMessage(arrayMsg);
    for (int i = 0; i < 5; i++) {
        Message child = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage");
        arrayMsg.addElement(child);
        Property p3 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp3", "string", "AAP" + i, 0, "", "in", "");
        child.addProperty(p3);
        Property p4 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp4", "string", "NOOT" + i, 0, "", "in", "");
        child.addProperty(p4);
        Property p5 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp5", "string", "MIES" + i, 0, "", "in", "");
        child.addProperty(p5);
        Property p6 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp6", "string", "VUUR" + i, 0, "", "in", "");
        child.addProperty(p6);
    }
    Message someChildMsg = NavajoFactory.getInstance().createMessage(testDoc, "SomeChildMessage");
    myMessage.addMessage(someChildMsg);
    Message someValidChildMsg = NavajoFactory.getInstance().createMessage(testDoc, "SomeValidChildMessage");
    myMessage.addMessage(someValidChildMsg);
    Property p7 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp7", "string", "VUUR", 0, "", "in", "");
    someValidChildMsg.addProperty(p7);
    Property p8 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp8", "string", "VUUR", 0, "", "in", "");
    someValidChildMsg.addProperty(p8);
    // Construct mask.
    Navajo maskDoc = NavajoFactory.getInstance().createNavajo();
    Message myMask = NavajoFactory.getInstance().createMessage(maskDoc, "MyTop");
    maskDoc.addMessage(myMask);
    Property mp2 = NavajoFactory.getInstance().createProperty(maskDoc, "MyProp2", "string", "NOOT", 0, "", "in", "");
    myMask.addProperty(mp2);
    Message maskArrayMsg = NavajoFactory.getInstance().createMessage(maskDoc, "MyArrayMessage");
    maskArrayMsg.setType(Message.MSG_TYPE_ARRAY);
    myMask.addMessage(maskArrayMsg);
    Message defMsg = NavajoFactory.getInstance().createMessage(maskDoc, "MyArrayMessage");
    Property mp4 = NavajoFactory.getInstance().createProperty(maskDoc, "MyProp4", "integer", "", 0, "", "in", "");
    defMsg.addProperty(mp4);
    Property mp5 = NavajoFactory.getInstance().createProperty(maskDoc, "MyProp5", "string", "", 0, "", "in", "");
    defMsg.addProperty(mp5);
    maskArrayMsg.setDefinitionMessage(defMsg);
    Message validChild = NavajoFactory.getInstance().createMessage(maskDoc, "SomeValidChildMessage");
    myMask.addMessage(validChild);
    Property mp7 = NavajoFactory.getInstance().createProperty(maskDoc, "MyProp7", "string", "", 0, "", "in", "");
    validChild.addProperty(mp7);
    Assert.assertNotNull(myMessage.getProperty("MyProp1"));
    Assert.assertNotNull(myMessage.getProperty("MyProp2"));
    Assert.assertNotNull(myMessage.getProperty("MyArrayMessage@0/MyProp3"));
    Assert.assertNotNull(myMessage.getProperty("MyArrayMessage@0/MyProp6"));
    Assert.assertNotNull(myMessage.getProperty("MyArrayMessage@0/MyProp4"));
    Assert.assertNotNull(myMessage.getProperty("MyArrayMessage@0/MyProp5"));
    Assert.assertNotNull(myMessage.getMessage("SomeChildMessage"));
    Assert.assertNotNull(myMessage.getProperty("SomeValidChildMessage/MyProp7"));
    Assert.assertNotNull(myMessage.getProperty("SomeValidChildMessage/MyProp8"));
    myMessage.maskMessage(myMask);
    Assert.assertNull(myMessage.getProperty("MyProp1"));
    Assert.assertNotNull(myMessage.getProperty("MyProp2"));
    Assert.assertNull(myMessage.getProperty("MyArrayMessage@0/MyProp3"));
    Assert.assertNull(myMessage.getProperty("MyArrayMessage@0/MyProp6"));
    Assert.assertNotNull(myMessage.getProperty("MyArrayMessage@0/MyProp4"));
    Assert.assertNotNull(myMessage.getProperty("MyArrayMessage@0/MyProp5"));
    Assert.assertEquals("integer", myMessage.getProperty("MyArrayMessage@0/MyProp4").getType());
    Assert.assertNull(myMessage.getMessage("SomeChildMessage"));
    Assert.assertNotNull(myMessage.getProperty("SomeValidChildMessage/MyProp7"));
    Assert.assertNull(myMessage.getProperty("SomeValidChildMessage/MyProp8"));
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 70 with Navajo

use of com.dexels.navajo.document.Navajo in project navajo by Dexels.

the class TestMessage method testValueMap.

@Test
public void testValueMap() {
    Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message.xml"));
    Message m = n.getMessage("SimpleMessage");
    Map<String, Object> vv = m.getValueMap();
    Assert.assertNotNull(vv);
    Object pString = vv.get("pString");
    Assert.assertNotNull(pString);
    Assert.assertTrue(pString instanceof String);
    Object pBoolean = vv.get("pBoolean");
    Assert.assertNotNull(pBoolean);
    Assert.assertTrue(pBoolean instanceof Boolean);
    Assert.assertEquals(3, vv.size());
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Test(org.junit.Test)

Aggregations

Navajo (com.dexels.navajo.document.Navajo)258 Message (com.dexels.navajo.document.Message)131 Test (org.junit.Test)109 Property (com.dexels.navajo.document.Property)86 NavajoException (com.dexels.navajo.document.NavajoException)31 Access (com.dexels.navajo.script.api.Access)30 IOException (java.io.IOException)28 StringWriter (java.io.StringWriter)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)25 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)22 Selection (com.dexels.navajo.document.Selection)22 Header (com.dexels.navajo.document.Header)20 Operand (com.dexels.navajo.document.Operand)20 InputStream (java.io.InputStream)17 UserException (com.dexels.navajo.script.api.UserException)16 Optional (java.util.Optional)16 FatalException (com.dexels.navajo.script.api.FatalException)14 SystemException (com.dexels.navajo.script.api.SystemException)14 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13