Author: hardy.ferentschik
Date: 2009-08-17 09:43:03 -0400 (Mon, 17 Aug 2009)
New Revision: 17333
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidationProvider.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidatorConfiguration.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/UnkownProviderBootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/validation/javax.validation.spi.ValidationProvider
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorTest.java
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
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/validation/ValidationTest.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
HV-99, HV-200, HV-201
Refactored and added bootstrapping tests. Also updated the tck-audit file
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java
===================================================================
---
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-08-17
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validation.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -17,18 +17,18 @@
*/
package javax.validation;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.net.URL;
-import java.io.InputStream;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.security.PrivilegedAction;
-import java.security.AccessController;
import javax.validation.bootstrap.GenericBootstrap;
import javax.validation.bootstrap.ProviderSpecificBootstrap;
import javax.validation.spi.BootstrapState;
@@ -67,7 +67,7 @@
* <li>
* The third approach allows you to specify explicitly and in
* a type safe fashion the expected provider.
- *
+ * <p/>
* Optionally you can choose a custom
<code>ValidationProviderResolver</code>.
* <pre>{@code
* ACMEConfiguration configuration = Validation
@@ -105,6 +105,7 @@
*
<code>Validation.byDefaultProvider().configure().buildValidatorFactory()</code>
*
* @return <code>ValidatorFactory</code> instance.
+ *
* @throws ValidationException if the ValidatorFactory cannot be built
*/
public static ValidatorFactory buildDefaultValidatorFactory() {
@@ -126,7 +127,7 @@
* the first available provider will be returned.
*
* @return instance building a generic <code>Configuration</code>
- * compliant with the bootstrap state provided.
+ * compliant with the bootstrap state provided.
*/
public static GenericBootstrap byDefaultProvider() {
return new GenericBootstrapImpl();
@@ -152,10 +153,10 @@
* @param providerType the <code>ValidationProvider</code> implementation
type
*
* @return instance building a provider specific <code>Configuration</code>
- * sub interface implementation.
+ * sub interface implementation.
*/
public static <T extends Configuration<T>, U extends
ValidationProvider<T>>
- ProviderSpecificBootstrap<T> byProvider(Class<U> providerType) {
+ ProviderSpecificBootstrap<T> byProvider(Class<U> providerType) {
return new ProviderSpecificBootstrapImpl<T, U>( providerType );
}
@@ -204,7 +205,16 @@
//stay null if no resolver is defined
state.providerResolver( resolver );
}
- for ( ValidationProvider provider : resolver.getValidationProviders() ) {
+
+ List<ValidationProvider<?>> resolvers;
+ try {
+ resolvers = resolver.getValidationProviders();
+ }
+ catch ( RuntimeException re ) {
+ throw new ValidationException( "Unable to get available provider
resolvers.", re );
+ }
+
+ for ( ValidationProvider provider : resolvers ) {
if ( validationProviderClass.isAssignableFrom( provider.getClass() ) ) {
ValidationProvider<T> specificProvider = validationProviderClass.cast(
provider );
return specificProvider.createSpecializedConfiguration( state );
@@ -231,7 +241,7 @@
}
public ValidationProviderResolver getDefaultValidationProviderResolver() {
- if (defaultResolver == null) {
+ if ( defaultResolver == null ) {
defaultResolver = new DefaultValidationProviderResolver();
}
return defaultResolver;
@@ -242,11 +252,28 @@
getDefaultValidationProviderResolver() :
this.resolver;
- if ( resolver.getValidationProviders().size() == 0 ) {
+ List<ValidationProvider<?>> resolvers;
+ try {
+ resolvers = resolver.getValidationProviders();
+ }
+ catch ( RuntimeException re ) {
+ throw new ValidationException( "Unable to get available provider
resolvers.", re );
+ }
+
+ if ( resolvers.size() == 0 ) {
//FIXME looks like an assertion error almost
throw new ValidationException( "Unable to find a default provider" );
}
- return resolver.getValidationProviders().get( 0 ).createGenericConfiguration( this );
+
+ Configuration<?> config;
+ try {
+ config = resolver.getValidationProviders().get( 0 ).createGenericConfiguration( this
);
+ }
+ catch ( RuntimeException re ) {
+ throw new ValidationException( "Unable to instantiate Configuration.", re
);
+ }
+
+ return config;
}
}
@@ -360,7 +387,7 @@
public static ClassLoader fromContext() {
final GetClassLoader action = new GetClassLoader( null );
- if (System.getSecurityManager() != null) {
+ if ( System.getSecurityManager() != null ) {
return AccessController.doPrivileged( action );
}
else {
@@ -369,9 +396,11 @@
}
public static ClassLoader fromClass(Class<?> clazz) {
- if ( clazz == null ) throw new IllegalArgumentException("Class is null");
+ if ( clazz == null ) {
+ throw new IllegalArgumentException( "Class is null" );
+ }
final GetClassLoader action = new GetClassLoader( clazz );
- if (System.getSecurityManager() != null) {
+ if ( System.getSecurityManager() != null ) {
return AccessController.doPrivileged( action );
}
else {
@@ -384,7 +413,7 @@
}
public ClassLoader run() {
- if (clazz != null) {
+ if ( clazz != null ) {
return clazz.getClassLoader();
}
else {
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidationProvider.java
(from rev 17330,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidationProvider.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidationProvider.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -0,0 +1,64 @@
+// $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.common;
+
+import javax.validation.Configuration;
+import javax.validation.MessageInterpolator;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.BootstrapState;
+import javax.validation.spi.ConfigurationState;
+import javax.validation.spi.ValidationProvider;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class TCKValidationProvider implements
ValidationProvider<TCKValidatorConfiguration> {
+
+ public TCKValidatorConfiguration createSpecializedConfiguration(BootstrapState state) {
+ return TCKValidatorConfiguration.class.cast( new TCKValidatorConfiguration( this ) );
+ }
+
+ public Configuration<?> createGenericConfiguration(BootstrapState state) {
+ return new TCKValidatorConfiguration( this );
+ }
+
+ public ValidatorFactory buildValidatorFactory(ConfigurationState configurationState) {
+ return new DummyValidatorFactory();
+ }
+
+ public static class DummyValidatorFactory implements ValidatorFactory {
+
+ public Validator getValidator() {
+ throw new UnsupportedOperationException();
+ }
+
+ public ValidatorContext usingContext() {
+ throw new UnsupportedOperationException();
+ }
+
+ public MessageInterpolator getMessageInterpolator() {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> T unwrap(Class<T> type) {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidationProvider.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidatorConfiguration.java
(from rev 17330,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidatorConfiguration.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidatorConfiguration.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -0,0 +1,74 @@
+// $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.common;
+
+import java.io.InputStream;
+import javax.validation.Configuration;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.ValidationProvider;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class TCKValidatorConfiguration implements
Configuration<TCKValidatorConfiguration> {
+ private final ValidationProvider provider;
+
+ public TCKValidatorConfiguration() {
+ provider = null;
+ }
+
+ public TCKValidatorConfiguration(ValidationProvider provider) {
+ this.provider = provider;
+ }
+
+ public TCKValidatorConfiguration ignoreXmlConfiguration() {
+ throw new UnsupportedOperationException();
+ }
+
+ public TCKValidatorConfiguration messageInterpolator(MessageInterpolator interpolator)
{
+ throw new UnsupportedOperationException();
+ }
+
+ public TCKValidatorConfiguration traversableResolver(TraversableResolver resolver) {
+ throw new UnsupportedOperationException();
+ }
+
+ public TCKValidatorConfiguration constraintValidatorFactory(ConstraintValidatorFactory
constraintValidatorFactory) {
+ throw new UnsupportedOperationException();
+ }
+
+ public TCKValidatorConfiguration addMapping(InputStream stream) {
+ throw new UnsupportedOperationException();
+ }
+
+ public TCKValidatorConfiguration addProperty(String name, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ public MessageInterpolator getDefaultMessageInterpolator() {
+ throw new UnsupportedOperationException();
+ }
+
+ public ValidatorFactory buildValidatorFactory() {
+ return provider.buildValidatorFactory( null );
+ }
+
+}
Property changes on:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/common/TCKValidatorConfiguration.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified:
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
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -20,26 +20,36 @@
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.IntegrationTest;
-import org.jboss.test.audit.annotations.SpecAssertion;
-import org.jboss.test.audit.annotations.SpecAssertions;
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)
-(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
-@Resource( source = "javax.validation.spi.ValidationProvider", destination =
"WEB-INF/classes/META-INF/services/javax.validation.spi.ValidationProvider")
+@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 {
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java 2009-08-17
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -1,64 +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.Configuration;
-import javax.validation.MessageInterpolator;
-import javax.validation.Validator;
-import javax.validation.ValidatorContext;
-import javax.validation.ValidatorFactory;
-import javax.validation.spi.BootstrapState;
-import javax.validation.spi.ConfigurationState;
-import javax.validation.spi.ValidationProvider;
-
-/**
- * @author Hardy Ferentschik
- */
-public class TCKValidationProvider implements
ValidationProvider<TCKValidatorConfiguration> {
-
- public TCKValidatorConfiguration createSpecializedConfiguration(BootstrapState state) {
- return TCKValidatorConfiguration.class.cast( new TCKValidatorConfiguration( this ) );
- }
-
- public Configuration<?> createGenericConfiguration(BootstrapState state) {
- return new TCKValidatorConfiguration( this );
- }
-
- public ValidatorFactory buildValidatorFactory(ConfigurationState configurationState) {
- return new DummyValidatorFactory();
- }
-
- public static class DummyValidatorFactory implements ValidatorFactory {
-
- public Validator getValidator() {
- throw new UnsupportedOperationException();
- }
-
- public ValidatorContext usingContext() {
- throw new UnsupportedOperationException();
- }
-
- public MessageInterpolator getMessageInterpolator() {
- throw new UnsupportedOperationException();
- }
-
- public <T> T unwrap(Class<T> type) {
- throw new UnsupportedOperationException();
- }
- }
-}
Deleted:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java 2009-08-17
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -1,74 +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.io.InputStream;
-import javax.validation.Configuration;
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.MessageInterpolator;
-import javax.validation.TraversableResolver;
-import javax.validation.ValidatorFactory;
-import javax.validation.spi.ValidationProvider;
-
-/**
- * @author Hardy Ferentschik
- */
-public class TCKValidatorConfiguration implements
Configuration<TCKValidatorConfiguration> {
- private final ValidationProvider provider;
-
- public TCKValidatorConfiguration() {
- provider = null;
- }
-
- public TCKValidatorConfiguration(ValidationProvider provider) {
- this.provider = provider;
- }
-
- public TCKValidatorConfiguration ignoreXmlConfiguration() {
- throw new UnsupportedOperationException();
- }
-
- public TCKValidatorConfiguration messageInterpolator(MessageInterpolator interpolator)
{
- throw new UnsupportedOperationException();
- }
-
- public TCKValidatorConfiguration traversableResolver(TraversableResolver resolver) {
- throw new UnsupportedOperationException();
- }
-
- public TCKValidatorConfiguration constraintValidatorFactory(ConstraintValidatorFactory
constraintValidatorFactory) {
- throw new UnsupportedOperationException();
- }
-
- public TCKValidatorConfiguration addMapping(InputStream stream) {
- throw new UnsupportedOperationException();
- }
-
- public TCKValidatorConfiguration addProperty(String name, String value) {
- throw new UnsupportedOperationException();
- }
-
- public MessageInterpolator getDefaultMessageInterpolator() {
- throw new UnsupportedOperationException();
- }
-
- public ValidatorFactory buildValidatorFactory() {
- return provider.buildValidatorFactory( null );
- }
-
-}
Modified:
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
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ValidationProviderResolverTest.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -29,6 +29,7 @@
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;
@@ -37,13 +38,18 @@
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 })
+@Classes({
+ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class,
TCKValidationProvider.class,
+ TCKValidationProvider.DummyValidatorFactory.class, TCKValidatorConfiguration.class
+})
public class ValidationProviderResolverTest extends AbstractTest {
@Test
@@ -102,8 +108,11 @@
}
}
- @Test(expectedExceptions = ValidationException.class, enabled = false)
- @SpecAssertion(section = "4.4.4.2", id = "e")
+ @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() {
@@ -112,11 +121,6 @@
}
};
- Configuration<?> configuration = Validation
- .byDefaultProvider()
- .providerResolver( resolver )
- .configure();
-
- configuration.buildValidatorFactory();
+ Validation.byDefaultProvider().providerResolver( resolver ).configure();
}
}
\ No newline at end of file
Modified:
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
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -33,8 +33,8 @@
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
-import org.hibernate.jsr303.tck.tests.bootstrap.customprovider.TCKValidationProvider;
-import
org.hibernate.jsr303.tck.tests.bootstrap.customprovider.TCKValidatorConfiguration;
+import org.hibernate.jsr303.tck.common.TCKValidationProvider;
+import org.hibernate.jsr303.tck.common.TCKValidatorConfiguration;
import org.hibernate.jsr303.tck.util.TestUtil;
/**
Modified:
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
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/BootstrapTest.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -41,15 +41,12 @@
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.assertNotNull;
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.assertConstraintViolation;
import static
org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessages;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
-import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
/**
* @author Hardy Ferentschik
@@ -60,39 +57,15 @@
private static final String SERVICES_FILE = "META-INF/services/" +
ValidationProvider.class.getName();
@Test
- public void testGetDefaultValidator() {
- ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
- Validator validator = factory.getValidator();
- assertNotNull( validator, "We should be able to get a validator." );
-
- Person person = new Person();
- person.setPersonalNumber( 12345678900l );
-
- Set<ConstraintViolation<Person>> constraintViolations = validator.validate(
person );
- assertCorrectNumberOfViolations( constraintViolations, 3 );
- assertCorrectPropertyPaths(
- constraintViolations, "firstName", "lastName",
"personalNumber"
- );
-
- person.setFirstName( "John" );
- person.setLastName( "Doe" );
-
- constraintViolations = validator.validate( person );
- assertCorrectNumberOfViolations( constraintViolations, 1 );
- assertConstraintViolation(
- constraintViolations.iterator().next(), Person.class, 12345678900l,
"personalNumber"
- );
-
- person.setPersonalNumber( 1234567890l );
- constraintViolations = validator.validate( person );
- assertCorrectNumberOfViolations( constraintViolations, 0 );
- }
-
- @Test
@SpecAssertion(section = "4.4.4.1", id = "c")
public void testServiceFileExists() {
- List<ValidationProvider> providers = readBeanValidationServiceFile();
+ 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
@@ -123,12 +96,12 @@
);
}
- private List<ValidationProvider> readBeanValidationServiceFile() {
+ private List<Class<?>> readBeanValidationServiceFile() {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
if ( classloader == null ) {
classloader = BootstrapTest.class.getClassLoader();
}
- List<ValidationProvider> providers = new ArrayList<ValidationProvider>();
+ List<Class<?>> providers = new ArrayList<Class<?>>();
try {
Enumeration<URL> providerDefinitions = classloader.getResources( SERVICES_FILE
);
@@ -153,7 +126,7 @@
assertCorrectConstraintViolationMessages( constraintViolations, "my custom
message" );
}
- private void addProviderToList(List<ValidationProvider> providers, URL url)
+ private void addProviderToList(List<Class<?>> providers, URL url)
throws IOException, ClassNotFoundException, InstantiationException,
IllegalAccessException {
InputStream stream = url.openStream();
try {
@@ -167,9 +140,7 @@
BootstrapTest.class
);
- providers.add(
- ( ValidationProvider ) providerClass.newInstance()
- );
+ providers.add( providerClass );
}
name = reader.readLine();
}
Copied:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/UnkownProviderBootstrapTest.java
(from rev 17330,
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/validation/UnkownProviderBootstrapTest.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/UnkownProviderBootstrapTest.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -0,0 +1,47 @@
+// $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.validation;
+
+import javax.validation.Configuration;
+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.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Resource(source = "javax.validation.spi.ValidationProvider",
+ destination =
"WEB-INF/classes/META-INF/services/javax.validation.spi.ValidationProvider")
+@IntegrationTest
+public class UnkownProviderBootstrapTest extends AbstractTest {
+
+ @Test(expectedExceptions = ValidationException.class)
+ @SpecAssertion(section = "4.4.5", id = "f")
+ public void testUnkownProviderThrowsValiationException() {
+ Validation.byDefaultProvider().configure();
+ //ValidatorFactory factory = configuration.buildValidatorFactory();
+ }
+}
\ No newline at end of file
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidationTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidationTest.java 2009-08-17
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidationTest.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -22,28 +22,100 @@
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
+import javax.validation.Configuration;
+import javax.validation.Validation;
+import javax.validation.ValidationProviderResolver;
+import javax.validation.ValidatorFactory;
+import javax.validation.bootstrap.GenericBootstrap;
+import javax.validation.bootstrap.ProviderSpecificBootstrap;
+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.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
import static org.testng.Assert.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;
/**
- * Tests for the implementation of <code>Validator</code>.
+ * Tests for the implementation of <code>Validation</code>.
*
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+@Classes({
+ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class,
TCKValidationProvider.class,
+ TCKValidationProvider.DummyValidatorFactory.class, TCKValidatorConfiguration.class
+})
public class ValidationTest extends AbstractTest {
@Test
@SpecAssertion(section = "4.4.5", id = "a")
+ public void testBuildDefaultValidatorFactory() {
+ ValidatorFactory defaultFactory = Validation.buildDefaultValidatorFactory();
+ assertNotNull( defaultFactory, "We should be able to get a factory." );
+
+ ValidatorFactory defaultProviderFactory =
Validation.byDefaultProvider().configure().buildValidatorFactory();
+ assertNotNull( defaultProviderFactory, "We should be able to get a factory."
);
+
+ assertEquals( defaultFactory.getClass(), defaultFactory.getClass(), "The factories
have to be identical." );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.4.5", id = "b"),
+ @SpecAssertion(section = "4.4.5", id = "e")
+ })
+ public void testCustomValidationProviderResolution() {
+ ValidationProviderResolver resolver = new ValidationProviderResolver() {
+
+ public List<ValidationProvider<?>> getValidationProviders() {
+ List<ValidationProvider<?>> list = new
ArrayList<ValidationProvider<?>>();
+ list.add( new TCKValidationProvider() );
+ return list;
+ }
+ };
+
+ GenericBootstrap bootstrap = Validation.byDefaultProvider();
+ Configuration<?> config = bootstrap.providerResolver( resolver ).configure();
+
+ ValidatorFactory factory = config.buildValidatorFactory();
+ assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.4.5", id = "c"),
+ @SpecAssertion(section = "4.4.5", id = "e")
+ })
+ public void testSpecificValidationProvider() {
+ ValidationProviderResolver resolver = new ValidationProviderResolver() {
+
+ public List<ValidationProvider<?>> getValidationProviders() {
+ List<ValidationProvider<?>> list = new
ArrayList<ValidationProvider<?>>();
+ list.add( new TCKValidationProvider() );
+ return list;
+ }
+ };
+
+ // with resolver
+ ProviderSpecificBootstrap<TCKValidatorConfiguration> bootstrap =
Validation.byProvider( TCKValidationProvider.class );
+ Configuration<?> config = bootstrap.providerResolver( resolver ).configure();
+ ValidatorFactory factory = config.buildValidatorFactory();
+ assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
+ }
+
+ @Test
+ @SpecAssertion(section = "4.4.5", id = "d")
public void testVerifyMethodsOfValidationObjects() {
Class<?> validatorClass = javax.validation.Validation.class;
@@ -53,7 +125,7 @@
buildDefaultValidatorFactoryMethod = validatorClass.getMethod(
"buildDefaultValidatorFactory" );
}
catch ( NoSuchMethodException e ) {
- fail( "Validation class is mising bootstrap method." );
+ fail( "Validation class is missing bootstrap method." );
}
expectedValidationMethods.add( buildDefaultValidatorFactoryMethod );
@@ -62,7 +134,7 @@
byDefaultProviderMethod = validatorClass.getMethod( "byDefaultProvider" );
}
catch ( NoSuchMethodException e ) {
- fail( "Validation class is mising bootstrap method." );
+ fail( "Validation class is missing bootstrap method." );
}
expectedValidationMethods.add( byDefaultProviderMethod );
@@ -71,7 +143,7 @@
byProviderMethod = validatorClass.getMethod( "byProvider", Class.class );
}
catch ( NoSuchMethodException e ) {
- fail( "Validation class is mising bootstrap method." );
+ fail( "Validation class is missing bootstrap method." );
}
expectedValidationMethods.add( byProviderMethod );
Modified:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider 2009-08-17
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider 2009-08-17
13:43:03 UTC (rev 17333)
@@ -1 +1 @@
-org.hibernate.jsr303.tck.tests.bootstrap.customprovider.TCKValidationProvider
\ No newline at end of file
+org.hibernate.jsr303.tck.common.TCKValidationProvider
\ No newline at end of file
Modified:
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
10:29:14 UTC (rev 17332)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml 2009-08-17
13:43:03 UTC (rev 17333)
@@ -2,5 +2,5 @@
<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.tests.bootstrap.customprovider.TCKValidationProvider</default-provider>
+
<default-provider>org.hibernate.jsr303.tck.common.TCKValidationProvider</default-provider>
</validation-config>
\ No newline at end of file
Copied:
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/validation/javax.validation.spi.ValidationProvider
(from rev 17330,
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider)
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/validation/javax.validation.spi.ValidationProvider
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/validation/javax.validation.spi.ValidationProvider 2009-08-17
13:43:03 UTC (rev 17333)
@@ -0,0 +1 @@
+provider.UnkownValidationProvider
\ 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
10:29:14 UTC (rev 17332)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-08-17
13:43:03 UTC (rev 17333)
@@ -200,8 +200,8 @@
path to the bean or property hosting the constraint</text>
</assertion>
<assertion id="q">
- <text>You can point an error to a subpath of this default path by using
the er-
- ror builder fluent API.</text>
+ <text>You can point an error to a subpath of this default path by using
the er- ror
+ builder fluent API.</text>
</assertion>
</section>
<section id="2.5" title="The ConstraintValidatorFactory">
@@ -752,8 +752,9 @@
</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>
+ 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
@@ -810,23 +811,39 @@
</section>
<section id="4.4.5" title="Validation">
<assertion id="a">
+ <text> Validation.buildDefaultValidatorFactory(), is considered to be
the default
+ ValidatorFactory and is equivalent to the ValidatorFactory returned by
+ Validation.byDefaultProvider().configure().buildValidatorFactory()
</text>
+ </assertion>
+ <assertion id="b">
+ <text>ValidationProvider.createGenericConfiguration(BootstrapState
state) is the second
+ bootstrapping entry point and let the client provide a custom
+ ValidationProviderResolution instance</text>
+ </assertion>
+ <assertion id="c">
+ <text>ValidationProvider.createGenericConfiguration(BootstrapState
state) is the third
+ bootstrapping entry point and let the client define the specific Bean
Validation
+ provider requested as well as a custom ValidationProviderResolver
implementation if
+ needed</text>
+ </assertion>
+ <assertion id="d">
<text>The Validation implementation provided by the Bean Validation
provider must not
contain any non private attribute or method aside from the three public
static
bootstrap methods</text>
</assertion>
- <assertion id="b">
+ <assertion id="e">
<text>The bootstrap implementation must ensure it can bootstrap third
party
providers</text>
</assertion>
- <assertion id="c">
- <text>When building the Configuration object, if the
ValidationProviderResolver fais or
+ <assertion id="f">
+ <text>When building the Configuration object, if the
ValidationProviderResolver fails or
if the expected provider is not found, a ValidationException is
raised</text>
</assertion>
</section>
<section id="4.4.6" title="XML Configuration">
<assertion id="a">
<text>Unless explicitly ignored by calling
Configuration.ignoreXMLConfiguration(), a
- Configuration takes into ac- count the configuration available in
+ Configuration takes into account the configuration available in
META-INF/validation.xml</text>
</assertion>
<assertion id="b">
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorTest.java 2009-08-17
13:43:03 UTC (rev 17333)
@@ -0,0 +1,52 @@
+// $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.validation.engine;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.validation.util.TestUtil;
+import static org.hibernate.validation.util.TestUtil.assertCorrectPropertyPaths;
+import static org.hibernate.validation.util.TestUtil.assertNumberOfViolations;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ValidatorTest {
+
+ /**
+ * HV-208
+ */
+ @Test
+ public void testPropertyPathDoesNotStartWithLeadingDot() {
+ Validator validator = TestUtil.getValidator();
+ A testInstance = new A();
+ Set<ConstraintViolation<A>> constraintViolations = validator.validate(
testInstance );
+ assertNumberOfViolations( constraintViolations, 1 );
+ assertCorrectPropertyPaths( constraintViolations, "b" );
+ }
+
+ class A {
+ @NotNull
+ String b;
+ }
+}