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);
}
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);
}
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);
}
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"));
}
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());
}
Aggregations