Search in sources :

Example 71 with Navajo

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

the class TestNavajo method testMerge.

@Test
public void testMerge() {
    // testmessage
    Navajo extra = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(extra, "testmessage");
    Property p = NavajoFactory.getInstance().createProperty(extra, "extrapropje", Property.STRING_PROPERTY, "", 0, "", "");
    Property p2 = NavajoFactory.getInstance().createProperty(extra, "stringprop", Property.STRING_PROPERTY, "SUPERNAVAJO", 0, "", "");
    m.addProperty(p);
    m.addProperty(p2);
    extra.addMessage(m);
    Message m2 = NavajoFactory.getInstance().createMessage(extra, "testmessage_sub2");
    m.addMessage(m2);
    p = NavajoFactory.getInstance().createProperty(extra, "nogeenextrapropje", Property.STRING_PROPERTY, "", 0, "", "");
    m2.addProperty(p);
    m = NavajoFactory.getInstance().createMessage(extra, "testmessage_extra");
    p = NavajoFactory.getInstance().createProperty(extra, "extrapropje", Property.STRING_PROPERTY, "", 0, "", "");
    m.addProperty(p);
    extra.addMessage(m);
    // Before merge assert value of stringprop.
    Assert.assertEquals("navajo", testDoc.getProperty("/testmessage/stringprop").getValue());
    testDoc.merge(extra);
    Property assertprop = testDoc.getProperty("/testmessage/extrapropje");
    Assert.assertNotNull(assertprop);
    assertprop = testDoc.getProperty("/testmessage/integerprop");
    Assert.assertNotNull(assertprop);
    // After merge assert value of stringprop.
    Assert.assertEquals("SUPERNAVAJO", testDoc.getProperty("/testmessage/stringprop").getValue());
}
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 72 with Navajo

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

the class TestNavajo method testAppendDocBuffer.

@Test
public void testAppendDocBuffer() {
    Navajo extra = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(extra, "appendedmessage");
    Property p = NavajoFactory.getInstance().createProperty(extra, "propje", Property.STRING_PROPERTY, "", 0, "", "");
    m.addProperty(p);
    extra.addMessage(m);
    Message m2 = NavajoFactory.getInstance().createMessage(extra, "bliep");
    extra.addMessage(m2);
    testDoc.appendDocBuffer(extra.getMessageBuffer());
    Message result = testDoc.getMessage("appendedmessage");
    Assert.assertNotNull(result);
    Assert.assertEquals("appendedmessage", result.getName());
}
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 73 with Navajo

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

the class TestCheckTypes method createNavajoEntity.

private Navajo createNavajoEntity() {
    Navajo n1 = NavajoFactory.getInstance().createNavajo();
    Message m1 = NavajoFactory.getInstance().createMessage(n1, "Match");
    n1.addMessage(m1);
    Property p1 = NavajoFactory.getInstance().createProperty(n1, "MatchId", Property.INTEGER_PROPERTY, "", 0, "", "");
    m1.addProperty(p1);
    Property p2 = NavajoFactory.getInstance().createProperty(n1, "MatchName", Property.STRING_PROPERTY, "", 0, "", "");
    m1.addProperty(p2);
    // Add definition.
    Message m2 = NavajoFactory.getInstance().createMessage(n1, "Facilities", Message.MSG_TYPE_ARRAY);
    m1.addMessage(m2);
    Message def = NavajoFactory.getInstance().createMessage(n1, "Facilities", Message.MSG_TYPE_DEFINITION);
    Property p1c = NavajoFactory.getInstance().createProperty(n1, "FacilityName", Property.STRING_PROPERTY, "", 0, "", "");
    Property p2c = NavajoFactory.getInstance().createProperty(n1, "Size", Property.STRING_PROPERTY, "", 0, "", "");
    Property p3c = NavajoFactory.getInstance().createProperty(n1, "Address", Property.STRING_PROPERTY, "", 0, "", "");
    def.addProperty(p1c);
    def.addProperty(p2c);
    def.addProperty(p3c);
    m2.setDefinitionMessage(def);
    Message extra = NavajoFactory.getInstance().createMessage(n1, "Extra");
    m1.addMessage(extra);
    return n1;
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 74 with Navajo

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

the class TestNavajoDoc method testMarteMessage.

@Test
public void testMarteMessage() {
    // Unit test for ignoring message under an array message and keep the correct
    // index number.
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message array = NavajoFactory.getInstance().createMessage(n, "Actor");
    n.addMessage(array);
    array.setType(Message.MSG_TYPE_ARRAY);
    // creating children messages
    // child 1
    Message child1 = NavajoFactory.getInstance().createMessage(n, "Actor");
    // child1.setIndex(0);
    array.addElement(child1);
    Property property1_child1 = NavajoFactory.getInstance().createProperty(n, "Id", Property.INTEGER_PROPERTY, "1", 0, "", "out");
    Property property2_child1 = NavajoFactory.getInstance().createProperty(n, "FirstName", Property.STRING_PROPERTY, "Penelope", 0, "", "out");
    Property property3_child1 = NavajoFactory.getInstance().createProperty(n, "LastName", Property.STRING_PROPERTY, "1", 0, "", "out");
    child1.addProperty(property1_child1);
    child1.addProperty(property2_child1);
    child1.addProperty(property3_child1);
    // child 2
    Message child2 = NavajoFactory.getInstance().createMessage(n, "Actor");
    // child2.setIndex(0);
    array.addElement(child2);
    Property property1_child2 = NavajoFactory.getInstance().createProperty(n, "Id", Property.INTEGER_PROPERTY, "2", 0, "", "out");
    Property property2_child2 = NavajoFactory.getInstance().createProperty(n, "FirstName", Property.STRING_PROPERTY, "Nick", 0, "", "out");
    Property property3_child2 = NavajoFactory.getInstance().createProperty(n, "LastName", Property.STRING_PROPERTY, "Wahlberg", 0, "", "out");
    child2.addProperty(property1_child2);
    child2.addProperty(property2_child2);
    child2.addProperty(property3_child2);
    // System.out.println("Array message size "+
    // n.getMessage("Array").getArraySize());
    n.write(System.out);
    // Assert.assertEquals(1, n.getMessage("Array").getArraySize());
    Assert.assertEquals(0, n.getMessage("Actor").getMessage(0).getIndex());
    Assert.assertEquals(1, n.getMessage("Actor").getMessage(1).getIndex());
}
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 75 with Navajo

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

the class TestOperation method testOperation.

@Test
public void testOperation() {
    NavajoFactory f = NavajoFactory.getInstance();
    Navajo n = f.createNavajo();
    Message msg = f.createMessage(n, "__Mongo__");
    Operation o = f.createOperation(n, "PUT", "vla/ProcessInsertPerson", null, "Person", null);
    n.addOperation(o);
    o.setExtraMessage(msg);
    Method m = f.createMethod(n, "vla/ProcessUpdatePerson", null);
    m.addRequired("Apenoot");
    n.addMethod(m);
    n.write(System.err);
}
Also used : NavajoFactory(com.dexels.navajo.document.NavajoFactory) Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Operation(com.dexels.navajo.document.Operation) Method(com.dexels.navajo.document.Method) 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