Permalink
Browse files

Merge branch 'master' of github.com:grails/grails-core

  • Loading branch information...
2 parents e263b38 + 17d2ccc commit a5bf8e178b20e6fe937ecb2ba3ec70f9013bd7a1 @graemerocher graemerocher committed Jul 8, 2010
Showing with 252 additions and 28 deletions.
  1. +4 −1 src/java/org/codehaus/groovy/grails/commons/GrailsDomainConfigurationUtil.java
  2. +14 −0 src/test/grails/test/GrailsUnitTestCaseTests.groovy
  3. +6 −0 src/test/grails/test/MockUtilsSaveDomainTests.groovy
  4. +10 −2 src/test/grails/test/MockUtilsTests.groovy
  5. +14 −0 src/test/org/codehaus/groovy/grails/commons/DefaultGrailsDomainClassTests.groovy
  6. +7 −0 src/test/org/codehaus/groovy/grails/commons/GrailsDomainConfigurationUtilTests.java
  7. +5 −0 src/test/org/codehaus/groovy/grails/orm/hibernate/AbstractGrailsHibernateTests.groovy
  8. +11 −0 src/test/org/codehaus/groovy/grails/orm/hibernate/BidirectionalListMappingTests.groovy
  9. +10 −0 src/test/org/codehaus/groovy/grails/orm/hibernate/ComponentDomainTests.groovy
  10. +14 −0 src/test/org/codehaus/groovy/grails/orm/hibernate/DerivedPropertiesTests.groovy
  11. +14 −2 src/test/org/codehaus/groovy/grails/orm/hibernate/UnidirectionalOneToManyHibernateMappedTests.groovy
  12. +14 −2 src/test/org/codehaus/groovy/grails/orm/hibernate/cfg/GORMNamespaceHandlerTests.groovy
  13. +9 −1 src/test/org/codehaus/groovy/grails/orm/hibernate/cfg/GrailsDomainBinderTests.java
  14. +16 −0 src/test/org/codehaus/groovy/grails/scaffolding/DomainClassPropertyComparatorTests.java
  15. +17 −0 src/test/org/codehaus/groovy/grails/validation/ConstrainedPropertyTests.java
  16. +11 −0 src/test/org/codehaus/groovy/grails/validation/ConstraintsBuilderTests.groovy
  17. +24 −5 src/test/org/codehaus/groovy/grails/validation/ConstraintsEvaluatingPropertyTests.java
  18. +16 −10 src/test/org/codehaus/groovy/grails/validation/GrailsDomainClassValidatorTests.groovy
  19. +12 −0 src/test/org/codehaus/groovy/grails/validation/NullableConstraintTests.groovy
  20. +10 −0 src/test/org/codehaus/groovy/grails/web/taglib/PropertyEditorTests.groovy
  21. +14 −5 src/test/org/codehaus/groovy/grails/web/taglib/ValidationTagLibTests.groovy
@@ -55,6 +55,7 @@
import org.codehaus.groovy.grails.exceptions.GrailsConfigurationException;
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder;
import org.codehaus.groovy.grails.orm.hibernate.cfg.PropertyConfig;
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder;
import org.codehaus.groovy.grails.validation.ConstrainedProperty;
import org.codehaus.groovy.grails.validation.ConstrainedPropertyBuilder;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
@@ -376,8 +377,10 @@ public static boolean isNotConfigurational(PropertyDescriptor descriptor) {
Map<String, ConstrainedProperty> constrainedProperties = delegate.getConstrainedProperties();
if (properties != null && !(constrainedProperties.isEmpty() && javaEntity)) {
+ boolean hasHibernate = PluginManagerHolder.getPluginManager().hasGrailsPlugin("hibernate");
for (GrailsDomainClassProperty p : properties) {
- PropertyConfig propertyConfig = GrailsDomainBinder.getPropertyConfig(p);
+ // assume no formula issues if Hibernate isn't available to avoid CNFE
+ PropertyConfig propertyConfig = hasHibernate ? GrailsDomainBinder.getPropertyConfig(p) : null;
if (propertyConfig != null && propertyConfig.getFormula() != null) {
if (constrainedProperties.remove(p.getName()) != null) {
// constraint is registered but cannot be applied to a derived property
@@ -20,6 +20,9 @@ import grails.converters.XML
import junit.framework.AssertionFailedError
import org.codehaus.groovy.grails.commons.ConfigurationHolder
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
import org.codehaus.groovy.grails.plugins.codecs.HTMLCodec
/**
@@ -150,6 +153,17 @@ class GrailsUnitTestCaseTests extends GroovyTestCase {
class TestUnitTestCase extends GrailsUnitTestCase {
+ protected void setUp() {
+ super.setUp()
+ PluginManagerHolder.pluginManager = new MockGrailsPluginManager()
+ PluginManagerHolder.pluginManager.registerMockPlugin([getName: { -> 'hibernate' }] as GrailsPlugin)
+ }
+
+ protected void tearDown() {
+ super.tearDown()
+ PluginManagerHolder.pluginManager = null
+ }
+
void testMockInstances1() {
mockDomain(GrailsUnitTestClass)
@@ -14,6 +14,9 @@
*/
package grails.test
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
import org.springframework.validation.Errors
class MockUtilsSaveDomainTests extends GroovyTestCase {
@@ -30,11 +33,14 @@ class MockUtilsSaveDomainTests extends GroovyTestCase {
protected void setUp() {
metaTestHelper.setUp()
errorsMap = new IdentityHashMap()
+ PluginManagerHolder.pluginManager = new MockGrailsPluginManager()
+ PluginManagerHolder.pluginManager.registerMockPlugin([getName: { -> 'hibernate' }] as GrailsPlugin)
}
protected void tearDown() {
metaTestHelper.tearDown()
MockUtils.resetIds()
+ PluginManagerHolder.pluginManager = null
}
/**
@@ -14,6 +14,9 @@
*/
package grails.test
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
import org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
import org.springframework.mock.web.MockHttpServletRequest
import org.springframework.mock.web.MockHttpServletResponse
@@ -37,14 +40,19 @@ class MockUtilsTests extends GroovyTestCase {
private Map errorsMap
- void setUp() {
+ protected void setUp() {
+ super.setUp()
metaTestHelper.setUp()
errorsMap = new IdentityHashMap()
+ PluginManagerHolder.pluginManager = new MockGrailsPluginManager()
+ PluginManagerHolder.pluginManager.registerMockPlugin([getName: { -> 'hibernate' }] as GrailsPlugin)
}
- void tearDown() {
+ protected void tearDown() {
+ super.tearDown()
metaTestHelper.tearDown()
MockUtils.resetIds()
+ PluginManagerHolder.pluginManager = null
}
/**
@@ -1,6 +1,9 @@
package org.codehaus.groovy.grails.commons
import org.codehaus.groovy.grails.exceptions.InvalidPropertyException
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
/**
* Note there are more tests for DefaultGrailsDomainClass in test/persistence written in Java
@@ -9,6 +12,17 @@ class DefaultGrailsDomainClassTests extends GroovyTestCase {
def gcl = new GroovyClassLoader()
+ protected void setUp() {
+ super.setUp()
+ PluginManagerHolder.pluginManager = new MockGrailsPluginManager()
+ PluginManagerHolder.pluginManager.registerMockPlugin([getName: { -> 'hibernate' }] as GrailsPlugin)
+ }
+
+ protected void tearDown() {
+ super.tearDown()
+ PluginManagerHolder.pluginManager = null
+ }
+
void testFetchMode() {
gcl.parseClass """
class Test {
@@ -26,6 +26,9 @@
import org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration;
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder;
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager;
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder;
+import org.codehaus.groovy.grails.scaffolding.DefaultGrailsTemplateGeneratorTests;
import org.codehaus.groovy.grails.validation.ConstrainedProperty;
import org.codehaus.groovy.grails.validation.NullableConstraint;
import org.hibernate.cfg.ImprovedNamingStrategy;
@@ -42,12 +45,16 @@
protected void setUp() throws Exception {
super.setUp();
ExpandoMetaClass.enableGlobally();
+ MockGrailsPluginManager pluginManager = new MockGrailsPluginManager();
+ PluginManagerHolder.setPluginManager(pluginManager);
+ pluginManager.registerMockPlugin(DefaultGrailsTemplateGeneratorTests.fakeHibernatePlugin);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
GrailsDomainBinder.namingStrategy = ImprovedNamingStrategy.INSTANCE;
+ PluginManagerHolder.setPluginManager(null);
}
public void testIsBasicType() {
@@ -102,6 +102,8 @@ hibernate {
mockManager.doArtefactConfiguration()
ctx.registerMockBean(PluginMetaManager.BEAN_ID, new DefaultPluginMetaManager())
+ afterPluginInitialization()
+
ga.initialise()
ga.setApplicationContext(ctx)
ApplicationHolder.setApplication(ga)
@@ -164,6 +166,9 @@ hibernate {
protected void onTearDown() {
}
+
+ protected void afterPluginInitialization() {
+ }
}
class MockHibernateGrailsPlugin {
@@ -2,6 +2,9 @@ package org.codehaus.groovy.grails.orm.hibernate
import org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration
import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
import org.hibernate.FetchMode
import org.hibernate.engine.CascadeStyle
@@ -35,6 +38,9 @@ class BidirectionalListMappingTests extends GroovyTestCase {
protected void setUp() {
ExpandoMetaClass.enableGlobally()
+ PluginManagerHolder.pluginManager = new MockGrailsPluginManager()
+ PluginManagerHolder.pluginManager.registerMockPlugin([getName: { -> 'hibernate' }] as GrailsPlugin)
+
def gcl = new GroovyClassLoader()
gcl.parseClass '''
class TestFaqSection {
@@ -63,6 +69,11 @@ class TestFaqElement {
config.buildMappings()
}
+ protected void tearDown() {
+ super.tearDown()
+ PluginManagerHolder.pluginManager = null
+ }
+
void testIndexBackrefMapping() {
PersistentClass faqSection = config.getClassMapping("TestFaqSection")
PersistentClass faqElement = config.getClassMapping("TestFaqElement")
@@ -1,6 +1,9 @@
package org.codehaus.groovy.grails.orm.hibernate
import org.codehaus.groovy.grails.commons.test.AbstractGrailsMockTests
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
class ComponentDomainTests extends AbstractGrailsMockTests {
@@ -17,6 +20,9 @@ class ComponentDomainTests extends AbstractGrailsMockTests {
}
protected void onSetUp() {
+ PluginManagerHolder.pluginManager = new MockGrailsPluginManager()
+ PluginManagerHolder.pluginManager.registerMockPlugin([getName: { -> 'hibernate' }] as GrailsPlugin)
+
gcl.parseClass('''
class Person {
Long id
@@ -36,4 +42,8 @@ class Address {
'''
)
}
+
+ protected void onTearDown() {
+ PluginManagerHolder.pluginManager = null
+ }
}
@@ -1,5 +1,9 @@
package org.codehaus.groovy.grails.orm.hibernate
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
+
class DerivedPropertiesTests extends AbstractGrailsHibernateTests {
protected void onSetUp() {
@@ -29,7 +33,17 @@ class ClassWithConstrainedDerivedProperty {
'''
}
+ protected void afterPluginInitialization() {
+ // base class registers its own plugins but the hibernate plugin has the wrong name
+ PluginManagerHolder.pluginManager.plugins['hibernate'] = PluginManagerHolder.pluginManager.plugins['mockHibernate']
+ }
+
+ protected void onTearDown() {
+ PluginManagerHolder.pluginManager = null
+ }
+
void testDerivedPropertiesCannotBeMadeValidateable() {
+
def myDomainClass = ga.getDomainClass('ClassWithConstrainedDerivedProperty')
def myClass = myDomainClass.clazz
@@ -2,15 +2,27 @@ package org.codehaus.groovy.grails.orm.hibernate
import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
/**
* @author Graeme Rocher
* @since 1.0
- *
- * Created: Apr 8, 2008
*/
class UnidirectionalOneToManyHibernateMappedTests extends GroovyTestCase {
+ protected void setUp() {
+ super.setUp()
+ PluginManagerHolder.pluginManager = new MockGrailsPluginManager()
+ PluginManagerHolder.pluginManager.registerMockPlugin([getName: { -> 'hibernate' }] as GrailsPlugin)
+ }
+
+ protected void tearDown() {
+ super.tearDown()
+ PluginManagerHolder.pluginManager = null
+ }
+
void testAnnotatedOneToManyDomain() {
def config = new GrailsAnnotationConfiguration()
def gcl = new GroovyClassLoader()
@@ -5,18 +5,30 @@ import grails.spring.BeanBuilder
import org.apache.commons.dbcp.BasicDataSource
import org.codehaus.groovy.grails.commons.GrailsApplication
+import org.codehaus.groovy.grails.plugins.GrailsPlugin
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder
import org.hibernate.SessionFactory
import org.springframework.core.io.ByteArrayResource
import org.springframework.context.support.StaticMessageSource
/**
* @author Graeme Rocher
* @since 1.1
- *
- * Created: Jan 16, 2009
*/
class GORMNamespaceHandlerTests extends GroovyTestCase {
+ protected void setUp() {
+ super.setUp()
+ PluginManagerHolder.pluginManager = new MockGrailsPluginManager()
+ PluginManagerHolder.pluginManager.registerMockPlugin([getName: { -> 'hibernate' }] as GrailsPlugin)
+ }
+
+ protected void tearDown() {
+ super.tearDown()
+ PluginManagerHolder.pluginManager = null
+ }
+
/* void testGORMSessionFromXML() {
def appCtx = new GenericApplicationContext()
@@ -20,18 +20,22 @@
import groovy.lang.IntRange;
import groovy.lang.ObjectRange;
+import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.lang.reflect.Field;
import junit.framework.TestCase;
+
import org.codehaus.groovy.grails.commons.DefaultGrailsApplication;
import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass;
import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.commons.GrailsDomainClass;
+import org.codehaus.groovy.grails.plugins.MockGrailsPluginManager;
+import org.codehaus.groovy.grails.plugins.PluginManagerHolder;
+import org.codehaus.groovy.grails.scaffolding.DefaultGrailsTemplateGeneratorTests;
import org.codehaus.groovy.grails.validation.ConstrainedProperty;
import org.codehaus.groovy.grails.validation.TestClass;
import org.hibernate.cfg.ImprovedNamingStrategy;
@@ -212,12 +216,16 @@
protected void setUp() throws Exception {
super.setUp();
ExpandoMetaClass.enableGlobally();
+ MockGrailsPluginManager pluginManager = new MockGrailsPluginManager();
+ PluginManagerHolder.setPluginManager(pluginManager);
+ pluginManager.registerMockPlugin(DefaultGrailsTemplateGeneratorTests.fakeHibernatePlugin);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
GrailsDomainBinder.namingStrategy = ImprovedNamingStrategy.INSTANCE;
+ PluginManagerHolder.setPluginManager(null);
}
public void testCachedMapProperty() {
Oops, something went wrong.

0 comments on commit a5bf8e1

Please sign in to comment.