Revision: 9615
Author: [email protected]
Date: Tue Jan 25 11:20:03 2011
Log: If some unrecoverable failure happens during validation, a ValidationException is raised.

[JSR 303 TCK Result] 66 of 257 (25.68%) Pass with 25 Failures and 3 Errors.

Review at http://gwt-code-reviews.appspot.com/1295803

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9615

Modified:
/trunk/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java /trunk/user/test/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyGwtTest.java

=======================================
--- /trunk/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java Tue Jan 25 07:30:57 2011 +++ /trunk/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java Tue Jan 25 11:20:03 2011
@@ -230,9 +230,10 @@

   @Override
   protected void compose(ClassSourceFileComposerFactory composerFactory) {
-    addImports(composerFactory, GWT.class, GwtBeanDescriptor.class,
-        GwtValidationContext.class, Set.class, HashSet.class,
-        ConstraintViolation.class, Annotation.class);
+ addImports(composerFactory, Annotation.class, ConstraintViolation.class,
+        GWT.class, GwtBeanDescriptor.class, GwtValidationContext.class,
+        HashSet.class, IllegalArgumentException.class, Set.class,
+        ValidationException.class);
composerFactory.setSuperclass(AbstractGwtSpecificValidator.class.getCanonicalName()
         + "<" + beanType.getQualifiedSourceName() + ">");
     composerFactory.addImplementedInterface(validatorType.getName());
@@ -536,6 +537,36 @@
     sw.outdent();
     sw.outdent();
   }
+
+ private void writeCatchUnexpectedException(SourceWriter sw, String message) {
+    // } catch (IllegalArgumentException e) {
+    sw.outdent();
+    sw.println("} catch (IllegalArgumentException e) {");
+    sw.indent();
+
+    // throw e;
+    sw.println("throw e;");
+
+    // } catch (ValidationException e) {
+    sw.outdent();
+    sw.println("} catch (ValidationException e) {");
+    sw.indent();
+
+    // throw e;
+    sw.println("throw e;");
+
+    // } catch (Exception e) {
+    sw.outdent();
+    sw.println("} catch (Exception e) {");
+    sw.indent();
+
+    // throw new ValidationException("my message", e);
+    sw.println("throw new ValidationException(" + message + ", e);");
+
+    // }
+    sw.outdent();
+    sw.println("}");
+  }

   private void writeConstraintDescriptor(SourceWriter sw,
       ConstraintDescriptor<? extends Annotation> constraint,
@@ -893,6 +924,10 @@
     sw.println("Class<?>... groups) {");
     sw.outdent();

+    // try {
+    sw.println("try {");
+    sw.indent();
+
     writeNewViolations(sw);

     if (beanHelper.getBeanDescriptor().isBeanConstrained()) {
@@ -956,6 +991,10 @@
     // return violations;
     sw.println("return violations;");

+    writeCatchUnexpectedException(
+        sw,
+        "\"Error validating " + beanHelper.getTypeCanonicalName() + "\"");
+
     sw.outdent();
     sw.println("}");
   }
@@ -1173,15 +1212,19 @@
     sw.println("public <T> Set<ConstraintViolation<T>> validateProperty(");

// GwtValidationContext<T> context, BeanType object, String propertyName,
-    // Class<?>... groups) {
+    // Class<?>... groups) throws ValidationException {
     sw.indent();
     sw.indent();
     sw.println("GwtValidationContext<T> context,");
     sw.println(beanHelper.getTypeCanonicalName() + " object,");
     sw.println("String propertyName,");
-    sw.println("Class<?>... groups) {");
+    sw.println("Class<?>... groups) throws ValidationException {");
     sw.outdent();

+    // try {
+    sw.println("try {");
+    sw.indent();
+
     writeNewViolations(sw);

for (PropertyDescriptor property : beanHelper.getBeanDescriptor().getConstrainedProperties()) {
@@ -1207,6 +1250,12 @@
     // return violations;
     sw.println("return violations;");

+    writeCatchUnexpectedException(
+        sw,
+        "\"Error validating \" + propertyName + \" of "
+        + beanHelper.getTypeCanonicalName() + "\"");
+
+    // }
     sw.outdent();
     sw.println("}");
   }
@@ -1257,8 +1306,7 @@

       // throw new ValidationException(value.getClass +
       // " is not a valid type for " + propertyName);
-      sw.print("throw new ");
-      sw.print(ValidationException.class.getCanonicalName());
+      sw.print("throw new ValidationException");
sw.println("(value.getClass() +\" is not a valid type for \"+ propertyName);");

       // }
@@ -1365,6 +1413,10 @@
     sw.println("Class<?>... groups) {");
     sw.outdent();

+    // try {
+    sw.println("try {");
+    sw.indent();
+
     writeNewViolations(sw);

     for (PropertyDescriptor property :
@@ -1393,6 +1445,11 @@
     // return violations;
     sw.println("return violations;");

+    writeCatchUnexpectedException(
+        sw,
+        "\"Error validating \" + propertyName + \" of "
+            + beanHelper.getTypeCanonicalName() + "\"");
+
     sw.outdent();
     sw.println("}");
   }
=======================================
--- /trunk/user/test/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyGwtTest.java Thu Jan 20 09:39:05 2011 +++ /trunk/user/test/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyGwtTest.java Tue Jan 25 11:20:03 2011
@@ -34,7 +34,6 @@
     delegate.testPassingNullAsGroup();
   }

-  @Failing(issue = 5804)
public void testUnexpectedExceptionsInValidatePropertyGetWrappedInValidationExceptions() {
     // Wrap the test to catch the @Test expected exception.
     try {

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to