Search in sources :

Example 6 with GrailsApplication

use of grails.core.GrailsApplication in project grails-core by grails.

the class ConstraintsEvaluatingPropertyTests method testGet.

/*
     * Test method for 'ConstraintsDynamicProperty.get(Object)'
     */
@SuppressWarnings("rawtypes")
public void testGet() throws Exception {
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> groovyClass = gcl.parseClass("package org.grails.validation\n" + "class Test {\n" + // WE NEED this even though GORM 2 doesn't, as we're not a "domain" class within grails-app
    "   Long id\n" + // WE NEED this even though GORM 2 doesn't, as we're not a "domain" class within grails-app
    "   Long version\n" + " String name\n" + "}");
    GrailsApplication ga = new DefaultGrailsApplication(groovyClass);
    ga.initialise();
    new MappingContextBuilder(ga).build(groovyClass);
    GrailsDomainClass domainClass = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, groovyClass.getName());
    Map constraints = domainClass.getConstrainedProperties();
    assertNotNull(constraints);
    assertFalse(constraints.isEmpty());
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) GrailsApplication(grails.core.GrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) GrailsDomainClass(grails.core.GrailsDomainClass) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) Map(java.util.Map)

Example 7 with GrailsApplication

use of grails.core.GrailsApplication 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)

Example 8 with GrailsApplication

use of grails.core.GrailsApplication in project grails-core by grails.

the class Holders method getGrailsApplication.

public static GrailsApplication getGrailsApplication() {
    GrailsApplication grailsApplication = findApplication();
    Assert.notNull(grailsApplication, "GrailsApplication not found");
    return grailsApplication;
}
Also used : GrailsApplication(grails.core.GrailsApplication)

Example 9 with GrailsApplication

use of grails.core.GrailsApplication in project grails-core by grails.

the class GroovyPage method initRun.

public void initRun(Writer target, OutputContext outputContext, GroovyPageMetaInfo metaInfo) {
    OutputEncodingStackAttributes.Builder attributesBuilder = new OutputEncodingStackAttributes.Builder();
    if (metaInfo != null) {
        setJspTags(metaInfo.getJspTags());
        setJspTagLibraryResolver(metaInfo.getJspTagLibraryResolver());
        setGspTagLibraryLookup(metaInfo.getTagLibraryLookup());
        setHtmlParts(metaInfo.getHtmlParts());
        setPluginContextPath(metaInfo.getPluginPath());
        attributesBuilder.outEncoder(metaInfo.getOutEncoder());
        attributesBuilder.staticEncoder(metaInfo.getStaticEncoder());
        attributesBuilder.expressionEncoder(metaInfo.getExpressionEncoder());
        attributesBuilder.defaultTaglibEncoder(metaInfo.getTaglibEncoder());
        applyModelFieldsFromBinding(metaInfo.getModelFields());
    }
    attributesBuilder.allowCreate(true).topWriter(target).autoSync(false).pushTop(true);
    attributesBuilder.outputContext(outputContext);
    attributesBuilder.inheritPreviousEncoders(false);
    outputStack = OutputEncodingStack.currentStack(attributesBuilder.build());
    out = outputStack.getOutWriter();
    staticOut = outputStack.getStaticWriter();
    expressionOut = outputStack.getExpressionWriter();
    this.outputContext = outputContext;
    if (outputContext != null) {
        outputContext.setCurrentWriter(out);
        GrailsApplication grailsApplication = outputContext.getGrailsApplication();
        if (grailsApplication != null) {
            rawEncoder = WithCodecHelper.lookupEncoder(grailsApplication, "Raw");
        }
    }
    setVariableDirectly(OUT, out);
    setVariableDirectly(EXPRESSION_OUT, expressionOut);
}
Also used : GrailsApplication(grails.core.GrailsApplication) OutputEncodingStackAttributes(org.grails.taglib.encoder.OutputEncodingStackAttributes)

Example 10 with GrailsApplication

use of grails.core.GrailsApplication in project grails-core by grails.

the class ConstraintsEvaluatingPropertyTests method ensureConstraintsPresent.

@SuppressWarnings("rawtypes")
private void ensureConstraintsPresent(String[] classSource, int classIndexToTest, int constraintCount) throws Exception {
    // We need to do a real test here to make sure
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class[] classes = new Class[classSource.length];
    for (int i = 0; i < classSource.length; i++) {
        classes[i] = gcl.parseClass(classSource[i]);
    }
    GrailsApplication ga = new DefaultGrailsApplication(classes[classIndexToTest]);
    ga.initialise();
    new MappingContextBuilder(ga).build(classes[classIndexToTest]);
    GrailsDomainClass domainClass = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, classes[classIndexToTest].getName());
    Map constraints = domainClass.getConstrainedProperties();
    grails.gorm.validation.ConstrainedProperty p = (grails.gorm.validation.ConstrainedProperty) constraints.get("name");
    Collection cons = p.getAppliedConstraints();
    assertEquals("Incorrect number of constraints extracted: " + constraints, constraintCount, cons.size());
}
Also used : GrailsDomainClass(grails.core.GrailsDomainClass) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) GroovyClassLoader(groovy.lang.GroovyClassLoader) GrailsApplication(grails.core.GrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) Collection(java.util.Collection) GrailsDomainClass(grails.core.GrailsDomainClass) Map(java.util.Map) grails.gorm.validation(grails.gorm.validation)

Aggregations

GrailsApplication (grails.core.GrailsApplication)18 DefaultGrailsApplication (grails.core.DefaultGrailsApplication)9 GrailsDomainClass (grails.core.GrailsDomainClass)8 GroovyClassLoader (groovy.lang.GroovyClassLoader)8 Map (java.util.Map)4 CollectionDataBindingSource (grails.databinding.CollectionDataBindingSource)3 IncludingPluginFilter (org.grails.plugins.IncludingPluginFilter)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 DataBindingSource (grails.databinding.DataBindingSource)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 WebApplicationContext (org.springframework.web.context.WebApplicationContext)2 GrailsClass (grails.core.GrailsClass)1 GrailsControllerClass (grails.core.GrailsControllerClass)1 DataBinder (grails.databinding.DataBinder)1 grails.gorm.validation (grails.gorm.validation)1 Constrained (grails.gorm.validation.Constrained)1 ValidationErrors (grails.validation.ValidationErrors)1 GrailsWebDataBinder (grails.web.databinding.GrailsWebDataBinder)1