Public: GWT version of the JSR 303 Bean Validation TCK
So far only one test is wrapped, One test passses and one fails,
but this shows the patern to use to get the tests going.
The test failure is expected, and represent code that needs to be implemeted.
Review at http://gwt-code-reviews.appspot.com/1085801
Review by: rchandia@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9233 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/build.xml b/samples/build.xml
index 6b78224..b5061e1 100644
--- a/samples/build.xml
+++ b/samples/build.xml
@@ -42,6 +42,10 @@
<gwt.ant dir="validation" />
</target>
+ <target name="validationtck" description="Build validation TCK">
+ <gwt.ant dir="validationtck" />
+ </target>
+
<target name="-do" description="Run all subprojects" >
<antcall target="dynatable" />
<antcall target="dynatablerf" />
@@ -52,6 +56,7 @@
<antcall target="mail" />
<antcall target="showcase" />
<antcall target="validation" />
+ <!-- don't include validationtck, it is not really a sample -->
</target>
<target name="build" description="Builds GWT">
diff --git a/samples/common.ant.xml b/samples/common.ant.xml
index 73468b9..5de8f54 100755
--- a/samples/common.ant.xml
+++ b/samples/common.ant.xml
@@ -3,7 +3,7 @@
<property name="project.tail" value="samples/${sample.root}" />
<import file="${gwt.root}/common.ant.xml" />
- <!--
+ <!--
Number of localworkers for sample compilation. This depends on your
hardware, so it's a good candidate to specify in local.ant.properties
if this default isn't good for you. Ideally, it should approximate
@@ -71,7 +71,7 @@
<target name="compile" description="Compile all java files">
<mkdir dir="${sample.build}/war/WEB-INF/classes" />
- <gwt.javac destdir="${sample.build}/war/WEB-INF/classes"
+ <gwt.javac destdir="${sample.build}/war/WEB-INF/classes"
excludes="**/super/**">
<classpath>
<pathelement location="${gwt.user.jar}" />
@@ -155,7 +155,9 @@
<target name="checkstyle" description="Static analysis of source">
<gwt.checkstyle outputdirectory="${sample.build}">
- <fileset dir="src" />
+ <fileset dir="src" >
+ <exclude name="org/**/super/org/**/*.java"/>
+ </fileset>
</gwt.checkstyle>
</target>
diff --git a/samples/validationtck/README.txt b/samples/validationtck/README.txt
new file mode 100644
index 0000000..f6fe5e8
--- /dev/null
+++ b/samples/validationtck/README.txt
@@ -0,0 +1,11 @@
+This is not actually a sample.
+It is a GWT HACK to run the JSR 303 Technology Compatibility Kit.
+
+See
+http://docs.jboss.org/hibernate/stable/beanvalidation/tck/reference/html_single/
+
+from this dir run
+ant tck
+
+A html report will be generated.
+
diff --git a/samples/validationtck/build.xml b/samples/validationtck/build.xml
new file mode 100755
index 0000000..a283414
--- /dev/null
+++ b/samples/validationtck/build.xml
@@ -0,0 +1,142 @@
+<project name="validationtck" default="build" basedir=".">
+ <property name="sample.root" value="validationtck" />
+ <property name="sample.module" value="ValidationTck" />
+ <property name="sample.path" value="src" />
+ <property name="test.args" value="-ea" />
+ <property name="test.jvmargs" value="-ea" />
+ <import file="../common.ant.xml" />
+
+ <!-- these are after the common.ant.xml so they have gwt.tools etc. -->
+ <path id="sample.extraclasspath">
+ <pathelement location="${gwt.tools.lib}/apache/log4j/log4j-1.2.16.jar" />
+ <pathelement location="${gwt.tools.lib}/javax/validation/validation-api-1.0.0.GA.jar" />
+ <pathelement location="${gwt.tools.lib}/javax/validation/validation-api-1.0.0.GA-sources.jar" />
+ <pathelement location="${gwt.tools.lib}/hibernate/validator/hibernate-validator-4.1.0.Final.jar" />
+ <pathelement location="${gwt.tools.lib}/hibernate/validator/hibernate-validator-4.1.0.Final-sources.jar" />
+ <pathelement location="${gwt.tools.lib}/slf4j/slf4j-api/slf4j-api-1.6.1.jar" />
+ <pathelement location="${gwt.tools.lib}/slf4j/slf4j-log4j12/slf4j-log4j12-1.6.1.jar" />
+ <!-- TCK jars -->
+ <pathelement location="${gwt.tools.lib}/hibernate/validator/tck/jsr303-tck-1.0.3.GA-sources.jar" />
+ <pathelement location="${gwt.tools.lib}/hibernate/validator/tck/jsr303-tck-1.0.3.GA.jar" />
+ <pathelement location="${gwt.tools.lib}/jboss/test-audit/jboss-test-audit-api-1.0.0-sources.jar" />
+ <pathelement location="${gwt.tools.lib}/jboss/test-audit/jboss-test-audit-api-1.0.0.jar" />
+ <pathelement location="${gwt.tools.lib}/jboss/test-harness/jboss-test-harness-1.0.0-sources.jar" />
+ <pathelement location="${gwt.tools.lib}/jboss/test-harness/jboss-test-harness-1.0.0.jar" />
+ <pathelement location="${gwt.tools.lib}/jboss/test-harness/jboss-test-harness-api-1.0.0-sources.jar" />
+ <pathelement location="${gwt.tools.lib}/jboss/test-harness/jboss-test-harness-api-1.0.0.jar" />
+ <pathelement location="${gwt.tools.lib}/testng/testng-5.14.1-sources.jar" />
+ <pathelement location="${gwt.tools.lib}/testng/testng-5.14.1.jar" />
+ <!-- Needed for JDK 1.5-->
+ <pathelement location="${gwt.tools.lib}/javax/activation/activation-1.1.jar" />
+ <pathelement location="${gwt.tools.lib}/javax/xml/bind/jaxb-api-2.1.jar" />
+ <pathelement location="${gwt.tools.lib}/sun/jaxb/jaxb-impl-2.1.3.jar" />
+ <pathelement location="${gwt.tools.lib}/javax/xml/stream/stax-api-1.0-2.jar" />
+ </path>
+ <fileset id="sample.server.libs" dir="${gwt.tools.lib}">
+ <include name="hibernate/validator/hibernate-validator-4.1.0.Final.jar" />
+ <include name="apache/log4j/log4j-1.2.16.jar" />
+ <include name="slf4j/slf4j-api/slf4j-api-1.6.1.jar" />
+ <include name="slf4j/slf4j-log4j12/slf4j-log4j12-1.6.1.jar" />
+ <!-- Needed for JDK 1.5-->
+ <include name="javax/activation/activation-1.1.jar" />
+ <include name="javax/xml/bind/jaxb-api-2.1.jar" />
+ <include name="sun/jaxb/jaxb-impl-2.1.3.jar" />
+ <include name="javax/xml/stream/stax-api-1.0-2.jar" />
+ </fileset>
+
+
+ <!--
+ Classpaths added for test cases
+ -->
+ <path id="test.extraclasspath">
+ <pathelement location="${gwt.build}/out/dev/bin-test" />
+ <pathelement location="${gwt.dev.jar}" />
+ <pathelement location="${gwt.build.lib}/gwt-user.jar" />
+ <path refid="sample.extraclasspath" />
+ </path>
+
+
+ <property name="test.timeout" value="4" />
+ <property name="emma.merged.out" value="${junit.out}/emma-coverage" />
+ <property name="gwt.junit.testcase.web.includes" value="${gwt.junit.testcase.includes}" />
+ <property name="gwt.junit.testcase.web.excludes" value="" />
+
+ <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"
+ depends="compile.emma.if.enabled"
+ unless="compile.tests.complete">
+ <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>
+
+
+ <target name="tck"
+ depends="compile, compile.tests"
+ description="Run all tests for this project.">
+ <!-- Prevent compilation for every target. -->
+ <property name="compile.complete" value="true"/>
+ <property name="compile.tests.complete" value="true"/>
+
+ <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}"
+ 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>
+ <antcall target="test.dev.remote"/>
+ <antcall target="test.emma.remote"/>
+ <antcall target="test.web.remote"/>
+ <antcall target="test.draft.remote"/>
+ <antcall target="test.nometa.remote"/>
+ </sequential>
+ <antcall target="test.dev.selenium"/>
+ <antcall target="test.emma.selenium"/>
+ <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.web.htmlunit"/>
+ <antcall target="test.draft.htmlunit"/>
+ <antcall target="test.nometa.htmlunit"/-->
+ </parallel>
+ </limit>
+ </target>
+
+ <target name="test.dev.htmlunit"
+ depends="compile, compile.tests"
+ description="Run dev-mode tests with HtmlUnit."
+ unless="test.dev.htmlunit.disable">
+ <fileset id="test.dev.htmlunit.tests" dir="${javac.junit.out}"
+ includes="${gwt.junit.testcase.dev.includes}"
+ excludes="${gwt.junit.testcase.dev.excludes}" />
+ <gwt.junit test.name="test.dev.htmlunit"
+ test.args="${test.args} -standardsMode "
+ test.jvmargs="${test.jvmargs}"
+ test.out="${junit.out}/dev-htmlunit"
+ test.cases="test.dev.htmlunit.tests" >
+ <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
new file mode 100644
index 0000000..b38464a
--- /dev/null
+++ b/samples/validationtck/src/com/google/gwt/sample/validationtck/Tck.java
@@ -0,0 +1,39 @@
+/*
+ * 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.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
new file mode 100644
index 0000000..ebab05b
--- /dev/null
+++ b/samples/validationtck/src/com/google/gwt/sample/validationtck/TckTestValidator.java
@@ -0,0 +1,55 @@
+/*
+ * 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
new file mode 100644
index 0000000..bfb9b4a
--- /dev/null
+++ b/samples/validationtck/src/com/google/gwt/sample/validationtck/TckValidator.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;
+
+import com.google.gwt.validation.client.GwtValidation;
+
+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 = {
+ Woman.class,
+ SuperWoman.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
new file mode 100644
index 0000000..a3a1610
--- /dev/null
+++ b/samples/validationtck/src/com/google/gwt/sample/validationtck/ValidationTck.gwt.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.0.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.0.1/distro-source/core/src/gwt-module.dtd">
+<!--
+ 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.
+-->
+<module rename-to="validationtck">
+ <inherits name="com.google.gwt.user.User" />
+ <inherits name="org.hibernate.jsr303.tck.Jsr303Tck" />
+ <inherits name="org.hibernate.validator.HibernateValidator" />
+ <source path="">
+ <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
new file mode 100644
index 0000000..83d9cef
--- /dev/null
+++ b/samples/validationtck/src/org/hibernate/jsr303/tck/Jsr303Tck.gwt.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+This is a HACK, is not a complete Validation TCK solution.
+It is only enough to run the tests in the GWT Validation TCK.
+-->
+<module>
+ <inherits name='com.google.gwt.validation.Validation' />
+ <inherits name='org.jboss.test.audit.JbossTestAudit' />
+ <inherits name='org.jboss.testharness.JbossTestHarness' />
+ <inherits name='org.testng.TestNg' />
+ <source path="">
+ <exclude name="super/" />
+ <!-- things not used in any current test -->
+ <exclude name="common/" />
+ <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>
+ <super-source path="super" />
+</module>
\ No newline at end of file
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
new file mode 100644
index 0000000..5538759
--- /dev/null
+++ b/samples/validationtck/src/org/hibernate/jsr303/tck/super/org/hibernate/jsr303/tck/util/TestUtil.java
@@ -0,0 +1,409 @@
+// $Id: TestUtil.java 17620 2009-10-04 19:19:28Z hardy.ferentschik $
+/*
+ * JBoss, Home of Professional Open Source Copyright 2009, Red Hat, Inc. and/or
+ * its affiliates, and individual contributors by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * 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 org.hibernate.jsr303.tck.util;
+
+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;
+import static org.testng.Assert.fail;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.validation.Configuration;
+import javax.validation.ConstraintViolation;
+import javax.validation.MessageInterpolator;
+import javax.validation.Path;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor;
+import javax.validation.metadata.PropertyDescriptor;
+import javax.validation.spi.ValidationProvider;
+
+/**
+ * Modified by Google.
+ * <ul>
+ * <li>Use RegExp instead of Pattern</li>
+ * <li>Hard code the validator</li>
+ * </ul>
+ * @author Hardy Ferentschik
+ */
+public final class TestUtil {
+
+ private static String VALIDATION_PROVIDER_TEST_CLASS = "validation.provider";
+
+ private static ValidationProvider<?> validationProviderUnderTest;
+
+ private TestUtil() {
+ }
+
+ public static Validator getValidatorUnderTest() {
+ // return getValidatorFactoryUnderTest().getValidator();
+ return GWT.create(Validator.class);
+ }
+
+ public static ValidationProvider<?> getValidationProviderUnderTest() {
+ if (validationProviderUnderTest == null) {
+ instantiateValidationProviderUnderTest();
+ }
+ return validationProviderUnderTest;
+ }
+
+ public static ValidatorFactory getValidatorFactoryUnderTest() {
+ Configuration<?> config = getConfigurationUnderTest();
+ return config.buildValidatorFactory();
+ }
+
+ public static Configuration<?> getConfigurationUnderTest() {
+ if (validationProviderUnderTest == null) {
+ instantiateValidationProviderUnderTest();
+ }
+
+ // ProviderSpecificBootstrap<?> bootstrap =
+ // Validation.byProvider(validationProviderUnderTest.getClass());
+ return null; // bootstrap.configure();
+ }
+
+ public static MessageInterpolator getDefaultMessageInterpolator() {
+ Configuration<?> config = getConfigurationUnderTest();
+ return config.getDefaultMessageInterpolator();
+ }
+
+ public static <T> void assertCorrectNumberOfViolations(
+ Set<ConstraintViolation<T>> violations, int expectedViolations) {
+ assertEquals(violations.size(), expectedViolations,
+ "Wrong number of constraint violations. Expected: "
+ + expectedViolations + " Actual: " + violations.size());
+ }
+
+ public static <T> void assertCorrectConstraintViolationMessages(
+ Set<ConstraintViolation<T>> violations, String... messages) {
+ List<String> actualMessages = new ArrayList<String>();
+ for (ConstraintViolation<?> violation : violations) {
+ actualMessages.add(violation.getMessage());
+ }
+
+ assertTrue(actualMessages.size() == messages.length,
+ "Wrong number or error messages. Expected: " + messages.length
+ + " Actual: " + actualMessages.size());
+
+ for (String expectedMessage : messages) {
+ assertTrue(actualMessages.contains(expectedMessage), "The message '"
+ + expectedMessage
+ + "' should have been in the list of actual messages: "
+ + actualMessages);
+ actualMessages.remove(expectedMessage);
+ }
+ assertTrue(actualMessages.isEmpty(),
+ "Actual messages contained more messages as specified expected messages");
+ }
+
+ public static <T> void assertCorrectConstraintTypes(
+ Set<ConstraintViolation<T>> violations,
+ Class<?>... expectedConsraintTypes) {
+ List<String> actualConstraintTypes = new ArrayList<String>();
+ for (ConstraintViolation<?> violation : violations) {
+ actualConstraintTypes.add(((Annotation) violation.getConstraintDescriptor().getAnnotation()).annotationType().getName());
+ }
+
+ assertEquals(expectedConsraintTypes.length, actualConstraintTypes.size(),
+ "Wrong number of constraint types.");
+
+ for (Class<?> expectedConstraintType : expectedConsraintTypes) {
+ assertTrue(
+ actualConstraintTypes.contains(expectedConstraintType.getName()),
+ "The constraint type " + expectedConstraintType.getName()
+ + " is not in the list of actual violated constraint types: "
+ + actualConstraintTypes);
+ }
+ }
+
+ public static <T> void assertCorrectPropertyPaths(
+ Set<ConstraintViolation<T>> violations, String... propertyPaths) {
+ List<Path> propertyPathsOfViolations = new ArrayList<Path>();
+ for (ConstraintViolation<?> violation : violations) {
+ propertyPathsOfViolations.add(violation.getPropertyPath());
+ }
+
+ assertEquals(propertyPaths.length, propertyPathsOfViolations.size(),
+ "Wrong number of property paths. Expected: " + propertyPaths.length
+ + " Actual: " + propertyPathsOfViolations.size());
+
+ for (String propertyPath : propertyPaths) {
+ Path expectedPath = PathImpl.createPathFromString(propertyPath);
+ boolean containsPath = false;
+ for (Path actualPath : propertyPathsOfViolations) {
+ if (assertEqualPaths(expectedPath, actualPath)) {
+ containsPath = true;
+ break;
+ }
+ }
+ if (!containsPath) {
+ fail(expectedPath
+ + " is not in the list of path instances contained in the actual constraint violations: "
+ + propertyPathsOfViolations);
+ }
+ }
+ }
+
+ public static <T> void assertConstraintViolation(
+ ConstraintViolation<T> violation, Class<?> rootBean, Object invalidValue,
+ String propertyPath) {
+ Path expectedPath = PathImpl.createPathFromString(propertyPath);
+ if (!assertEqualPaths(violation.getPropertyPath(), expectedPath)) {
+ fail("Property paths differ. Actual: " + violation.getPropertyPath()
+ + " Expected: " + expectedPath);
+ }
+
+ assertEquals(violation.getRootBeanClass(), rootBean, "Wrong root bean.");
+ assertEquals(violation.getInvalidValue(), invalidValue,
+ "Wrong invalid value.");
+ }
+
+ public static boolean assertEqualPaths(Path p1, Path p2) {
+ Iterator<Path.Node> p1Iterator = p1.iterator();
+ Iterator<Path.Node> p2Iterator = p2.iterator();
+ while (p1Iterator.hasNext()) {
+ Path.Node p1Node = p1Iterator.next();
+ if (!p2Iterator.hasNext()) {
+ return false;
+ }
+ Path.Node p2Node = p2Iterator.next();
+
+ // do the comparison on the node values
+ if (p2Node.getName() == null) {
+ if (p1Node.getName() != null) {
+ return false;
+ }
+ } else if (!p2Node.getName().equals(p1Node.getName())) {
+ return false;
+ }
+
+ if (p2Node.isInIterable() != p1Node.isInIterable()) {
+ return false;
+ }
+
+ if (p2Node.getIndex() == null) {
+ if (p1Node.getIndex() != null) {
+ return false;
+ }
+ } else if (!p2Node.getIndex().equals(p1Node.getIndex())) {
+ return false;
+ }
+
+ if (p2Node.getKey() == null) {
+ if (p1Node.getKey() != null) {
+ return false;
+ }
+ } else if (!p2Node.getKey().equals(p1Node.getKey())) {
+ return false;
+ }
+ }
+
+ return !p2Iterator.hasNext();
+ }
+
+ public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz,
+ String property) {
+ Validator validator = getValidatorUnderTest();
+ return validator.getConstraintsForClass(clazz).getConstraintsForProperty(
+ property);
+ }
+
+ public static Set<ConstraintDescriptor<?>> getConstraintDescriptorsFor(
+ Class<?> clazz, String property) {
+ ElementDescriptor elementDescriptor = getPropertyDescriptor(clazz, property);
+ return elementDescriptor.getConstraintDescriptors();
+ }
+
+ public static Object getInputStreamForPath(String path) {
+
+ return null;
+ }
+
+ private static <U extends ValidationProvider<?>> void instantiateValidationProviderUnderTest() {
+
+ }
+
+ public static class PathImpl implements Path {
+
+ /**
+ * Regular expression used to split a string path into its elements.
+ *
+ * @see <a href="http://www.regexplanet.com/simple/index.jsp">Regular
+ * expression tester</a>
+ */
+ private static final RegExp pathPattern = RegExp.compile("(\\w+)(\\[(\\w*)\\])?(\\.(.*))*");
+
+ private static final String PROPERTY_PATH_SEPARATOR = ".";
+
+ private final List<Node> nodeList;
+
+ public static PathImpl createPathFromString(String propertyPath) {
+ if (propertyPath == null) {
+ throw new IllegalArgumentException(
+ "null is not allowed as property path.");
+ }
+
+ if (propertyPath.length() == 0) {
+ return createNewPath(null);
+ }
+
+ return parseProperty(propertyPath);
+ }
+
+ public static PathImpl createNewPath(String name) {
+ PathImpl path = new PathImpl();
+ NodeImpl node = new NodeImpl(name);
+ path.addNode(node);
+ return path;
+ }
+
+ private PathImpl() {
+ nodeList = new ArrayList<Node>();
+ }
+
+ public void addNode(Node node) {
+ nodeList.add(node);
+ }
+
+ public Iterator<Path.Node> iterator() {
+ return nodeList.iterator();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ Iterator<Path.Node> iter = iterator();
+ while (iter.hasNext()) {
+ Node node = iter.next();
+ builder.append(node.toString());
+ if (iter.hasNext()) {
+ builder.append(PROPERTY_PATH_SEPARATOR);
+ }
+ }
+ return builder.toString();
+ }
+
+ private static PathImpl parseProperty(String property) {
+ PathImpl path = new PathImpl();
+ String tmp = property;
+ do {
+ MatchResult matcher = pathPattern.exec(tmp);
+ if (matcher != null) {
+ String value = matcher.getGroup(1);
+ String indexed = matcher.getGroup(2);
+ String index = matcher.getGroup(3);
+ NodeImpl node = new NodeImpl(value);
+ if (indexed != null) {
+ node.setInIterable(true);
+ }
+ if (index != null && index.length() > 0) {
+ try {
+ Integer i = Integer.parseInt(index);
+ node.setIndex(i);
+ } catch (NumberFormatException e) {
+ node.setKey(index);
+ }
+ }
+ path.addNode(node);
+ tmp = matcher.getGroup(5);
+ } else {
+ throw new IllegalArgumentException("Unable to parse property path "
+ + property);
+ }
+ } while (tmp != null);
+ return path;
+ }
+ }
+
+ public static class NodeImpl implements Path.Node {
+
+ private static final String INDEX_OPEN = "[";
+ private static final String INDEX_CLOSE = "]";
+
+ private final String name;
+ private boolean isInIterable;
+ private Integer index;
+ private Object key;
+
+ public NodeImpl(String name) {
+ this.name = name;
+ }
+
+ NodeImpl(Path.Node node) {
+ this.name = node.getName();
+ this.isInIterable = node.isInIterable();
+ this.index = node.getIndex();
+ this.key = node.getKey();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isInIterable() {
+ return isInIterable;
+ }
+
+ public void setInIterable(boolean inIterable) {
+ isInIterable = inIterable;
+ }
+
+ public Integer getIndex() {
+ return index;
+ }
+
+ public void setIndex(Integer index) {
+ isInIterable = true;
+ this.index = index;
+ }
+
+ public Object getKey() {
+ return key;
+ }
+
+ public void setKey(Object key) {
+ isInIterable = true;
+ this.key = key;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder(name == null ? "" : name);
+ if (isInIterable) {
+ builder.append(INDEX_OPEN);
+ if (getIndex() != null) {
+ builder.append(getIndex());
+ } else if (getKey() != null) {
+ builder.append(getKey());
+ }
+ builder.append(INDEX_CLOSE);
+ }
+ return builder.toString();
+ }
+ }
+}
diff --git a/samples/validationtck/src/org/jboss/test/audit/JbossTestAudit.gwt.xml b/samples/validationtck/src/org/jboss/test/audit/JbossTestAudit.gwt.xml
new file mode 100644
index 0000000..3e95704
--- /dev/null
+++ b/samples/validationtck/src/org/jboss/test/audit/JbossTestAudit.gwt.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+This is a HACK, is not a general solution for using JBoss Test Audit.
+It is only enough to run the tests in the GWT Validation TCK.
+-->
+<module>
+ <inherits name="com.google.gwt.user.User" />
+ <source path="">
+ <exclude name="super/" />
+ </source>
+ <super-source path="super" />
+</module>
\ No newline at end of file
diff --git a/samples/validationtck/src/org/jboss/testharness/JbossTestHarness.gwt.xml b/samples/validationtck/src/org/jboss/testharness/JbossTestHarness.gwt.xml
new file mode 100644
index 0000000..bb851ef
--- /dev/null
+++ b/samples/validationtck/src/org/jboss/testharness/JbossTestHarness.gwt.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+This is a HACK, is not a general solution for using JBoss Test Harness.
+It is only enough to run the tests in the GWT Validation TCK.
+-->
+<module>
+ <inherits name="org.testng.TestNg" />
+ <source path="">
+ <exclude name="super/" />
+ <include name="api/DeploymentException.java"/>
+ </source>
+ <super-source path="super" />
+</module>
\ No newline at end of file
diff --git a/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/AbstractTest.java b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/AbstractTest.java
new file mode 100644
index 0000000..8773ba6
--- /dev/null
+++ b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/AbstractTest.java
@@ -0,0 +1,200 @@
+//Modified by Google.
+package org.jboss.testharness;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import java.util.logging.Logger;
+import org.jboss.testharness.api.Configuration;
+import org.jboss.testharness.api.DeploymentException;
+//import org.jboss.testharness.api.TestResult;
+//import org.jboss.testharness.api.TestResult.Status;
+//import org.jboss.testharness.impl.ConfigurationImpl;
+//import org.jboss.testharness.impl.packaging.ArtifactGenerator;
+import org.jboss.testharness.impl.packaging.TCKArtifact;
+import org.testng.IHookCallBack;
+import org.testng.IHookable;
+//import org.testng.ITestContext;
+import org.testng.ITestResult;
+//import org.testng.annotations.AfterClass;
+//import org.testng.annotations.AfterSuite;
+//import org.testng.annotations.BeforeClass;
+//import org.testng.annotations.BeforeSuite;
+
+/**
+ * Abstract Test
+ * <p>
+ * Modified by Google to only include the minimum needed to run the JSR-303 tck.
+ */
+public abstract class AbstractTest implements IHookable
+{
+
+ private static Logger log = Logger.getLogger(AbstractTest.class.getName());
+
+ private static boolean inContainer = false;
+
+ public static boolean isInContainer()
+ {
+ return inContainer;
+ }
+
+ public static void setInContainer(boolean inContainer)
+ {
+ AbstractTest.inContainer = inContainer;
+ }
+
+ private TCKArtifact artifact;
+ private DeploymentException deploymentException;
+ private boolean skipTest = false;
+
+ private boolean isSuiteDeployingTestsToContainer()
+ {
+ return !isInContainer() && (!getCurrentConfiguration().isStandalone() || getCurrentConfiguration().isRunIntegrationTests());
+ }
+
+ private void generateArtifact()
+ {
+
+ }
+
+ protected TCKArtifact postCreate(TCKArtifact artifact)
+ {
+ return artifact;
+ }
+
+ private boolean isDeployToContainerNeeded()
+ {
+ /*
+ * If this isn't running inside the container AND there is an artifact to
+ * deploy AND EITHER we are in standalone mode and it isn't a unit test OR
+ * we aren't in standalone mode THEN we need to deploy
+ */
+ return !isInContainer() && artifact != null && ((getCurrentConfiguration().isStandalone() && !artifact.isUnit() && getCurrentConfiguration().isRunIntegrationTests()) || !getCurrentConfiguration().isStandalone());
+ }
+
+ private void deployArtifact()
+ {
+
+ }
+
+ protected DeploymentException handleDeploymentFailure(DeploymentException deploymentException)
+ {
+ return deploymentException;
+ }
+
+
+ private void undeployArtifact() throws Exception
+ {
+ if (isDeployToContainerNeeded())
+ {
+ getCurrentConfiguration().getContainers().undeploy(artifact.getDefaultName());
+ }
+ if (getCurrentConfiguration().isStandalone() && artifact != null && artifact.isUnit())
+ {
+ getCurrentConfiguration().getStandaloneContainers().undeploy();
+ }
+ }
+
+ private void checkAssertionsEnabled()
+ {
+ boolean assertionsEnabled = false;
+ try
+ {
+ assert false;
+ }
+ catch (AssertionError error)
+ {
+ assertionsEnabled = true;
+ }
+ if (!assertionsEnabled)
+ {
+ throw new IllegalStateException("Assertions must be enabled!");
+ }
+ }
+
+ //@BeforeSuite(alwaysRun = true, groups = "scaffold")
+// public void beforeSuite(ITestContext context) throws Exception
+// {
+// if (isSuiteDeployingTestsToContainer())
+// {
+// getCurrentConfiguration().getContainers().setup();
+// }
+// if (getCurrentConfiguration().isStandalone())
+// {
+// getCurrentConfiguration().getStandaloneContainers().setup();
+// }
+// checkAssertionsEnabled();
+// }
+
+ //@AfterSuite(alwaysRun = true, groups = "scaffold")
+ public void afterSuite() throws Exception
+ {
+ if (isSuiteDeployingTestsToContainer())
+ {
+ getCurrentConfiguration().getContainers().cleanup();
+ }
+ if (getCurrentConfiguration().isStandalone())
+ {
+ getCurrentConfiguration().getStandaloneContainers().cleanup();
+ }
+ }
+
+ //@BeforeClass(alwaysRun = true, groups = "scaffold")
+ public void beforeClass() throws Throwable
+ {
+ generateArtifact();
+ deployArtifact();
+
+ }
+
+ //@AfterClass(alwaysRun = true, groups = "scaffold")
+ public void afterClass() throws Exception
+ {
+ undeployArtifact();
+ this.artifact = null;
+ this.deploymentException = null;
+ skipTest = false;
+ }
+
+ public void beforeMethod()
+ {
+
+ }
+
+ public void afterMethod()
+ {
+
+ }
+
+ public final void run(IHookCallBack callback, ITestResult testResult)
+ {
+ }
+
+ protected Configuration getCurrentConfiguration()
+ {
+ return null; //ConfigurationImpl.get();
+ }
+
+ protected String getContextPath()
+ {
+ return "http://" + getCurrentConfiguration().getHost() + "/" + this.getClass().getName() + "/";
+ }
+
+ protected boolean isThrowablePresent(Class<? extends Throwable> throwableType, Throwable throwable)
+ {
+ if (throwable == null)
+ {
+ return false;
+ }
+// else if (throwableType.isAssignableFrom(throwable.getClass()))
+// {
+// return true;
+// }
+// else
+// {
+// return isThrowablePresent(throwableType, throwable.getCause());
+// }
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/api/Configuration.java b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/api/Configuration.java
new file mode 100644
index 0000000..cf7c5a0
--- /dev/null
+++ b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/api/Configuration.java
@@ -0,0 +1,138 @@
+package org.jboss.testharness.api;
+
+import java.util.List;
+
+import org.jboss.testharness.spi.Containers;
+import org.jboss.testharness.spi.StandaloneContainers;
+
+/**
+ * The configuration of the TCK.
+ *
+ * The TCK may be configured using system properties or placed in a properties
+ * file called META-INF/web-beans-tck.properties.
+ *
+ * Porting package property names are the FQCN of the SPI class. Other property
+ * names (one for each non-porting package SPI configuration option) are
+ * specified here. The defaults are also listed here.
+ *
+ * The TCK may also be configured programatically through this interface
+ *
+ * <p>
+ * Modified by Google.
+ * <ul>
+ * <li>Removed references to TestLauncher</li>
+ * <li>Removed revernces to the output dir.</li>
+ * <ul>
+ *
+ * @author Pete Muir
+ *
+ */
+public interface Configuration
+{
+
+ public static final String OUTPUT_DIRECTORY_PROPERTY_NAME = "org.jboss.testharness.outputDirectory";
+ public static final String STANDALONE_PROPERTY_NAME = "org.jboss.testharness.standalone";
+ public static final String RUN_INTEGRATION_TESTS_PROPERTY_NAME = "org.jboss.testharness.runIntegrationTests";
+ public static final String CONNECT_TIMEOUT_PROPERTY_NAME = "org.jboss.testharness.connectTimeout";
+ public static final String LIBRARY_DIRECTORY_PROPERTY_NAME = "org.jboss.testharness.libraryDirectory";
+ public static final String HOST_PROPERTY_NAME = "org.jboss.testharness.host";
+ public static final String TEST_PACKAGE_PROPERTY_NAME = "org.jboss.testharness.testPackage";
+
+ public static final boolean DEFAULT_STANDALONE = true;
+ public static final boolean DEFAULT_RUN_INTEGRATION_TESTS = false;
+ public static final int DEFAULT_CONNECT_DELAY = 5000;
+ public static final boolean DEFAULT_WRITE_DEPLOYED_ARCHIVES_TO_DISK = false;
+ public static final String DEFAULT_LIBRARY_DIRECTORY = null;
+ public static final String DEFAULT_HOST = "localhost:8080";
+
+ /**
+ * The output directory to put TCK specific output. The TestNG output
+ * directory is configured via TestNG.
+ *
+ * By default set to ${tmp}/jsr-299-tck
+ */
+ public String getOutputDirectory();
+
+ /**
+ * Whether the TCK is in standalone mode or not.
+ *
+ * By default true
+ */
+ public boolean isStandalone();
+
+ /**
+ * When the TCK is running in container tests it will attempt to connect to
+ * the server every 200ms until the timeout is reached.
+ *
+ * By default 5000ms
+ */
+ public int getConnectTimeout();
+
+ /**
+ * The TCK allows additional libraries to be put in the deployed test
+ * artifacts (for example the porting package for the implementation). Any
+ * jars in this directory will be added to the deployed artifact.
+ *
+ * By default no directory is used.
+ */
+ public String getLibraryDirectory();
+
+ /**
+ * The TCK test launcher
+ *
+ * @see TestLauncher
+ *
+ */
+ public Object getInContainerTestLauncher();
+
+ /**
+ * The implementation of {@link Containers} in use.
+ */
+ public Containers getContainers();
+
+ /**
+ * Whether to run integration tests, by default false.
+ */
+ public boolean isRunIntegrationTests();
+
+ public void setOutputDirectory(String outputDirectory);
+
+ public void setStandalone(boolean standalone);
+
+ public void setConnectTimeout(int connectTimeout);
+
+ public void setLibraryDirectory(String libraryDir);
+
+ public void setInContainerTestLauncher(Object testLauncher);
+
+ public void setContainers(Containers containers);
+
+ /**
+ * The implementation of {@link StandaloneContainers} in use.
+ */
+ public StandaloneContainers getStandaloneContainers();
+
+ public void setStandaloneContainers(StandaloneContainers standaloneContainers);
+
+ public void setRunIntegrationTests(boolean runIntegrationTests);
+
+ /**
+ * The TCK will use this as the remote host to connect to run in container
+ * tests. By default localhost:8080
+ *
+ */
+ public String getHost();
+
+ public void setHost(String host);
+
+ public List<String> getExtraPackages();
+
+ public List<ResourceDescriptor> getExtraResources();
+
+ public List<String> getExtraDeploymentProperties();
+
+ public String getTestPackage();
+
+ public void setTestPackage(String packageName);
+
+}
\ No newline at end of file
diff --git a/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/api/ResourceDescriptor.java b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/api/ResourceDescriptor.java
new file mode 100644
index 0000000..772f06b
--- /dev/null
+++ b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/api/ResourceDescriptor.java
@@ -0,0 +1,14 @@
+//Modified by Google:
+//Removed URL
+package org.jboss.testharness.api;
+
+
+public interface ResourceDescriptor
+{
+
+ public String getName();
+
+ //public URL getSource();
+ public Object getSource();
+
+}
\ No newline at end of file
diff --git a/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/impl/packaging/TCKArtifact.java b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/impl/packaging/TCKArtifact.java
new file mode 100644
index 0000000..49f70c1
--- /dev/null
+++ b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/impl/packaging/TCKArtifact.java
@@ -0,0 +1,77 @@
+package org.jboss.testharness.impl.packaging;
+
+import java.util.Set;
+
+import org.jboss.testharness.api.ResourceDescriptor;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface TCKArtifact {
+ TCKArtifact initialize();
+
+ Object getJarAsStream();
+
+ Object getJar();
+
+ Object getExplodedJar();
+
+ void create();
+
+ void writeArtifactToDisk(String outputDirectory);
+
+ void writeArtifactToDisk(String outputDirectory, String ObjectName);
+
+ String getDefaultName();
+
+ Set<Class<?>> getClasses();
+
+ Set<ResourceDescriptor> getResources();
+
+ void addPackage(Object pkg);
+
+ void addPackage(String packageName, boolean addRecursively);
+
+ Object getClassesRoot(Object archiveRoot);
+
+ String getClassesRoot();
+
+ void setClassesRoot(String classesRoot);
+
+ Class<?> getDeclaringClass();
+
+ String getExtension();
+
+ void setExtension(String extension);
+
+ Set<ResourceDescriptor> getLibraries();
+
+ Object getLibraryRoot(Object archiveRoot);
+
+ void setLibrariesRoot(String libraryRoot);
+
+ boolean isLibrariesSupported();
+
+ void setLibrariesSupported(boolean librariesSupported);
+
+ boolean isUnit();
+
+ void setUnit(boolean unit);
+
+ Class<? extends Throwable> getExpectedDeploymentException();
+
+ void setExpectedDeploymentException(Class<? extends Throwable> expectedDeploymentException);
+
+ boolean isRunLocally();
+
+ void setRunLocally(boolean runLocally);
+
+ String getXmlConfigDestination();
+
+ void setXmlConfigDestination(String xmlConfigDest);
+
+ ResourceDescriptor getXmlConfig();
+
+ void skipIncludeXmlConfig(boolean skip);
+}
+
diff --git a/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/spi/Containers.java b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/spi/Containers.java
new file mode 100644
index 0000000..9456642
--- /dev/null
+++ b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/spi/Containers.java
@@ -0,0 +1,85 @@
+//Modified by Google
+package org.jboss.testharness.spi;
+
+//import java.io.IOException;
+//import java.io.InputStream;
+
+import org.jboss.testharness.api.DeploymentException;
+
+/**
+ * Incontainer mode deployment related operations
+ *
+ * The TCK porting package must provide an implementation of this interface
+ * which is suitable for the target implementation and application server
+ *
+ * <p>
+ * Modified by Google.
+ * <ul>
+ * <li>Removed refrences to java.io.</li>
+ * <ul>
+ *
+ * @author Pete Muir
+ *
+ */
+public interface Containers
+{
+
+ public static final String PROPERTY_NAME = Containers.class.getName();
+
+ /**
+ * The war/ear to deploy to the container, it should be read using a
+ * JarInputStream. Any deployment exceptions can be found through
+ * {@link #getDeploymentException()}.
+ *
+ * For a successful deployment, a symmetric {@link #undeploy(String)} will be
+ * called.
+ *
+ * @see #undeploy(String)
+ *
+ * @param archive the archive
+ * @param name the name the TCK uses to refer to this archive, unique within
+ * this tck run
+ * @return true if the deployment suceeded, otherwise false
+ * @throws IOException if any communication problems with the server occur
+ * during deployment. These will cause the test suite to fail.
+ */
+ public boolean deploy(Object archive, String name);
+
+ public DeploymentException getDeploymentException();
+
+ /**
+ * Undeploy the war/ear from the container.
+ *
+ * @see #deploy(InputStream, String)
+ *
+ * @param name the name the TCK uses to refer to this archive, unique within
+ * this tck run
+ * @throws IOException if any communication problems with the server occur
+ * during deployment. These will cause the test suite to fail.
+ */
+ public void undeploy(String name);
+
+ /**
+ * Called before the TCK starts executing the testsuite, but after the suite
+ * has been configured.
+ *
+ * A TCK suite lifecycle callback, useful for setting up the container. This
+ * method may be a no-op if no setup is required.
+ *
+ * @throws IOException if any communication problems with the server occur
+ * during setup. These will cause the test suite to fail.
+ */
+ public void setup();
+
+ /**
+ * Called after the TCK finishes executing the testsuite.
+ *
+ * A TCK suite lifecycle callback, useful for cleaning up and shutting down
+ * the container. This method may be a no-op if no setup is required.
+ *
+ * @throws IOException if any communication problems with the server occur
+ * during cleanup. These will cause the test suite to fail.
+ */
+ public void cleanup() ;
+
+}
\ No newline at end of file
diff --git a/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/spi/StandaloneContainers.java b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/spi/StandaloneContainers.java
new file mode 100644
index 0000000..354fb13
--- /dev/null
+++ b/samples/validationtck/src/org/jboss/testharness/super/org/jboss/testharness/spi/StandaloneContainers.java
@@ -0,0 +1,102 @@
+//Modified by Google
+package org.jboss.testharness.spi;
+
+import java.util.Collection;
+
+import org.jboss.testharness.api.DeploymentException;
+
+/**
+ * Standalone mode deployment related operations. If the TCK is placed in
+ * standalone mode, unit tests will be deployed via this interface.
+ *
+ * You must implement this as part of the porting package if you intend to run
+ * the TCK in standalone mode
+ *
+ * @author Pete Muir
+ *
+ */
+public interface StandaloneContainers
+{
+
+ public static final String PROPERTY_NAME = StandaloneContainers.class.getName();
+
+ /**
+ * <p>Bootstrap the container by registering Beans and Observers, raising
+ * @Initialized event, validating the deployment, and raising the
+ * @Deployed event.</p>
+ *
+ * <p>Any classes passed in should be fully deployed. This includes:</p>
+ *
+ * <ul>
+ * <li>Simple beans</li>
+ * <li>Session beans</li>
+ * <li>Producer methods and producer fields</li>
+ * <li>Observer methods</li>
+ * <li>support for Event and Instance injection points</li>
+ * </ul>
+ *
+ * The container should be in an fully initialized state when the
+ * method returns
+ *
+ * @param classes the classes to deploy
+ */
+ public void deploy(Collection<Class<?>> classes) throws DeploymentException;
+
+ /**
+ * <p>Bootstrap the container for a test by registering Beans and Observers,
+ * raising @Initialized event, validating the deployment, and raising the
+ * @Deployed event.</p>
+ *
+ * <p>Any classes passed in should be fully deployed. This includes:</p>
+ *
+ * <ul>
+ * <li>Simple beans</li>
+ * <li>Session beans</li>
+ * <li>Producer methods and producer fields</li>
+ * <li>Observer methods</li>
+ * <li>support for Event and Instance injection points</li>
+ * </ul>
+ *
+ * The container should be in an fully initialized state when the
+ * method returns
+ *
+ * @param classes the classes to deploy
+ * @param beansXmls the beans.xml files to deploy
+ *
+ * @return true if the deployment suceeded, otherwise false
+ */
+ public boolean deploy(Collection<Class<?>> classes, Collection<Object> beansXmls);
+
+ /**
+ * Any deployment exception, or null if the deployment suceeded
+ *
+ * @return
+ */
+ public DeploymentException getDeploymentException();
+
+ /**
+ * Cleanup the container after this test
+ *
+ */
+ public void undeploy();
+
+ /**
+ * Called before the TCK starts executing the testsuite, but after the suite
+ * has been configured.
+ *
+ * A TCK suite lifecycle callback, useful for setting up the container. This
+ * method may be a no-op if no setup is required.
+ *
+ */
+ public void setup();
+
+ /**
+ * Called after the TCK finishes executing the testsuite.
+ *
+ * A TCK suite lifecycle callback, useful for cleaning up and shutting down
+ * the container. This method may be a no-op if no setup is required.
+ *
+ */
+ public void cleanup();
+
+}
diff --git a/samples/validationtck/src/org/testng/TestNg.gwt.xml b/samples/validationtck/src/org/testng/TestNg.gwt.xml
new file mode 100644
index 0000000..23d6f62
--- /dev/null
+++ b/samples/validationtck/src/org/testng/TestNg.gwt.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+This is a HACK, is not a general solution for using TestNg.
+It is only enough to run the tests in the GWT Validation TCK.
+-->
+<module>
+ <inherits name="com.google.gwt.user.User" />
+ <source path="annotations">
+ <exclude name="ITestAnnotation.java" />
+ <exclude name="Listeners.java" />
+ <exclude name="Optional.java" />
+ </source>
+ <source path="collections" />
+ <source path="">
+ <include name="Assert.java" />
+ <include name="AssertJUnit.java" />
+ <include name="IClass.java" />
+ <include name="IHookable.java" />
+ <include name="IHookCallBack.java" />
+ <include name="ITestResult.java" />
+ <include name="ITestNGListener.java" />
+ <include name="ITestNGMethod.java" />
+ <include name="IAttributes.java" />
+ <include name="IRetryAnalyzer.java" />
+ <include name="ITestClass.java" />
+ </source>
+ <super-source path="super" />
+</module>
\ No newline at end of file
diff --git a/samples/validationtck/src/org/testng/super/org/testng/Assert.java b/samples/validationtck/src/org/testng/super/org/testng/Assert.java
new file mode 100644
index 0000000..0d915e2
--- /dev/null
+++ b/samples/validationtck/src/org/testng/super/org/testng/Assert.java
@@ -0,0 +1,695 @@
+package org.testng;
+
+import org.testng.collections.Lists;
+
+//import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * 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>
+ * </ul>
+ *
+ * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>
+ */
+public class Assert {
+
+ /**
+ * Protect constructor since it is a static only class
+ */
+ protected Assert() {
+ // hide constructor
+ }
+
+ /**
+ * Asserts that a condition is true. If it isn't,
+ * an AssertionError, with the given message, is thrown.
+ * @param condition the condition to evaluate
+ * @param message the assertion error message
+ */
+ static public void assertTrue(boolean condition, String message) {
+ if(!condition) {
+ failNotEquals( Boolean.valueOf(condition), Boolean.TRUE, message);
+ }
+ }
+
+ /**
+ * Asserts that a condition is true. If it isn't,
+ * an AssertionError is thrown.
+ * @param condition the condition to evaluate
+ */
+ static public void assertTrue(boolean condition) {
+ assertTrue(condition, null);
+ }
+
+ /**
+ * Asserts that a condition is false. If it isn't,
+ * an AssertionError, with the given message, is thrown.
+ * @param condition the condition to evaluate
+ * @param message the assertion error message
+ */
+ static public void assertFalse(boolean condition, String message) {
+ if(condition) {
+ failNotEquals( Boolean.valueOf(condition), Boolean.FALSE, message); // TESTNG-81
+ }
+ }
+
+ /**
+ * Asserts that a condition is false. If it isn't,
+ * an AssertionError is thrown.
+ * @param condition the condition to evaluate
+ */
+ static public void assertFalse(boolean condition) {
+ assertFalse(condition, null);
+ }
+
+ /**
+ * Fails a test with the given message and wrapping the original exception.
+ *
+ * @param message the assertion error message
+ * @param realCause the original exception
+ */
+ static public void fail(String message, Throwable realCause) {
+ AssertionError ae = new AssertionError(message);
+ ae.initCause(realCause);
+
+ throw ae;
+ }
+
+ /**
+ * Fails a test with the given message.
+ * @param message the assertion error message
+ */
+ static public void fail(String message) {
+ throw new AssertionError(message);
+ }
+
+ /**
+ * Fails a test with no message.
+ */
+ static public void fail() {
+ fail(null);
+ }
+
+ /**
+ * Asserts that two objects are equal. If they are not,
+ * an AssertionError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(Object actual, Object expected, String message) {
+ if((expected == null) && (actual == null)) {
+ return;
+ }
+ if(expected != null) {
+ if (expected.getClass().isArray()) {
+ assertArrayEquals(actual, expected, message);
+ return;
+ } else if (expected.equals(actual)) {
+ return;
+ }
+ }
+ failNotEquals(actual, expected, message);
+ }
+
+ /**
+ * Asserts that two objects are equal. It they are not, an AssertionError,
+ * with given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value (should be an non-null array value)
+ * @param message the assertion error message
+ */
+ private static void assertArrayEquals(Object actual, Object expected, String message) {
+ //is called only when expected is an array
+// if (actual.getClass().isArray()) {
+// int expectedLength = Array.getLength(expected);
+// if (expectedLength == Array.getLength(actual)) {
+// for (int i = 0 ; i < expectedLength ; i++) {
+// Object _actual = Array.get(actual, i);
+// Object _expected = Array.get(expected, i);
+// try {
+// assertEquals(_actual, _expected);
+// } catch (AssertionError ae) {
+// failNotEquals(actual, expected, message == null ? "" : message
+// + " (values as index " + i + " are not the same)");
+// }
+// }
+// //array values matched
+// return;
+// } else {
+// failNotEquals(Array.getLength(actual), expectedLength, message == null ? "" : message
+// + " (Array lengths are not the same)");
+// }
+// }
+// failNotEquals(actual, expected, message);
+ fail("assertArrayEquals not implemented");
+ }
+
+/**
+ * Asserts that two objects are equal. If they are not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(Object actual, Object expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two Strings are equal. If they are not,
+ * an AssertionError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(String actual, String expected, String message) {
+ assertEquals((Object) actual, (Object) expected, message);
+ }
+
+ /**
+ * Asserts that two Strings are equal. If they are not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(String actual, String expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two doubles are equal concerning a delta. If they are not,
+ * an AssertionError, with the given message, is thrown. If the expected
+ * value is infinity then the delta value is ignored.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param delta the absolute tolerate value value between the actual and expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(double actual, double expected, double delta, String message) {
+ // handle infinity specially since subtracting to infinite values gives NaN and the
+ // the following test fails
+ if(Double.isInfinite(expected)) {
+ if(!(expected == actual)) {
+ failNotEquals(new Double(actual), new Double(expected), message);
+ }
+ }
+ else if(!(Math.abs(expected - actual) <= delta)) { // Because comparison with NaN always returns false
+ failNotEquals(new Double(actual), new Double(expected), message);
+ }
+ }
+
+ /**
+ * Asserts that two doubles are equal concerning a delta. If they are not,
+ * an AssertionError is thrown. If the expected value is infinity then the
+ * delta value is ignored.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param delta the absolute tolerate value value between the actual and expected value
+ */
+ static public void assertEquals(double actual, double expected, double delta) {
+ assertEquals(actual, expected, delta, null);
+ }
+
+ /**
+ * Asserts that two floats are equal concerning a delta. If they are not,
+ * an AssertionError, with the given message, is thrown. If the expected
+ * value is infinity then the delta value is ignored.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param delta the absolute tolerate value value between the actual and expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(float actual, float expected, float delta, String message) {
+ // handle infinity specially since subtracting to infinite values gives NaN and the
+ // the following test fails
+ if(Float.isInfinite(expected)) {
+ if(!(expected == actual)) {
+ failNotEquals(new Float(actual), new Float(expected), message);
+ }
+ }
+ else if(!(Math.abs(expected - actual) <= delta)) {
+ failNotEquals(new Float(actual), new Float(expected), message);
+ }
+ }
+
+ /**
+ * Asserts that two floats are equal concerning a delta. If they are not,
+ * an AssertionError is thrown. If the expected
+ * value is infinity then the delta value is ignored.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param delta the absolute tolerate value value between the actual and expected value
+ */
+ static public void assertEquals(float actual, float expected, float delta) {
+ assertEquals(actual, expected, delta, null);
+ }
+
+ /**
+ * Asserts that two longs are equal. If they are not,
+ * an AssertionError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(long actual, long expected, String message) {
+ assertEquals(Long.valueOf(actual), Long.valueOf(expected), message);
+ }
+
+ /**
+ * Asserts that two longs are equal. If they are not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(long actual, long expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two booleans are equal. If they are not,
+ * an AssertionError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(boolean actual, boolean expected, String message) {
+ assertEquals( Boolean.valueOf(actual), Boolean.valueOf(expected), message);
+ }
+
+ /**
+ * Asserts that two booleans are equal. If they are not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(boolean actual, boolean expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two bytes are equal. If they are not,
+ * an AssertionError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(byte actual, byte expected, String message) {
+ assertEquals(Byte.valueOf(actual), Byte.valueOf(expected), message);
+ }
+
+ /**
+ * Asserts that two bytes are equal. If they are not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(byte actual, byte expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two chars are equal. If they are not,
+ * an AssertionFailedError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(char actual, char expected, String message) {
+ assertEquals(Character.valueOf(actual), Character.valueOf(expected), message);
+ }
+
+ /**
+ * Asserts that two chars are equal. If they are not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(char actual, char expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two shorts are equal. If they are not,
+ * an AssertionFailedError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(short actual, short expected, String message) {
+ assertEquals(Short.valueOf(actual), Short.valueOf(expected), message);
+ }
+
+ /**
+ * Asserts that two shorts are equal. If they are not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(short actual, short expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two ints are equal. If they are not,
+ * an AssertionFailedError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(int actual, int expected, String message) {
+ assertEquals(Integer.valueOf(actual), Integer.valueOf(expected), message);
+ }
+
+ /**
+ * Asserts that two ints are equal. If they are not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(int actual, int expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that an object isn't null. If it is,
+ * an AssertionError is thrown.
+ * @param object the assertion object
+ */
+ static public void assertNotNull(Object object) {
+ assertNotNull(object, null);
+ }
+
+ /**
+ * Asserts that an object isn't null. If it is,
+ * an AssertionFailedError, with the given message, is thrown.
+ * @param object the assertion object
+ * @param message the assertion error message
+ */
+ static public void assertNotNull(Object object, String message) {
+ assertTrue(object != null, message);
+ }
+
+ /**
+ * Asserts that an object is null. If it is not,
+ * an AssertionError, with the given message, is thrown.
+ * @param object the assertion object
+ */
+ static public void assertNull(Object object) {
+ assertNull(object, null);
+ }
+
+ /**
+ * Asserts that an object is null. If it is not,
+ * an AssertionFailedError, with the given message, is thrown.
+ * @param object the assertion object
+ * @param message the assertion error message
+ */
+ static public void assertNull(Object object, String message) {
+ assertTrue(object == null, message);
+ }
+
+ /**
+ * Asserts that two objects refer to the same object. If they do not,
+ * an AssertionFailedError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertSame(Object actual, Object expected, String message) {
+ if(expected == actual) {
+ return;
+ }
+ failNotSame(actual, expected, message);
+ }
+
+ /**
+ * Asserts that two objects refer to the same object. If they do not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertSame(Object actual, Object expected) {
+ assertSame(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two objects do not refer to the same objects. If they do,
+ * an AssertionError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertNotSame(Object actual, Object expected, String message) {
+ if(expected == actual) {
+ failSame(actual, expected, message);
+ }
+ }
+
+ /**
+ * Asserts that two objects do not refer to the same object. If they do,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertNotSame(Object actual, Object expected) {
+ assertNotSame(actual, expected, null);
+ }
+
+ static private void failSame(Object actual, Object expected, String message) {
+ String formatted = "";
+ if(message != null) {
+ formatted = message + " ";
+ }
+ fail(formatted + "expected not same with:<" + expected +"> but was same:<" + actual + ">");
+ }
+
+ static private void failNotSame(Object actual, Object expected, String message) {
+ String formatted = "";
+ if(message != null) {
+ formatted = message + " ";
+ }
+ fail(formatted + "expected same with:<" + expected + "> but was:<" + actual + ">");
+ }
+
+ static private void failNotEquals(Object actual , Object expected, String message ) {
+ fail(format(actual, expected, message));
+ }
+
+ static String format(Object actual, Object expected, String message) {
+ String formatted = "";
+ if (null != message) {
+ formatted = message + " ";
+ }
+
+ return formatted + "expected:<" + expected + "> but was:<" + actual + ">";
+ }
+
+ /**
+ * Asserts that two collections contain the same elements in the same order. If they do not,
+ * an AssertionError is thrown.
+ *
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(Collection actual, Collection expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two collections contain the same elements in the same order. If they do not,
+ * an AssertionError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(Collection actual, Collection expected, String message) {
+ if(actual == expected) return;
+
+ if (actual == null || expected == null) {
+ if (message != null) fail(message);
+ else fail("Collections not equal: expected: " + expected + " and actual: " + actual);
+ }
+
+ assertEquals(actual.size(), expected.size(), message + ": lists don't have the same size");
+
+ Iterator actIt = actual.iterator();
+ Iterator expIt = expected.iterator();
+ int i = -1;
+ while(actIt.hasNext() && expIt.hasNext()) {
+ i++;
+ Object e = expIt.next();
+ Object a = actIt.next();
+ String errorMessage = message == null
+ ? "Lists differ at element [" + i + "]: " + e + " != " + a
+ : message + ": Lists differ at element [" + i + "]: " + e + " != " + a;
+
+ assertEquals(a, e, errorMessage);
+ }
+ }
+
+ /**
+ * Asserts that two arrays contain the same elements in the same order. If they do not,
+ * an AssertionError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(Object[] actual, Object[] expected, String message) {
+ if(actual == expected) return;
+
+ if ((actual == null && expected != null) || (actual != null && expected == null)) {
+ if (message != null) fail(message);
+ else fail("Arrays not equal: " + Arrays.toString(expected) + " and " + Arrays.toString(actual));
+ }
+ assertEquals(Arrays.asList(actual), Arrays.asList(expected), message);
+ }
+
+ /**
+ * Asserts that two arrays contain the same elements in no particular order. If they do not,
+ * an AssertionError, with the given message, is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEqualsNoOrder(Object[] actual, Object[] expected, String message) {
+ if(actual == expected) return;
+
+ if ((actual == null && expected != null) || (actual != null && expected == null)) {
+ failAssertNoEqual(actual, expected,
+ "Arrays not equal: " + Arrays.toString(expected) + " and " + Arrays.toString(actual),
+ message);
+ }
+
+ if (actual.length != expected.length) {
+ failAssertNoEqual(actual, expected,
+ "Arrays do not have the same size:" + actual.length + " != " + expected.length,
+ message);
+ }
+
+ List actualCollection = Lists.newArrayList();
+ for (Object a : actual) {
+ actualCollection.add(a);
+ }
+ for (Object o : expected) {
+ actualCollection.remove(o);
+ }
+ if (actualCollection.size() != 0) {
+ failAssertNoEqual(actual, expected,
+ "Arrays not equal: " + Arrays.toString(expected) + " and " + Arrays.toString(actual),
+ message);
+ }
+ }
+
+ private static void failAssertNoEqual(Object[] actual, Object[] expected,
+ String message, String defaultMessage)
+ {
+ if (message != null) fail(message);
+ else fail(defaultMessage);
+ }
+
+ /**
+ * Asserts that two arrays contain the same elements in the same order. If they do not,
+ * an AssertionError is thrown.
+ *
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(Object[] actual, Object[] expected) {
+ assertEquals(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two arrays contain the same elements in no particular order. If they do not,
+ * an AssertionError is thrown.
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEqualsNoOrder(Object[] actual, Object[] expected) {
+ assertEqualsNoOrder(actual, expected, null);
+ }
+
+ /**
+ * Asserts that two arrays contain the same elements in the same order. If they do not,
+ * an AssertionError is thrown.
+ *
+ * @param actual the actual value
+ * @param expected the expected value
+ */
+ static public void assertEquals(final byte[] actual, final byte[] expected) {
+ assertEquals(actual, expected, "");
+ }
+
+ /**
+ * Asserts that two arrays contain the same elements in the same order. If they do not,
+ * an AssertionError, with the given message, is thrown.
+ *
+ * @param actual the actual value
+ * @param expected the expected value
+ * @param message the assertion error message
+ */
+ static public void assertEquals(final byte[] actual, final byte[] expected, final String message) {
+ if(expected == actual) {
+ return;
+ }
+ if(null == expected) {
+ fail("expected a null array, but not null found. " + message);
+ }
+ if(null == actual) {
+ fail("expected not null array, but null found. " + message);
+ }
+
+ assertEquals(actual.length, expected.length, "arrays don't have the same size. " + message);
+
+ for(int i= 0; i < expected.length; i++) {
+ if(expected[i] != actual[i]) {
+ fail("arrays differ firstly at element [" + i +"]; "
+ + "expected value is <" + expected[i] +"> but was <"
+ + actual[i] + ">. "
+ + message);
+ }
+ }
+ }
+
+ /**
+ * Asserts that two sets are equal.
+ */
+ static public void assertEquals(Set actual, Set expected) {
+ if(actual == expected) return;
+
+ if (actual == null || expected == null) {
+ fail("Sets not equal: expected: " + expected + " and actual: " + actual);
+ }
+
+ if (!actual.equals(expected)) {
+ fail("Sets differ: expected " + expected + " but got " + actual);
+ }
+ }
+
+ /**
+ * Asserts that two maps are equal.
+ */
+ static public void assertEquals(Map actual, Map expected) {
+ if(actual == expected) return;
+
+ if (actual == null || expected == null) {
+ fail("Maps not equal: expected: " + expected + " and actual: " + actual);
+ }
+
+ if (!actual.equals(expected)) {
+ fail("Maps differ: expected " + expected + " but got " + actual);
+ }
+ }
+
+}
diff --git a/samples/validationtck/src/org/testng/super/org/testng/IClass.java b/samples/validationtck/src/org/testng/super/org/testng/IClass.java
new file mode 100644
index 0000000..d957929
--- /dev/null
+++ b/samples/validationtck/src/org/testng/super/org/testng/IClass.java
@@ -0,0 +1,53 @@
+// Modified by Google
+// Removed xml classes
+package org.testng;
+
+import java.io.Serializable;
+
+
+/**
+ * <code>IClass</code> represents a test class and a collection of its instances.
+ *
+ * <p>
+ * Modified by Google
+ * <ul><li>Removed xml classes</li>
+ * </ul>
+ *
+ * @author <a href = "mailto:cedric@beust.com">Cedric Beust</a>
+ */
+public interface IClass extends Serializable {
+
+ /**
+ * @return this test class name. This is the name of the
+ * corresponding Java class.
+ */
+ String getName();
+
+ /**
+ * @return the <test> tag this class was found in.
+ */
+ Object getXmlTest();
+
+ /**
+ * @return the *lt;class> tag this class was found in.
+ */
+ Object getXmlClass();
+
+ /**
+ * If this class implements ITest, returns its test name, otherwise returns null.
+ */
+ String getTestName();
+
+ /**
+ * @return the Java class corresponding to this IClass.
+ */
+ Class getRealClass();
+
+ Object[] getInstances(boolean create);
+
+ int getInstanceCount();
+
+ long[] getInstanceHashCodes();
+
+ void addInstance(Object instance);
+}
diff --git a/samples/validationtck/src/org/testng/super/org/testng/ITestNGMethod.java b/samples/validationtck/src/org/testng/super/org/testng/ITestNGMethod.java
new file mode 100644
index 0000000..df2683b
--- /dev/null
+++ b/samples/validationtck/src/org/testng/super/org/testng/ITestNGMethod.java
@@ -0,0 +1,238 @@
+package org.testng;
+
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Describes a TestNG annotated method and the instance on which it will be invoked.
+ *
+ * This interface is not meant to be implemented by users.
+ *
+ * <p>
+ * Modified by Google
+ * <ul>
+ * <li>removed java.reflect.Method</li>
+ * </ul>
+ *
+ * @author Cedric Beust, May 3, 2004
+ */
+public interface ITestNGMethod extends Comparable, Serializable, Cloneable {
+
+ /**
+ * @return The real class on which this method was declared
+ * (can be different from getMethod().getDeclaringClass() if
+ * the test method was defined in a superclass).
+ */
+ Class getRealClass();
+
+ ITestClass getTestClass();
+
+ /**
+ * Sets the test class having this method. This is not necessarily the declaring class.
+ *
+ * @param cls The test class having this method.
+ */
+ void setTestClass(ITestClass cls);
+
+ /**
+ * Returns the corresponding Java test method.
+ * @return the corresponding Java test method.
+ */
+ Object getMethod();
+
+ /**
+ * Returns the method name. This is needed for serialization because
+ * methods are not Serializable.
+ * @return the method name.
+ */
+ String getMethodName();
+
+ /**
+ * @return All the instances the methods will be invoked upon.
+ * This will typically be an array of one object in the absence
+ * of an @Factory annotation.
+ */
+ Object[] getInstances();
+
+ /**
+ * Needed for serialization.
+ */
+ long[] getInstanceHashCodes();
+
+ /**
+ * @return The groups this method belongs to, possibly added to the groups
+ * declared on the class.
+ */
+ String[] getGroups();
+
+ /**
+ * @return The groups this method depends on, possibly added to the groups
+ * declared on the class.
+ */
+ String[] getGroupsDependedUpon();
+
+ /**
+ * If a group was not found.
+ */
+ String getMissingGroup();
+ public void setMissingGroup(String group);
+
+ /**
+ * Before and After groups
+ */
+ public String[] getBeforeGroups();
+ public String[] getAfterGroups();
+
+ /**
+ * @return The methods this method depends on, possibly added to the methods
+ * declared on the class.
+ */
+ String[] getMethodsDependedUpon();
+ void addMethodDependedUpon(String methodName);
+
+ /**
+ * @return true if this method was annotated with @Test
+ */
+ boolean isTest();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeTestMethod = true
+ */
+ boolean isBeforeMethodConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeTestMethod = false
+ */
+ boolean isAfterMethodConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeClassMethod = true
+ */
+ boolean isBeforeClassConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeClassMethod = false
+ */
+ boolean isAfterClassConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeSuite = true
+ */
+ boolean isBeforeSuiteConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and afterSuite = true
+ */
+ boolean isAfterSuiteConfiguration();
+
+ /**
+ * @return <tt>true</tt> if this method is a @BeforeTest (@Configuration beforeTest=true)
+ */
+ boolean isBeforeTestConfiguration();
+
+ /**
+ * @return <tt>true</tt> if this method is an @AfterTest (@Configuration afterTest=true)
+ */
+ boolean isAfterTestConfiguration();
+
+ boolean isBeforeGroupsConfiguration();
+
+ boolean isAfterGroupsConfiguration();
+
+ /**
+ * @return The timeout in milliseconds.
+ */
+ long getTimeOut();
+ void setTimeOut(long timeOut);
+
+ /**
+ * @return the number of times this method needs to be invoked.
+ */
+ int getInvocationCount();
+ void setInvocationCount(int count);
+
+ /**
+ * @return the success percentage for this method (between 0 and 100).
+ */
+ int getSuccessPercentage();
+
+ /**
+ * @return The id of the thread this method was run in.
+ */
+ String getId();
+
+ void setId(String id);
+
+ long getDate();
+
+ void setDate(long date);
+
+ /**
+ * Returns if this ITestNGMethod can be invoked from within IClass.
+ */
+ boolean canRunFromClass(IClass testClass);
+
+ /**
+ * @return true if this method is alwaysRun=true
+ */
+ boolean isAlwaysRun();
+
+ /**
+ * @return the number of threads to be used when invoking the method on parallel
+ */
+ int getThreadPoolSize();
+
+ void setThreadPoolSize(int threadPoolSize);
+
+ public String getDescription();
+
+ public void incrementCurrentInvocationCount();
+ public int getCurrentInvocationCount();
+ public void setParameterInvocationCount(int n);
+ public int getParameterInvocationCount();
+
+ public ITestNGMethod clone();
+
+ public IRetryAnalyzer getRetryAnalyzer();
+ public void setRetryAnalyzer(IRetryAnalyzer retryAnalyzer);
+
+ public boolean skipFailedInvocations();
+ public void setSkipFailedInvocations(boolean skip);
+
+ /**
+ * The time under which all invocationCount methods need to complete by.
+ */
+ public long getInvocationTimeOut();
+
+ public boolean ignoreMissingDependencies();
+ public void setIgnoreMissingDependencies(boolean ignore);
+
+ /**
+ * Which invocation numbers of this method should be used (only applicable
+ * if it uses a data provider). If this value is an empty list, use all the values
+ * returned from the data provider. These values are read from the XML file in
+ * the <include invocationNumbers="..."> tag.
+ */
+ public List<Integer> getInvocationNumbers();
+ public void setInvocationNumbers(List<Integer> numbers);
+
+ /**
+ * The list of invocation numbers that failed, which is only applicable for
+ * methods that have a data provider.
+ */
+ public void addFailedInvocationNumber(int number);
+ public List<Integer> getFailedInvocationNumbers();
+
+ /**
+ * The scheduling priority. Lower priorities get scheduled first.
+ */
+ public int getPriority();
+ public void setPriority(int priority);
+}
diff --git a/samples/validationtck/src/org/testng/super/org/testng/collections/Maps.java b/samples/validationtck/src/org/testng/super/org/testng/collections/Maps.java
new file mode 100644
index 0000000..778f637
--- /dev/null
+++ b/samples/validationtck/src/org/testng/super/org/testng/collections/Maps.java
@@ -0,0 +1,15 @@
+package org.testng.collections;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Maps {
+
+ public static <K, V> Map<K,V> newHashMap() {
+ return new HashMap<K, V>();
+ }
+
+ public static <K, V> Map<K,V> newHashtable() {
+ throw new RuntimeException("Hashtable are not supported in GWT");
+ }
+}
diff --git a/samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java b/samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java
new file mode 100644
index 0000000..219d95a
--- /dev/null
+++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/TckGwtSuite.java
@@ -0,0 +1,34 @@
+/*
+ * 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.junit.tools.GWTTestSuite;
+import com.google.gwt.sample.validationtck.constraints.application.ValidationRequirementTest;
+
+import junit.framework.Test;
+
+/**
+ * All Tck Tests
+ */
+public class TckGwtSuite {
+
+ public static Test suite() {
+ GWTTestSuite suite = new GWTTestSuite("TCK for GWT Validation");
+ 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/ValidationTckTest.gwt.xml
new file mode 100644
index 0000000..36b9a9e
--- /dev/null
+++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/ValidationTckTest.gwt.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.0.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.0.1/distro-source/core/src/gwt-module.dtd">
+<!--
+ 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.
+-->
+<module>
+ <inherits name="com.google.gwt.sample.validationtck.ValidationTck" />
+
+ <source path="">
+ <exclude name="super" />
+ </source>
+ <entry-point class="com.google.gwt.sample.validationtck.Tck" />
+</module>
\ No newline at end of file
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
new file mode 100644
index 0000000..ceb95d5
--- /dev/null
+++ b/samples/validationtck/test/com/google/gwt/sample/validationtck/constraints/application/ValidationRequirementTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.junit.client.GWTTestCase;
+
+/**
+ * Wraps
+ * {@link org.hibernate.jsr303.tck.tests.constraints.application.ValidationRequirementTest}
+ */
+public class ValidationRequirementTest extends GWTTestCase {
+ org.hibernate.jsr303.tck.tests.constraints.application.ValidationRequirementTest delegate =
+ new org.hibernate.jsr303.tck.tests.constraints.application.ValidationRequirementTest();
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.sample.validationtck.ValidationTckTest";
+ }
+
+ public void testClassLevelConstraints() {
+ delegate.testClassLevelConstraints();
+ }
+
+ public void testConstraintAppliedOnFieldAndProperty() {
+ delegate.testConstraintAppliedOnFieldAndProperty();
+ }
+
+ public void testFieldAccess() {
+ delegate.testFieldAccess();
+ }
+
+ public void testFieldAndPropertyVisibilityIsNotConstrained() {
+ delegate.testFieldAndPropertyVisibilityIsNotConstrained();
+ }
+
+ public void testIgnoreStaticFieldsAndProperties() {
+ delegate.testIgnoreStaticFieldsAndProperties();
+ }
+
+ public void testPropertyAccess() {
+ delegate.testPropertyAccess();
+ }
+}
diff --git a/user/src/com/google/gwt/validation/rebind/BeanHelper.java b/user/src/com/google/gwt/validation/rebind/BeanHelper.java
index fc1aae0..cf0d2d4 100644
--- a/user/src/com/google/gwt/validation/rebind/BeanHelper.java
+++ b/user/src/com/google/gwt/validation/rebind/BeanHelper.java
@@ -26,8 +26,8 @@
final class BeanHelper {
private final BeanDescriptor beanDescriptor;
- private final JClassType jClass;
+ private final JClassType jClass;
public BeanHelper(JClassType jClass,
BeanDescriptor beanDescriptor) {
super();
@@ -52,7 +52,7 @@
}
public String getFullyQualifiedValidatorName() {
- return jClass.getQualifiedSourceName() + "Validator";
+ return getPackage() + "." + getValidatorName();
}
public String getPackage() {
@@ -64,15 +64,20 @@
}
public String getValidatorInstanceName() {
- return jClass.getName().toLowerCase() + "Validator";
+ return makeJavaSafe(jClass.getName().toLowerCase() + "Validator");
}
public String getValidatorName() {
- return jClass.getName() + "Validator";
+ return makeJavaSafe(jClass.getName() + "Validator");
}
@Override
public String toString() {
return getTypeCanonicalName();
}
+
+ private String makeJavaSafe(String in) {
+ return in.replaceAll("\\.", "_");
+ }
+
}
diff --git a/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java b/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
index f6a7500..7100a81 100644
--- a/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
+++ b/user/src/com/google/gwt/validation/rebind/GwtSpecificValidatorCreator.java
@@ -56,22 +56,22 @@
/**
* Returns the literal value of an object that is suitable for inclusion in
- * Java Source code.
- *
+ * Java Source code.
+ *
* <p>
* Supports all types that {@link Annotation) value can have.
- *
- *
+ *
+ *
* @throws IllegalArgumentException if the type of the object does not have a java literal form.
*/
public static String asLiteral(Object value) throws IllegalArgumentException {
Class<?> clazz = value.getClass();
JProgram jProgram = new JProgram();
-
+
if (clazz.isArray()) {
StringBuilder sb = new StringBuilder();
Object[] array = (Object[]) value;
-
+
sb.append("new " + clazz.getComponentType().getCanonicalName() + "[] ");
sb.append("{");
boolean first = true;
@@ -96,6 +96,9 @@
if (value instanceof Integer) {
return jProgram.getLiteralInt(((Integer) value).intValue()).toSource();
}
+ if (value instanceof Long) {
+ return jProgram.getLiteralLong(((Long) value).intValue()).toSource();
+ }
if (value instanceof String) {
return '"' + ((String) value).toString().replace("\"", "\\\"") + '"';
}
@@ -243,10 +246,10 @@
// .setConstraintValidatorClasses(classes )
sw.print(".setConstraintValidatorClasses(");
- sw.print(asLiteral(asArray(constraint.getConstraintValidatorClasses(),
+ sw.print(asLiteral(asArray(constraint.getConstraintValidatorClasses(),
new Class[0])));
sw.println(")");
-
+
// .getGroups(groups)
sw.print(".setGroups(");
Set<Class<?>> groups = constraint.getGroups();