Add bootstrap tests 159 of 257 (61.87%) Pass with 32 Failures and 7 Errors. Review at http://gwt-code-reviews.appspot.com/1526804 Review by: rchandia@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10559 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/test-super/org/hibernate/jsr303/tck/super/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorTest.java b/user/test-super/org/hibernate/jsr303/tck/super/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorTest.java new file mode 100644 index 0000000..260b5b5 --- /dev/null +++ b/user/test-super/org/hibernate/jsr303/tck/super/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorTest.java
@@ -0,0 +1,134 @@ +// $Id: CustomMessageInterpolatorTest.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.tests.bootstrap; + +import com.google.gwt.i18n.shared.GwtLocale; + +import java.util.Set; +import javax.validation.Configuration; +import javax.validation.ConstraintViolation; +import javax.validation.MessageInterpolator; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import javax.validation.constraints.Digits; +import javax.validation.constraints.NotNull; + +import org.jboss.test.audit.annotations.SpecAssertion; +import org.jboss.test.audit.annotations.SpecAssertions; +import org.jboss.testharness.AbstractTest; +import org.jboss.testharness.impl.packaging.Artifact; +import org.jboss.testharness.impl.packaging.ArtifactType; +import org.jboss.testharness.impl.packaging.Classes; +import static org.testng.Assert.assertFalse; +import org.testng.annotations.Test; + +import org.hibernate.jsr303.tck.util.TestUtil; +import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessages; +import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations; + +/** + * @author Hardy Ferentschik + */ +@Artifact(artifactType = ArtifactType.JSR303) +@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) +public class CustomMessageInterpolatorTest extends AbstractTest { + + @Test + @SpecAssertion(section = "4.3.2", id = "b") + public void testCustomMessageInterpolatorViaConfiguration() { + Configuration config = Validation.byDefaultProvider().configure(); + config = config.messageInterpolator( new DummyMessageInterpolator() ); + Validator validator = config.buildValidatorFactory().getValidator(); + + assertCustomMessageInterpolatorUsed( validator ); + } + + @Test + @SpecAssertions({ + @SpecAssertion(section = "4.4.2", id = "a"), + @SpecAssertion(section = "4.4.2", id = "b"), + @SpecAssertion(section = "4.3.2", id = "b") + }) + public void testCustomMessageInterpolatorViaValidatorContext() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + DummyMessageInterpolator dummyMessageInterpolator = new DummyMessageInterpolator(); + Validator validator = factory.usingContext().messageInterpolator( dummyMessageInterpolator ).getValidator(); + assertCustomMessageInterpolatorUsed( validator ); + assertFalse( + factory.getMessageInterpolator().equals( dummyMessageInterpolator ), + "getMessageInterpolator() should return the default message interpolator." + ); + } + + private void assertCustomMessageInterpolatorUsed(Validator validator) { + Person person = new Person(); + person.setFirstName( "John" ); + person.setPersonalNumber( 1234567890l ); + + Set<ConstraintViolation<Person>> constraintViolations = validator.validate( person ); + assertCorrectNumberOfViolations( constraintViolations, 1 ); + assertCorrectConstraintViolationMessages( constraintViolations, "my custom message" ); + } + + private static class DummyMessageInterpolator implements MessageInterpolator { + public String interpolate(String message, Context context) { + return "my custom message"; + } + + public String interpolate(String message, Context context, GwtLocale locale) { + throw new UnsupportedOperationException( "No specific locale is possible" ); + } + } + + public class Person { + @NotNull + private String firstName; + + @NotNull + private String lastName; + + @Digits(integer = 10, fraction = 0) + private long personalNumber; + + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public long getPersonalNumber() { + return personalNumber; + } + + public void setPersonalNumber(long personalNumber) { + this.personalNumber = personalNumber; + } + } +}
diff --git a/user/test/com/google/gwt/validation/tck/BootstrapGwtSuite.java b/user/test/com/google/gwt/validation/tck/BootstrapGwtSuite.java new file mode 100644 index 0000000..d7262cc --- /dev/null +++ b/user/test/com/google/gwt/validation/tck/BootstrapGwtSuite.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.validation.tck; + +import junit.framework.Test; + +import org.hibernate.jsr303.tck.tests.bootstrap.ConfigurationGwtTest; +import org.hibernate.jsr303.tck.tests.bootstrap.CustomMessageInterpolatorGwtTest; +import org.hibernate.jsr303.tck.tests.bootstrap.ValidationProviderGwtTest; +import org.hibernate.jsr303.tck.tests.bootstrap.ValidationProviderResolverGwtTest; +import org.hibernate.jsr303.tck.util.TckTestSuiteWrapper; + +/** + * Tck Tests for the {@code bootstrap} package. + */ +public class BootstrapGwtSuite { + public static Test suite() { + TckTestSuiteWrapper suite = new TckTestSuiteWrapper( + "TCK for GWT Validation, constraints bootstrap package"); + suite.addTestSuite(ConfigurationGwtTest.class); + suite.addTestSuite(CustomMessageInterpolatorGwtTest.class); + suite.addTestSuite(ValidationProviderGwtTest.class); + suite.addTestSuite(ValidationProviderResolverGwtTest.class); + return suite; + } +}
diff --git a/user/test/org/hibernate/jsr303/tck/tests/bootstrap/ConfigurationGwtTest.java b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/ConfigurationGwtTest.java new file mode 100644 index 0000000..504e2da --- /dev/null +++ b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/ConfigurationGwtTest.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 org.hibernate.jsr303.tck.tests.bootstrap; + +import com.google.gwt.junit.client.GWTTestCase; + +import org.hibernate.jsr303.tck.util.client.Failing; +import org.hibernate.jsr303.tck.util.client.NonTckTest; + +/** + * Wraps {@link ConfigurationTest} . + */ +public class ConfigurationGwtTest extends GWTTestCase { + + @Override + public String getModuleName() { + return "org.hibernate.jsr303.tck.tests.bootstrap.TckTest"; + } + + @Failing(issue = 6663) + public void testProviderUnderTestDefinesSubInterfaceOfConfiguration() { + fail("TODO(nchalko) figure out how to test this in GWT"); + } + + @NonTckTest + public void testThereMustBeOnePassingTest() { + } +}
diff --git a/user/test/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorGwtTest.java b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorGwtTest.java new file mode 100644 index 0000000..949bc13 --- /dev/null +++ b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorGwtTest.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 org.hibernate.jsr303.tck.tests.bootstrap; + +import com.google.gwt.junit.client.GWTTestCase; + +import org.hibernate.jsr303.tck.util.client.Failing; + +/** + * Wraps {@link CustomMessageInterpolatorTest} . + */ +public class CustomMessageInterpolatorGwtTest extends GWTTestCase { + CustomMessageInterpolatorTest delegate = new CustomMessageInterpolatorTest(); + + @Override + public String getModuleName() { + return "org.hibernate.jsr303.tck.tests.bootstrap.TckTest"; + } + + @Failing(issue = 6663) + public void testCustomMessageInterpolatorViaConfiguration() { + delegate.testCustomMessageInterpolatorViaConfiguration(); + } + + public void testCustomMessageInterpolatorViaValidatorContext() { + delegate.testCustomMessageInterpolatorViaValidatorContext(); + } +}
diff --git a/user/test/org/hibernate/jsr303/tck/tests/bootstrap/TckTest.gwt.xml b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/TckTest.gwt.xml new file mode 100644 index 0000000..5e69439 --- /dev/null +++ b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/TckTest.gwt.xml
@@ -0,0 +1,26 @@ +<?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="org.hibernate.jsr303.tck.tests.ValidationTck" /> + <source path=""> + <include name="*.java" /> + </source> + <replace-with class="org.hibernate.jsr303.tck.tests.bootstrap.TckTestValidatorFactory"> + <when-type-is class="javax.validation.ValidatorFactory"/> + </replace-with> +</module> \ No newline at end of file
diff --git a/user/test/org/hibernate/jsr303/tck/tests/bootstrap/TckTestValidatorFactory.java b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/TckTestValidatorFactory.java new file mode 100644 index 0000000..d173ee3 --- /dev/null +++ b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/TckTestValidatorFactory.java
@@ -0,0 +1,43 @@ +/* + * 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 org.hibernate.jsr303.tck.tests.bootstrap; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.validation.client.AbstractGwtValidatorFactory; +import com.google.gwt.validation.client.GwtValidation; +import com.google.gwt.validation.client.impl.AbstractGwtValidator; + +import org.hibernate.jsr303.tck.tests.bootstrap.CustomMessageInterpolatorTest.Person; + +import javax.validation.Validator; + +/** + * {@link AbstractGwtValidatorFactory} implementation that uses + * {@link com.google.gwt.validation.client.GwtValidation GwtValidation}. + */ +public final class TckTestValidatorFactory extends AbstractGwtValidatorFactory { + /** + * Marker Interface for {@link GWT#create(Class)}. + */ + @GwtValidation(value = {Person.class}) + public static interface GwtValidator extends Validator { + } + + @Override + public AbstractGwtValidator createValidator() { + return GWT.create(GwtValidator.class); + } +}
diff --git a/user/test/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderGwtTest.java b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderGwtTest.java new file mode 100644 index 0000000..d2771f5 --- /dev/null +++ b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderGwtTest.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 org.hibernate.jsr303.tck.tests.bootstrap; + +import com.google.gwt.junit.client.GWTTestCase; + +import org.hibernate.jsr303.tck.util.client.Failing; +import org.hibernate.jsr303.tck.util.client.NonTckTest; + +/** + * Wraps {@link ValidationProviderTest} . + */ +public class ValidationProviderGwtTest extends GWTTestCase { + + @Override + public String getModuleName() { + return "org.hibernate.jsr303.tck.tests.bootstrap.TckTest"; + } + + @Failing(issue = 6663) + public void testByDefaultProviderUsesTheFirstProviderReturnedByValidationProviderResolver() { + fail("TODO(nchalko) figure out how to test this in GWT"); + } + + @Failing(issue = 6663) + public void testFirstMatchingValidationProviderResolverIsReturned() { + fail("TODO(nchalko) figure out how to test this in GWT"); + } + + @NonTckTest + public void testThereMustBeOnePassingTest(){} + + @Failing(issue = 6663) + public void testValidationExceptionIsThrownInCaseValidatorFactoryCreationFails() { + fail("TODO(nchalko) figure out how to test this in GWT"); + } + + @Failing(issue = 6663) + public void testValidationProviderContainsNoArgConstructor() { + fail("TODO(nchalko) figure out how to test this in GWT"); + } +}
diff --git a/user/test/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderResolverGwtTest.java b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderResolverGwtTest.java new file mode 100644 index 0000000..a399f41 --- /dev/null +++ b/user/test/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderResolverGwtTest.java
@@ -0,0 +1,40 @@ +/* + * 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 org.hibernate.jsr303.tck.tests.bootstrap; + +import com.google.gwt.junit.client.GWTTestCase; + +import org.hibernate.jsr303.tck.util.client.Failing; +import org.hibernate.jsr303.tck.util.client.NonTckTest; + +/** + * Wraps {@link ValidationProviderResolverTest} . + */ +public class ValidationProviderResolverGwtTest extends GWTTestCase { + + @Override + public String getModuleName() { + return "org.hibernate.jsr303.tck.tests.bootstrap.TckTest"; + } + + @Failing(issue = 6663) + public void testServiceFileExists() { + fail("TODO(nchalko) figure out how to test this in GWT"); + } + + @NonTckTest + public void testThereMustBeOnePassingTest(){} +}