Ejemplo n.º 1
0
 @SuppressWarnings("unchecked")
 private Map resolveConstrainedProperties(Object object, GrailsDomainClass dc) {
   Map constrainedProperties = null;
   if (dc != null) {
     constrainedProperties = dc.getConstrainedProperties();
   } else {
     // is this dead code? , didn't remove in case it's used somewhere
     MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(object.getClass());
     MetaProperty metaProp = mc.getMetaProperty(CONSTRAINTS_PROPERTY);
     if (metaProp != null) {
       Object constrainedPropsObj = getMetaPropertyValue(metaProp, object);
       if (constrainedPropsObj instanceof Map) {
         constrainedProperties = (Map) constrainedPropsObj;
       }
     }
   }
   return constrainedProperties;
 }
  /*
   * Test method for 'org.codehaus.groovy.grails.validation.metaclass.ConstraintsDynamicProperty.get(Object)'
   */
  @SuppressWarnings("rawtypes")
  public void testGet() throws Exception {
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> groovyClass =
        gcl.parseClass(
            "package org.codehaus.groovy.grails.validation\n"
                + "class Test {\n"
                + "   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"
                + // WE NEED this even though GORM 2 doesn't, as we're not a "domain" class within
                  // grails-app
                " String name\n"
                + "}");

    GrailsDomainClass domainClass = new DefaultGrailsDomainClass(groovyClass);

    Map constraints = domainClass.getConstrainedProperties();

    assertNotNull(constraints);
    assertFalse(constraints.isEmpty());
  }