Permalink
Browse files

fix failing tests

  • Loading branch information...
graemerocher committed Jul 4, 2014
1 parent 8837bc9 commit ff9f6c463bdd28ac54aa498fbad735a99ca2c30e
Showing with 541 additions and 459 deletions.
  1. +1 −1 grails-compatibility/src/main/groovy/org/codehaus/groovy/grails/validation/AbstractConstraint.groovy
  2. +6 −1 grails-core/src/main/groovy/grails/core/GrailsControllerClass.java
  3. +2 −1 grails-core/src/main/groovy/grails/util/GrailsClassUtils.java
  4. +192 −1 grails-core/src/main/groovy/org/codehaus/groovy/grails/commons/GrailsDomainClass.groovy
  5. +22 −0 grails-core/src/main/groovy/org/grails/core/DefaultGrailsControllerClass.java
  6. +1 −1 grails-core/src/main/groovy/org/grails/core/DefaultGrailsDomainClass.java
  7. +19 −4 grails-core/src/main/groovy/org/grails/core/LegacyGrailsApplication.groovy
  8. +239 −0 grails-core/src/main/groovy/org/grails/core/LegacyGrailsDomainClass.groovy
  9. +3 −3 grails-core/src/main/groovy/org/grails/plugins/CoreGrailsPlugin.groovy
  10. +1 −0 ...plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/api/ControllersApi.java
  11. +2 −2 ...in-domain-class/src/main/groovy/org/codehaus/groovy/grails/plugins/DomainClassGrailsPlugin.groovy
  12. +8 −5 grails-plugin-testing/src/main/groovy/grails/test/mixin/web/UrlMappingsUnitTestMixin.groovy
  13. +3 −2 ...e/src/main/groovy/org/codehaus/groovy/grails/web/servlet/mvc/AbstractGrailsControllerTests.groovy
  14. +1 −0 grails-test-suite-uber/build.gradle
  15. +1 −0 ...s-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/CoreGrailsPluginTests.groovy
  16. +1 −1 .../src/test/groovy/org/codehaus/groovy/grails/plugins/datasource/DataSourceGrailsPluginTests.groovy
  17. +19 −27 ...e-uber/src/test/groovy/org/codehaus/groovy/grails/plugins/web/ControllersGrailsPluginTests.groovy
  18. +0 −343 ...rc/test/groovy/org/codehaus/groovy/grails/plugins/web/mapping/UrlMappingsGrailsPluginTests.groovy
  19. +0 −58 grails-test-suite-uber/src/test/groovy/org/codehaus/groovy/grails/reload/TagLibReloadTests.groovy
  20. +3 −2 ...te-uber/src/test/groovy/org/codehaus/groovy/grails/web/errors/GrailsExceptionResolverTests.groovy
  21. +1 −1 ...t-suite-uber/src/test/groovy/org/codehaus/groovy/grails/web/servlet/GrailsHttpSessionTests.groovy
  22. +3 −0 ...-uber/src/test/groovy/org/codehaus/groovy/grails/web/servlet/mvc/TagLibDynamicMethodsTests.groovy
  23. +1 −1 grails-test-suite-uber/src/test/groovy/org/grails/plugins/web/ServletsGrailsPluginTests.groovy
  24. +2 −1 ...e-uber/src/test/groovy/org/grails/web/servlet/context/support/GrailsRuntimeConfiguratorTests.java
  25. +2 −1 grails-test-suite-web/build.gradle
  26. +5 −2 grails-validation/src/main/groovy/grails/validation/ConstrainedProperty.java
  27. +2 −0 grails-validation/src/main/groovy/org/codehaus/groovy/grails/validation/ConstraintFactory.groovy
  28. +1 −1 grails-validation/src/main/resources/META-INF/grails.factories
@@ -23,5 +23,5 @@ package org.codehaus.groovy.grails.validation
* @deprecated Use {@link grails.validation.AbstractConstraint}
*/
@Deprecated
-public abstract class AbstractConstraint extends grails.validation.AbstractConstraint {
+public abstract class AbstractConstraint extends grails.validation.AbstractConstraint implements Constraint {
}
@@ -82,7 +82,12 @@
* Initialize the controller class
*/
void initialize();
-
+ /**
+ * Tests if a controller maps to a given URI.
+ *
+ * @return true if controller maps to URI
+ */
+ boolean mapsToURI(String uri);
/**
* Invokes a controller action on the given controller instance
*
@@ -819,7 +819,8 @@ public static Object getStaticPropertyValue(Class<?> clazz, String name) {
Method getter = BeanUtils.findDeclaredMethod(clazz, getGetterName(name), (Class[])null);
try {
if (getter != null) {
- return getter.invoke(null);
+ ReflectionUtils.makeAccessible(getter);
+ return getter.invoke(clazz);
}
return getStaticFieldValue(clazz, name);
}
@@ -15,6 +15,8 @@
*/
package org.codehaus.groovy.grails.commons
+import org.springframework.validation.Validator
+
/**
* Represents a persistable Grails domain class.
*
@@ -26,5 +28,194 @@ package org.codehaus.groovy.grails.commons
* @deprecated Use {@link grails.core.GrailsDomainClass} instead
*/
@Deprecated
-public interface GrailsDomainClass extends grails.core.GrailsDomainClass {
+public interface GrailsDomainClass extends grails.core.GrailsClass, GrailsClass {
+
+ /**
+ * The name of the default ORM implementation used to map the class
+ */
+ String GORM = "GORM";
+
+ String ORM_MAPPING = "mapping";
+
+ /**
+ * @param domainClass
+ * @return true if the specifying domain class is on the owning side of a relationship
+ */
+ @SuppressWarnings("rawtypes")
+ boolean isOwningClass(Class domainClass);
+
+ /**
+ * Returns all of the properties of the domain class
+ * @return The domain class properties
+ */
+ GrailsDomainClassProperty[] getProperties();
+
+ /**
+ * Returns all of the persistant properties of the domain class
+ * @return The domain class' persistant properties
+ * @deprecated Use #getPersistentProperties instead
+ */
+ @Deprecated
+ GrailsDomainClassProperty[] getPersistantProperties();
+
+ /**
+ * Returns all of the persistant properties of the domain class
+ * @return The domain class' persistant properties
+ */
+ GrailsDomainClassProperty[] getPersistentProperties();
+
+ /**
+ * Returns the identifier property
+ * @return The identifier property
+ */
+ GrailsDomainClassProperty getIdentifier();
+
+ /**
+ * Returns the version property
+ * @return The version property
+ */
+ GrailsDomainClassProperty getVersion();
+
+ /**
+ * Returns this classes association map
+ * @return The association map
+ */
+ @SuppressWarnings("rawtypes")
+ Map getAssociationMap();
+
+ /**
+ * Returns the property for the given name
+ *
+ * @param name The property for the name
+ * @throws org.grails.core.exceptions.InvalidPropertyException
+ * @return The domain class property for the given name
+ */
+ GrailsDomainClassProperty getPropertyByName(String name);
+
+ /**
+ * Returns the property for the given name or null if non exists
+ *
+ * @param name The property name
+ * @return The property or null
+ */
+ GrailsDomainClassProperty getPersistentProperty(String name);
+
+ /**
+ * Returns the field name for the given property name
+ * @param propertyName
+ * @return The field representation of the property name
+ */
+ String getFieldName(String propertyName);
+
+ /**
+ * <p>Returns the default property name of the GrailsClass. For example the property name for
+ * a class called "User" would be "user"</p>
+ *
+ * @return The property name representation of the class name
+ */
+ String getPropertyName();
+
+ /**
+ * Returns true if the given property is a one to many relationship
+ * @param propertyName The name of the property
+ * @return A boolean value
+ */
+ boolean isOneToMany(String propertyName);
+
+ /**
+ * Returns true if the given property is a many to one relationship
+ * @param propertyName The name of the property
+ * @return A boolean value
+ */
+ boolean isManyToOne(String propertyName);
+
+ /**
+ * Returns true if the given property is a bi-directional relationship
+ *
+ * @param propertyName The name of the property
+ * @return A boolean value
+ */
+ boolean isBidirectional(String propertyName);
+
+ /**
+ * Returns the type of the related class of the given property
+ *
+ * @param propertyName The name of the property
+ * @return The type of the class or null if no relationship exists for the specified property
+ */
+ @SuppressWarnings("rawtypes")
+ Class getRelatedClassType(String propertyName);
+
+ /**
+ * Returns a map of constraints applied to this domain class with the keys being the property name
+ * and the values being ConstrainedProperty instances
+ *
+ * @return A map of constraints
+ */
+ @SuppressWarnings("rawtypes")
+ Map getConstrainedProperties();
+
+ /**
+ * Retreives the validator for this domain class
+ *
+ * @return A validator instance or null if none exists
+ */
+ Validator getValidator();
+
+ /**
+ * Sets the validator for this domain class
+ *
+ * @param validator The domain class validator to set
+ */
+ void setValidator(Validator validator);
+
+ /**
+ * @return The name of the ORM implementation used to map the domain class (default is "GORM")
+ */
+ String getMappingStrategy();
+
+ /**
+ * Whether the class is the root of a heirarchy
+ *
+ * @return true if it is the root of the heirarchy
+ */
+ boolean isRoot();
+
+ /**
+ * Returns the sub-classes for this class if any
+ *
+ * @return A set of sub classes or an empty set if none exist
+ */
+ Set<GrailsDomainClass> getSubClasses();
+
+ /**
+ * Refreshes the constraint defined on a domain class
+ */
+ void refreshConstraints();
+
+ /**
+ * Returns true if the domain classes has sub classes
+ * @return true if it does
+ */
+ boolean hasSubClasses();
+
+ /**
+ * @return The map that defines association mappings
+ */
+ @SuppressWarnings("rawtypes")
+ Map getMappedBy();
+
+ /**
+ * Returns true if this domain class has a persistent property for the given name
+ * @param propertyName The property name
+ * @return true if it does
+ */
+ boolean hasPersistentProperty(String propertyName);
+
+ /**
+ * Sets the strategy to use for ORM mapping. Default is GORM
+ * @param strategy The mapping strategy
+ */
+ void setMappingStrategy(String strategy);
+
}
@@ -87,6 +87,28 @@ private void methodStrategy(Map<String, Method> methodNames) {
}
}
+ @Override
+ public boolean mapsToURI(String uri) {
+ if(uri.startsWith("/")) {
+ String[] tokens = uri.substring(1).split("\\/");
+ if(tokens.length>0) {
+ String controllerName = tokens[0];
+ if(getLogicalPropertyName().equals(controllerName)) {
+ if(tokens.length>1) {
+ String actionName = tokens[1];
+ if(actions.containsKey(actionName) || defaultActionName.equals(actionName)) {
+ return true;
+ }
+ }
+ else {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
/**
* Invokes the controller action for the given name on the given controller instance
*
@@ -48,7 +48,7 @@
* @author Graeme Rocher
*/
@SuppressWarnings("rawtypes")
-public class DefaultGrailsDomainClass extends AbstractGrailsClass implements GrailsDomainClass, ComponentCapableDomainClass, org.codehaus.groovy.grails.commons.GrailsDomainClass {
+public class DefaultGrailsDomainClass extends AbstractGrailsClass implements GrailsDomainClass, ComponentCapableDomainClass{
private GrailsDomainClassProperty identifier;
private GrailsDomainClassProperty version;
@@ -1,11 +1,13 @@
package org.grails.core
+import grails.core.GrailsDomainClass
import grails.util.Metadata
import groovy.transform.CompileStatic
import org.codehaus.groovy.grails.commons.ArtefactHandler
import org.codehaus.groovy.grails.commons.ArtefactInfo
import org.codehaus.groovy.grails.commons.GrailsApplication
import org.codehaus.groovy.grails.commons.GrailsClass
+import org.grails.core.artefact.DomainClassArtefactHandler
import org.springframework.context.ApplicationContext
import org.springframework.core.io.Resource
@@ -106,7 +108,8 @@ class LegacyGrailsApplication implements GrailsApplication {
@Override
GrailsClass getArtefact(String artefactType, String name) {
- return (GrailsClass)grailsApplication.getArtefact(artefactType, name)
+ def grailsClass = (GrailsClass) grailsApplication.getArtefact(artefactType, name)
+ return coerceToLegacyType(grailsClass)
}
@Override
@@ -121,22 +124,27 @@ class LegacyGrailsApplication implements GrailsApplication {
@Override
GrailsClass[] getArtefacts(String artefactType) {
+ if(DomainClassArtefactHandler.TYPE.equals(artefactType)) {
+ return grailsApplication.getArtefacts(artefactType).collect() { GrailsClass grailsClass ->
+ new LegacyGrailsDomainClass((GrailsDomainClass)grailsClass)
+ } as GrailsClass[]
+ }
return grailsApplication.getArtefacts(artefactType) as GrailsClass[]
}
@Override
GrailsClass getArtefactForFeature(String artefactType, Object featureID) {
- return (GrailsClass)grailsApplication.getArtefactForFeature(artefactType, featureID)
+ return coerceToLegacyType( (GrailsClass)grailsApplication.getArtefactForFeature(artefactType, featureID) )
}
@Override
GrailsClass addArtefact(String artefactType, Class artefactClass) {
- return (GrailsClass)grailsApplication.addArtefact(artefactType, artefactClass)
+ return coerceToLegacyType((GrailsClass)grailsApplication.addArtefact(artefactType, artefactClass))
}
@Override
GrailsClass addArtefact(String artefactType, GrailsClass artefactGrailsClass) {
- return (GrailsClass)grailsApplication.addArtefact(artefactType, artefactGrailsClass)
+ return coerceToLegacyType((GrailsClass)grailsApplication.addArtefact(artefactType, artefactGrailsClass))
}
@Override
@@ -198,4 +206,11 @@ class LegacyGrailsApplication implements GrailsApplication {
ArtefactHandler getArtefactHandler(String type) {
return (ArtefactHandler)grailsApplication.getArtefactHandler(type)
}
+
+ private GrailsClass coerceToLegacyType(GrailsClass grailsClass) {
+ if (grailsClass instanceof GrailsDomainClass) {
+ return new LegacyGrailsDomainClass(grailsClass)
+ }
+ return grailsClass
+ }
}
Oops, something went wrong.

0 comments on commit ff9f6c4

Please sign in to comment.