Author: hardy.ferentschik
Date: 2009-08-18 05:35:56 -0400 (Tue, 18 Aug 2009)
New Revision: 17345
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ConfigurationTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderResolverTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInServiceFileTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInValidationXmlTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapUnknownCustomProviderTest.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/validation-BootstrapCustomProviderDefinedInValidationXmlTest.xml
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/validation-BootstrapUnknownCustomProviderTest.xml
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ValidationProviderResolverTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/Person.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml
Modified:
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
Completed and refactored bootstrapping tests
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ConfigurationTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ConfigurationTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ConfigurationTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -0,0 +1,61 @@
+// $Id: ValidationProviderResolverTest.java 17333 2009-08-17 13:43:03Z hardy.ferentschik
$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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 java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import javax.validation.Configuration;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+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.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({
+ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class
+})
+public class ConfigurationTest extends AbstractTest {
+
+ @Test
+ @SpecAssertion(section = "4.4.3", id = "a")
+ public void testProviderUnderTestDefinesSubInterfaceOfConfiguration() {
+ boolean foundSubinterfaceOfConfiguration = false;
+ Type[] types =
TestUtil.getValidationProviderUnderTest().getClass().getGenericInterfaces();
+ for ( Type type : types ) {
+ if ( type instanceof ParameterizedType ) {
+ ParameterizedType paramType = ( ParameterizedType ) type;
+ Type[] typeArguments = paramType.getActualTypeArguments();
+ for ( Type typeArgument : typeArguments ) {
+ if ( typeArgument instanceof Class && Configuration.class.isAssignableFrom(
( Class ) typeArgument ) ) {
+ foundSubinterfaceOfConfiguration = true;
+ }
+ }
+ }
+ }
+ assertTrue( foundSubinterfaceOfConfiguration, "Could not find subinterface of
Configuration" );
+ }
+}
\ No newline at end of file
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorTest.java
(from rev 17334,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -0,0 +1,133 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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 java.util.Locale;
+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, Locale 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;
+ }
+ }
+}
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/CustomMessageInterpolatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderResolverTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderResolverTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderResolverTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -0,0 +1,133 @@
+// $Id: BootstrapTest.java 17334 2009-08-17 14:28:29Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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 java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import javax.validation.Configuration;
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.ValidationProvider;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+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.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.common.TCKValidationProvider;
+import org.hibernate.jsr303.tck.common.TCKValidatorConfiguration;
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({
+ TestUtil.class,
+ TestUtil.PathImpl.class,
+ TestUtil.NodeImpl.class,
+ TCKValidationProvider.class,
+ TCKValidatorConfiguration.class,
+ TCKValidationProvider.DummyValidatorFactory.class
+})
+public class ValidationProviderResolverTest extends AbstractTest {
+ private static final String SERVICES_FILE = "META-INF/services/" +
ValidationProvider.class.getName();
+
+ @Test
+ @SpecAssertion(section = "4.4.4.1", id = "c")
+ public void testServiceFileExists() {
+ List<Class<?>> providers = readBeanValidationServiceFile();
+ assertTrue( !providers.isEmpty(), "There should be at least one provider" );
+
+ assertTrue(
+ providers.contains( TestUtil.getValidationProviderUnderTest().getClass() ),
+ "The validation class of the provider under test has to be in the list."
+ );
+ }
+
+ private List<Class<?>> readBeanValidationServiceFile() {
+ ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+ if ( classloader == null ) {
+ classloader = ValidationProviderResolverTest.class.getClassLoader();
+ }
+ List<Class<?>> providers = new ArrayList<Class<?>>();
+ try {
+
+ Enumeration<URL> providerDefinitions = classloader.getResources( SERVICES_FILE
);
+ while ( providerDefinitions.hasMoreElements() ) {
+ URL url = providerDefinitions.nextElement();
+ addProviderToList( providers, url );
+ }
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to load service file", e );
+ }
+ return providers;
+ }
+
+ private void addProviderToList(List<Class<?>> providers, URL url)
+ throws IOException, ClassNotFoundException, InstantiationException,
IllegalAccessException {
+ InputStream stream = url.openStream();
+ try {
+ BufferedReader reader = new BufferedReader( new InputStreamReader( stream ), 100 );
+ String name = reader.readLine();
+ while ( name != null ) {
+ name = name.trim();
+ if ( !name.startsWith( "#" ) ) {
+ final Class<?> providerClass = loadClass(
+ name,
+ ValidationProviderResolverTest.class
+ );
+
+ providers.add( providerClass );
+ }
+ name = reader.readLine();
+ }
+ }
+ finally {
+ stream.close();
+ }
+ }
+
+ private static Class<?> loadClass(String name, Class caller) throws
ClassNotFoundException {
+ try {
+ //try context classloader, if fails try caller classloader
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if ( loader != null ) {
+ return loader.loadClass( name );
+ }
+ }
+ catch ( ClassNotFoundException e ) {
+ //trying caller classloader
+ if ( caller == null ) {
+ throw e;
+ }
+ }
+ return Class.forName( name, true, caller.getClassLoader() );
+ }
+}
\ No newline at end of file
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderTest.java
(from rev 17333,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ValidationProviderResolverTest.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -0,0 +1,126 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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 java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+import javax.validation.Configuration;
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import javax.validation.ValidationProviderResolver;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.ValidationProvider;
+
+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.assertTrue;
+import static org.testng.FileAssert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.common.TCKValidationProvider;
+import org.hibernate.jsr303.tck.common.TCKValidatorConfiguration;
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({
+ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class,
TCKValidationProvider.class,
+ TCKValidationProvider.DummyValidatorFactory.class, TCKValidatorConfiguration.class
+})
+public class ValidationProviderTest extends AbstractTest {
+
+ @Test
+ @SpecAssertion(section = "4.4.4.2", id = "b")
+ public void testFirstMatchingValidationProviderResolverIsReturned() {
+ ValidationProviderResolver resolver = new ValidationProviderResolver() {
+
+ public List<ValidationProvider<?>> getValidationProviders() {
+ List<ValidationProvider<?>> list = new
ArrayList<ValidationProvider<?>>();
+ list.add( TestUtil.getValidationProviderUnderTest() );
+ list.add( new TCKValidationProvider() );
+ return list;
+ }
+ };
+
+ Configuration<?> configuration = Validation
+ .byProvider( TCKValidationProvider.class )
+ .providerResolver( resolver )
+ .configure();
+
+ ValidatorFactory factory = configuration.buildValidatorFactory();
+ assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
+ }
+
+ @Test
+ @SpecAssertion(section = "4.4.4.2", id = "c")
+ public void
testByDefaultProviderUsesTheFirstProviderReturnedByValidationProviderResolver() {
+ ValidationProviderResolver resolver = new ValidationProviderResolver() {
+
+ public List<ValidationProvider<?>> getValidationProviders() {
+ List<ValidationProvider<?>> list = new
ArrayList<ValidationProvider<?>>();
+ list.add( new TCKValidationProvider() );
+ list.add( TestUtil.getValidationProviderUnderTest() );
+ return list;
+ }
+ };
+
+ Configuration<?> configuration = Validation
+ .byDefaultProvider()
+ .providerResolver( resolver )
+ .configure();
+ ValidatorFactory factory = configuration.buildValidatorFactory();
+ assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
+ }
+
+ @Test
+ @SpecAssertion(section = "4.4.4.2", id = "d")
+ public void testValidationProviderContainsNoArgConstructor() {
+ ValidationProvider<?> validationProviderUnderTest =
TestUtil.getValidationProviderUnderTest();
+ try {
+ Constructor<?> constructor =
validationProviderUnderTest.getClass().getConstructor();
+ assertTrue( Modifier.isPublic( constructor.getModifiers() ) );
+ }
+ catch ( Exception e ) {
+ fail( "The validation provider must have a public no arg constructor" );
+ }
+ }
+
+ @Test(expectedExceptions = ValidationException.class)
+ @SpecAssertions({
+ @SpecAssertion(section = "4.4.5", id = "f"),
+ @SpecAssertion(section = "4.4.4.2", id = "e")
+ })
+ public void testValidationExceptionIsThrownInCaseValidatorFactoryCreationFails() {
+ ValidationProviderResolver resolver = new ValidationProviderResolver() {
+
+ public List<ValidationProvider<?>> getValidationProviders() {
+ throw new RuntimeException( "ValidationProviderResolver failed!" );
+ }
+ };
+
+ Validation.byDefaultProvider().providerResolver( resolver ).configure();
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/ValidationProviderTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInServiceFileTest.java
(from rev 17333,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInServiceFileTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInServiceFileTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -0,0 +1,85 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.customprovider;
+
+import javax.validation.Configuration;
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+
+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 org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Resource;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.common.TCKValidationProvider;
+import org.hibernate.jsr303.tck.common.TCKValidatorConfiguration;
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({
+ TestUtil.class,
+ TestUtil.PathImpl.class,
+ TestUtil.NodeImpl.class,
+ TCKValidationProvider.class,
+ TCKValidatorConfiguration.class,
+ TCKValidationProvider.DummyValidatorFactory.class
+})
+@Resource(source = "javax.validation.spi.ValidationProvider",
+ destination =
"WEB-INF/classes/META-INF/services/javax.validation.spi.ValidationProvider")
+@IntegrationTest
+public class BootstrapCustomProviderDefinedInServiceFileTest extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.4", id = "a"),
+ @SpecAssertion(section = "4.4.4.2", id = "a")
+ })
+ public void testGetFactoryByProviderSpecifiedProgrammatically() {
+ TCKValidatorConfiguration configuration = Validation.byProvider(
TCKValidationProvider.class ).configure();
+ ValidatorFactory factory = configuration.buildValidatorFactory();
+ assertNotNull( factory );
+ assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
+ }
+
+ @Test
+ @SpecAssertion(section = "4.4.4.1", id = "a")
+ public void testProviderResolverReturnsListOfAvailableProviders() {
+
+ // really an indirect test since there is no way to get hold of the default provider
resolver.
+ // we just confirm that the provider under test and the TCKValidationProvider are
loadable.
+
+ TCKValidatorConfiguration configuration = Validation.byProvider(
TCKValidationProvider.class ).configure();
+ ValidatorFactory factory = configuration.buildValidatorFactory();
+ assertNotNull( factory );
+
+ Configuration<?> config = Validation.byProvider(
TestUtil.getValidationProviderUnderTest().getClass() )
+ .configure();
+ factory = config.buildValidatorFactory();
+ assertNotNull( factory );
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInServiceFileTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInValidationXmlTest.java
(from rev 17333,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInValidationXmlTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInValidationXmlTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -0,0 +1,83 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.customprovider;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.validation.Validation;
+import javax.validation.ValidationProviderResolver;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.ValidationProvider;
+
+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 org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.common.TCKValidationProvider;
+import org.hibernate.jsr303.tck.common.TCKValidatorConfiguration;
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({
+ TestUtil.class,
+ TCKValidationProvider.class,
+ TCKValidatorConfiguration.class,
+ TCKValidationProvider.DummyValidatorFactory.class
+})
+@ValidationXml("validation-BootstrapCustomProviderDefinedInValidationXmlTest.xml")
+public class BootstrapCustomProviderDefinedInValidationXmlTest extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.4", id = "a"),
+ @SpecAssertion(section = "4.4.4.2", id = "a")
+ })
+ public void testGetFactoryByProviderSpecifiedInValidationXml() {
+
+ ValidationProviderResolver resolver = new ValidationProviderResolver() {
+
+ public List<ValidationProvider<?>> getValidationProviders() {
+ List<ValidationProvider<?>> list = new
ArrayList<ValidationProvider<?>>();
+ list.add( TestUtil.getValidationProviderUnderTest() );
+ list.add( new TCKValidationProvider() );
+ return list;
+ }
+ };
+
+ ValidatorFactory factory = Validation.byDefaultProvider()
+ .providerResolver( resolver )
+ .configure()
+ .buildValidatorFactory();
+ assertNotNull( factory );
+ assertTrue(
+ factory instanceof TCKValidationProvider.DummyValidatorFactory,
+ "Since TCKValidationProvider is configured in validation.xml it should be the
bootstrapped provider " +
+ "even though the provider under test is first in the list of providers in the
resolver."
+ );
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapCustomProviderDefinedInValidationXmlTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapUnknownCustomProviderTest.java
(from rev 17330,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/validationxml/ValidationXmlBootstrapTest.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapUnknownCustomProviderTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapUnknownCustomProviderTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -0,0 +1,49 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, 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.customprovider;
+
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+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.jsr303.ValidationXml;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@ValidationXml(value = "validation-BootstrapUnknownCustomProviderTest.xml")
+public class BootstrapUnknownCustomProviderTest extends AbstractTest {
+
+ @Test
+ @SpecAssertion(section = "8", id = "a")
+ public void testWrongProviderConfiguredInValidationXml() {
+ try {
+ Validation.buildDefaultValidatorFactory();
+ fail( "validation.xml contains a invalid provider.
Validation.buildDefaultValidatorFactory() should have failed." );
+ }
+ catch ( ValidationException e ) {
+ // success
+ }
+ }
+}
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/BootstrapUnknownCustomProviderTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java 2009-08-17
22:27:23 UTC (rev 17344)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -1,67 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, 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.customprovider;
-
-import javax.validation.Validation;
-import javax.validation.ValidatorFactory;
-
-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 org.jboss.testharness.impl.packaging.IntegrationTest;
-import org.jboss.testharness.impl.packaging.Resource;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import org.testng.annotations.Test;
-
-import org.hibernate.jsr303.tck.common.TCKValidationProvider;
-import org.hibernate.jsr303.tck.common.TCKValidatorConfiguration;
-import org.hibernate.jsr303.tck.util.TestUtil;
-
-/**
- * @author Hardy Ferentschik
- */
-@Artifact(artifactType = ArtifactType.JSR303)
-@Classes({
- TestUtil.class,
- TestUtil.PathImpl.class,
- TestUtil.NodeImpl.class,
- TCKValidationProvider.class,
- TCKValidatorConfiguration.class,
- TCKValidationProvider.DummyValidatorFactory.class
-})
-@Resource(source = "javax.validation.spi.ValidationProvider",
- destination =
"WEB-INF/classes/META-INF/services/javax.validation.spi.ValidationProvider")
-@IntegrationTest
-public class ExplicitCustomProviderBootstrapTest extends AbstractTest {
-
- @Test
- @SpecAssertions({
- @SpecAssertion(section = "4.4", id = "a"),
- @SpecAssertion(section = "4.4.4.2", id = "a")
- })
- public void testGetFactoryByProviderSpecifiedProgrammatically() {
- TCKValidatorConfiguration configuration = Validation.byProvider(
TCKValidationProvider.class ).configure();
- ValidatorFactory factory = configuration.buildValidatorFactory();
- assertNotNull( factory );
- assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
- }
-}
\ No newline at end of file
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ValidationProviderResolverTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ValidationProviderResolverTest.java 2009-08-17
22:27:23 UTC (rev 17344)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ValidationProviderResolverTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -1,126 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, 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.customprovider;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-import javax.validation.Configuration;
-import javax.validation.Validation;
-import javax.validation.ValidationException;
-import javax.validation.ValidationProviderResolver;
-import javax.validation.ValidatorFactory;
-import javax.validation.spi.ValidationProvider;
-
-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.assertTrue;
-import static org.testng.FileAssert.fail;
-import org.testng.annotations.Test;
-
-import org.hibernate.jsr303.tck.common.TCKValidationProvider;
-import org.hibernate.jsr303.tck.common.TCKValidatorConfiguration;
-import org.hibernate.jsr303.tck.util.TestUtil;
-
-/**
- * @author Hardy Ferentschik
- */
-@Artifact(artifactType = ArtifactType.JSR303)
-@Classes({
- TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class,
TCKValidationProvider.class,
- TCKValidationProvider.DummyValidatorFactory.class, TCKValidatorConfiguration.class
-})
-public class ValidationProviderResolverTest extends AbstractTest {
-
- @Test
- @SpecAssertion(section = "4.4.4.2", id = "b")
- public void testFirstMatchingValidationProviderResolverIsReturned() {
- ValidationProviderResolver resolver = new ValidationProviderResolver() {
-
- public List<ValidationProvider<?>> getValidationProviders() {
- List<ValidationProvider<?>> list = new
ArrayList<ValidationProvider<?>>();
- list.add( TestUtil.getValidationProviderUnderTest() );
- list.add( new TCKValidationProvider() );
- return list;
- }
- };
-
- Configuration<?> configuration = Validation
- .byProvider( TCKValidationProvider.class )
- .providerResolver( resolver )
- .configure();
-
- ValidatorFactory factory = configuration.buildValidatorFactory();
- assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
- }
-
- @Test
- @SpecAssertion(section = "4.4.4.2", id = "c")
- public void
testByDefaultProviderUsesTheFirstProviderReturnedByValidationProviderResolver() {
- ValidationProviderResolver resolver = new ValidationProviderResolver() {
-
- public List<ValidationProvider<?>> getValidationProviders() {
- List<ValidationProvider<?>> list = new
ArrayList<ValidationProvider<?>>();
- list.add( new TCKValidationProvider() );
- list.add( TestUtil.getValidationProviderUnderTest() );
- return list;
- }
- };
-
- Configuration<?> configuration = Validation
- .byDefaultProvider()
- .providerResolver( resolver )
- .configure();
- ValidatorFactory factory = configuration.buildValidatorFactory();
- assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
- }
-
- @Test
- @SpecAssertion(section = "4.4.4.2", id = "d")
- public void testValidationProviderContainsNoArgConstructor() {
- ValidationProvider<?> validationProviderUnderTest =
TestUtil.getValidationProviderUnderTest();
- try {
- Constructor<?> constructor =
validationProviderUnderTest.getClass().getConstructor();
- assertTrue( Modifier.isPublic( constructor.getModifiers() ) );
- }
- catch ( Exception e ) {
- fail( "The validation provider must have a public no arg constructor" );
- }
- }
-
- @Test(expectedExceptions = ValidationException.class)
- @SpecAssertions({
- @SpecAssertion(section = "4.4.5", id = "f"),
- @SpecAssertion(section = "4.4.4.2", id = "e")
- })
- public void testValidationExceptionIsThrownInCaseValidatorFactoryCreationFails() {
- ValidationProviderResolver resolver = new ValidationProviderResolver() {
-
- public List<ValidationProvider<?>> getValidationProviders() {
- throw new RuntimeException( "ValidationProviderResolver failed!" );
- }
- };
-
- Validation.byDefaultProvider().providerResolver( resolver ).configure();
- }
-}
\ No newline at end of file
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java 2009-08-17
22:27:23 UTC (rev 17344)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -1,66 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, 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.customprovider.xmldefined;
-
-import javax.validation.Validation;
-import javax.validation.ValidatorFactory;
-
-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 org.jboss.testharness.impl.packaging.IntegrationTest;
-import org.jboss.testharness.impl.packaging.Resource;
-import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import org.testng.annotations.Test;
-
-import org.hibernate.jsr303.tck.common.TCKValidationProvider;
-import org.hibernate.jsr303.tck.common.TCKValidatorConfiguration;
-import org.hibernate.jsr303.tck.util.TestUtil;
-
-/**
- * @author Hardy Ferentschik
- */
-@Artifact(artifactType = ArtifactType.JSR303)
-@Classes({
- TestUtil.class,
- TCKValidationProvider.class,
- TCKValidatorConfiguration.class,
- TCKValidationProvider.DummyValidatorFactory.class
-})
-@Resource(source =
"/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider",
- destination =
"WEB-INF/classes/META-INF/services/javax.validation.spi.ValidationProvider")
-(a)ValidationXml("validation.xml")
-@IntegrationTest
-public class CustomProviderInXmlBootstrapTest extends AbstractTest {
-
- @Test
- @SpecAssertions({
- @SpecAssertion(section = "4.4", id = "a"),
- @SpecAssertion(section = "4.4.4.2", id = "a")
- })
- public void testGetFactoryByProviderSpecifiedInXml() {
- ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
- assertNotNull( factory );
- assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
- }
-}
\ No newline at end of file
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-08-17
22:27:23 UTC (rev 17344)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -1,179 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, 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.defaultprovider;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Locale;
-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.spi.ValidationProvider;
-
-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 static org.testng.Assert.assertTrue;
-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 BootstrapTest extends AbstractTest {
- private static final String SERVICES_FILE = "META-INF/services/" +
ValidationProvider.class.getName();
-
- @Test
- @SpecAssertion(section = "4.4.4.1", id = "c")
- public void testServiceFileExists() {
- List<Class<?>> providers = readBeanValidationServiceFile();
- assertTrue( !providers.isEmpty(), "There should be at least one provider" );
-
- assertTrue(
- providers.contains( TestUtil.getValidationProviderUnderTest().getClass() ),
- "The validation class of the provider under test has to be in the list."
- );
- }
-
- @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 List<Class<?>> readBeanValidationServiceFile() {
- ClassLoader classloader = Thread.currentThread().getContextClassLoader();
- if ( classloader == null ) {
- classloader = BootstrapTest.class.getClassLoader();
- }
- List<Class<?>> providers = new ArrayList<Class<?>>();
- try {
-
- Enumeration<URL> providerDefinitions = classloader.getResources( SERVICES_FILE
);
- while ( providerDefinitions.hasMoreElements() ) {
- URL url = providerDefinitions.nextElement();
- addProviderToList( providers, url );
- }
- }
- catch ( Exception e ) {
- throw new RuntimeException( "Unable to load service file", e );
- }
- return providers;
- }
-
- 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 void addProviderToList(List<Class<?>> providers, URL url)
- throws IOException, ClassNotFoundException, InstantiationException,
IllegalAccessException {
- InputStream stream = url.openStream();
- try {
- BufferedReader reader = new BufferedReader( new InputStreamReader( stream ), 100 );
- String name = reader.readLine();
- while ( name != null ) {
- name = name.trim();
- if ( !name.startsWith( "#" ) ) {
- final Class<?> providerClass = loadClass(
- name,
- BootstrapTest.class
- );
-
- providers.add( providerClass );
- }
- name = reader.readLine();
- }
- }
- finally {
- stream.close();
- }
- }
-
- private static Class<?> loadClass(String name, Class caller) throws
ClassNotFoundException {
- try {
- //try context classloader, if fails try caller classloader
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if ( loader != null ) {
- return loader.loadClass( name );
- }
- }
- catch ( ClassNotFoundException e ) {
- //trying caller classloader
- if ( caller == null ) {
- throw e;
- }
- }
- return Class.forName( name, true, caller.getClassLoader() );
- }
-
- private static class DummyMessageInterpolator implements MessageInterpolator {
- public String interpolate(String message, Context context) {
- return "my custom message";
- }
-
- public String interpolate(String message, Context context, Locale locale) {
- throw new UnsupportedOperationException( "No specific locale is possible"
);
- }
- }
-}
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/Person.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/Person.java 2009-08-17
22:27:23 UTC (rev 17344)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/Person.java 2009-08-18
09:35:56 UTC (rev 17345)
@@ -1,60 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, 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.defaultprovider;
-
-import javax.validation.constraints.Digits;
-import javax.validation.constraints.NotNull;
-
-/**
- * @author Hardy Ferentschik
- */
-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;
- }
-}
Copied:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/validation-BootstrapCustomProviderDefinedInValidationXmlTest.xml
(from rev 17333,
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/validation-BootstrapCustomProviderDefinedInValidationXmlTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/validation-BootstrapCustomProviderDefinedInValidationXmlTest.xml 2009-08-18
09:35:56 UTC (rev 17345)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configu...
validation-configuration-1.0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+
<default-provider>org.hibernate.jsr303.tck.common.TCKValidationProvider</default-provider>
+</validation-config>
\ No newline at end of file
Property changes on:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/validation-BootstrapCustomProviderDefinedInValidationXmlTest.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/validation-BootstrapUnknownCustomProviderTest.xml
(from rev 17330,
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/validationxml/validation.xml)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/validation-BootstrapUnknownCustomProviderTest.xml
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/validation-BootstrapUnknownCustomProviderTest.xml 2009-08-18
09:35:56 UTC (rev 17345)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configu...
validation-configuration-1.0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <default-provider>foo.bar.Provider</default-provider>
+</validation-config>
\ No newline at end of file
Deleted:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml 2009-08-17
22:27:23 UTC (rev 17344)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml 2009-08-18
09:35:56 UTC (rev 17345)
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<validation-config
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
-
xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configu...
validation-configuration-1.0.xsd"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-
<default-provider>org.hibernate.jsr303.tck.common.TCKValidationProvider</default-provider>
-</validation-config>
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-08-17
22:27:23 UTC (rev 17344)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-08-18
09:35:56 UTC (rev 17345)
@@ -743,33 +743,15 @@
<text>A Bean Validation provider must define a sub interface of
Configuration uniquely
identifying the provider.</text>
</assertion>
- <assertion id="b">
+ <assertion id="b" testable="false">
<text>Streams represented in the XML configuration and opened by the
Configuration
implementation must be closed by the Configuration implementation after
the
ValidatorFactory creation (or if an exception occurs)</text>
</assertion>
- <assertion id="c">
- <text>Use the provider implementation requested if Configuration has
been created from
- Validation.byProvider(Class)</text>
- </assertion>
- <assertion id="d">
- <text>Use the provider implementation associated with the Configuration
implementation
- described in the XML configuration if defined: the value of this element
is the
- fully qualified class name of the ValidationProvider implementation
uniquely
- identifying the provider.</text>
- </assertion>
- <assertion id="e">
- <text>Use the first provider implementation returned by
- validationProviderResolver.getValidationProviders()</text>
- </assertion>
- <assertion id="f">
+ <assertion id="c" testable="false">
<text>If no ValidationProviderResolver instance has been specified, the
default
ValidationProviderResolver is used</text>
</assertion>
- <assertion id="g">
- <text>If a problem occurs while building the ValidationFactory, a
ValidationException is
- raised</text>
- </assertion>
</section>
<section id="4.4.4.1" title="ValidationProviderResolver">
<assertion id="a">
@@ -786,7 +768,7 @@
META-INF/services directory of one of its jar files</text>
</assertion>
</section>
- <section id="4.4.4.2" title="ValidationProviderResolver">
+ <section id="4.4.4.2" title="ValidationProvider">
<assertion id="a">
<text>A client can request a specific Bean Validation provider by
using
Validation.byProvider() or by defining the provider in the XML
configuration