Menu

WorkingExamples

Mark

ServiceMethodInvoker

Example Java Code

public class MyTestGroup {

    private String name;

    private int intValue;
    private Double doubleValue;
    private Date date;
    private int [] intValueArray;
    private Double [] doubleValueArray;

    private MyTestGroup innerGroup;

    private MyTestGroup [] memberGroupArray;

    private List<?> memberGroupList;

    private Set<?> memberGroupSet;

    private MyTestInterface testInterface;

        // With appropriate Constructor, Getters and Setters.....
}
import junit.framework.TestCase;
import parser.MyTestGroup;

public class SampleServiceMethodInvokerTest extends TestCase {

    ServiceMethodInvoker theServiceMethodInvoker = null;

    public void setUp() throws Exception {

    }

    public void testParserWithDeepArrayTypeCreation() throws Exception {

        theServiceMethodInvoker = new ServiceMethodInvoker(this, "serviceCallForTestParserWithDeepArrayTypeCreation");


        theServiceMethodInvoker.parseAndUpdate("group.memberGroupArray[0].name", "Member Group Name 0");
        theServiceMethodInvoker.parseAndUpdate("group.memberGroupArray[0].innerGroup.name", "Member Inner Group Name 0");


        theServiceMethodInvoker.invoke();


        assertEquals("Member Group Name 0", theServiceMethodInvoker.parseAndRetrieve("group.memberGroupArray[0].name"));
        assertEquals("Member Inner Group Name 0", theServiceMethodInvoker.parseAndRetrieve("group.memberGroupArray[0].innerGroup.name"));

    }


    protected MyTestGroup serviceCallForTestParserWithDeepArrayTypeCreation(MyTestGroup group) throws Exception {

        assertEquals("Member Group Name 0", group.getMemberGroupArray()[0].getName());
        assertEquals("Member Inner Group Name 0", group.getMemberGroupArray()[0].getInnerGroup().getName());

        return group;

    }
}

PojoNodeParser

Example Java Code

~~~~~~import java.util.ArrayList;
import java.util.LinkedHashSet;

import parser.PojoNodeParser;
import parser.node.PojoNode;
import parser.node.PojoRootNode;
import parser.pojo.UtcDateConverter;

import junit.framework.TestCase;

public class SamplePojoNodeParserTest extends TestCase {

PojoNodeParser thePojoNodeParser = PojoNodeParser.getInstance();

PojoRootNode rootPojoNode;
MyTestGroup rootPojoNodePojo;

PojoNode currentPojoNode;

public void setUp() throws Exception{
    rootPojoNode = getRootPojoNodeInstance();
    rootPojoNodePojo = (MyTestGroup)rootPojoNode.getPojo();
}

protected PojoRootNode getRootPojoNodeInstance() throws Exception{
    PojoRootNode newRootPojoNode = new PojoRootNode();
    MyTestGroup newRootPojoNodePojo = MyTestGroup.class.newInstance();
    newRootPojoNode.setPojo(newRootPojoNodePojo);
    return newRootPojoNode;
}

public void testArrayTypeCreation() throws Exception {

    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.name", "NAME");
    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.intValue", "25");
    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.doubleValue", "2.5");

    // 24 hour clock in UTC: 'yyyy-MM-dd HH:mm:ss', ex: '2006-01-20 23:59:59'
    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.date", "2006-01-20 23:59:59");
    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.intValueArray[0]", "10");
    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.intValueArray[1]", "11");
    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.doubleValueArray[0]", "1.01");
    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.doubleValueArray[1]", "1.11");

    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.memberGroupArray[0].name", "Member Group Name 0");
    thePojoNodeParser.parseAndUpdate(rootPojoNode, "group.memberGroupArray[1].innerGroup.name", "Member Inner Group Name 1");

    assertEquals("NAME", rootPojoNodePojo.getName());
    assertEquals(25, rootPojoNodePojo.getIntValue());
    assertEquals(2.5, rootPojoNodePojo.getDoubleValue());
    assertEquals("2006-01-20 23:59:59", UtcDateConverter.getUtcDateStringFromDate(rootPojoNodePojo.getDate()));
    assertEquals(10, rootPojoNodePojo.getIntValueArray()[0]);
    assertEquals(11, rootPojoNodePojo.getIntValueArray()[1]);
    assertEquals(1.01, rootPojoNodePojo.getDoubleValueArray()[0]);
    assertEquals(1.11, rootPojoNodePojo.getDoubleValueArray()[1]);

    assertEquals("Member Group Name 0", rootPojoNodePojo.getMemberGroupArray()[0].getName());
    assertEquals("Member Inner Group Name 1", rootPojoNodePojo.getMemberGroupArray()[1].getInnerGroup().getName());
}

}
~~~~~~


MongoDB Logo MongoDB