Hibernate.orgCommunity Documentation
This chapter explains how to obtain the TCK and supporting software and provides recommendations for how to install/extract it on your system.
You can obtain a release of the Bean Validation TCK project from the
from the download
page on the Hibernate Validator website. The Bean Validation TCK
is distributed as a ZIP file, which contains the TCK artifacts (the test
suite binary and source, the test suite descriptor, the audit source and
report), the TCK library dependencies in /lib
and
documentation in /doc
. The contents should look like (todo -
verify against final dist bundle):
artifacts/ changelog.txt docs/ lib/ license.txt src/
You can also download the source code from GitHub - https://github.com/beanvalidation/beanvalidation-tck.
The JSR 349 reference implementation (RI) project is named Hibernate Validator. You can obtain the Hibernate Validator release used as reference implementation from the Hibernate Validator download page.
Hibernate Validator is not required for running the Bean Validation TCK, but it can be used as a reference for familiarizing yourself with the TCK before testing your own Bean Validation implementation.
The TCK requires the following two Java runtime environments:
Java 6 or better
Java EE 7 or better (e.g., JBoss AS 7.x)
You should refer to vendor instructions for how to install the runtime.
The rest of the TCK software can simply be extracted. It's
recommended that you create a dedicated folder to hold all of the
jsr349-related artifacts. This guide assumes the folder is called
jsr349
. Extract the src
folder
of the TCK distribution into a sub-folder named tck
or
use the following git commands to
git clone git://github.com/beanvalidation/beanvalidation-tck tck git checkout 1.1.0.Final // TODO - add right version number
You can also check out the full Hibernate Validator source into a subfolder ri. This will allow you to run the TCK against Hibernate Validator.
git clone git://github.com/hibernate/hibernate-validator.git ri git checkout 4.2.0.Final // TODO - add right version number
The resulting folder structure is shown here:
jsr349/ ri/ tck/
Now lets have a look at one concrete test of the TCK, namely
ConstraintInheritanceTest
(found in
tck/tck/src/main/java/org/hibernate/beanvalidation/tck/tests/constraints/inheritance/ConstraintInheritanceTest.java
):
package org.hibernate.beanvalidation.tck.tests.constraints.inheritance; import java.lang.annotation.Annotation; import javax.validation.Validator; import javax.validation.constraints.NotNull; import javax.validation.metadata.BeanDescriptor; import javax.validation.metadata.PropertyDescriptor; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.testng.Arquillian; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.jboss.test.audit.annotations.SpecAssertion; import org.jboss.test.audit.annotations.SpecAssertions; import org.testng.annotations.Test; import org.hibernate.beanvalidation.tck.util.TestUtil; import org.hibernate.beanvalidation.tck.util.shrinkwrap.WebArchiveBuilder; import static org.testng.Assert.assertTrue; public class ConstraintInheritanceTest extends Arquillian { @Deployment public static WebArchive createTestArchive() { return new WebArchiveBuilder() .withTestClassPackage( ConstraintInheritanceTest.class ) .build(); } @Test @SpecAssertion(section = "3.3", id = "b") public void testConstraintsOnSuperClassAreInherited() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Bar.class ); String propertyName = "foo"; assertTrue( beanDescriptor.getConstraintsForProperty( propertyName ) != null ); PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( propertyName ); // cast is required for JDK 5 - at least on Mac OS X Annotation constraintAnnotation = (Annotation) propDescriptor.getConstraintDescriptors() .iterator() .next().getAnnotation(); assertTrue( constraintAnnotation.annotationType() == NotNull.class ); } @Test @SpecAssertions({ @SpecAssertion(section = "3.3", id = "a"), @SpecAssertion(section = "3.3", id = "b") }) public void testConstraintsOnInterfaceAreInherited() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Bar.class ); String propertyName = "fubar"; assertTrue( beanDescriptor.getConstraintsForProperty( propertyName ) != null ); PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( propertyName ); // cast is required for JDK 5 - at least on Mac OS X Annotation constraintAnnotation = (Annotation) propDescriptor.getConstraintDescriptors() .iterator() .next().getAnnotation(); assertTrue( constraintAnnotation.annotationType() == NotNull.class ); } }
Each test class is treated as an individual artifact (hence
the @Deployment
annotation on the class). In most tests
the created artifact is a standard Web
application Archive build via WebArchiveBuilder
which
in turn is a helper class of the TCK itself alleviating the creation of of
the artifact. All methods annotated with @Test
are
actual tests which are getting run. Last but not least we see the use of
the @SpecAssertion
annotation which creates the link between
the tck-audit.xml document and the actual test (see Section 1.1, “TCK Primer”).
Install Maven. You can find documentation on how to install Maven 2 in the Maven: The Definitive Guide book published by Sonatype.
Change to the
ri/hibernate-validator-tck-runner
directory.
Next, instruct Maven to run the TCK:
mvn test -Dincontainer
TestNG will report, via Maven, the outcome of the run, and
report any failures on the console. Details can be found in
target/surefire-reports/TestSuite.txt
.
Copyright © 2009 - 2012 Red Hat, Inc.