Public: Improve reporting of TCK failures Review at http://gwt-code-reviews.appspot.com/1117801 Review by: rchandia@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9262 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/validationtck/build.xml b/samples/validationtck/build.xml index a283414..27bccc8 100755 --- a/samples/validationtck/build.xml +++ b/samples/validationtck/build.xml
@@ -50,7 +50,7 @@ --> <path id="test.extraclasspath"> <pathelement location="${gwt.build}/out/dev/bin-test" /> - <pathelement location="${gwt.dev.jar}" /> + <pathelement location="${gwt.dev.jar}" /> <pathelement location="${gwt.build.lib}/gwt-user.jar" /> <path refid="sample.extraclasspath" /> </path> @@ -64,24 +64,24 @@ <property name="gwt.junit.testcase.dev.includes" value="${gwt.junit.testcase.includes}" /> <property name="gwt.junit.testcase.dev.excludes" value="" /> - <!-- + <!-- Compiles the test code for this project --> - <target name="compile.tests" + <target name="compile.tests" depends="compile.emma.if.enabled" unless="compile.tests.complete"> - <mkdir dir="${javac.junit.out}" /> - <gwt.javac srcdir="test" excludes="com/google/gwt/langtest/**" + <mkdir dir="${javac.junit.out}" /> + <gwt.javac srcdir="test" excludes="com/google/gwt/langtest/**" destdir="${javac.junit.out}"> - <classpath> - <pathelement location="${javac.out}" /> - <pathelement location="${gwt.tools.lib}/junit/junit-3.8.1.jar" /> - <pathelement location="${gwt.tools.lib}/selenium/selenium-java-client-driver.jar" /> - <path refid="sample.extraclasspath" /> - <path refid="test.extraclasspath" /> - </classpath> - </gwt.javac> - </target> + <classpath> + <pathelement location="${javac.out}" /> + <pathelement location="${gwt.tools.lib}/junit/junit-3.8.1.jar" /> + <pathelement location="${gwt.tools.lib}/selenium/selenium-java-client-driver.jar" /> + <path refid="sample.extraclasspath" /> + <path refid="test.extraclasspath" /> + </classpath> + </gwt.javac> + </target> <target name="tck" @@ -94,13 +94,13 @@ <property.ensure name="distro.built" location="${gwt.dev.staging.jar}" message="GWT must be built before performing any tests. This can be fixed by running ant in the ${gwt.root} directory." /> <limit failonerror="true" hours="${test.timeout}"> - <parallel threadsPerProcessor="${gwt.threadsPerProcessor}" + <parallel threadsPerProcessor="${gwt.threadsPerProcessor}" threadCount="${gwt.threadCount}"> - <!-- + <!-- The remote targets must be run sequentially or BrowserManager will queue requests, which will cause some tests to timeout while waiting. --> - <!--sequential> + <!--sequential> <antcall target="test.dev.remote"/> <antcall target="test.emma.remote"/> <antcall target="test.web.remote"/> @@ -112,13 +112,26 @@ <antcall target="test.web.selenium"/> <antcall target="test.draft.selenium"/> <antcall target="test.nometa.selenium"/--> - <antcall target="test.dev.htmlunit"/> - <!--antcall target="test.emma.htmlunit"/> + <antcall target="test.dev.htmlunit"/> + <!--antcall target="test.emma.htmlunit"/> <antcall target="test.web.htmlunit"/> <antcall target="test.draft.htmlunit"/> <antcall target="test.nometa.htmlunit"/--> - </parallel> + </parallel> </limit> + + + <mkdir dir="${junit.out}/tck-report"/> + <junitreport todir="${junit.out}/tck-report"> + <fileset dir="${junit.out}"> + <include name="*/reports/TEST-*.xml"/> + </fileset> + <report format="noframes" todir="${junit.out}/tck-report"/> + </junitreport> + + <fail + message="One or more junit tests failed for target: @{test.name} @{test.args}" + if="junit.failure" status="2" /> </target> <target name="test.dev.htmlunit" @@ -132,11 +145,15 @@ test.args="${test.args} -standardsMode " test.jvmargs="${test.jvmargs}" test.out="${junit.out}/dev-htmlunit" - test.cases="test.dev.htmlunit.tests" > + test.cases="test.dev.htmlunit.tests" + haltonfailure="false" + > <extraclasspaths> <path refid="test.extraclasspath" /> </extraclasspaths> </gwt.junit> + + </target> </project>
diff --git a/samples/validationtck/src/com/google/gwt/sample/validationtck/Tck.java b/samples/validationtck/src/com/google/gwt/sample/validationtck/Tck.java index b38464a..f5fd5d3 100644 --- a/samples/validationtck/src/com/google/gwt/sample/validationtck/Tck.java +++ b/samples/validationtck/src/com/google/gwt/sample/validationtck/Tck.java
@@ -16,23 +16,15 @@ package com.google.gwt.sample.validationtck; import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.RootPanel; -import org.hibernate.jsr303.tck.tests.constraints.application.Woman; - -import javax.validation.Validator; - /** * Just a place holder Entry point. */ public class Tck implements EntryPoint { public void onModuleLoad() { - Validator validator = GWT.create(Validator.class); - Woman w = new Woman(); - validator.validate(w); Label label = new Label("tck"); RootPanel.get("view").add(label); }
diff --git a/samples/validationtck/src/com/google/gwt/sample/validationtck/TckTestValidator.java b/samples/validationtck/src/com/google/gwt/sample/validationtck/TckTestValidator.java deleted file mode 100644 index ebab05b..0000000 --- a/samples/validationtck/src/com/google/gwt/sample/validationtck/TckTestValidator.java +++ /dev/null
@@ -1,55 +0,0 @@ -/* - * Copyright 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.sample.validationtck; - -import com.google.gwt.core.client.GWT; - -import java.util.Set; - -import javax.validation.ConstraintViolation; -import javax.validation.Validator; -import javax.validation.metadata.BeanDescriptor; - -/** - * TCK implementation that uses - * {@link com.google.gwt.validation.client.GwtValidation GwtValidation} - */ -public class TckTestValidator implements Validator { - - TckValidator validator = GWT.create(TckValidator.class); - - public BeanDescriptor getConstraintsForClass(Class<?> clazz) { - return validator.getConstraintsForClass(clazz); - } - - public <T> T unwrap(Class<T> type) { - return validator.unwrap(type); - } - - public <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups) { - return validator.validate(object, groups); - } - - public <T> Set<ConstraintViolation<T>> validateProperty(T object, - String propertyName, Class<?>... groups) { - return validator.validateProperty(object, propertyName, groups); - } - - public <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, - String propertyName, Object value, Class<?>... groups) { - return validator.validateValue(beanType, propertyName, value, groups); - } -}
diff --git a/samples/validationtck/src/com/google/gwt/sample/validationtck/TckValidator.java b/samples/validationtck/src/com/google/gwt/sample/validationtck/TckValidator.java deleted file mode 100644 index 6d343f0..0000000 --- a/samples/validationtck/src/com/google/gwt/sample/validationtck/TckValidator.java +++ /dev/null
@@ -1,35 +0,0 @@ -/* - * Copyright 2010 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.sample.validationtck; - -import com.google.gwt.validation.client.GwtValidation; - -import org.hibernate.jsr303.tck.tests.constraints.application.Building; -import org.hibernate.jsr303.tck.tests.constraints.application.SuperWoman; -import org.hibernate.jsr303.tck.tests.constraints.application.Woman; - -import javax.validation.Validator; - -/** - * Top Level validator for the TCK tests - */ -@GwtValidation(value = { - Building.class, - SuperWoman.class, - Woman.class - }) -public interface TckValidator extends Validator { -}
diff --git a/samples/validationtck/src/com/google/gwt/sample/validationtck/ValidationTck.gwt.xml b/samples/validationtck/src/com/google/gwt/sample/validationtck/ValidationTck.gwt.xml index a3a1610..76ba619 100644 --- a/samples/validationtck/src/com/google/gwt/sample/validationtck/ValidationTck.gwt.xml +++ b/samples/validationtck/src/com/google/gwt/sample/validationtck/ValidationTck.gwt.xml
@@ -23,7 +23,4 @@ <exclude name="super" /> </source> <entry-point class="com.google.gwt.sample.validationtck.Tck" /> - <replace-with class="com.google.gwt.sample.validationtck.TckTestValidator"> - <when-type-is class="javax.validation.Validator"/> - </replace-with> </module> \ No newline at end of file
diff --git a/samples/validationtck/src/org/hibernate/jsr303/tck/Jsr303Tck.gwt.xml b/samples/validationtck/src/org/hibernate/jsr303/tck/Jsr303Tck.gwt.xml index 83d9cef..7e08774 100644 --- a/samples/validationtck/src/org/hibernate/jsr303/tck/Jsr303Tck.gwt.xml +++ b/samples/validationtck/src/org/hibernate/jsr303/tck/Jsr303Tck.gwt.xml
@@ -15,7 +15,6 @@ <exclude name="tests/bootstrap/" /> <exclude name="tests/constraints/builtinconstraints/" /> <exclude name="tests/messageinterpolation/" /> - <exclude name="tests/validation/" /> <exclude name="tests/xmlconfiguration/" /> <exclude name="util/StandaloneContainersImpl.java" /> </source>
diff --git a/samples/validationtck/src/org/hibernate/jsr303/tck/super/org/hibernate/jsr303/tck/util/TestUtil.java b/samples/validationtck/src/org/hibernate/jsr303/tck/super/org/hibernate/jsr303/tck/util/TestUtil.java index 5538759..3ce4185 100644 --- a/samples/validationtck/src/org/hibernate/jsr303/tck/super/org/hibernate/jsr303/tck/util/TestUtil.java +++ b/samples/validationtck/src/org/hibernate/jsr303/tck/super/org/hibernate/jsr303/tck/util/TestUtil.java
@@ -19,8 +19,6 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.regexp.shared.MatchResult; import com.google.gwt.regexp.shared.RegExp; -import com.google.gwt.sample.validationtck.TckTestValidator; -import com.google.gwt.sample.validationtck.TckValidator; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; @@ -48,7 +46,7 @@ * <ul> * <li>Use RegExp instead of Pattern</li> * <li>Hard code the validator</li> - * </ul> + * </ul> * @author Hardy Ferentschik */ public final class TestUtil {
diff --git a/samples/validationtck/src/org/testng/TestNg.gwt.xml b/samples/validationtck/src/org/testng/TestNg.gwt.xml index 23d6f62..d0a2fcb 100644 --- a/samples/validationtck/src/org/testng/TestNg.gwt.xml +++ b/samples/validationtck/src/org/testng/TestNg.gwt.xml
@@ -5,6 +5,7 @@ --> <module> <inherits name="com.google.gwt.user.User" /> + <inherits name="com.google.gwt.junit.JUnit" /> <source path="annotations"> <exclude name="ITestAnnotation.java" /> <exclude name="Listeners.java" />
diff --git a/samples/validationtck/src/org/testng/super/org/testng/Assert.java b/samples/validationtck/src/org/testng/super/org/testng/Assert.java index 0d915e2..7326ef0 100644 --- a/samples/validationtck/src/org/testng/super/org/testng/Assert.java +++ b/samples/validationtck/src/org/testng/super/org/testng/Assert.java
@@ -14,11 +14,12 @@ /** * Assertion tool class. Presents assertion methods with a more natural parameter order. * The order is always <B>actualValue</B>, <B>expectedValue</B> [, message]. - * + * * <p> * Modified by Google * <ul> * <li>Removed java.lang.reflect</li> + * <li>Delegate fail messages to junit</li> * </ul> * * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a> @@ -81,10 +82,14 @@ * @param realCause the original exception */ static public void fail(String message, Throwable realCause) { - AssertionError ae = new AssertionError(message); - ae.initCause(realCause); - - throw ae; + if(message == null){ + if (realCause != null){ + message = realCause.getMessage(); + } + } else { + message = message + ": " + realCause.getMessage(); + } + junit.framework.Assert.fail(message); } /** @@ -92,7 +97,7 @@ * @param message the assertion error message */ static public void fail(String message) { - throw new AssertionError(message); + junit.framework.Assert.fail(message); } /**
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/ConstraintApplicationGwtSuite.java similarity index 71% rename from samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java rename to samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/ConstraintApplicationGwtSuite.java index 219d95a..54a4693 100644 --- a/samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/ConstraintApplicationGwtSuite.java
@@ -13,22 +13,20 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.sample.validationtck; +package com.google.gwt.sample.validationtck.constraints.application; import com.google.gwt.junit.tools.GWTTestSuite; -import com.google.gwt.sample.validationtck.constraints.application.ValidationRequirementTest; import junit.framework.Test; /** - * All Tck Tests + * Tck Tests for the {@code constraints application} package. */ -public class TckGwtSuite { - +public class ConstraintApplicationGwtSuite { public static Test suite() { - GWTTestSuite suite = new GWTTestSuite("TCK for GWT Validation"); + GWTTestSuite suite = new GWTTestSuite( + "TCK for GWT Validation, constraints application package"); suite.addTestSuite(ValidationRequirementTest.class); - // suite.addTestSuite(CustomConstraintValidatorTest.class); return suite; } }
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml b/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/TckTest.gwt.xml similarity index 81% copy from samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml copy to samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/TckTest.gwt.xml index 36b9a9e..779fe81 100644 --- a/samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/TckTest.gwt.xml
@@ -17,9 +17,11 @@ --> <module> <inherits name="com.google.gwt.sample.validationtck.ValidationTck" /> - <source path=""> + <include name="*.java" /> <exclude name="super" /> </source> - <entry-point class="com.google.gwt.sample.validationtck.Tck" /> + <replace-with class="com.google.gwt.sample.validationtck.constraints.application.TckTestValidator"> + <when-type-is class="javax.validation.Validator"/> + </replace-with> </module> \ No newline at end of file
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/TckTestValidator.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/TckTestValidator.java new file mode 100644 index 0000000..d9e7e23 --- /dev/null +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/TckTestValidator.java
@@ -0,0 +1,45 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.sample.validationtck.constraints.application; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.validation.client.AbstractValidator; +import com.google.gwt.validation.client.GwtValidation; + +import org.hibernate.jsr303.tck.tests.constraints.application.Building; +import org.hibernate.jsr303.tck.tests.constraints.application.SuperWoman; +import org.hibernate.jsr303.tck.tests.constraints.application.Visibility; +import org.hibernate.jsr303.tck.tests.constraints.application.Woman; + +import javax.validation.Validator; + +/** + * {@link Validator} implementation that uses + * {@link com.google.gwt.validation.client.GwtValidation GwtValidation}. + */ +public final class TckTestValidator extends AbstractValidator { + /** + * Marker Interface for {@link GWT#create(Class)}. + */ + @GwtValidation(value = { + Building.class, SuperWoman.class, Visibility.class, Woman.class}) + public static interface GwtValidator extends Validator { + } + + public TckTestValidator() { + super((Validator) GWT.create(GwtValidator.class)); + } +}
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/ValidationRequirementTest.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/ValidationRequirementTest.java index ceb95d5..0c70a4f 100644 --- a/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/ValidationRequirementTest.java +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/ValidationRequirementTest.java
@@ -20,6 +20,7 @@ /** * Wraps * {@link org.hibernate.jsr303.tck.tests.constraints.application.ValidationRequirementTest} + * . */ public class ValidationRequirementTest extends GWTTestCase { org.hibernate.jsr303.tck.tests.constraints.application.ValidationRequirementTest delegate = @@ -27,7 +28,7 @@ @Override public String getModuleName() { - return "com.google.gwt.sample.validationtck.ValidationTckTest"; + return "com.google.gwt.sample.validationtck.constraints.application.TckTest"; } public void testClassLevelConstraints() {
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/AbstractValidationTest.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/AbstractValidationTest.java new file mode 100644 index 0000000..b35ebb5 --- /dev/null +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/AbstractValidationTest.java
@@ -0,0 +1,33 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.sample.validationtck.validation; + +import com.google.gwt.junit.client.GWTTestCase; + +/** + * Abstract Validation test for the {@code validation} package. + */ +public abstract class AbstractValidationTest extends GWTTestCase { + + public AbstractValidationTest() { + super(); + } + + @Override + public String getModuleName() { + return "com.google.gwt.sample.validationtck.validation.TckTest"; + } +} \ No newline at end of file
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/PropertyPathTest.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/PropertyPathTest.java new file mode 100644 index 0000000..5ac7db1 --- /dev/null +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/PropertyPathTest.java
@@ -0,0 +1,51 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.sample.validationtck.validation; + +/** + * Test wrapper for + * {@link org.hibernate.jsr303.tck.tests.validation.PropertyPathTest}. + */ +public class PropertyPathTest extends AbstractValidationTest { + + org.hibernate.jsr303.tck.tests.validation.PropertyPathTest delegate = + new org.hibernate.jsr303.tck.tests.validation.PropertyPathTest(); + + public void testPropertyPathSet() { + delegate.testPropertyPathSet(); + } + + public void testPropertyPathTraversedObject() { + delegate.testPropertyPathTraversedObject(); + } + + public void testPropertyPathWithArray() { + delegate.testPropertyPathWithArray(); + } + + public void testPropertyPathWithConstraintViolationForRootObject() { + delegate.testPropertyPathWithConstraintViolationForRootObject(); + } + + public void testPropertyPathWithList() { + delegate.testPropertyPathWithList(); + } + + public void testPropertyPathWithMap() { + delegate.testPropertyPathWithMap(); + } + +}
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/TckTest.gwt.xml similarity index 82% copy from samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml copy to samples/validationtck/test/com/google/gwt/sample/validationtck/validation/TckTest.gwt.xml index 36b9a9e..cac71d1 100644 --- a/samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/TckTest.gwt.xml
@@ -17,9 +17,11 @@ --> <module> <inherits name="com.google.gwt.sample.validationtck.ValidationTck" /> - <source path=""> + <include name="*.java" /> <exclude name="super" /> </source> - <entry-point class="com.google.gwt.sample.validationtck.Tck" /> + <replace-with class="com.google.gwt.sample.validationtck.validation.TckTestValidator"> + <when-type-is class="javax.validation.Validator"/> + </replace-with> </module> \ No newline at end of file
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/TckTestValidator.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/TckTestValidator.java new file mode 100644 index 0000000..707b44a --- /dev/null +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/TckTestValidator.java
@@ -0,0 +1,46 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.sample.validationtck.validation; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.validation.client.AbstractValidator; +import com.google.gwt.validation.client.GwtValidation; + +import org.hibernate.jsr303.tck.tests.validation.Actor; +import org.hibernate.jsr303.tck.tests.validation.BadlyBehavedEntity; +import org.hibernate.jsr303.tck.tests.validation.Customer; +import org.hibernate.jsr303.tck.tests.validation.Engine; + +import javax.validation.Validator; + +/** + * {@link Validator} implementation that uses + * {@link com.google.gwt.validation.client.GwtValidation GwtValidation}. + */ +public final class TckTestValidator extends AbstractValidator { + /** + * Marker Interface for {@link GWT#create(Class)}. + */ + @GwtValidation(value = { + Actor.class, BadlyBehavedEntity.class, Engine.class, + Customer.class}) + public static interface GwtValidator extends Validator { + } + + public TckTestValidator() { + super((Validator) GWT.create(GwtValidator.class)); + } +}
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/ValidatePropertyTest.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/ValidatePropertyTest.java new file mode 100644 index 0000000..0d7bd2f --- /dev/null +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/ValidatePropertyTest.java
@@ -0,0 +1,65 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.sample.validationtck.validation; + +import javax.validation.ValidationException; + +/** + * Test wrapper for + * {@link org.hibernate.jsr303.tck.tests.validation.ValidatePropertyTest}. + */ +public class ValidatePropertyTest extends AbstractValidationTest { + + private final org.hibernate.jsr303.tck.tests.validation.ValidatePropertyTest delegate = + new org.hibernate.jsr303.tck.tests.validation.ValidatePropertyTest(); + + public void testIllegalArgumentExceptionIsThrownForNullValue() { + delegate.testIllegalArgumentExceptionIsThrownForNullValue(); + } + + public void testPassingNullAsGroup() { + delegate.testPassingNullAsGroup(); + } + + public void testUnexpectedExceptionsInValidatePropertyGetWrappedInValidationExceptions() { + // Wrap the test to catch the @Test expected exception. + try { + delegate.testUnexpectedExceptionsInValidatePropertyGetWrappedInValidationExceptions(); + fail("Expected a " + ValidationException.class); + } catch (ValidationException expected) { + } + } + + public void testValidateProperty() { + delegate.testValidateProperty(); + } + + public void testValidatePropertyWithEmptyProperty() { + delegate.testValidatePropertyWithEmptyProperty(); + } + + public void testValidatePropertyWithInvalidPropertyPath() { + delegate.testValidatePropertyWithInvalidPropertyPath(); + } + + public void testValidatePropertyWithNullProperty() { + delegate.testValidatePropertyWithNullProperty(); + } + + public void testValidIsNotHonoredValidateProperty() { + delegate.testValidIsNotHonoredValidateProperty(); + } +}
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/ValidateValueTest.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/ValidateValueTest.java new file mode 100644 index 0000000..3706871 --- /dev/null +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/ValidateValueTest.java
@@ -0,0 +1,67 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.sample.validationtck.validation; + + +/** + * Test wrapper for + * {@link org.hibernate.jsr303.tck.tests.validation.ValidateValueTest}. + */ +public class ValidateValueTest extends AbstractValidationTest { + + private final org.hibernate.jsr303.tck.tests.validation.ValidateValueTest delegate = + new org.hibernate.jsr303.tck.tests.validation.ValidateValueTest(); + + public void testExistingPropertyWoConstraintsNorCascaded() { + delegate.testExistingPropertyWoConstraintsNorCascaded(); + } + + public void testValidateValue() { + delegate.testValidateValue(); + } + + public void testValidateValueFailure() { + delegate.testValidateValueFailure(); + } + + public void testValidateValuePassingNullAsGroup() { + delegate.testValidateValuePassingNullAsGroup(); + } + + public void testValidateValueSuccess() { + delegate.testValidateValueSuccess(); + } + + public void testValidateValueWithEmptyPropertyPath() { + delegate.testValidateValueWithEmptyPropertyPath(); + } + + public void testValidateValueWithInvalidPropertyPath() { + delegate.testValidateValueWithInvalidPropertyPath(); + } + + public void testValidateValueWithNullObject() { + delegate.testValidateValueWithNullObject(); + } + + public void testValidateValueWithNullPropertyName() { + delegate.testValidateValueWithNullPropertyName(); + } + + public void testValidIsNotHonoredValidateValue() { + delegate.testValidIsNotHonoredValidateValue(); + } +}
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/ValidationGwtSuite.java similarity index 65% copy from samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java copy to samples/validationtck/test/com/google/gwt/sample/validationtck/validation/ValidationGwtSuite.java index 219d95a..0a0a4ac 100644 --- a/samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validation/ValidationGwtSuite.java
@@ -13,22 +13,22 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.sample.validationtck; +package com.google.gwt.sample.validationtck.validation; import com.google.gwt.junit.tools.GWTTestSuite; -import com.google.gwt.sample.validationtck.constraints.application.ValidationRequirementTest; import junit.framework.Test; /** - * All Tck Tests + * Tck Tests for the {@code validation} package. */ -public class TckGwtSuite { - +public class ValidationGwtSuite { public static Test suite() { - GWTTestSuite suite = new GWTTestSuite("TCK for GWT Validation"); - suite.addTestSuite(ValidationRequirementTest.class); - // suite.addTestSuite(CustomConstraintValidatorTest.class); + GWTTestSuite suite = new GWTTestSuite( + "TCK for GWT Validation, validation package"); + suite.addTestSuite(PropertyPathTest.class); + suite.addTestSuite(ValidatePropertyTest.class); + suite.addTestSuite(ValidateValueTest.class); return suite; } }
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/ConstraintApplicationGwtSuite.java similarity index 65% copy from samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java copy to samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/ConstraintApplicationGwtSuite.java index 219d95a..590a1bb 100644 --- a/samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/ConstraintApplicationGwtSuite.java
@@ -13,22 +13,20 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.google.gwt.sample.validationtck; +package com.google.gwt.sample.validationtck.validatorfactory; import com.google.gwt.junit.tools.GWTTestSuite; -import com.google.gwt.sample.validationtck.constraints.application.ValidationRequirementTest; import junit.framework.Test; /** - * All Tck Tests + * Tck Tests for the {@code validatorfactory} package. */ -public class TckGwtSuite { - +public class ConstraintApplicationGwtSuite { public static Test suite() { - GWTTestSuite suite = new GWTTestSuite("TCK for GWT Validation"); - suite.addTestSuite(ValidationRequirementTest.class); - // suite.addTestSuite(CustomConstraintValidatorTest.class); + GWTTestSuite suite = new GWTTestSuite( + "TCK for GWT Validation, validatorfactory package"); + suite.addTestSuite(CustomConstraintValidatorTest.class); return suite; } }
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/CustomConstraintValidatorTest.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/CustomConstraintValidatorTest.java new file mode 100644 index 0000000..6bbc4b6 --- /dev/null +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/CustomConstraintValidatorTest.java
@@ -0,0 +1,44 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.sample.validationtck.validatorfactory; + +import com.google.gwt.junit.client.GWTTestCase; + +/** + * Wraps + * {@link org.hibernate.jsr303.tck.tests.constraints.customconstraint.CustomConstraintValidatorTest} + * . + */ +public class CustomConstraintValidatorTest extends GWTTestCase { + org.hibernate.jsr303.tck.tests.validatorfactory.CustomConstraintValidatorTest delegate = new org.hibernate.jsr303.tck.tests.validatorfactory.CustomConstraintValidatorTest(); + + @Override + public String getModuleName() { + return "com.google.gwt.sample.validationtck.validatorfactory.TckTest"; + } + + public void testDefaultConstructorInValidatorCalled() { + delegate.testDefaultConstructorInValidatorCalled(); + } + + public void testRuntimeExceptionInValidatorCreationIsWrapped() { + delegate.testRuntimeExceptionInValidatorCreationIsWrapped(); + } + + public void testValidationExceptionIsThrownInCaseFactoryReturnsNull() { + delegate.testValidationExceptionIsThrownInCaseFactoryReturnsNull(); + } +}
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml b/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/TckTest.gwt.xml similarity index 82% rename from samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml rename to samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/TckTest.gwt.xml index 36b9a9e..03b25d6 100644 --- a/samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/TckTest.gwt.xml
@@ -17,9 +17,11 @@ --> <module> <inherits name="com.google.gwt.sample.validationtck.ValidationTck" /> - <source path=""> + <include name="*.java" /> <exclude name="super" /> </source> - <entry-point class="com.google.gwt.sample.validationtck.Tck" /> + <replace-with class="com.google.gwt.sample.validationtck.validatorfactory.TckTestValidator"> + <when-type-is class="javax.validation.Validator"/> + </replace-with> </module> \ No newline at end of file
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/TckTestValidator.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/TckTestValidator.java new file mode 100644 index 0000000..3e5438a --- /dev/null +++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/validatorfactory/TckTestValidator.java
@@ -0,0 +1,41 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.sample.validationtck.validatorfactory; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.validation.client.AbstractValidator; +import com.google.gwt.validation.client.GwtValidation; + +import org.hibernate.jsr303.tck.tests.validatorfactory.CustomConstraintValidatorTest.Dummy; + +import javax.validation.Validator; + +/** + * {@link Validator} implementation that uses + * {@link com.google.gwt.validation.client.GwtValidation GwtValidation}. + */ +public final class TckTestValidator extends AbstractValidator { + /** + * Marker Interface for {@link GWT#create(Class)}. + */ + @GwtValidation(value = {Dummy.class}) + public static interface GwtValidator extends Validator { + } + + public TckTestValidator() { + super((Validator) GWT.create(GwtValidator.class)); + } +}
diff --git a/user/src/com/google/gwt/validation/client/AbstractValidator.java b/user/src/com/google/gwt/validation/client/AbstractValidator.java new file mode 100644 index 0000000..ddef4e6 --- /dev/null +++ b/user/src/com/google/gwt/validation/client/AbstractValidator.java
@@ -0,0 +1,84 @@ +/* + * Copyright 2010 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.gwt.validation.client; + +import java.util.Set; + +import javax.validation.ConstraintViolation; +import javax.validation.Validator; +import javax.validation.metadata.BeanDescriptor; + +/** + * Abstract {@link Validator} that delegates to a GWT generated validator. + * <p> + * Extend this class create a default no arg constructor like. + * + * <pre> + * public class MyValidator { + * @GwtValidation(value = {Pojo.class,Other.class}) + * public static interface GwtValidator extends Validator { + * } + * + * MyValidator() { + * super((Validator) GWT.create(GwtValidator.class)); + * } + * } + * </pre> + * <p> + * Then add a line like this to your Gwt Module config (gwt.xml) file. + * + * <pre> + * <replace-with class="com.example.MyValidator.GwtValidator"> + * <when-type-is class="javax.validation.Validator"/> + * </replace-with> + * </pre> + */ +public abstract class AbstractValidator implements Validator { + + private final Validator validator; + + /** + * Pass a GWT created {@link Validator} to this constructor. + */ + public AbstractValidator(Validator validator) { + super(); + this.validator = validator; + } + + public final BeanDescriptor getConstraintsForClass(Class<?> clazz) { + return validator.getConstraintsForClass(clazz); + } + + public final <T> T unwrap(Class<T> type) { + return validator.unwrap(type); + } + + public final <T> Set<ConstraintViolation<T>> validate(T object, + Class<?>... groups) { + return validator.validate(object, groups); + } + + public final <T> Set<ConstraintViolation<T>> validateProperty(T object, + String propertyName, Class<?>... groups) { + return validator.validateProperty(object, propertyName, groups); + } + + public final <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, + String propertyName, Object value, + Class<?>... groups) { + return validator.validateValue(beanType, propertyName, value, groups); + } +} \ No newline at end of file