コード例 #1
0
  @Test
  public void testCycle() throws JSONObjectAdapterException {
    // Create an object with nesting
    ObjectSchema root = new ObjectSchema();
    root.setName("Root");
    String rootId = new String("root");
    root.setId(rootId);
    // Create a child class
    ObjectSchema child = new ObjectSchema();
    String childId = new String("child");
    child.setName("Child");
    child.setId(childId);
    child.setType(TYPE.OBJECT);
    root.putProperty("childInstance1", child);
    // Add a self reference child
    ObjectSchema rootRef = new ObjectSchema();
    rootRef.setRef(rootId);
    child.putProperty("rootRef", rootRef);
    // Create a grand child

    List<ObjectSchema> list = new ArrayList<ObjectSchema>();
    list.add(root);
    Map<String, ObjectSchema> register =
        PojoGeneratorDriver.registerAllIdentifiedObjectSchemas(list);
    PojoGeneratorDriver.findAndReplaceAllReferencesSchemas(register, list);
  }
コード例 #2
0
 @Test
 public void testCreateOrGetTypeExtends() throws ClassNotFoundException {
   JCodeModel codeModel = new JCodeModel();
   ObjectSchema parent = new ObjectSchema();
   parent.setType(TYPE.OBJECT);
   parent.setName("ParentClass");
   parent.setId("org.sample." + parent.getName());
   schema.setExtends(parent);
   schema.setType(TYPE.OBJECT);
   schema.setName("ChildClass");
   JType type = driver.createOrGetType(codeModel, schema);
   assertNotNull(type);
   JDefinedClass def = (JDefinedClass) type;
   String classDeffString = declareToString(def);
   assertTrue(classDeffString.indexOf("extends org.sample.ParentClass") > 0);
 }
コード例 #3
0
 @Before
 public void before() {
   driver = new PojoGeneratorDriver(new HandlerFactoryImpl03());
   schema = new ObjectSchema();
   schema.setName("SampleClass");
   schema.setId("org.sample." + schema.getName());
 }
コード例 #4
0
  @Test
  public void testInterfaceField() throws JSONObjectAdapterException, ClassNotFoundException {
    // Create an object with nesting
    ObjectSchema inter = new ObjectSchema();
    inter.setName("SomeInterface");
    inter.setType(TYPE.INTERFACE);
    inter.setId("example.org.SomeInterface");

    ObjectSchema interRef = new ObjectSchema();
    interRef.setRef(inter.getId());

    ObjectSchema impl = new ObjectSchema();
    impl.setName("SomeInterfaceImpl");
    impl.setType(TYPE.OBJECT);
    impl.setId("example.org.SomeInterfaceImpl");
    impl.setImplements(new ObjectSchema[] {interRef});

    ObjectSchema root = new ObjectSchema();
    root.setName("Root");
    root.setId(new String("root"));
    root.setType(TYPE.OBJECT);

    // Create a child class
    ObjectSchema child = new ObjectSchema();
    String childId = new String("child");
    child.setName("Child");
    child.setId(childId);
    child.setType(TYPE.OBJECT);
    child.setRef(inter.getId());
    root.putProperty("interfaceField", child);

    List<ObjectSchema> list = new ArrayList<ObjectSchema>();
    list.add(inter);
    list.add(impl);
    list.add(root);
    //		Map<String, ObjectSchema> register =
    // PojoGeneratorDriver.registerAllIdentifiedObjectSchemas(list);
    //		List<ObjectSchema> schemaList =
    // PojoGeneratorDriver.findAndReplaceAllReferencesSchemas(register, list);
    JCodeModel codeModel = new JCodeModel();
    driver.createAllClasses(codeModel, list);
  }
コード例 #5
0
 @Test
 public void testCreateOrGetTypeImplements() throws ClassNotFoundException {
   JCodeModel codeModel = new JCodeModel();
   ObjectSchema parent = new ObjectSchema();
   parent.setType(TYPE.INTERFACE);
   parent.setName("ParentInterface");
   parent.setId("org.sample." + parent.getName());
   schema.setImplements(new ObjectSchema[] {parent});
   schema.setType(TYPE.OBJECT);
   schema.setName("ChildClass");
   JType type = driver.createOrGetType(codeModel, schema);
   assertNotNull(type);
   JDefinedClass def = (JDefinedClass) type;
   String classDeffString = declareToString(def);
   //		System.out.println(classDeffString);
   assertTrue(
       classDeffString.indexOf(
               "implements java.io.Serializable, org.sagebionetworks.schema.adapter.JSONEntity, org.sample.ParentInterface")
           > 0);
 }
コード例 #6
0
  @Test
  public void testNestedObjects() throws JSONObjectAdapterException {
    // Create an object with nesting
    ObjectSchema root = new ObjectSchema();
    root.setName("Root");
    root.setId(new String("root"));
    // Create a child class
    ObjectSchema child = new ObjectSchema();
    child.setName("Child");
    child.setType(TYPE.OBJECT);
    root.putProperty("childInstance1", child);
    // Create a grand child
    ObjectSchema grand = new ObjectSchema();
    grand.setName("Grand");
    grand.setType(TYPE.OBJECT);
    String grandId = new String("grand");
    grand.setId(grandId);
    child.putProperty("grandChildInstance1", grand);
    ObjectSchema grandRef = new ObjectSchema();
    grandRef.setRef(grandId);
    child.putProperty("grandChildInstance2", grandRef);
    System.out.println(root.toJSONString(new JSONObjectAdapterImpl()));
    List<ObjectSchema> list = new ArrayList<ObjectSchema>();
    list.add(root);

    // Now before the are replaces this should be a references
    ObjectSchema test = child.getProperties().get("grandChildInstance2");
    assertNotNull(test);
    assertEquals(grandId, test.getRef());

    Map<String, ObjectSchema> register =
        PojoGeneratorDriver.registerAllIdentifiedObjectSchemas(list);
    PojoGeneratorDriver.findAndReplaceAllReferencesSchemas(register, list);
    // Validate that the nest grand child reference is replaced
    test = child.getProperties().get("grandChildInstance2");
    assertNotNull(test);
    assertEquals(null, test.getRef());
    assertEquals(grand, test);
  }