Search in sources :

Example 1 with MappingContextBuilder

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());
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) GrailsApplication(grails.core.GrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) GrailsDomainClass(grails.core.GrailsDomainClass) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) MappingContextBuilder(org.grails.core.support.MappingContextBuilder)

Aggregations

DefaultGrailsApplication (grails.core.DefaultGrailsApplication)1 GrailsApplication (grails.core.GrailsApplication)1 GrailsDomainClass (grails.core.GrailsDomainClass)1 GroovyClassLoader (groovy.lang.GroovyClassLoader)1 MappingContextBuilder (org.grails.core.support.MappingContextBuilder)1