/** * Clone a set of AttributeDescriptors. * * @param refs a set of AttributeDescriptors * @return cloned set of AttributeDescriptors */ protected static Set<AttributeDescriptor> cloneAttributeDescriptors( Set<AttributeDescriptor> refs) { Set<AttributeDescriptor> copy = new HashSet<AttributeDescriptor>(); for (AttributeDescriptor ref : refs) { copy.add(new AttributeDescriptor(ref.getName(), ref.getType())); } return copy; }
/** * Clone a set of AttributeDescriptors. * * @param refs a set of AttributeDescriptors * @return cloned set of AttributeDescriptors */ protected static Set<AttributeDescriptor> cloneAttributeDescriptors( Set<AttributeDescriptor> refs) { Set<AttributeDescriptor> copy = new HashSet<AttributeDescriptor>(); for (AttributeDescriptor ref : refs) { copy.add(new AttributeDescriptor(ref.getName(), ref.getType())); } return copy; }
private Set<AttributeDescriptor> getAttributes() { Set<AttributeDescriptor> attributes = new HashSet<AttributeDescriptor>(); AttributeDescriptor atd1 = new AttributeDescriptor("atd1", "java.lang.String"); AttributeDescriptor atd2 = new AttributeDescriptor("atd2", "java.lang.Integer"); attributes.add(atd1); attributes.add(atd2); return attributes; }
public void testConstructorEmptyName() throws Exception { try { new AttributeDescriptor("", "int"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
public void testConstructorNullName() throws Exception { try { new AttributeDescriptor(null, "int"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
public void testConstructorNullType() throws Exception { try { new AttributeDescriptor("name", null); fail("Expected: IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
public void testConstructorEmptyType() throws Exception { try { new AttributeDescriptor("name", ""); fail("Expected: IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
public void testGenerateEquals() throws Exception { AttributeDescriptor atd1 = new AttributeDescriptor("atd1", "java.lang.String"); Set atts = new HashSet(Collections.singleton(atd1)); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, atts, new HashSet(), new HashSet()); Model model = new Model("model", "package.name", new HashSet(Collections.singleton(cld1))); String expected = INDENT + "@Override public boolean equals(Object o) { return (o instanceof Class1 && id != null) ? id.equals(((Class1)o).getId()) : this == o; }" + ENDL; assertEquals(expected, mo.generateEquals(cld1)); }
public void testGenerateGetSet() throws Exception { AttributeDescriptor atd1 = new AttributeDescriptor("atd1", "java.lang.String"); Set atts = new HashSet(Collections.singleton(atd1)); ClassDescriptor cld1 = new ClassDescriptor("Class1", null, false, atts, new HashSet(), new HashSet()); Model model = new Model("model", "", new HashSet(Collections.singleton(cld1))); String expected = INDENT + "public java.lang.String getAtd1() { return atd1; }" + ENDL + INDENT + "public void setAtd1(final java.lang.String atd1) { this.atd1 = atd1; }" + ENDL; assertEquals(expected, mo.generateGetSet(atd1, true)); }
public void testGenerateAttributeDescriptor() throws Exception { AttributeDescriptor atd1 = new AttributeDescriptor("atd1", "java.lang.String"); Set atts = new HashSet(Collections.singleton(atd1)); ClassDescriptor cld1 = new ClassDescriptor("Class1", null, false, atts, new HashSet(), new HashSet()); Model model = new Model("model", "", new HashSet(Collections.singleton(cld1))); String expected = INDENT + "// Attr: Class1.atd1" + ENDL + INDENT + "protected java.lang.String atd1;" + ENDL + INDENT + "public java.lang.String getAtd1() { return atd1; }" + ENDL + INDENT + "public void setAtd1(final java.lang.String atd1) { this.atd1 = atd1; }" + ENDL + ENDL; assertEquals(expected, mo.generate(atd1, true)); }
public void testMultiInheritanceLegal() throws Exception { AttributeDescriptor atd1 = new AttributeDescriptor("atd1", "int"); AttributeDescriptor atd2 = new AttributeDescriptor("atd1", "int"); Set<AttributeDescriptor> atds1 = Collections.singleton(atd1); Set<AttributeDescriptor> atds2 = Collections.singleton(atd2); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, true, atds1, noRefs, noColls); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, true, atds2, noRefs, noColls); ClassDescriptor cld3 = makeClass("package.name.Class3", "package.name.Class1 package.name.Class2"); new Model("model", "package.name", Arrays.asList(cld1, cld2, cld3)); }
public void testGetAllAttributeDescriptors() throws Exception { // three superclass levels with one attribute each, getAllAttributeDescriptors on cld3 should return all 3 AttributeDescriptor atb1 = new AttributeDescriptor("att1", "java.lang.String"); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, Collections.singleton(atb1), noRefs, noColls); AttributeDescriptor atb2 = new AttributeDescriptor("att2", "java.lang.String"); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", "package.name.Class1", false, Collections.singleton(atb2), noRefs, noColls); AttributeDescriptor atb3 = new AttributeDescriptor("att3", "java.lang.String"); ClassDescriptor cld3 = new ClassDescriptor("package.name.Class3", "package.name.Class2", false, Collections.singleton(atb3), noRefs, noColls); new Model("test", "package.name", Arrays.asList(cld1, cld2, cld3)); FieldDescriptor id = cld3.getFieldDescriptorByName("id"); Set<FieldDescriptor> atts = new HashSet<FieldDescriptor>(Arrays.asList(atb3, atb2, atb1, id)); assertEquals(atts, cld3.getAllAttributeDescriptors()); }
public void testToString() throws Exception { AttributeDescriptor attr = new AttributeDescriptor("attr", "int"); String expected = "<attribute name=\"attr\" type=\"int\"/>"; assertEquals(expected, attr.toString()); } }
public void testEquals() throws Exception { AttributeDescriptor attr1 = new AttributeDescriptor("name1", "int"); AttributeDescriptor attr2 = new AttributeDescriptor("name1", "int"); AttributeDescriptor attr3 = new AttributeDescriptor("name2", "int"); AttributeDescriptor attr4 = new AttributeDescriptor("name1", "float"); assertEquals(attr1, attr2); assertEquals(attr1.hashCode(), attr2.hashCode()); assertFalse(attr1.equals(attr3)); assertFalse(attr1.equals(attr4)); }
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 testMultiInheritanceIllegalDueToAttributeTypeMismatch() throws Exception { AttributeDescriptor atd1 = new AttributeDescriptor("collision", "int"); AttributeDescriptor atd2 = new AttributeDescriptor("collision", "float"); Set<AttributeDescriptor> atds1 = Collections.singleton(atd1); Set<AttributeDescriptor> atds2 = Collections.singleton(atd2); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, true, atds1, noRefs, noColls); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, true, atds2, noRefs, 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 testRelationType() throws Exception { AttributeDescriptor attr = new AttributeDescriptor("name", "int"); assertEquals(FieldDescriptor.NOT_RELATION, attr.relationType()); }
public void testMultiInheritanceIllegalAttCol() throws Exception { CollectionDescriptor coll = new CollectionDescriptor("collision", "package.name.Class2", null); AttributeDescriptor attr = new AttributeDescriptor("collision", "float"); Set<CollectionDescriptor> colls = Collections.singleton(coll); Set<AttributeDescriptor> attrs = Collections.singleton(attr); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, true, noAttrs, noRefs, colls); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, true, attrs, noRefs, 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 testGetColumnName() throws Exception { FieldDescriptor attr = new AttributeDescriptor("attr1", "int"); assertEquals(DatabaseUtil.generateSqlCompatibleName("attr1"), DatabaseUtil.getColumnName(attr)); }
public void testMultiInheritanceIllegalAttRef() throws Exception { AttributeDescriptor attr = new AttributeDescriptor("collision", "float"); ReferenceDescriptor ref = new ReferenceDescriptor("collision", "package.name.Class2", null); Set<AttributeDescriptor> attrs = Collections.singleton(attr); Set<ReferenceDescriptor> refs = Collections.singleton(ref); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, true, noAttrs, refs, noColls); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, true, attrs, noRefs, 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) { } }