private Set<CollectionDescriptor> getCollections() { Set<CollectionDescriptor> collections = new HashSet<CollectionDescriptor>(); CollectionDescriptor cld1 = new CollectionDescriptor("cld1", "String", "reverse1"); CollectionDescriptor cld2 = new CollectionDescriptor("cld2", "Integer", "reverse2"); collections.add(cld1); collections.add(cld2); return collections; }
private static CollectionDescriptor cloneCollectionDescriptor(CollectionDescriptor ref) { return new CollectionDescriptor(ref.getName(), ref.getReferencedClassName(), ref.getReverseReferenceFieldName()); }
private static CollectionDescriptor cloneCollectionDescriptor(CollectionDescriptor ref) { return new CollectionDescriptor(ref.getName(), ref.getReferencedClassName(), ref.getReverseReferenceFieldName()); }
public void testRelationTypeManyToMany() throws Exception { CollectionDescriptor col1 = new CollectionDescriptor("col1", "package.name.Class1", "col2"); CollectionDescriptor col2 = new CollectionDescriptor("col2", "package.name.Class1", null); Set<CollectionDescriptor> cols = new HashSet<CollectionDescriptor>(Arrays.asList(col1, col2)); ClassDescriptor cld = new ClassDescriptor("package.name.Class1", null, false, noAttrs, noRefs, cols); new Model("model1", "package.name", Collections.singleton(cld)); assertEquals(FieldDescriptor.M_N_RELATION, col1.relationType()); }
public void testGenerateCollectionDescriptor() throws Exception { CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "Class2", null); Set cols = new HashSet(Collections.singleton(cod1)); ClassDescriptor cld1 = new ClassDescriptor("Class1", null, false, new HashSet(), new HashSet(), cols); ClassDescriptor cld2 = new ClassDescriptor("Class2", null, false, new HashSet(), new HashSet(), new HashSet()); Model model = new Model("model", "", new HashSet(Arrays.asList(new Object[] {cld1, cld2}))); String expected = INDENT + "// Col: Class1.cod1" + ENDL + INDENT + "protected java.util.Set<Class2> cod1 = new java.util.HashSet<Class2>();" + ENDL + INDENT + "public java.util.Set<Class2> getCod1() { return cod1; }" + ENDL + INDENT + "public void setCod1(final java.util.Set<Class2> cod1) { this.cod1 = cod1; }" + ENDL + INDENT + "public void addCod1(final Class2 arg) { cod1.add(arg); }" + ENDL + ENDL; assertEquals(expected, mo.generate(cod1, true)); }
public void testGetIndirectionTableNameRef() throws Exception { CollectionDescriptor col1 = new CollectionDescriptor("col1", "package.name.Class2", "ref1"); Set cols = new HashSet(Arrays.asList(new Object[] {col1})); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, new HashSet(), new HashSet(), cols); ReferenceDescriptor ref1 = new ReferenceDescriptor("ref1", "package.name.Class1", null); Set refs = new HashSet(Arrays.asList(new Object[] {ref1})); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, new HashSet(), refs, new HashSet()); Set clds = new HashSet(Arrays.asList(new Object[] {cld1, cld2})); new Model("test", "package.name", clds); try { DatabaseUtil.getIndirectionTableName(col1); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
public void testToString() throws Exception { CollectionDescriptor col = new CollectionDescriptor("ref", "package.name.Class1", null); String expected = "<collection name=\"ref\" referenced-type=\"Class1\"/>"; assertEquals(col.toString(), expected); col = new CollectionDescriptor("ref", "package.name.Class1", "reverseRef"); expected = "<collection name=\"ref\" referenced-type=\"Class1\" reverse-reference=\"reverseRef\"/>"; assertEquals(col.toString(), expected); } }
public void testEquals() throws Exception { CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "Class1", "cod1"); CollectionDescriptor cod2 = new CollectionDescriptor("cod1", "Class1", "cod1"); CollectionDescriptor cod3 = new CollectionDescriptor("cod2", "Class1", "cod1"); CollectionDescriptor cod5 = new CollectionDescriptor("cod1", "Class2", "cod1"); CollectionDescriptor cod6 = new CollectionDescriptor("cod1", "Class1", "cod2"); assertEquals(cod1, cod2); assertEquals(cod1.hashCode(), cod2.hashCode()); assertFalse(cod1.equals(cod3)); assertFalse(cod1.equals(cod5)); assertFalse(cod1.equals(cod6)); }
public void testGenerateToString() throws Exception { AttributeDescriptor atd1 = new AttributeDescriptor("inty", "int"); AttributeDescriptor atd2 = new AttributeDescriptor("str", "java.lang.String"); AttributeDescriptor atd3 = new AttributeDescriptor("integery", "java.lang.Integer"); ReferenceDescriptor rfd1 = new ReferenceDescriptor("rfd1", "package.name.Class2", null); CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "package.name.Class2", null); Set<AttributeDescriptor> atts = new LinkedHashSet(Arrays.asList(atd1, atd2, atd3)); Set<ReferenceDescriptor> refs = new LinkedHashSet(Arrays.asList(rfd1)); Set<CollectionDescriptor> cols = new LinkedHashSet(Arrays.asList(cod1)); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, atts, refs, cols); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, new HashSet(), new HashSet(), new HashSet()); Model model = new Model("model", "package.name", new LinkedHashSet(Arrays.asList(cld1, cld2))); String expected = INDENT + "@Override public String toString() { return \"Class1 [id=\" + id + \", integery=\" + integery + \", inty=\" + inty + \", rfd1=\" + (rfd1 == null ? \"null\" : (rfd1.getId() == null ? \"no id\" : rfd1.getId().toString())) + \", str=\" + (str == null ? \"null\" : \"\\\"\" + str + \"\\\"\") + \"]\"; }" + ENDL; assertEquals(expected, mo.generateToString(cld1)); }
public void testGetType() throws Exception { AttributeDescriptor atd1 = new AttributeDescriptor("atd1", "java.lang.String"); assertEquals("java.lang.String", mo.getType(atd1)); ReferenceDescriptor rfd1 = new ReferenceDescriptor("rfd1", "package.name.Class2", null); CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "package.name.Class2", null); Set refs = new HashSet(Collections.singleton(rfd1)); Set cols = new HashSet(Collections.singleton(cod1)); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, new HashSet(), refs, cols); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, new HashSet(), new HashSet(), new HashSet()); Model model = new Model("model", "package.name", new HashSet(Arrays.asList(new Object[] {cld1, cld2}))); assertEquals("package.name.Class2", mo.getType(rfd1)); assertEquals("java.util.Set<package.name.Class2>", mo.getType(cod1)); }
public void testMultiInheritanceLegalCol() throws Exception { CollectionDescriptor coll1 = new CollectionDescriptor("atd1", "package.name.Class2", null); CollectionDescriptor coll2 = new CollectionDescriptor("atd1", "package.name.Class2", null); Set<CollectionDescriptor> colls1 = Collections.singleton(coll1); Set<CollectionDescriptor> colls2 = Collections.singleton(coll2); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, true, noAttrs, noRefs, colls1); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, true, noAttrs, noRefs, colls2); ClassDescriptor cld3 = makeClass("package.name.Class3", "package.name.Class1 package.name.Class2"); new Model("model", "package.name", Arrays.asList(cld1, cld2, cld3)); ReferenceDescriptor rd = cld3.getCollectionDescriptorByName("atd1", true); assertEquals("package.name.Class2", rd.getReferencedClassName()); }
public void testGetIndirectionTableNameCol() throws Exception { CollectionDescriptor col1 = new CollectionDescriptor("col1", "package.name.Class2", "col2"); Set cols = new HashSet(Arrays.asList(new Object[] {col1})); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, new HashSet(), new HashSet(), cols); CollectionDescriptor col2 = new CollectionDescriptor("col2", "package.name.Class1", "col1"); cols = new HashSet(Arrays.asList(new Object[] {col2})); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, new HashSet(), new HashSet(), cols); Set clds = new HashSet(Arrays.asList(new Object[] {cld1, cld2})); new Model("test", "package.name", clds); assertEquals("Col1Col2", DatabaseUtil.getIndirectionTableName(col1)); assertEquals("Col1", DatabaseUtil.getInwardIndirectionColumnName(col1, 0)); assertEquals("Col2", DatabaseUtil.getOutwardIndirectionColumnName(col1, 0)); assertEquals("Col2", DatabaseUtil.getInwardIndirectionColumnName(col1, 1)); assertEquals("Col1", DatabaseUtil.getOutwardIndirectionColumnName(col1, 1)); }
public void testRelationTypeManyToOne() throws Exception { CollectionDescriptor col = new CollectionDescriptor("col1", "package.name.Class1", null); ReferenceDescriptor ref = new ReferenceDescriptor("ref1", "package.name.Class1", "col1"); Set<CollectionDescriptor> cols = Collections.singleton(col); Set<ReferenceDescriptor> refs = Collections.singleton(ref); ClassDescriptor cld = new ClassDescriptor("package.name.Class1", null, false, ClassDescriptorFactory.NO_ATTRS, refs, cols); new Model("model1", "package.name", Collections.singleton(cld)); assertEquals(FieldDescriptor.N_ONE_RELATION, ref.relationType()); }
public void testRelationTypeUnidirectional() throws Exception { CollectionDescriptor col = new CollectionDescriptor("col1", "package.name.Class1", null); Set<CollectionDescriptor> cols = Collections.singleton(col); ClassDescriptor cld = new ClassDescriptor("package.name.Class1", null, false, noAttrs, noRefs, cols); new Model("model1", "package.name", Collections.singleton(cld)); assertEquals(FieldDescriptor.M_N_RELATION, col.relationType()); }
public void testGetIndirectionTableNameNull() throws Exception { CollectionDescriptor col1 = new CollectionDescriptor("col1", "package.name.Class2", null); Set cols = new HashSet(Arrays.asList(new Object[] {col1})); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, new HashSet(), new HashSet(), cols); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, new HashSet(), new HashSet(), new HashSet()); Set clds = new HashSet(Arrays.asList(new Object[] {cld1, cld2})); new Model("test", "package.name", clds); assertEquals("Class1Col1", DatabaseUtil.getIndirectionTableName(col1)); assertEquals("Col1", DatabaseUtil.getInwardIndirectionColumnName(col1, 0)); assertEquals("Class1", DatabaseUtil.getOutwardIndirectionColumnName(col1, 0)); assertEquals("Class1", DatabaseUtil.getInwardIndirectionColumnName(col1, 1)); assertEquals("Col1", DatabaseUtil.getOutwardIndirectionColumnName(col1, 1)); }
public void testRelationTypeOneToMany() throws Exception { CollectionDescriptor col = new CollectionDescriptor("col1", "package.name.Class1", "ref1"); ReferenceDescriptor ref = new ReferenceDescriptor("ref1", "package.name.Class1", null); Set<CollectionDescriptor> cols = Collections.singleton(col); Set<ReferenceDescriptor> refs = Collections.singleton(ref); ClassDescriptor cld = new ClassDescriptor("package.name.Class1", null, false, noAttrs, refs, cols); new Model("model1", "package.name", Collections.singleton(cld)); assertEquals(FieldDescriptor.ONE_N_RELATION, col.relationType()); }
public void testReferencedClassNotSet() throws Exception { CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "Class2", null); Set<CollectionDescriptor> collections = Collections.singleton(cod1); // cld1 has a CollectionDescriptor that contains objects of type Class2 new ClassDescriptor("Class1", null, false, noAttrs, noRefs, collections); new ClassDescriptor("Class2", null, false, noAttrs, noRefs, noColls); try { cod1.getReferencedClassDescriptor(); fail("Expected IllegalStateException, model has not yet been set"); } catch (IllegalStateException e) { } }
public void testMultiInheritanceIllegalRefCol() throws Exception { CollectionDescriptor coll = new CollectionDescriptor("atd1", "package.name.Class2", null); ReferenceDescriptor ref = new ReferenceDescriptor("atd1", "package.name.Class2", null); Set<CollectionDescriptor> colls = Collections.singleton(coll); Set<ReferenceDescriptor> refs = Collections.singleton(ref); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, true, noAttrs, noRefs, colls); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, true, noAttrs, refs, noColls); ClassDescriptor cld3 = makeClass("package.name.Class3", "package.name.Class1 package.name.Class2"); try { new Model("model", "package.name", Arrays.asList(cld1, cld2, cld3)); fail("Expected: MetaDataException"); } catch (MetaDataException e) { } }
public void testGetReferencedClass() throws Exception { CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "package.name.Class2", null); Set<CollectionDescriptor> collections = Collections.singleton(cod1); // cld1 has a ReferenceDescriptor that points to Class2 ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, noAttrs, noRefs, collections); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, noAttrs, noRefs, noColls); new Model("model", "package.name", Arrays.asList(cld1, cld2)); try { ClassDescriptor refCld = cod1.getReferencedClassDescriptor(); assertTrue("ClassDescriptor was null", refCld != null); assertTrue("Expected ClassDescriptor to be Class2", refCld.getName().equals("package.name.Class2")); } catch (IllegalStateException e) { fail("Should have returned a ClassDescriptor"); } }
public void testSetClassDescriptor() throws Exception { ClassDescriptor cld = new ClassDescriptor("Class1", null, false, noAttrs, noRefs, noColls); CollectionDescriptor cod = new CollectionDescriptor("name", "String", null); try { cod.setClassDescriptor(cld); } catch (IllegalStateException e) { fail("should have been able set ClassDescriptor"); } try { cod.setClassDescriptor(cld); fail("Expected: IllegalStateException, ClassDescriptor already set"); } catch (IllegalStateException e) { } }