Hibernate SVN: r16250 - in search/trunk/src: main/java/org/hibernate/search/impl and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-04-02 08:24:02 -0400 (Thu, 02 Apr 2009)
New Revision: 16250
Modified:
search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java
search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
Log:
HSEARCH-352 add analyzerDef support
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java 2009-04-02 12:10:40 UTC (rev 16249)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java 2009-04-02 12:24:02 UTC (rev 16250)
@@ -4,6 +4,8 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.Collection;
+import java.util.ArrayList;
/**
* @author Emmanuel Bernard
@@ -11,7 +13,7 @@
public class PropertyDescriptor {
private ElementType type;
private String name;
- private Set<Map<String, Object>> fields = new HashSet<Map<String, Object>>();
+ private Collection<Map<String, Object>> fields = new ArrayList<Map<String, Object>>();
public PropertyDescriptor(String name, ElementType type) {
this.name = name;
@@ -22,7 +24,7 @@
fields.add( field );
}
- public Set<Map<String, Object>> getFields() {
+ public Collection<Map<String, Object>> getFields() {
return fields;
}
}
Modified: search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-04-02 12:10:40 UTC (rev 16249)
+++ search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-04-02 12:24:02 UTC (rev 16250)
@@ -5,6 +5,7 @@
import java.util.Set;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Collection;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -25,6 +26,11 @@
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.Fields;
+import org.hibernate.search.annotations.AnalyzerDef;
+import org.hibernate.search.annotations.TokenizerDef;
+import org.hibernate.search.annotations.Parameter;
+import org.hibernate.search.annotations.TokenFilterDef;
+import org.hibernate.search.annotations.AnalyzerDefs;
/**
* @author Emmanuel Bernard
@@ -44,13 +50,22 @@
private final MetadataProvider delegate;
private final SearchMapping mapping;
private final Map<AnnotatedElement, AnnotationReader> cache = new HashMap<AnnotatedElement, AnnotationReader>(100);
+ private Map<Object, Object> defaults;
public MappingModelMetadataProvider(MetadataProvider delegate, SearchMapping mapping) {
this.delegate = delegate;
this.mapping = mapping;
}
+
public Map<Object, Object> getDefaults() {
- return delegate.getDefaults();
+ if (defaults == null) {
+ final Map<Object, Object> delegateDefaults = delegate.getDefaults();
+ defaults = delegateDefaults == null ?
+ new HashMap<Object, Object>() :
+ new HashMap<Object, Object>(delegateDefaults);
+ defaults.put( AnalyzerDefs.class, createAnalyzerDefArray() );
+ }
+ return defaults;
}
public AnnotationReader getAnnotationReader(AnnotatedElement annotatedElement) {
@@ -62,6 +77,78 @@
return reader;
}
+ private AnalyzerDef[] createAnalyzerDefArray() {
+ AnalyzerDef[] defs = new AnalyzerDef[ mapping.getAnalyzerDefs().size() ];
+ int index = 0;
+ for ( Map<String, Object> analyzerDef : mapping.getAnalyzerDefs() ) {
+ defs[index] = createAnalyzerDef( analyzerDef );
+ index++;
+ }
+ return defs;
+ }
+
+ private AnalyzerDef createAnalyzerDef(Map<String, Object> analyzerDef) {
+ AnnotationDescriptor analyzerDefAnnotation = new AnnotationDescriptor( AnalyzerDef.class );
+ for ( Map.Entry<String, Object> entry : analyzerDef.entrySet() ) {
+ if ( entry.getKey().equals( "tokenizer" ) ) {
+ AnnotationDescriptor tokenizerAnnotation = new AnnotationDescriptor( TokenizerDef.class );
+ @SuppressWarnings( "unchecked" )
+ Map<String, Object> tokenizer = (Map<String, Object>) entry.getValue();
+ for( Map.Entry<String, Object> tokenizerEntry : tokenizer.entrySet() ) {
+ if ( tokenizerEntry.getKey().equals( "params" ) ) {
+ Parameter[] paramsArray = createParams( (List<Map<String, Object>>) tokenizerEntry.getValue() );
+ tokenizerAnnotation.setValue( "params", paramsArray );
+ }
+ else {
+ tokenizerAnnotation.setValue( tokenizerEntry.getKey(), tokenizerEntry.getValue() );
+ }
+ }
+ analyzerDefAnnotation.setValue( "tokenizer", AnnotationFactory.create( tokenizerAnnotation ) );
+ }
+ else if ( entry.getKey().equals( "filters" ) ) {
+ TokenFilterDef[] filtersArray = createFilters( (List<Map<String, Object>>) entry.getValue() );
+ analyzerDefAnnotation.setValue( "filters", filtersArray );
+ }
+ else {
+ analyzerDefAnnotation.setValue( entry.getKey(), entry.getValue() );
+ }
+ }
+ return AnnotationFactory.create( analyzerDefAnnotation );
+ }
+
+ private TokenFilterDef[] createFilters(List<Map<String, Object>> filters) {
+ TokenFilterDef[] filtersArray = new TokenFilterDef[filters.size()];
+ int index = 0;
+ for (Map<String, Object> filter : filters) {
+ AnnotationDescriptor filterAnn = new AnnotationDescriptor( TokenFilterDef.class );
+ for ( Map.Entry<String, Object> filterEntry : filter.entrySet() ) {
+ if ( filterEntry.getKey().equals( "params" ) ) {
+ Parameter[] paramsArray = createParams( (List<Map<String, Object>>) filterEntry.getValue() );
+ filterAnn.setValue( "params", paramsArray );
+ }
+ else {
+ filterAnn.setValue( filterEntry.getKey(), filterEntry.getValue() );
+ }
+ }
+ filtersArray[index] = AnnotationFactory.create( filterAnn );
+ index++;
+ }
+ return filtersArray;
+ }
+
+ private Parameter[] createParams(List<Map<String, Object>> params) {
+ Parameter[] paramArray = new Parameter[ params.size() ];
+ int index = 0;
+ for ( Map<String, Object> entry : params) {
+ AnnotationDescriptor paramAnnotation = new AnnotationDescriptor( Parameter.class );
+ paramAnnotation.setValue( "name", entry.get("name") );
+ paramAnnotation.setValue( "value", entry.get("value") );
+ paramArray[index] = AnnotationFactory.create( paramAnnotation );
+ index++;
+ }
+ return paramArray;
+ }
+
private static class MappingModelAnnotationReader implements AnnotationReader {
private AnnotationReader delegate;
private SearchMapping mapping;
@@ -147,7 +234,7 @@
}
private void createFields(PropertyDescriptor property) {
- final Set<Map<String,Object>> fields = property.getFields();
+ final Collection<Map<String,Object>> fields = property.getFields();
List<org.hibernate.search.annotations.Field> fieldAnnotations =
new ArrayList<org.hibernate.search.annotations.Field>( fields.size() );
for(Map<String, Object> field : fields) {
@@ -172,7 +259,8 @@
final org.hibernate.search.annotations.Field[] fieldArray =
new org.hibernate.search.annotations.Field[fieldAnnotations.size()];
- fieldsAnnotation.setValue( "value", fieldAnnotations.toArray( fieldArray ));
+ final org.hibernate.search.annotations.Field[] fieldAsArray = fieldAnnotations.toArray( fieldArray );
+ fieldsAnnotation.setValue( "value", fieldAsArray );
annotations.put( Fields.class, AnnotationFactory.create( fieldsAnnotation ) );
}
Modified: search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-04-02 12:10:40 UTC (rev 16249)
+++ search/trunk/src/main/java/org/hibernate/search/impl/SearchFactoryImpl.java 2009-04-02 12:24:02 UTC (rev 16250)
@@ -33,6 +33,8 @@
import org.hibernate.search.annotations.FullTextFilterDefs;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Key;
+import org.hibernate.search.annotations.AnalyzerDef;
+import org.hibernate.search.annotations.AnalyzerDefs;
import org.hibernate.search.backend.BackendQueueProcessorFactory;
import org.hibernate.search.backend.LuceneIndexingParameters;
import org.hibernate.search.backend.LuceneWork;
@@ -403,6 +405,8 @@
Iterator<Class<?>> iter = cfg.getClassMappings();
DirectoryProviderFactory factory = new DirectoryProviderFactory();
+ initProgrammaticAnalyzers(context, reflectionManager);
+
while ( iter.hasNext() ) {
Class mappedClass = iter.next();
if ( mappedClass == null ) {
@@ -452,6 +456,17 @@
factory.startDirectoryProviders();
}
+ private void initProgrammaticAnalyzers(InitContext context, ReflectionManager reflectionManager) {
+ final Map defaults = reflectionManager.getDefaults();
+
+ if (defaults != null) {
+ AnalyzerDef[] defs = (AnalyzerDef[]) defaults.get( AnalyzerDefs.class );
+ for (AnalyzerDef def : defs) {
+ context.addAnalyzerDef( def );
+ }
+ }
+ }
+
private static FilterCachingStrategy buildFilterCachingStrategy(Properties properties) {
FilterCachingStrategy filterCachingStrategy;
String impl = properties.getProperty( Environment.FILTER_CACHING_STRATEGY );
Modified: search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
===================================================================
--- search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-04-02 12:10:40 UTC (rev 16249)
+++ search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-04-02 12:24:02 UTC (rev 16250)
@@ -7,6 +7,7 @@
import org.apache.solr.analysis.LowerCaseFilterFactory;
import org.apache.solr.analysis.NGramFilterFactory;
import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.hibernate.search.cfg.SearchMapping;
@@ -17,6 +18,8 @@
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.FullTextQuery;
+import org.hibernate.search.store.RAMDirectoryProvider;
+import org.hibernate.search.store.FSDirectoryProvider;
import org.hibernate.cfg.Configuration;
import org.hibernate.Transaction;
@@ -39,7 +42,7 @@
tx = s.beginTransaction();
- QueryParser parser = new QueryParser( "id", new StandardAnalyzer() );
+ QueryParser parser = new QueryParser( "id", new StandardAnalyzer( ) );
org.apache.lucene.search.Query luceneQuery = parser.parse( "street1:peachtree" );
FullTextQuery query = s.createFullTextQuery( luceneQuery ).setProjection( "idx_street2", FullTextQuery.THIS );
assertEquals( "Not properly indexed", 1, query.getResultSize() );
@@ -52,16 +55,49 @@
}
+ public void testAnalyzerDef() throws Exception{
+ Address address = new Address();
+ address.setStreet1( "3340 Peachtree Rd NE" );
+ address.setStreet2( "JBoss" );
+
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ s.persist( address );
+ tx.commit();
+
+ s.clear();
+
+ tx = s.beginTransaction();
+
+ QueryParser parser = new QueryParser( "id", new StandardAnalyzer( ) );
+ org.apache.lucene.search.Query luceneQuery = parser.parse( "street1_ngram:pea" );
+ System.out.print( luceneQuery.toString() );
+ final FullTextQuery query = s.createFullTextQuery( luceneQuery );
+ assertEquals( "Analyzer inoperant", 1, query.getResultSize() );
+
+ s.delete( query.list().get( 0 ));
+ tx.commit();
+ s.close();
+
+ }
+
@Override
protected void configure(Configuration cfg) {
super.configure( cfg );
+ //cfg.setProperty( "hibernate.search.default.directory_provider", FSDirectoryProvider.class.getName() );
SearchMapping mapping = new SearchMapping();
- mapping.indexedClass( Address.class )
- .property( "street1", ElementType.FIELD )
- .field()
- .property( "street2", ElementType.METHOD )
- .field().name( "idx_street2" )
- .store( Store.YES );
+ mapping.analyzerDef( "ngram", StandardTokenizerFactory.class )
+ .filter( LowerCaseFilterFactory.class )
+ .filter( NGramFilterFactory.class )
+ .param( "minGramSize", "3" )
+ .param( "maxGramSize", "3" )
+
+ .indexedClass( Address.class )
+ .property( "street1", ElementType.FIELD )
+ .field()
+ .field().name( "street1_ngram" ).analyzer( "ngram" )
+ .property( "street2", ElementType.METHOD )
+ .field().name( "idx_street2" ).store( Store.YES );
cfg.getProperties().put( "hibernate.search.mapping_model", mapping );
}
15 years, 8 months
Hibernate SVN: r16249 - in validator/trunk/hibernate-validator: src/test and 13 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-04-02 08:10:40 -0400 (Thu, 02 Apr 2009)
New Revision: 16249
Added:
validator/trunk/hibernate-validator/src/test/suite/
validator/trunk/hibernate-validator/src/test/suite/unit-tests.xml
Modified:
validator/trunk/hibernate-validator/pom.xml
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/constraintcomposition/ConstraintCompositionTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/GraphNavigationTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainGeneratorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/BeanDescriptorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ConstraintDescriptorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ElementDescriptorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/PropertyDescriptorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/ValidatorResolutionTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/IdentitySetTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyIteratorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/annotationfactory/AnnotationFactoryTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/Junit4TestFactory.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java
Log:
Switched to TestNG in order to be able to reuse some of the webbeans tck stuff
Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/pom.xml 2009-04-02 12:10:40 UTC (rev 16249)
@@ -49,19 +49,29 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.4</version>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.8</version>
<scope>test</scope>
+ <classifier>jdk15</classifier>
+ <exclusions>
+ <exclusion>
+ <artifactId>junit</artifactId>
+ <groupId>junit</groupId>
+ </exclusion>
+ </exclusions>
</dependency>
+
<dependency>
- <groupId>junitperf</groupId>
- <artifactId>junitperf</artifactId>
- <version>1.8</version>
+ <groupId>org.jboss.test-harness</groupId>
+ <artifactId>jboss-test-harness</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
+
</dependencies>
<build>
+ <defaultGoal>test</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
@@ -90,6 +100,33 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <suiteXmlFiles>
+ <suiteXmlFile>${basedir}/src/test/suite/unit-tests.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-test-report</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report-only</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <outputDirectory>${project.build.directory}/surefire-reports</outputDirectory>
+ <outputName>test-report</outputName>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -37,19 +37,19 @@
import javax.validation.bootstrap.ProviderSpecificBootstrap;
import javax.validation.spi.ValidationProvider;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.junit.Test;
+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.validation.HibernateValidationProvider;
import org.hibernate.validation.constraints.NotNullValidator;
-import org.hibernate.validation.engine.metadata.Customer;
import org.hibernate.validation.engine.ConfigurationImpl;
import org.hibernate.validation.engine.ConstraintValidatorFactoryImpl;
import org.hibernate.validation.engine.HibernateValidatorConfiguration;
import org.hibernate.validation.engine.ValidatorFactoryImpl;
+import org.hibernate.validation.engine.metadata.Customer;
/**
* Tests the Bean Validation bootstrapping.
@@ -84,12 +84,12 @@
customer.setFirstName( "John" );
Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
customer.setLastName( "Doe" );
constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -106,9 +106,9 @@
customer.setFirstName( "John" );
Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
ConstraintViolation<Customer> constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong message", "may not be null", constraintViolation.getMessage() );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
// now we modify the configuration, get a new factory and valiator and try again
configuration = Validation.byDefaultProvider().configure();
@@ -126,9 +126,9 @@
factory = configuration.buildValidatorFactory();
validator = factory.getValidator();
constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong message", "my custom message", constraintViolation.getMessage() );
+ assertEquals( "my custom message", constraintViolation.getMessage(), "Wrong message" );
}
@Test
@@ -144,9 +144,9 @@
customer.setFirstName( "John" );
Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
ConstraintViolation<Customer> constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong message", "may not be null", constraintViolation.getMessage() );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
// get a new factory using a custom configuration
configuration = Validation.byDefaultProvider().configure();
@@ -164,7 +164,7 @@
factory = configuration.buildValidatorFactory();
validator = factory.getValidator();
constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -225,9 +225,9 @@
}
catch ( ValidationException e ) {
assertEquals(
- "Wrong error message",
"Unable to find provider: interface org.hibernate.validation.engine.HibernateValidatorConfiguration",
- e.getMessage()
+ e.getMessage(),
+ "Wrong error message"
);
}
}
@@ -265,9 +265,9 @@
customer.setFirstName( "John" );
Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
ConstraintViolation<Customer> constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong message", "may not be null", constraintViolation.getMessage() );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
// get a new factory using a custom configuration
configuration = Validation.byDefaultProvider().configure();
@@ -281,6 +281,6 @@
factory = configuration.buildValidatorFactory();
validator = factory.getValidator();
constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertFalseValidatorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -17,10 +17,10 @@
*/
package org.hibernate.validation.constraints;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/AssertTrueValidatorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -17,10 +17,10 @@
*/
package org.hibernate.validation.constraints;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
/**
* @author Alaa Nassef
@@ -43,3 +43,4 @@
assertFalse( constraint.isValid( Boolean.FALSE, null ) );
}
}
+
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForNumberTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForNumberTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForNumberTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -21,9 +21,9 @@
import javax.validation.ValidationException;
import javax.validation.constraints.Digits;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
@@ -80,7 +80,7 @@
assertFalse( constraint.isValid( Double.valueOf( "500.2" ), null ) );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testNegativeIntegerLength() {
AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
@@ -93,7 +93,7 @@
constraint.initialize( p );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testNegativeFractionLength() {
AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForStringTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForStringTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/DigitsValidatorForStringTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -20,10 +20,10 @@
import javax.validation.ValidationException;
import javax.validation.constraints.Digits;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
@@ -62,7 +62,7 @@
assertFalse( constraint.isValid( "12.0001", null ) );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testNegativeIntegerLength() {
AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
@@ -75,7 +75,7 @@
constraint.initialize( p );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testNegativeFractionLength() {
AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForCalendarTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -19,10 +19,10 @@
import java.util.Calendar;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/FutureValidatorForDateTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -19,10 +19,10 @@
import java.util.Date;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
public class FutureValidatorForDateTest {
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/LengthValidatorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -19,9 +19,9 @@
import javax.validation.ValidationException;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
@@ -50,7 +50,7 @@
assertFalse( constraint.isValid( "foobar", null ) );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testNegativeMinValue() {
AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class );
descriptor.setValue( "min", -1 );
@@ -62,7 +62,7 @@
constraint.initialize( p );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testNegativeMaxValue() {
AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class );
descriptor.setValue( "min", 1 );
@@ -74,7 +74,7 @@
constraint.initialize( p );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testNegativeLength() {
AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class );
descriptor.setValue( "min", 5 );
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForNumberTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -21,10 +21,10 @@
import java.math.BigInteger;
import javax.validation.constraints.Max;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MaxValidatorForStringTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -19,10 +19,10 @@
import javax.validation.constraints.Max;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForNumberTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -21,10 +21,10 @@
import java.math.BigInteger;
import javax.validation.constraints.Min;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/MinValidatorForStringTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -19,10 +19,10 @@
import javax.validation.constraints.Min;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotEmptyValidatorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -17,10 +17,10 @@
*/
package org.hibernate.validation.constraints;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NotNullValidatorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -17,9 +17,9 @@
*/
package org.hibernate.validation.constraints;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/NullValidatorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -17,10 +17,10 @@
*/
package org.hibernate.validation.constraints;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForCalendarTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -19,10 +19,10 @@
import java.util.Calendar;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
/**
* @author Alaa Nassef
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PastValidatorForDateTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -19,10 +19,10 @@
import java.util.Date;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
public class PastValidatorForDateTest {
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/PatternValidatorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -20,9 +20,9 @@
import javax.validation.ValidationException;
import javax.validation.constraints.Pattern;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
@@ -49,7 +49,7 @@
assertFalse( constraint.isValid( "This test is not foobar", null ) );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testInvalidRegularExpression() {
AnnotationDescriptor<Pattern> descriptor = new AnnotationDescriptor<Pattern>( Pattern.class );
descriptor.setValue( "regexp", "(unbalanced parentheses" );
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/constraints/validatorcontext/ConstraintValidatorContextTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -23,10 +23,10 @@
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import org.junit.Test;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
import org.hibernate.validation.util.TestUtil;
@@ -45,9 +45,9 @@
DummyBean bean = new DummyBean( "foobar" );
Set<ConstraintViolation<DummyBean>> constraintViolations = validator.validate( bean );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong message", "dummy message", constraintViolation.getMessage() );
+ assertEquals( "dummy message", constraintViolation.getMessage(), "Wrong message" );
}
/**
@@ -64,7 +64,7 @@
DummyBean bean = new DummyBean( "foobar" );
Set<ConstraintViolation<DummyBean>> constraintViolations = validator.validate( bean );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -79,10 +79,10 @@
DummyBean bean = new DummyBean( "foobar" );
Set<ConstraintViolation<DummyBean>> constraintViolations = validator.validate( bean );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong message", "message1", constraintViolation.getMessage() );
- assertEquals( "Wrong property", "property1", constraintViolation.getPropertyPath() );
+ assertEquals( "message1", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( "property1", constraintViolation.getPropertyPath(), "Wrong property" );
}
@Test
@@ -96,15 +96,15 @@
bean.setNestedDummy( new DummyBean( "bar" ) );
Set<ConstraintViolation<DummyBean>> constraintViolations = validator.validate( bean );
- assertEquals( "Wrong number of constraints", 2, constraintViolations.size() );
+ assertEquals( 2, constraintViolations.size(), "Wrong number of constraints" );
boolean validatedNestedBean = false;
for ( ConstraintViolation<DummyBean> violation : constraintViolations ) {
if ( violation.getPropertyPath().equals( "value" ) ) {
- assertEquals( "Wrong message", "dummy message", violation.getMessage() );
+ assertEquals( "dummy message", violation.getMessage(), "Wrong message" );
}
else if ( violation.getPropertyPath().equals( "nestedDummy.value" ) ) {
- assertEquals( "Wrong message", "dummy message", violation.getMessage() );
+ assertEquals( "dummy message", violation.getMessage(), "Wrong message" );
validatedNestedBean = true;
}
else {
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ConstraintHelperTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -23,17 +23,15 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
import org.hibernate.validation.constraints.invalidvalidators.NoGroups;
import org.hibernate.validation.constraints.invalidvalidators.NoMessage;
import org.hibernate.validation.constraints.invalidvalidators.ValidProperty;
-import org.hibernate.validation.engine.Engine;
-import org.hibernate.validation.engine.Order;
import org.hibernate.validation.util.ReflectionHelper;
/**
@@ -60,7 +58,7 @@
}
};
assertFalse(
- "The constraint annotation should not be valid", constraintHelper.isConstraintAnnotation( annotation )
+ constraintHelper.isConstraintAnnotation( annotation ), "The constraint annotation should not be valid"
);
}
@@ -76,7 +74,7 @@
}
};
assertFalse(
- "The constraint annotation should not be valid", constraintHelper.isConstraintAnnotation( annotation )
+ constraintHelper.isConstraintAnnotation( annotation ), "The constraint annotation should not be valid"
);
}
@@ -100,7 +98,7 @@
}
};
assertFalse(
- "The constraint annotation should not be valid", constraintHelper.isConstraintAnnotation( annotation )
+ constraintHelper.isConstraintAnnotation( annotation ), "The constraint annotation should not be valid"
);
}
@@ -115,9 +113,9 @@
Annotation annotation = fields[0].getAnnotation( Pattern.List.class );
assertNotNull( annotation );
List<Annotation> multiValueConstraintAnnotations = constraintHelper.getMultiValueConstraints( annotation );
- assertTrue( "There should be two constraint annotations", multiValueConstraintAnnotations.size() == 2 );
- assertTrue( "Wrong constraint annotation", multiValueConstraintAnnotations.get( 0 ) instanceof Pattern );
- assertTrue( "Wrong constraint annotation", multiValueConstraintAnnotations.get( 1 ) instanceof Pattern );
+ assertTrue( multiValueConstraintAnnotations.size() == 2, "There should be two constraint annotations" );
+ assertTrue( multiValueConstraintAnnotations.get( 0 ) instanceof Pattern, "Wrong constraint annotation" );
+ assertTrue( multiValueConstraintAnnotations.get( 1 ) instanceof Pattern, "Wrong constraint annotation" );
Order order = new Order();
@@ -129,6 +127,6 @@
annotation = fields[0].getAnnotation( NotNull.class );
assertNotNull( annotation );
multiValueConstraintAnnotations = constraintHelper.getMultiValueConstraints( annotation );
- assertTrue( "There should be no constraint annotations", multiValueConstraintAnnotations.size() == 0 );
+ assertTrue( multiValueConstraintAnnotations.size() == 0, "There should be no constraint annotations" );
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ResourceBundleMessageInterpolatorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -24,14 +24,14 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.ResourceBundle;
+import javax.validation.MessageInterpolator;
+import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
-import javax.validation.constraints.Max;
-import javax.validation.MessageInterpolator;
-import static org.junit.Assert.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
@@ -47,7 +47,7 @@
private NotNull notNull;
private Size size;
- @Before
+ @BeforeTest
public void setUp() {
// Create some annotations for testing using AnnotationProxies
AnnotationDescriptor<NotNull> descriptor = new AnnotationDescriptor<NotNull>( NotNull.class );
@@ -67,19 +67,19 @@
MessageInterpolator.Context context = new MessageInterpolatorContext( descriptor, null );
String expected = "replacement worked";
String actual = interpolator.interpolate( "{foo}", context );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
expected = "replacement worked replacement worked";
actual = interpolator.interpolate( "{foo} {foo}", context );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
expected = "This replacement worked just fine";
actual = interpolator.interpolate( "This {foo} just fine", context );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
expected = "{} { replacement worked }";
actual = interpolator.interpolate( "{} { {foo} }", context );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
}
@Test
@@ -93,11 +93,11 @@
String expected = "foo"; // missing {}
String actual = interpolator.interpolate( "foo", context );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
expected = "#{foo {}";
actual = interpolator.interpolate( "#{foo {}", context );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
}
@Test
@@ -111,7 +111,7 @@
String expected = "{bar}"; // unkown token {}
String actual = interpolator.interpolate( "{bar}", context );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
}
@Test
@@ -125,7 +125,7 @@
String expected = "may not be null";
String actual = interpolator.interpolate( notNull.message(), context );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
ConstraintDescriptorImpl<Size> sizeDescriptor = new ConstraintDescriptorImpl<Size>(
size, new Class<?>[] { }, new ConstraintHelper()
@@ -133,7 +133,7 @@
expected = "size must be between 0 and 2147483647"; // unkown token {}
context = new MessageInterpolatorContext( sizeDescriptor, null );
actual = interpolator.interpolate( size.message(), context );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
}
@Test
@@ -147,7 +147,7 @@
String expected = "kann nicht null sein";
MessageInterpolator.Context context = new MessageInterpolatorContext( descriptor, null );
String actual = interpolator.interpolate( notNull.message(), context, Locale.GERMAN );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
}
@Test
@@ -161,7 +161,7 @@
String expected = "may not be null";
String actual = interpolator.interpolate( notNull.message(), context, Locale.JAPAN );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
}
@Test
@@ -175,7 +175,7 @@
String expected = "no puede ser null";
String actual = interpolator.interpolate( notNull.message(), context, new Locale( "es", "ES" ) );
- assertEquals( "Wrong substitution", expected, actual );
+ assertEquals( expected, actual, "Wrong substitution" );
}
/**
@@ -185,7 +185,7 @@
public void testRecursiveMessageInterpoliation() {
AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>( Max.class );
descriptor.setValue( "message", "{replace.in.user.bundle1}" );
- descriptor.setValue( "value", 10l);
+ descriptor.setValue( "value", 10l );
Max max = AnnotationFactory.create( descriptor );
@@ -198,7 +198,9 @@
String expected = "{replace.in.default.bundle2}";
String actual = interpolator.interpolate( max.message(), context );
- assertEquals( "Within default bundle replacement parameter evauation should not be recursive!", expected, actual );
+ assertEquals(
+ expected, actual, "Within default bundle replacement parameter evauation should not be recursive!"
+ );
}
/**
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/ValidatorImplTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -26,22 +26,13 @@
import javax.validation.Validator;
import javax.validation.groups.Default;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.junit.Test;
import org.slf4j.Logger;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
-import org.hibernate.validation.engine.Actor;
-import org.hibernate.validation.engine.Address;
-import org.hibernate.validation.engine.Boy;
import org.hibernate.validation.engine.metadata.Customer;
-import org.hibernate.validation.engine.Engine;
-import org.hibernate.validation.engine.Order;
-import org.hibernate.validation.engine.Person;
-import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.Last;
-import org.hibernate.validation.engine.Second;
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.TestUtil;
import static org.hibernate.validation.util.TestUtil.assertConstraintViolation;
@@ -64,19 +55,19 @@
}
catch ( ValidationException e ) {
assertEquals(
- "Wrong error message",
"Annotated methods must follow the JavaBeans naming convention. age() does not.",
- e.getMessage()
+ e.getMessage(),
+ "Wrong error message"
);
}
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expectedExceptions = IllegalArgumentException.class)
public void testNullParamterToValidatorImplConstructor() {
TestUtil.getValidator().getConstraintsForClass( null );
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expectedExceptions = IllegalArgumentException.class)
public void testValidateWithNull() {
Validator validator = TestUtil.getValidator();
validator.validate( null );
@@ -148,12 +139,12 @@
customer.setFirstName( "John" );
Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
customer.setLastName( "Doe" );
constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -167,30 +158,30 @@
Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
assertEquals(
- "we should have been 2 not null violation for addresslines and one lenth violation for city",
3,
- constraintViolations.size()
+ constraintViolations.size(),
+ "we should have been 2 not null violation for addresslines and one lenth violation for city"
);
constraintViolations = validator.validateProperty( address, "city" );
assertEquals(
- "only city should be validated",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "only city should be validated"
);
constraintViolations = validator.validateProperty( address, "city" );
assertEquals(
- "only city should be validated",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "only city should be validated"
);
constraintViolations = validator.validateValue( Address.class, "city", "Paris" );
assertEquals(
- "Paris should be a valid city name.",
0,
- constraintViolations.size()
+ constraintViolations.size(),
+ "Paris should be a valid city name."
);
}
@@ -203,19 +194,18 @@
customer.setLastName( "Doe" );
Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
Order order = new Order();
customer.addOrder( order );
constraintViolations = validator.validate( customer );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
- assertEquals( "Wrong message", "may not be null", constraintViolation.getMessage() );
- assertEquals( "Wrong root entity", customer, constraintViolation.getRootBean() );
- assertEquals( "Wrong value", order.getOrderNumber(), constraintViolation.getInvalidValue() );
- assertEquals( "Wrong propertyName", "orderList[0].orderNumber", constraintViolation.getPropertyPath() );
-
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( customer, constraintViolation.getRootBean(), "Wrong root entity" );
+ assertEquals( order.getOrderNumber(), constraintViolation.getInvalidValue(), "Wrong value" );
+ assertEquals( "orderList[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
}
@Test
@@ -225,15 +215,15 @@
Engine engine = new Engine();
engine.setSerialNumber( "mail(a)foobar.com" );
Set<ConstraintViolation<Engine>> constraintViolations = validator.validate( engine );
- assertEquals( "Wrong number of constraints", 2, constraintViolations.size() );
+ assertEquals( 2, constraintViolations.size(), "Wrong number of constraints" );
engine.setSerialNumber( "ABCDEFGH1234" );
constraintViolations = validator.validate( engine );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
engine.setSerialNumber( "ABCD-EFGH-1234" );
constraintViolations = validator.validate( engine );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -254,12 +244,12 @@
Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
- assertEquals( "Wrong message", "may not be empty", constraintViolation.getMessage() );
- assertEquals( "Wrong root entity", clint, constraintViolation.getRootBean() );
- assertEquals( "Wrong value", morgan.getLastName(), constraintViolation.getInvalidValue() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
+ assertEquals( "may not be empty", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( clint, constraintViolation.getRootBean(), "Wrong root entity" );
+ assertEquals( morgan.getLastName(), constraintViolation.getInvalidValue(), "Wrong value" );
assertEquals(
- "Wrong propertyName", "playedWith[0].playedWith[1].lastName", constraintViolation.getPropertyPath()
+ "playedWith[0].playedWith[1].lastName", constraintViolation.getPropertyPath(), "Wrong propertyName"
);
}
@@ -270,17 +260,17 @@
Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
Customer.class, "orderList[0].orderNumber", null
);
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
- assertEquals( "Wrong message", "may not be null", constraintViolation.getMessage() );
- assertEquals( "Wrong root entity", null, constraintViolation.getRootBean() );
- assertEquals( "Wrong value", null, constraintViolation.getInvalidValue() );
- assertEquals( "Wrong propertyName", "orderList[0].orderNumber", constraintViolation.getPropertyPath() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( null, constraintViolation.getRootBean(), "Wrong root entity" );
+ assertEquals( null, constraintViolation.getInvalidValue(), "Wrong value" );
+ assertEquals( "orderList[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
constraintViolations = validator.validateValue( Customer.class, "orderList[0].orderNumber", "1234" );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -323,18 +313,18 @@
Set<ConstraintViolation<Customer>> constraintViolations = validator.validateProperty(
customer, "orderList[0].orderNumber"
);
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
- assertEquals( "Wrong message", "may not be null", constraintViolation.getMessage() );
- assertEquals( "Wrong root entity", customer, constraintViolation.getRootBean() );
- assertEquals( "Wrong value", order.getOrderNumber(), constraintViolation.getInvalidValue() );
- assertEquals( "Wrong propertyName", "orderList[0].orderNumber", constraintViolation.getPropertyPath() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( customer, constraintViolation.getRootBean(), "Wrong root entity" );
+ assertEquals( order.getOrderNumber(), constraintViolation.getInvalidValue(), "Wrong value" );
+ assertEquals( "orderList[0].orderNumber", constraintViolation.getPropertyPath(), "Wrong propertyName" );
order.setOrderNumber( 1234 );
constraintViolations = validator.validateProperty( customer, "orderList[0].orderNumber" );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -395,7 +385,7 @@
Person person = customer;
Set<ConstraintViolation<Person>> constraintViolations = validator.validate( person );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
assertConstraintViolation(
constraintViolations.iterator().next(),
@@ -408,7 +398,7 @@
order.setOrderNumber( 123 );
constraintViolations = validator.validate( person );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -427,7 +417,7 @@
Set<ConstraintViolation<Customer>> constraintViolations = validator.validate(
customer, Default.class, First.class, Second.class, Last.class
);
- assertEquals( "Wrong number of constraints", 100, constraintViolations.size() );
+ assertEquals( 100, constraintViolations.size(), "Wrong number of constraints" );
}
/**
@@ -441,14 +431,14 @@
PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderNumber" );
Set<ConstraintDescriptor<?>> descriptors = propertyDescriptor.getConstraintDescriptors();
- assertEquals( "There should be only one constraint descriptor", 1, descriptors.size() );
+ assertEquals( 1, descriptors.size(), "There should be only one constraint descriptor" );
ConstraintDescriptor<?> descriptor = descriptors.iterator().next();
Set<Class<?>> groups = descriptor.getGroups();
- assertTrue( "There should be only one group", groups.size() == 1 );
+ assertTrue( groups.size() == 1, "There should be only one group" );
assertEquals(
- "The declared constraint does not explicitly define a group, hence Default is expected",
Default.class,
- groups.iterator().next()
+ groups.iterator().next(),
+ "The declared constraint does not explicitly define a group, hence Default is expected"
);
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/constraintcomposition/ConstraintCompositionTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/constraintcomposition/ConstraintCompositionTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/constraintcomposition/ConstraintCompositionTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -21,11 +21,9 @@
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
-import static org.junit.Assert.fail;
-import org.junit.Test;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
-import org.hibernate.validation.engine.constraintcomposition.FrenchAddress;
-import org.hibernate.validation.engine.constraintcomposition.GermanAddress;
import static org.hibernate.validation.util.TestUtil.assertConstraintViolation;
import static org.hibernate.validation.util.TestUtil.assertNumberOfViolations;
import static org.hibernate.validation.util.TestUtil.getValidator;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/GraphNavigationTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/GraphNavigationTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/GraphNavigationTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -23,9 +23,9 @@
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
import org.hibernate.validation.util.TestUtil;
@@ -61,7 +61,7 @@
Validator validator = TestUtil.getValidator();
Set<ConstraintViolation<Order>> constraintViolations = validator.validate( order );
- assertEquals( "Wrong number of constraints", 3, constraintViolations.size() );
+ assertEquals( 3, constraintViolations.size(), "Wrong number of constraints" );
List<String> expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add( "shippingAddress.addressline1" );
@@ -74,7 +74,7 @@
}
}
- assertTrue( "All error messages should have occured once", expectedErrorMessages.size() == 0 );
+ assertTrue( expectedErrorMessages.size() == 0, "All error messages should have occured once" );
}
@Test
@@ -85,7 +85,7 @@
Validator validator = TestUtil.getValidator();
Set<ConstraintViolation<User>> constraintViolations = validator.validate( john );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
TestUtil.assertConstraintViolation(
constraintViolations.iterator().next(), "may not be null", User.class, null, "lastName"
);
@@ -96,21 +96,19 @@
john.knows( jane );
constraintViolations = validator.validate( john );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
TestUtil.assertConstraintViolation(
constraintViolations.iterator().next(), "may not be null", User.class, null, "lastName"
);
constraintViolations = validator.validate( jane );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
TestUtil.assertConstraintViolation(
constraintViolations.iterator().next(), "may not be null", User.class, null, "knowsUser[0].lastName"
);
john.setLastName( "Doe" );
constraintViolations = validator.validate( john );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
-
-
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainGeneratorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainGeneratorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupChainGeneratorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -19,14 +19,14 @@
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
-import java.util.List;
import javax.validation.ValidationException;
import javax.validation.groups.Default;
-import static org.junit.Assert.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
import org.hibernate.validation.engine.First;
import org.hibernate.validation.engine.Last;
@@ -39,36 +39,36 @@
GroupChainGenerator generator;
- @Before
+ @BeforeTest
public void init() {
generator = new GroupChainGenerator();
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testGroupChainForNonInterface() {
Set<Class<?>> groups = new HashSet<Class<?>>();
groups.add( String.class );
generator.getGroupChainFor( groups );
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expectedExceptions = IllegalArgumentException.class)
public void testGroupChainForNull() {
generator.getGroupChainFor( null );
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expectedExceptions = IllegalArgumentException.class)
public void testGroupChainForEmptySet() {
generator.getGroupChainFor( new HashSet<Class<?>>() );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testCyclicGroupSequences() {
Set<Class<?>> groups = new HashSet<Class<?>>();
groups.add( CyclicGroupSequence1.class );
generator.getGroupChainFor( groups );
}
- @Test(expected = ValidationException.class)
+ @Test(expectedExceptions = ValidationException.class)
public void testCyclicGroupSequence() {
Set<Class<?>> groups = new HashSet<Class<?>>();
groups.add( CyclicGroupSequence.class );
@@ -83,14 +83,14 @@
groups.add( Last.class );
GroupChain chain = generator.getGroupChainFor( groups );
int count = countGroups( chain );
- assertEquals( "Wrong number of groups", 3, count );
+ assertEquals( 3, count, "Wrong number of groups" );
groups.clear();
groups.add( First.class );
groups.add( First.class );
chain = generator.getGroupChainFor( groups );
count = countGroups( chain );
- assertEquals( "Wrong number of groups", 1, count );
+ assertEquals( 1, count, "Wrong number of groups" );
groups.clear();
groups.add( First.class );
@@ -98,13 +98,13 @@
groups.add( First.class );
chain = generator.getGroupChainFor( groups );
count = countGroups( chain );
- assertEquals( "Wrong number of groups", 2, count );
+ assertEquals( 2, count, "Wrong number of groups" );
}
private int countGroups(GroupChain chain) {
Iterator<Group> groupIterator = chain.getGroupIterator();
int count = 0;
- while (groupIterator.hasNext()) {
+ while ( groupIterator.hasNext() ) {
groupIterator.next();
count++;
}
@@ -119,7 +119,7 @@
Iterator<List<Group>> sequences = chain.getSequenceIterator();
List<Group> sequence = sequences.next();
- assertEquals( "Wrong group", Default.class, sequence.get(0).getGroup() );
- assertEquals( "Wrong group", Address.HighLevelCoherence.class, sequence.get(1).getGroup() );
+ assertEquals( Default.class, sequence.get( 0 ).getGroup(), "Wrong group" );
+ assertEquals( Address.HighLevelCoherence.class, sequence.get( 1 ).getGroup(), "Wrong group" );
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -20,22 +20,18 @@
import java.util.Set;
import javax.validation.BeanDescriptor;
import javax.validation.ConstraintViolation;
+import javax.validation.PropertyDescriptor;
import javax.validation.ValidationException;
import javax.validation.Validator;
-import javax.validation.PropertyDescriptor;
import javax.validation.groups.Default;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
-import org.hibernate.validation.engine.groups.Animal;
-import org.hibernate.validation.engine.groups.Author;
-import org.hibernate.validation.engine.groups.Book;
import org.hibernate.validation.engine.DefaultAlias;
import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.groups.Dictonary;
import org.hibernate.validation.engine.Last;
import org.hibernate.validation.engine.Second;
import org.hibernate.validation.util.TestUtil;
@@ -62,45 +58,45 @@
Set<ConstraintViolation<Book>> constraintViolations = validator.validate(
book, First.class, Second.class, Last.class
);
- assertEquals( "Wrong number of constraints", 3, constraintViolations.size() );
+ assertEquals( 3, constraintViolations.size(), "Wrong number of constraints" );
author.setFirstName( "Gavin" );
author.setLastName( "King" );
constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
- assertEquals( "Wrong message", "may not be empty", constraintViolation.getMessage() );
- assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
- assertEquals( "Wrong value", book.getTitle(), constraintViolation.getInvalidValue() );
- assertEquals( "Wrong propertyName", "title", constraintViolation.getPropertyPath() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
+ assertEquals( "may not be empty", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( book, constraintViolation.getRootBean(), "Wrong root entity" );
+ assertEquals( book.getTitle(), constraintViolation.getInvalidValue(), "Wrong value" );
+ assertEquals( "title", constraintViolation.getPropertyPath(), "Wrong propertyName" );
book.setTitle( "Hibernate Persistence with JPA" );
book.setSubtitle( "Revised Edition of Hibernate in Action" );
constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong message", "length must be between 0 and 30", constraintViolation.getMessage() );
- assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
- assertEquals( "Wrong value", book.getSubtitle(), constraintViolation.getInvalidValue() );
- assertEquals( "Wrong propertyName", "subtitle", constraintViolation.getPropertyPath() );
+ assertEquals( "length must be between 0 and 30", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( book, constraintViolation.getRootBean(), "Wrong root entity" );
+ assertEquals( book.getSubtitle(), constraintViolation.getInvalidValue(), "Wrong value" );
+ assertEquals( "subtitle", constraintViolation.getPropertyPath(), "Wrong propertyName" );
book.setSubtitle( "Revised Edition" );
author.setCompany( "JBoss a divison of RedHat" );
constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
- assertEquals( "Wrong message", "length must be between 0 and 20", constraintViolation.getMessage() );
- assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
- assertEquals( "Wrong value", author.getCompany(), constraintViolation.getInvalidValue() );
- assertEquals( "Wrong propertyName", "author.company", constraintViolation.getPropertyPath() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
+ assertEquals( "length must be between 0 and 20", constraintViolation.getMessage() );
+ assertEquals( book, constraintViolation.getRootBean(), "Wrong root entity" );
+ assertEquals( author.getCompany(), constraintViolation.getInvalidValue(), "Wrong value" );
+ assertEquals( "author.company", constraintViolation.getPropertyPath(), "Wrong propertyName" );
author.setCompany( "JBoss" );
constraintViolations = validator.validate( book, First.class, Second.class, Last.class );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -114,35 +110,35 @@
book.setAuthor( author );
Set<ConstraintViolation<Book>> constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( "Wrong number of constraints", 2, constraintViolations.size() );
+ assertEquals( 2, constraintViolations.size(), "Wrong number of constraints" );
author.setFirstName( "Gavin" );
author.setLastName( "King" );
constraintViolations = validator.validate( book, Book.All.class );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
- assertEquals( "Wrong message", "may not be null", constraintViolation.getMessage() );
- assertEquals( "Wrong root entity", book, constraintViolation.getRootBean() );
- assertEquals( "Wrong value", book.getTitle(), constraintViolation.getInvalidValue() );
- assertEquals( "Wrong propertyName", "title", constraintViolation.getPropertyPath() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
+ assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+ assertEquals( book, constraintViolation.getRootBean(), "Wrong root entity" );
+ assertEquals( book.getTitle(), constraintViolation.getInvalidValue(), "Wrong value" );
+ assertEquals( "title", constraintViolation.getPropertyPath(), "Wrong propertyName" );
book.setTitle( "Hibernate Persistence with JPA" );
book.setSubtitle( "Revised Edition of Hibernate in Action" );
constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
book.setSubtitle( "Revised Edition" );
author.setCompany( "JBoss a divison of RedHat" );
constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+ assertEquals( 1, constraintViolations.size(), "Wrong number of constraints" );
author.setCompany( "JBoss" );
constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -158,7 +154,7 @@
dictonary.setAuthor( author );
Set<ConstraintViolation<Dictonary>> constraintViolations = validator.validate( dictonary, DefaultAlias.class );
- assertEquals( "Wrong number of constraints", 0, constraintViolations.size() );
+ assertEquals( 0, constraintViolations.size(), "Wrong number of constraints" );
}
@Test
@@ -172,9 +168,9 @@
elepfant, First.class, Second.class
);
assertEquals(
- "The should be two invalid constraints since the same propertyName gets validated in both groups",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "The should be two invalid constraints since the same propertyName gets validated in both groups"
);
}
@@ -188,65 +184,65 @@
Set<ConstraintViolation<User>> constraintViolations = validator.validate( user );
assertEquals(
- "There should be two violations against the implicit default group",
2,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should be two violations against the implicit default group"
);
constraintViolations = validator.validate( user, Default.class );
assertEquals(
- "There should be two violations against the explicit defualt group",
2,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should be two violations against the explicit defualt group"
);
constraintViolations = validator.validate( user, Billable.class );
assertEquals(
- "There should be one violation against Billable",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should be one violation against Billable"
);
constraintViolations = validator.validate( user, Default.class, Billable.class );
assertEquals(
- "There should be 3 violation against Default and Billable",
3,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should be 3 violation against Default and Billable"
);
constraintViolations = validator.validate( user, BuyInOneClick.class );
assertEquals(
- "Three violations expected since BuyInOneClick extends Default and Billable",
3,
- constraintViolations.size()
+ constraintViolations.size(),
+ "Three violations expected since BuyInOneClick extends Default and Billable"
);
constraintViolations = validator.validate( user, BuyInOneClick.class, Billable.class );
assertEquals(
- "BuyInOneClick already contains all other groups. Adding Billable does not change the number of violations",
3,
- constraintViolations.size()
+ constraintViolations.size(),
+ "BuyInOneClick already contains all other groups. Adding Billable does not change the number of violations"
);
constraintViolations = validator.validate( user, BuyInOneClick.class, Default.class );
assertEquals(
- "BuyInOneClick already contains all other groups. Adding Default does not change the number of violations",
3,
- constraintViolations.size()
+ constraintViolations.size(),
+ "BuyInOneClick already contains all other groups. Adding Default does not change the number of violations"
);
constraintViolations = validator.validate( user, BuyInOneClick.class, Default.class, Billable.class );
assertEquals(
- "BuyInOneClick already contains all other groups. Adding Billable and Default does not change the number of violations",
3,
- constraintViolations.size()
+ constraintViolations.size(),
+ "BuyInOneClick already contains all other groups. Adding Billable and Default does not change the number of violations"
);
constraintViolations = validator.validate( user, Billable.class, Billable.class );
assertEquals(
- "Adding the same group twice is still only leads to a single violation",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "Adding the same group twice is still only leads to a single violation"
);
}
@@ -266,9 +262,9 @@
user, BuyInOneClick.class, Optional.class
);
assertEquals(
- "There should be two violations against the implicit default group",
2,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should be two violations against the implicit default group"
);
for ( ConstraintViolation<User> constraintViolation : constraintViolations ) {
@@ -309,9 +305,9 @@
Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
assertEquals(
- "There should only be one violation for zipcode",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should only be one violation for zipcode"
);
ConstraintViolation<Address> violation = constraintViolations.iterator().next();
@@ -322,9 +318,9 @@
// now the second group in the re-defined default group causes an error
constraintViolations = validator.validate( address );
assertEquals(
- "There should only be one violation for zipcode",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should only be one violation for zipcode"
);
violation = constraintViolations.iterator().next();
@@ -343,38 +339,38 @@
Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );
assertEquals(
- "There should be one violations due to the re-defintion of the default group",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should be one violations due to the re-defintion of the default group"
);
assertEquals(
- "Wrong constraint",
"length must be between 2 and 20",
- constraintViolations.iterator().next().getMessage()
+ constraintViolations.iterator().next().getMessage(),
+ "Wrong constraint"
);
constraintViolations = validator.validateProperty( car, "type" );
assertEquals(
- "There should be one violations due to the re-defintion of the default group",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should be one violations due to the re-defintion of the default group"
);
assertEquals(
- "Wrong constraint",
"length must be between 2 and 20",
- constraintViolations.iterator().next().getMessage()
+ constraintViolations.iterator().next().getMessage(),
+ "Wrong constraint"
);
constraintViolations = validator.validateValue( Car.class, "type", "A" );
assertEquals(
- "There should be one violations due to the re-defintion of the default group",
1,
- constraintViolations.size()
+ constraintViolations.size(),
+ "There should be one violations due to the re-defintion of the default group"
);
assertEquals(
- "Wrong constraint",
"length must be between 2 and 20",
- constraintViolations.iterator().next().getMessage()
+ constraintViolations.iterator().next().getMessage(),
+ "Wrong constraint"
);
}
@@ -391,7 +387,7 @@
}
catch ( ValidationException e ) {
assertEquals(
- "Wrong message", "'Default.class' cannot appear in default group sequence list.", e.getMessage()
+ "'Default.class' cannot appear in default group sequence list.", e.getMessage(), "Wrong message"
);
}
}
@@ -406,14 +402,14 @@
assertTrue( beanDescriptor.isBeanConstrained() );
Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
- assertTrue( "Each of the properties should have at least one constraint.", constraintProperties.size() == 5 );
+ assertTrue( constraintProperties.size() == 5, "Each of the properties should have at least one constraint." );
Order order = new Order();
Set<ConstraintViolation<Order>> violations = validator.validate( order );
- assertTrue( "All 5 NotNull constraints should fail.", violations.size() == 5 );
+ assertTrue( violations.size() == 5, "All 5 NotNull constraints should fail." );
// use implicit group Auditable
violations = validator.validate( order, Auditable.class );
- assertTrue( "All 4 NotNull constraints on Auditable should fail.", violations.size() == 4 );
+ assertTrue( violations.size() == 4, "All 4 NotNull constraints on Auditable should fail." );
}
}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/BeanDescriptorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/BeanDescriptorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/BeanDescriptorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -22,14 +22,16 @@
import javax.validation.PropertyDescriptor;
import javax.validation.Validator;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import org.slf4j.Logger;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
import org.hibernate.validation.engine.Order;
+import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.TestUtil;
@@ -38,32 +40,34 @@
*/
public class BeanDescriptorTest {
+ private static final Logger log = LoggerFactory.make();
+
@Test
public void testIsBeanConstrained() {
Validator validator = TestUtil.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
// constraint via @Valid
- assertFalse( "There should be no direct constraints on the specified bean.", beanDescriptor.hasConstraints() );
- assertTrue( "Bean should be constrainted due to @valid ", beanDescriptor.isBeanConstrained() );
+ assertFalse( beanDescriptor.hasConstraints(), "There should be no direct constraints on the specified bean." );
+ assertTrue( beanDescriptor.isBeanConstrained(), "Bean should be constrainted due to @valid " );
// constraint hosted on bean itself
beanDescriptor = validator.getConstraintsForClass( Account.class );
- assertTrue( "There should be direct constraints on the specified bean.", beanDescriptor.hasConstraints() );
- assertTrue( "Bean should be constrainted due to @valid", beanDescriptor.isBeanConstrained() );
+ assertTrue( beanDescriptor.hasConstraints(), "There should be direct constraints on the specified bean." );
+ assertTrue( beanDescriptor.isBeanConstrained(), "Bean should be constrainted due to @valid" );
// constraint on bean property
beanDescriptor = validator.getConstraintsForClass( Order.class );
- assertFalse( "There should be no direct constraints on the specified bean.", beanDescriptor.hasConstraints() );
- assertTrue( "Bean should be constrainted due to @NotNull", beanDescriptor.isBeanConstrained() );
+ assertFalse( beanDescriptor.hasConstraints(), "There should be no direct constraints on the specified bean." );
+ assertTrue( beanDescriptor.isBeanConstrained(), "Bean should be constrainted due to @NotNull" );
}
@Test
public void testUnconstraintClass() {
Validator validator = TestUtil.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( UnconstraintEntity.class );
- assertFalse( "There should be no direct constraints on the specified bean.", beanDescriptor.hasConstraints() );
- assertFalse( "Bean should be unconstrainted.", beanDescriptor.isBeanConstrained() );
+ assertFalse( beanDescriptor.hasConstraints(), "There should be no direct constraints on the specified bean." );
+ assertFalse( beanDescriptor.isBeanConstrained(), "Bean should be unconstrainted." );
}
@Test
@@ -72,15 +76,15 @@
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderNumber" );
assertEquals(
- "There should be one constraint descriptor", 1, propertyDescriptor.getConstraintDescriptors().size()
+ 1, propertyDescriptor.getConstraintDescriptors().size(), "There should be one constraint descriptor"
);
beanDescriptor = validator.getConstraintsForClass( Customer.class );
propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderList" );
assertEquals(
- "There should be no constraint descriptors", 0, propertyDescriptor.getConstraintDescriptors().size()
+ 0, propertyDescriptor.getConstraintDescriptors().size(), "There should be no constraint descriptors"
);
- assertTrue( "The property should be cascaded", propertyDescriptor.isCascaded() );
+ assertTrue( propertyDescriptor.isCascaded(), "The property should be cascaded" );
}
@Test
@@ -89,16 +93,16 @@
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderList" );
assertEquals(
- "There should be no constraint descriptors", 0, propertyDescriptor.getConstraintDescriptors().size()
+ 0, propertyDescriptor.getConstraintDescriptors().size(), "There should be no constraint descriptors"
);
- assertTrue( "The property should be cascaded", propertyDescriptor.isCascaded() );
+ assertTrue( propertyDescriptor.isCascaded(), "The property should be cascaded" );
}
@Test
public void testGetConstraintsForNonExistingProperty() {
Validator validator = TestUtil.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
- assertNull( "There should be no descriptor", beanDescriptor.getConstraintsForProperty( "foobar" ) );
+ assertNull( beanDescriptor.getConstraintsForProperty( "foobar" ), "There should be no descriptor" );
}
/**
@@ -108,7 +112,7 @@
public void testGetConstraintsForNullProperty() {
Validator validator = TestUtil.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
- assertNull( "There should be no descriptor", beanDescriptor.getConstraintsForProperty( null ) );
+ assertNull( beanDescriptor.getConstraintsForProperty( null ), "There should be no descriptor" );
}
/**
@@ -119,12 +123,12 @@
Validator validator = TestUtil.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
- assertEquals( "There should be only one property", 1, constraintProperties.size() );
+ assertEquals( 1, constraintProperties.size(), "There should be only one property" );
boolean hasOrderNumber = false;
for ( PropertyDescriptor pd : constraintProperties ) {
hasOrderNumber |= pd.getPropertyName().equals( "orderNumber" );
}
- assertTrue( "Wrong property", hasOrderNumber );
+ assertTrue( hasOrderNumber, "Wrong property" );
}
/**
@@ -140,7 +144,7 @@
fail( "Set should be immutable" );
}
catch ( UnsupportedOperationException e ) {
-
+ log.trace( "success" );
}
try {
@@ -148,7 +152,7 @@
fail( "Set should be immutable" );
}
catch ( UnsupportedOperationException e ) {
-
+ log.trace( "success" );
}
}
@@ -160,6 +164,6 @@
Validator validator = TestUtil.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( UnconstraintEntity.class );
Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
- assertEquals( "We should get the empty set.", 0, constraintProperties.size() );
+ assertEquals( 0, constraintProperties.size(), "We should get the empty set." );
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ConstraintDescriptorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ConstraintDescriptorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ConstraintDescriptorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -24,16 +24,18 @@
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
-import static junit.framework.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import org.slf4j.Logger;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+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.validation.constraints.NotNullValidator;
import org.hibernate.validation.engine.Order;
import org.hibernate.validation.engine.constraintcomposition.GermanAddress;
+import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.TestUtil;
@@ -41,6 +43,8 @@
* @author Hardy Ferentschik
*/
public class ConstraintDescriptorTest {
+ private static final Logger log = LoggerFactory.make();
+
@Test
public void testConstraintDescriptorImmutable() {
ConstraintDescriptor<?> descriptor = TestUtil.getSingleConstraintDescriptorFor( Order.class, "orderNumber" );
@@ -50,7 +54,7 @@
fail( "Should be immutable" );
}
catch ( UnsupportedOperationException e ) {
-
+ log.trace( "success" );
}
try {
@@ -58,7 +62,7 @@
fail( "Should be immutable" );
}
catch ( UnsupportedOperationException e ) {
-
+ log.trace( "success" );
}
try {
@@ -66,7 +70,7 @@
fail( "Should be immutable" );
}
catch ( UnsupportedOperationException e ) {
-
+ log.trace( "success" );
}
try {
@@ -74,7 +78,7 @@
fail( "Should be immutable" );
}
catch ( UnsupportedOperationException e ) {
-
+ log.trace( "success" );
}
}
@@ -101,7 +105,7 @@
ConstraintDescriptor<?> descriptor = TestUtil.getSingleConstraintDescriptorFor(
GermanAddress.class, "zipCode"
);
- assertEquals( "Wrong number of composing constraints", 1, descriptor.getComposingConstraints().size() );
+ assertEquals( 1, descriptor.getComposingConstraints().size(), "Wrong number of composing constraints" );
}
@Test
@@ -117,13 +121,13 @@
ConstraintDescriptor<?> descriptor = TestUtil.getSingleConstraintDescriptorFor( Order.class, "orderNumber" );
Set<Class<?>> groups = descriptor.getGroups();
assertTrue( groups.size() == 1 );
- assertEquals( "Wrong group", Default.class, groups.iterator().next() );
+ assertEquals( Default.class, groups.iterator().next(), "Wrong group" );
}
@Test
public void testGetConstraintValidatorClasses() {
ConstraintDescriptor<?> descriptor = TestUtil.getSingleConstraintDescriptorFor( Order.class, "orderNumber" );
- assertEquals( "Wrong classes", NotNullValidator.class, descriptor.getConstraintValidatorClasses().get( 0 ) );
+ assertEquals( NotNullValidator.class, descriptor.getConstraintValidatorClasses().get( 0 ), "Wrong classes" );
}
@Test
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ElementDescriptorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ElementDescriptorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/ElementDescriptorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -23,12 +23,14 @@
import javax.validation.ElementDescriptor;
import javax.validation.Validator;
-import static junit.framework.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import org.slf4j.Logger;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
import org.hibernate.validation.engine.Order;
+import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.TestUtil;
@@ -37,17 +39,19 @@
*/
public class ElementDescriptorTest {
+ private static final Logger log = LoggerFactory.make();
+
@Test
public void testGetTypeForConstrainedBean() {
Validator validator = TestUtil.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
- assertEquals( "Wrong type.", Customer.class, beanDescriptor.getType() );
+ assertEquals( Customer.class, beanDescriptor.getType(), "Wrong type." );
}
@Test
public void testGetTypeForConstrainedProperty() {
ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
- assertEquals( "Wrong type.", Integer.class, elementDescriptor.getType() );
+ assertEquals( Integer.class, elementDescriptor.getType(), "Wrong type." );
}
/**
@@ -57,7 +61,7 @@
public void testElementDescriptorForProperty() {
ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
Set<ConstraintDescriptor<?>> constraintDescriptors = elementDescriptor.getConstraintDescriptors();
- assertTrue( "There should be a descriptor", constraintDescriptors.size() == 1 );
+ assertTrue( constraintDescriptors.size() == 1, "There should be a descriptor" );
}
/**
@@ -73,7 +77,7 @@
fail( "Set should be immutable" );
}
catch ( UnsupportedOperationException e ) {
-
+ log.trace( "success" );
}
try {
@@ -81,7 +85,7 @@
fail( "Set should be immutable" );
}
catch ( UnsupportedOperationException e ) {
-
+ log.trace( "success" );
}
}
}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/PropertyDescriptorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/PropertyDescriptorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/metadata/PropertyDescriptorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -19,10 +19,10 @@
import javax.validation.PropertyDescriptor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
import org.hibernate.validation.engine.Order;
import org.hibernate.validation.util.TestUtil;
@@ -35,19 +35,19 @@
@Test
public void testIsNotCascaded() {
PropertyDescriptor descriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
- assertFalse( "Should not be cascaded", descriptor.isCascaded() );
+ assertFalse( descriptor.isCascaded(), "Should not be cascaded" );
}
@Test
public void testIsCascaded() {
PropertyDescriptor descriptor = TestUtil.getPropertyDescriptor( Customer.class, "orderList" );
- assertTrue( "Should be cascaded", descriptor.isCascaded() );
+ assertTrue( descriptor.isCascaded(), "Should be cascaded" );
}
@Test
public void testPropertyName() {
String propertyName = "orderList";
PropertyDescriptor descriptor = TestUtil.getPropertyDescriptor( Customer.class, propertyName );
- assertEquals( "Wrong property name", propertyName, descriptor.getPropertyName() );
+ assertEquals( propertyName, descriptor.getPropertyName(), "Wrong property name" );
}
}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/ValidatorResolutionTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/ValidatorResolutionTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/validatorresolution/ValidatorResolutionTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -17,19 +17,18 @@
*/
package org.hibernate.validation.engine.validatorresolution;
-import java.util.Set;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.UnexpectedTypeException;
import javax.validation.Validator;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
-import org.hibernate.validation.engine.validatorresolution.MultipleMinMax;
import static org.hibernate.validation.util.TestUtil.assertConstraintViolation;
import static org.hibernate.validation.util.TestUtil.assertNumberOfViolations;
import static org.hibernate.validation.util.TestUtil.getValidator;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/IdentitySetTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/IdentitySetTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/IdentitySetTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -20,8 +20,8 @@
import java.util.HashSet;
import java.util.Set;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyIteratorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyIteratorTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/PropertyIteratorTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -17,10 +17,10 @@
*/
package org.hibernate.validation.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
/**
* @author Hardy Ferentschik
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ReflectionHelperTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -31,12 +31,12 @@
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
/**
* Tests for the <code>ReflectionHelper</code>.
@@ -93,17 +93,17 @@
map.put( key, testObject );
Object value = ReflectionHelper.getIndexedValue( map, key );
- assertEquals( "We should be able to retrieve the indexed object", testObject, value );
+ assertEquals( testObject, value, "We should be able to retrieve the indexed object" );
// try to get to the value by integer index
value = ReflectionHelper.getIndexedValue( map, "0" );
- assertEquals( "We should be able to retrieve the indexed object", testObject, value );
+ assertEquals( testObject, value, "We should be able to retrieve the indexed object" );
value = ReflectionHelper.getIndexedValue( map, "foo" );
- assertNull( "A non existent index should return the null value", value );
+ assertNull( value, "A non existent index should return the null value" );
value = ReflectionHelper.getIndexedValue( map, "2" );
- assertNull( "A non existent index should return the null value", value );
+ assertNull( value, "A non existent index should return the null value" );
}
@Test
@@ -113,10 +113,10 @@
list.add( testObject );
Object value = ReflectionHelper.getIndexedValue( list, "0" );
- assertEquals( "We should be able to retrieve the indexed object", testObject, value );
+ assertEquals( testObject, value, "We should be able to retrieve the indexed object" );
value = ReflectionHelper.getIndexedValue( list, "2" );
- assertNull( "A non existent index should return the null value", value );
+ assertNull( value, "A non existent index should return the null value" );
}
@Test
@@ -141,17 +141,17 @@
}
};
String message = ReflectionHelper.getAnnotationParameter( testAnnotation, "message", String.class );
- assertEquals( "Wrong message", "test", message );
+ assertEquals( "test", message, "Wrong message" );
Class<?>[] group = ReflectionHelper.getAnnotationParameter( testAnnotation, "groups", Class[].class );
- assertEquals( "Wrong message", Default.class, group[0] );
+ assertEquals( Default.class, group[0], "Wrong message" );
try {
ReflectionHelper.getAnnotationParameter( testAnnotation, "message", Integer.class );
fail();
}
catch ( ValidationException e ) {
- assertTrue( "Wrong exception message", e.getMessage().startsWith( "Wrong parameter type." ) );
+ assertTrue( e.getMessage().startsWith( "Wrong parameter type." ), "Wrong exception message" );
}
try {
@@ -160,8 +160,8 @@
}
catch ( ValidationException e ) {
assertTrue(
- "Wrong exception message",
- e.getMessage().startsWith( "The specified annotation defines no parameter" )
+ e.getMessage().startsWith( "The specified annotation defines no parameter" ),
+ "Wrong exception message"
);
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/TestUtil.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -21,12 +21,12 @@
import javax.validation.ConstraintDescriptor;
import javax.validation.ConstraintViolation;
import javax.validation.ElementDescriptor;
+import javax.validation.PropertyDescriptor;
import javax.validation.Validation;
import javax.validation.Validator;
-import javax.validation.PropertyDescriptor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
import org.hibernate.validation.engine.HibernateValidatorConfiguration;
@@ -55,7 +55,7 @@
public static ConstraintDescriptor<?> getSingleConstraintDescriptorFor(Class<?> clazz, String property) {
Set<ConstraintDescriptor<?>> constraintDescriptors = getConstraintDescriptorsFor( clazz, property );
assertTrue(
- "This method should only be used when there is a single constraint", constraintDescriptors.size() == 1
+ constraintDescriptors.size() == 1, "This method should only be used when there is a single constraint"
);
return constraintDescriptors.iterator().next();
}
@@ -72,45 +72,46 @@
public static void assertConstraintViolation(ConstraintViolation violation, String errorMessage, Class rootBean, Object invalidValue, String propertyPath, Class leafBean) {
assertEquals(
- "Wrong leaf bean type",
+
leafBean,
- violation.getLeafBean().getClass()
+ violation.getLeafBean().getClass(),
+ "Wrong leaf bean type"
);
assertConstraintViolation( violation, errorMessage, rootBean, invalidValue, propertyPath );
}
public static void assertConstraintViolation(ConstraintViolation violation, String errorMessage, Class rootBean, Object invalidValue, String propertyPath) {
assertEquals(
- "Wrong propertyPath",
propertyPath,
- violation.getPropertyPath()
+ violation.getPropertyPath(),
+ "Wrong propertyPath"
);
assertConstraintViolation( violation, errorMessage, rootBean, invalidValue );
}
public static void assertConstraintViolation(ConstraintViolation violation, String errorMessage, Class rootBean, Object invalidValue) {
assertEquals(
- "Wrong invalid value",
invalidValue,
- violation.getInvalidValue()
+ violation.getInvalidValue(),
+ "Wrong invalid value"
);
assertConstraintViolation( violation, errorMessage, rootBean );
}
public static void assertConstraintViolation(ConstraintViolation violation, String errorMessage, Class rootBean) {
assertEquals(
- "Wrong root bean type",
rootBean,
- violation.getRootBean().getClass()
+ violation.getRootBean().getClass(),
+ "Wrong root bean type"
);
assertConstraintViolation( violation, errorMessage );
}
public static void assertConstraintViolation(ConstraintViolation violation, String message) {
- assertEquals( "Wrong message", message, violation.getMessage() );
+ assertEquals( message, violation.getMessage(), "Wrong message" );
}
public static void assertNumberOfViolations(Set violations, int expectedViolations) {
- assertEquals( "Wrong number of constraint violations", expectedViolations, violations.size() );
+ assertEquals( expectedViolations, violations.size(), "Wrong number of constraint violations" );
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/ValidatorTypeTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -17,18 +17,17 @@
*/
package org.hibernate.validation.util;
-import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.validation.ConstraintValidator;
-import static org.junit.Assert.assertEquals;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
-import org.hibernate.validation.constraints.composition.FrenchZipcodeConstraintValidator;
import org.hibernate.validation.constraints.composition.FrenchZipcode;
+import org.hibernate.validation.constraints.composition.FrenchZipcodeConstraintValidator;
/**
* Tests for message resolution.
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/annotationfactory/AnnotationFactoryTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/annotationfactory/AnnotationFactoryTest.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/annotationfactory/AnnotationFactoryTest.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -17,11 +17,11 @@
*/
package org.hibernate.validation.util.annotationfactory;
+import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
-import javax.validation.constraints.Pattern;
-import static org.junit.Assert.assertEquals;
-import org.junit.Test;
+import static org.testng.Assert.assertEquals;
+import org.testng.annotations.Test;
/**
@@ -37,11 +37,11 @@
Size size = AnnotationFactory.create( descriptor );
- assertEquals( "Wrong parameter value", 5, size.min() );
- assertEquals( "Wrong parameter value", 10, size.max() );
+ assertEquals( 5, size.min(), "Wrong parameter value" );
+ assertEquals( 10, size.max(), "Wrong parameter value" );
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expectedExceptions = IllegalArgumentException.class)
public void createAnnotationProxyMissingRequiredParamter() {
AnnotationDescriptor<Pattern> descriptor = new AnnotationDescriptor<Pattern>( Pattern.class );
AnnotationFactory.create( descriptor );
@@ -54,6 +54,6 @@
Pattern pattern = AnnotationFactory.create( descriptor );
- assertEquals( "Wrong parameter value", ".*", pattern.regexp() );
+ assertEquals( ".*", pattern.regexp(), "Wrong parameter value" );
}
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/Junit4TestFactory.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/Junit4TestFactory.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/Junit4TestFactory.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
@@ -17,36 +17,36 @@
*/
package org.hibernate.validation.util.performance;
-import java.util.List;
+//import java.util.List;
+//
+//import com.clarkware.junitperf.TestFactory;
+//import junit.framework.JUnit4TestAdapter;
+//import junit.framework.TestCase;
+//import junit.framework.TestSuite;
-import com.clarkware.junitperf.TestFactory;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+class JUnit4TestFactory { //extends TestFactory {
-class JUnit4TestFactory extends TestFactory {
-
- static class DummyTestCase extends TestCase {
- public void test() {
- }
- }
-
- private List<Class<?>> junit4TestClass;
-
- public JUnit4TestFactory(List<Class<?>> testClasses) {
- super( DummyTestCase.class );
- this.junit4TestClass = testClasses;
- }
-
- @Override
- protected TestSuite makeTestSuite() {
- TestSuite testSuite = new TestSuite( "JUnit4TestFactory" );
- JUnit4TestAdapter unit4TestAdapter;
- for ( Class<?> testClass : junit4TestClass ) {
- unit4TestAdapter = new JUnit4TestAdapter( testClass );
- testSuite.addTest( unit4TestAdapter );
- }
- return testSuite;
- }
+// static class DummyTestCase extends TestCase {
+// public void test() {
+// }
+// }
+//
+// private List<Class<?>> junit4TestClass;
+//
+// public JUnit4TestFactory(List<Class<?>> testClasses) {
+// super( DummyTestCase.class );
+// this.junit4TestClass = testClasses;
+// }
+//
+// @Override
+// protected TestSuite makeTestSuite() {
+// TestSuite testSuite = new TestSuite( "JUnit4TestFactory" );
+// JUnit4TestAdapter unit4TestAdapter;
+// for ( Class<?> testClass : junit4TestClass ) {
+// unit4TestAdapter = new JUnit4TestAdapter( testClass );
+// testSuite.addTest( unit4TestAdapter );
+// }
+// return testSuite;
+// }
}
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java 2009-04-01 13:04:03 UTC (rev 16248)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/util/performance/ValidationPerformace.java 2009-04-02 12:10:40 UTC (rev 16249)
@@ -20,8 +20,8 @@
import java.util.ArrayList;
import java.util.List;
-import com.clarkware.junitperf.TimedTest;
-import junit.framework.Test;
+//import com.clarkware.junitperf.TimedTest;
+//import junit.framework.Test;
import org.hibernate.validation.engine.ValidatorImplTest;
import org.hibernate.validation.engine.ResourceBundleMessageInterpolatorTest;
@@ -34,18 +34,18 @@
*/
public class ValidationPerformace {
- public static Test suite() {
-
- long maxTimeInMillis = 1000;
- List<Class<?>> testClasses = new ArrayList<Class<?>>();
- //testClasses.add( ValidatorImplTest.class );
- testClasses.add( ResourceBundleMessageInterpolatorTest.class );
- //testClasses.add( ConstraintCompositionTest.class );
- Test test = new JUnit4TestFactory( testClasses ).makeTestSuite();
- return new TimedTest( test, maxTimeInMillis );
- }
-
- public static void main(String args[]) {
- junit.textui.TestRunner.run( suite() );
- }
+// public static Test suite() {
+//
+// long maxTimeInMillis = 1000;
+// List<Class<?>> testClasses = new ArrayList<Class<?>>();
+// //testClasses.add( ValidatorImplTest.class );
+// testClasses.add( ResourceBundleMessageInterpolatorTest.class );
+// //testClasses.add( ConstraintCompositionTest.class );
+// Test test = new JUnit4TestFactory( testClasses ).makeTestSuite();
+// return new TimedTest( test, maxTimeInMillis );
+// }
+//
+// public static void main(String args[]) {
+// junit.textui.TestRunner.run( suite() );
+// }
}
Added: validator/trunk/hibernate-validator/src/test/suite/unit-tests.xml
===================================================================
--- validator/trunk/hibernate-validator/src/test/suite/unit-tests.xml (rev 0)
+++ validator/trunk/hibernate-validator/src/test/suite/unit-tests.xml 2009-04-02 12:10:40 UTC (rev 16249)
@@ -0,0 +1,19 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+
+<suite name="Hibernate Validator Unit Tests" verbose="1">
+ <test name="Unit tests">
+ <packages>
+ <package name="org.hibernate.validation.bootstrap"/>
+ <package name="org.hibernate.validation.constraints"/>
+ <package name="org.hibernate.validation.constraints.validatorcontext"/>
+ <package name="org.hibernate.validation.engine"/>
+ <package name="org.hibernate.validation.engine.constraintcomposition"/>
+ <package name="org.hibernate.validation.engine.graphnavigation"/>
+ <package name="org.hibernate.validation.engine.groups"/>
+ <package name="org.hibernate.validation.engine.metadata"/>
+ <package name="org.hibernate.validation.engine.validatorresolution"/>
+ <package name="org.hibernate.validation.util"/>
+ <package name="org.hibernate.validation.util.annotationfactory"/>
+ </packages>
+ </test>
+</suite>
\ No newline at end of file
15 years, 8 months
Hibernate SVN: r16248 - in validator/trunk: hibernate-validator and 7 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-04-01 09:04:03 -0400 (Wed, 01 Apr 2009)
New Revision: 16248
Added:
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/order-constraints.xml
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml
Modified:
validator/trunk/hibernate-validator-legacy/pom.xml
validator/trunk/hibernate-validator/pom.xml
validator/trunk/hibernate-validator/src/main/docbook/en-US/master.xml
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
validator/trunk/hibernate-validator/src/main/xsd/validation-configuration-1.0.xsd
validator/trunk/hibernate-validator/src/test/resources/META-INF/validation.xml
validator/trunk/pom.xml
Log:
HV-111 Completed the validation.xml parsing code.
Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml 2009-03-31 22:26:36 UTC (rev 16247)
+++ validator/trunk/hibernate-validator/pom.xml 2009-04-01 13:04:03 UTC (rev 16248)
@@ -1,8 +1,10 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>hibernate-validator-parent</artifactId>
<groupId>org.hibernate</groupId>
- <version>4.0.0.Alpha4-SNAPSHOT</version>
+ <version>4.0.0.Beta1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -66,7 +68,8 @@
<filtering>true</filtering>
</resource>
<resource>
- <directory>src/main/xsd</directory>
+ <directory>src/main/xsd</directory>
+ <targetPath>META-INF</targetPath>
</resource>
</resources>
<plugins>
@@ -211,8 +214,8 @@
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.1.3</version>
- </dependency>
+ </dependency>
</dependencies>
</profile>
- </profiles>
+ </profiles>
</project>
Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/master.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/master.xml 2009-03-31 22:26:36 UTC (rev 16247)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/master.xml 2009-04-01 13:04:03 UTC (rev 16248)
@@ -25,7 +25,7 @@
-->
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
-<!ENTITY versionNumber "4.0.0.Alpha3">
+<!ENTITY versionNumber "4.0.0.Beta1">
<!ENTITY copyrightYear "2009">
<!ENTITY copyrightHolder "Red Hat Middleware, LLC. & Gunnar Morling">
]>
Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml 2009-03-31 22:26:36 UTC (rev 16247)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml 2009-04-01 13:04:03 UTC (rev 16248)
@@ -147,7 +147,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
- <version>4.0.0.Alpha3</version>
+ <version>4.0.0.Beta1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-03-31 22:26:36 UTC (rev 16247)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConfigurationImpl.java 2009-04-01 13:04:03 UTC (rev 16248)
@@ -49,6 +49,7 @@
import org.hibernate.validation.util.LoggerFactory;
import org.hibernate.validation.util.ReflectionHelper;
import org.hibernate.validation.util.Version;
+import org.hibernate.validation.xml.PropertyType;
import org.hibernate.validation.xml.ValidationConfigType;
/**
@@ -65,20 +66,15 @@
private static final Logger log = LoggerFactory.make();
private static final String VALIDATION_XML_FILE = "/META-INF/validation.xml";
- private static final String VALIDATION_CONFIGURATION_XSD = "validation-configuration-1.0.xsd";
+ private static final String VALIDATION_CONFIGURATION_XSD = "META-INF/validation-configuration-1.0.xsd";
private static final MessageInterpolator defaultMessageInterpolator = new ResourceBundleMessageInterpolator();
private static final TraversableResolver defaultTraversableResolver = new DefaultTraversableResolver();
+ private static final ConstraintValidatorFactory defaultValidatorFactory = new ConstraintValidatorFactoryImpl();
- private final ValidationProvider provider;
private final ValidationProviderResolver providerResolver;
- private final Map<String, String> configProperties = new HashMap<String, String>();
- private final Set<InputStream> mappings = new HashSet<InputStream>();
- private MessageInterpolator messageInterpolator;
- private ConstraintValidatorFactory constraintValidatorFactory = new ConstraintValidatorFactoryImpl();
- private TraversableResolver traversableResolver;
- private boolean ignoreXmlConfiguration = true; // false;
- private Class<? extends Configuration<?>> providerClass = null;
+ private ParameterHolder parameterHolder;
+ private boolean ignoreXmlConfiguration = false;
public ConfigurationImpl(BootstrapState state) {
if ( state.getValidationProviderResolver() == null ) {
@@ -87,19 +83,16 @@
else {
this.providerResolver = state.getValidationProviderResolver();
}
- this.provider = null;
- this.messageInterpolator = defaultMessageInterpolator;
- this.traversableResolver = defaultTraversableResolver;
+ parameterHolder = new ParameterHolder();
}
public ConfigurationImpl(ValidationProvider provider) {
if ( provider == null ) {
throw new ValidationException( "Assertion error: inconsistent ConfigurationImpl construction" );
}
- this.provider = provider;
this.providerResolver = null;
- this.messageInterpolator = defaultMessageInterpolator;
- this.traversableResolver = defaultTraversableResolver;
+ parameterHolder = new ParameterHolder();
+ parameterHolder.provider = provider;
}
public HibernateValidatorConfiguration ignoreXmlConfiguration() {
@@ -108,43 +101,45 @@
}
public ConfigurationImpl messageInterpolator(MessageInterpolator interpolator) {
- this.messageInterpolator = interpolator;
+ this.parameterHolder.messageInterpolator = interpolator;
return this;
}
public ConfigurationImpl traversableResolver(TraversableResolver resolver) {
- this.traversableResolver = resolver;
+ this.parameterHolder.traversableResolver = resolver;
return this;
}
public ConfigurationImpl constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory) {
- this.constraintValidatorFactory = constraintValidatorFactory;
+ this.parameterHolder.constraintValidatorFactory = constraintValidatorFactory;
return this;
}
public HibernateValidatorConfiguration addMapping(InputStream stream) {
- mappings.add( stream );
+ parameterHolder.mappings.add( stream );
return this;
}
public HibernateValidatorConfiguration addProperty(String name, String value) {
- configProperties.put( name, value );
+ if ( value != null ) {
+ parameterHolder.configProperties.put( name, value );
+ }
return this;
}
public ValidatorFactory buildValidatorFactory() {
parseValidationXml();
if ( isSpecificProvider() ) {
- return provider.buildValidatorFactory( this );
+ return parameterHolder.provider.buildValidatorFactory( this );
}
else {
- if ( providerClass != null ) {
+ if ( parameterHolder.providerClass != null ) {
for ( ValidationProvider provider : providerResolver.getValidationProviders() ) {
- if ( provider.isSuitable( providerClass ) ) {
+ if ( provider.isSuitable( parameterHolder.providerClass ) ) {
return provider.buildValidatorFactory( this );
}
}
- throw new ValidationException( "Unable to find provider: " + providerClass );
+ throw new ValidationException( "Unable to find provider: " + parameterHolder.providerClass );
}
else {
List<ValidationProvider> providers = providerResolver.getValidationProviders();
@@ -159,23 +154,23 @@
}
public MessageInterpolator getMessageInterpolator() {
- return messageInterpolator;
+ return parameterHolder.messageInterpolator;
}
public Set<InputStream> getMappingStreams() {
- return mappings;
+ return parameterHolder.mappings;
}
public ConstraintValidatorFactory getConstraintValidatorFactory() {
- return constraintValidatorFactory;
+ return parameterHolder.constraintValidatorFactory;
}
public TraversableResolver getTraversableResolver() {
- return traversableResolver;
+ return parameterHolder.traversableResolver;
}
public Map<String, String> getProperties() {
- return configProperties;
+ return parameterHolder.configProperties;
}
public MessageInterpolator getDefaultMessageInterpolator() {
@@ -183,7 +178,7 @@
}
private boolean isSpecificProvider() {
- return provider != null;
+ return parameterHolder.provider != null;
}
/**
@@ -200,12 +195,103 @@
return;
}
- setMessageInterpolatorFromXml( config );
- setTraversableResolverFromXml( config );
- setProviderClassFromXml( config );
+ // collect the paramters from the xml file
+ ParameterHolder xmlParameters = new ParameterHolder();
+ setProviderClassFromXml( config, xmlParameters );
+ setMessageInterpolatorFromXml( config, xmlParameters );
+ setTraversableResolverFromXml( config, xmlParameters );
+ setConstraintFactoryFromXml( config, xmlParameters );
+ setMappingStreamsFromXml( config, xmlParameters );
+ setPropertiesFromXml( config, xmlParameters );
+
+ applyXmlSettings( xmlParameters );
}
- private void setMessageInterpolatorFromXml(ValidationConfigType config) {
+ private void applyXmlSettings(ParameterHolder xmlParameters) {
+ parameterHolder.providerClass = xmlParameters.providerClass;
+
+ if ( parameterHolder.messageInterpolator == null ) {
+ if ( xmlParameters.messageInterpolator != null ) {
+ parameterHolder.messageInterpolator = xmlParameters.messageInterpolator;
+ }
+ else {
+ parameterHolder.messageInterpolator = defaultMessageInterpolator;
+ }
+ }
+
+ if ( parameterHolder.traversableResolver == null ) {
+ if ( xmlParameters.traversableResolver != null ) {
+ parameterHolder.traversableResolver = xmlParameters.traversableResolver;
+ }
+ else {
+ parameterHolder.traversableResolver = defaultTraversableResolver;
+ }
+ }
+
+ if ( parameterHolder.constraintValidatorFactory == null ) {
+ if ( xmlParameters.constraintValidatorFactory != null ) {
+ parameterHolder.constraintValidatorFactory = xmlParameters.constraintValidatorFactory;
+ }
+ else {
+ parameterHolder.constraintValidatorFactory = defaultValidatorFactory;
+ }
+ }
+
+ parameterHolder.mappings.addAll( xmlParameters.mappings );
+
+ for ( Map.Entry<String, String> entry : xmlParameters.configProperties.entrySet() ) {
+ if ( parameterHolder.configProperties.get( entry.getKey() ) == null ) {
+ parameterHolder.configProperties.put( entry.getKey(), entry.getValue() );
+ }
+ }
+ }
+
+ private void setConstraintFactoryFromXml(ValidationConfigType config, ParameterHolder xmlParameters) {
+ String constraintFactoryClass = config.getConstraintValidatorFactory();
+ if ( constraintFactoryClass != null ) {
+ try {
+ @SuppressWarnings("unchecked")
+ Class<ConstraintValidatorFactory> clazz = ( Class<ConstraintValidatorFactory> ) ReflectionHelper.classForName(
+ constraintFactoryClass, this.getClass()
+ );
+ xmlParameters.constraintValidatorFactory = clazz.newInstance();
+ log.info( "Using {} as constraint factory.", constraintFactoryClass );
+ }
+ catch ( Exception e ) {
+ throw new ValidationException( "Unable to instantiate message interpolator class " + constraintFactoryClass + "." );
+ }
+ }
+ }
+
+ private void setPropertiesFromXml(ValidationConfigType config, ParameterHolder xmlParameters) {
+ for ( PropertyType property : config.getProperty() ) {
+ if ( log.isDebugEnabled() ) {
+ log.debug(
+ "Found property '{}' with value '{}' in validation.xml.",
+ property.getName(),
+ property.getValue()
+ );
+ }
+ xmlParameters.configProperties.put( property.getName(), property.getValue() );
+ }
+ }
+
+ private void setMappingStreamsFromXml(ValidationConfigType config, ParameterHolder xmlParameters) {
+ for ( String mappingFileName : config.getConstraintMapping() ) {
+ if ( log.isDebugEnabled() ) {
+ log.debug(
+ "Trying to open input stream for {}.", mappingFileName
+ );
+ InputStream in = getInputStreamForPath( mappingFileName );
+ if ( in == null ) {
+ throw new ValidationException( " Unable to open input stream for mapping file." );
+ }
+ xmlParameters.mappings.add( in );
+ }
+ }
+ }
+
+ private void setMessageInterpolatorFromXml(ValidationConfigType config, ParameterHolder xmlParameters) {
String messageInterpolatorClass = config.getMessageInterpolator();
if ( messageInterpolatorClass != null ) {
try {
@@ -213,7 +299,7 @@
Class<MessageInterpolator> clazz = ( Class<MessageInterpolator> ) ReflectionHelper.classForName(
messageInterpolatorClass, this.getClass()
);
- messageInterpolator = clazz.newInstance();
+ xmlParameters.messageInterpolator = clazz.newInstance();
log.info( "Using {} as message interpolator.", messageInterpolatorClass );
}
catch ( Exception e ) {
@@ -222,7 +308,7 @@
}
}
- private void setTraversableResolverFromXml(ValidationConfigType config) {
+ private void setTraversableResolverFromXml(ValidationConfigType config, ParameterHolder xmlParameters) {
String traversableResolverClass = config.getTraversableResolver();
if ( traversableResolverClass != null ) {
try {
@@ -230,8 +316,8 @@
Class<TraversableResolver> clazz = ( Class<TraversableResolver> ) ReflectionHelper.classForName(
traversableResolverClass, this.getClass()
);
- traversableResolver = clazz.newInstance();
- log.info( "Using {} as traversable resolver", traversableResolverClass );
+ xmlParameters.traversableResolver = clazz.newInstance();
+ log.info( "Using {} as traversable resolver.", traversableResolverClass );
}
catch ( Exception e ) {
throw new ValidationException( "Unable to instantiate message interpolator class " + traversableResolverClass + "." );
@@ -240,11 +326,11 @@
}
@SuppressWarnings("unchecked")
- private void setProviderClassFromXml(ValidationConfigType config) {
+ private void setProviderClassFromXml(ValidationConfigType config, ParameterHolder xmlParamters) {
String providerClassName = config.getDefaultProvider();
if ( providerClassName != null ) {
try {
- providerClass = ( Class<? extends Configuration<?>> ) ReflectionHelper.classForName(
+ xmlParamters.providerClass = ( Class<? extends Configuration<?>> ) ReflectionHelper.classForName(
providerClassName, this.getClass()
);
log.info( "Using {} as validation provider.", providerClassName );
@@ -256,7 +342,7 @@
}
private ValidationConfigType getValidationConfig() {
- InputStream inputStream = this.getClass().getResourceAsStream( VALIDATION_XML_FILE );
+ InputStream inputStream = getInputStreamForPath( VALIDATION_XML_FILE );
if ( inputStream == null ) {
log.info( "No {} found. Using defaults.", VALIDATION_XML_FILE );
return null;
@@ -278,6 +364,19 @@
return validationConfig;
}
+ private InputStream getInputStreamForPath(String path) {
+ InputStream inputStream = this.getClass().getResourceAsStream( path );
+ // try absolute path
+ if ( inputStream == null && !path.startsWith( "/" ) ) {
+ inputStream = this.getClass().getResourceAsStream( "/" + path );
+ }
+
+ if ( inputStream == null && log.isDebugEnabled() ) {
+ log.debug( "Unable to open input stream for {}.", path );
+ }
+ return inputStream;
+ }
+
private Schema getValidationConfigurationSchema() {
URL schemaUrl = this.getClass().getClassLoader().getResource( VALIDATION_CONFIGURATION_XSD );
SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
@@ -290,4 +389,14 @@
}
return schema;
}
+
+ private class ParameterHolder {
+ ConstraintValidatorFactory constraintValidatorFactory;
+ MessageInterpolator messageInterpolator;
+ TraversableResolver traversableResolver;
+ ValidationProvider provider;
+ Class<? extends Configuration<?>> providerClass = null;
+ final Map<String, String> configProperties = new HashMap<String, String>();
+ final Set<InputStream> mappings = new HashSet<InputStream>();
+ }
}
Modified: validator/trunk/hibernate-validator/src/main/xsd/validation-configuration-1.0.xsd
===================================================================
--- validator/trunk/hibernate-validator/src/main/xsd/validation-configuration-1.0.xsd 2009-03-31 22:26:36 UTC (rev 16247)
+++ validator/trunk/hibernate-validator/src/main/xsd/validation-configuration-1.0.xsd 2009-04-01 13:04:03 UTC (rev 16248)
@@ -6,7 +6,7 @@
xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
version="1.0">
<xs:element name="validation-config" type="validation-configType"/>
- <xs:complexType name="validation-configType" >
+ <xs:complexType name="validation-configType">
<xs:sequence>
<xs:element type="xs:string" name="default-provider" minOccurs="0"/>
<xs:element type="xs:string" name="message-interpolator" minOccurs="0"/>
@@ -17,6 +17,10 @@
</xs:sequence>
</xs:complexType>
<xs:complexType name="propertyType">
- <xs:attribute name="name" use="required" type="xs:string"/>
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="name" use="required" type="xs:string"/>
+ </xs:extension>
+ </xs:simpleContent>
</xs:complexType>
</xs:schema>
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/order-constraints.xml
===================================================================
Added: validator/trunk/hibernate-validator/src/test/resources/META-INF/validation/user-constraints.xml
===================================================================
Modified: validator/trunk/hibernate-validator/src/test/resources/META-INF/validation.xml
===================================================================
--- validator/trunk/hibernate-validator/src/test/resources/META-INF/validation.xml 2009-03-31 22:26:36 UTC (rev 16247)
+++ validator/trunk/hibernate-validator/src/test/resources/META-INF/validation.xml 2009-04-01 13:04:03 UTC (rev 16248)
@@ -4,5 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<default-provider>org.hibernate.validation.engine.HibernateValidatorConfiguration</default-provider>
<message-interpolator>org.hibernate.validation.engine.ResourceBundleMessageInterpolator</message-interpolator>
- <constraint-mapping>META-INF/validation/order-constraints.xml</constraint-mapping>
+ <constraint-mapping>/META-INF/validation/order-constraints.xml</constraint-mapping>
+ <constraint-mapping>META-INF/validation/user-constraints.xml</constraint-mapping>
+ <property name="org.hibernate.validator.test">foobar</property>
</validation-config>
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-legacy/pom.xml
===================================================================
--- validator/trunk/hibernate-validator-legacy/pom.xml 2009-03-31 22:26:36 UTC (rev 16247)
+++ validator/trunk/hibernate-validator-legacy/pom.xml 2009-04-01 13:04:03 UTC (rev 16248)
@@ -4,7 +4,7 @@
<parent>
<artifactId>hibernate-validator-parent</artifactId>
<groupId>org.hibernate</groupId>
- <version>4.0.0.Alpha4-SNAPSHOT</version>
+ <version>4.0.0.Beta1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>hibernate-validator-legacy</artifactId>
Modified: validator/trunk/pom.xml
===================================================================
--- validator/trunk/pom.xml 2009-03-31 22:26:36 UTC (rev 16247)
+++ validator/trunk/pom.xml 2009-04-01 13:04:03 UTC (rev 16248)
@@ -3,7 +3,7 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-parent</artifactId>
<packaging>pom</packaging>
- <version>4.0.0.Alpha4-SNAPSHOT</version>
+ <version>4.0.0.Beta1-SNAPSHOT</version>
<name>Hibernate Validator Parent</name>
<url>http://validator.hibernate.org</url>
@@ -45,12 +45,12 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
- <version>1.4.2</version>
+ <version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
- <version>1.4.2</version>
+ <version>1.5.6</version>
</dependency>
</dependencies>
</dependencyManagement>
15 years, 8 months