use of org.grails.core.support.MappingContextBuilder in project grails-core by grails.
the class HeirarchyDomainClassTests method testClassHeirarchy.
public void testClassHeirarchy() throws Exception {
GroovyClassLoader gcl = new GroovyClassLoader();
gcl.parseClass("@grails.persistence.Entity class Super { Long id;Long version;}\n" + "class Sub extends Super { }\n" + "class Sub2 extends Sub { }");
GrailsApplication ga = new DefaultGrailsApplication(gcl.getLoadedClasses(), gcl);
ga.initialise();
new MappingContextBuilder(ga).build(gcl.getLoadedClasses());
GrailsDomainClass gdc1 = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, "Super");
assertNotNull(gdc1);
assertTrue(gdc1.isRoot());
assertEquals(2, gdc1.getSubClasses().size());
assertFalse(gdc1.getPropertyByName("id").isInherited());
GrailsDomainClass gdc2 = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, "Sub");
assertFalse(gdc2.isRoot());
assertEquals(1, gdc2.getSubClasses().size());
assertTrue(gdc2.getPropertyByName("id").isInherited());
GrailsDomainClass gdc3 = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, "Sub2");
assertFalse(gdc3.isRoot());
assertEquals(0, gdc3.getSubClasses().size());
assertTrue(gdc3.getPropertyByName("id").isInherited());
}
Aggregations