public void testNullConstructorFields() throws Exception { try { new CollectionDescriptor(null, "String", null); fail("Expected IllegalArgumentException for null name"); } catch (IllegalArgumentException e) { } try { new CollectionDescriptor("", "String", null); fail("Expected: IllegalArgumentException for empty name"); } catch (IllegalArgumentException e) { } try { new CollectionDescriptor("name", null, null); fail("Expected IllegalArgumentException for null referencedType"); } catch (IllegalArgumentException e) { } try { new CollectionDescriptor("name", "", null); fail("Expected: IllegalArgumentException for empty referencedType"); } catch (IllegalArgumentException e) { } }
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) { } }
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 testReverseReferenceInvalid() throws Exception { // cod1 points to Class2 but has reverse reference (codDummy) that is not a field of Class1 CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "package.name.Class2", "codDummy"); CollectionDescriptor cod2 = new CollectionDescriptor("cod2", "package.name.Class1", "cod1"); Set<CollectionDescriptor> cols1 = Collections.singleton(cod1); Set<CollectionDescriptor> cols2 = Collections.singleton(cod2); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, noAttrs, noRefs, cols1); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, noAttrs, noRefs, cols2); try { new Model("model", "package.name", Arrays.asList(cld1, cld2)); fail("Expected a MetaDataException to be thrown"); } 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 testReverseReferenceValid() throws Exception { // codd1 in Class1 points to Class2, cod2 in Class2 points to Class1 CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "package.name.Class2", "cod2"); CollectionDescriptor cod2 = new CollectionDescriptor("cod2", "package.name.Class1", "cod1"); Set<CollectionDescriptor> cols1 = Collections.singleton(cod1); Set<CollectionDescriptor> cols2 = Collections.singleton(cod2); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, noAttrs, noRefs, cols1); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, noAttrs, noRefs, cols2); new Model("model", "package.name", Arrays.asList(cld1, cld2)); try { ReferenceDescriptor rfdReverse = cod1.getReverseReferenceDescriptor(); assertEquals(cod2, rfdReverse); assertEquals(cld1, rfdReverse.getReferencedClassDescriptor()); } catch (IllegalStateException e) { fail("Should have returned reverse ReferenceDescriptor"); } }