コード例 #1
0
  @Test
  public void testFindAndReplaceAllReferencesSchemasFull() {
    String referenceId = new String("rootOne");
    ObjectSchema referenced = ObjectSchema.createNewWithId(referenceId);
    HashMap<String, ObjectSchema> registry = new HashMap<String, ObjectSchema>();
    // Add the referenced schema to the register.
    registry.put(referenceId, referenced);
    // Create a third self
    ObjectSchema self = ObjectSchema.createNewWithId(new String("self"));
    ObjectSchema refToSelf = new ObjectSchema();
    refToSelf.setRef(new String(ObjectSchema.SELF_REFERENCE));

    ObjectSchema referenceToOther = new ObjectSchema();
    referenceToOther.setRef(referenceId);

    // Add references in all places
    self.putProperty("one", referenceToOther);
    self.putAdditionalProperty("two", referenceToOther);
    self.setItems(refToSelf);
    self.setAdditionalItems(refToSelf);
    self.setImplements(new ObjectSchema[] {referenceToOther});

    // find and replace
    PojoGeneratorDriver.findAndReplaceAllReferencesSchemas(registry, self);
    // Make sure there are no references
    Iterator<ObjectSchema> it = self.getSubSchemaIterator();
    while (it.hasNext()) {
      ObjectSchema toTest = it.next();
      assertTrue(toTest.getRef() == null);
    }
  }
コード例 #2
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);
  }
コード例 #3
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);
 }