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());
}
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());
}
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;
}
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);
}
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());
}
Aggregations