/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class, TCKValidationProvider.class, TCKValidatorConfiguration.class, TCKValidationProvider.DummyValidatorFactory.class }) public class OptionalValidationXmlTest extends AbstractTest { @Test @SpecAssertions({ @SpecAssertion(section = "4.4.6", id = "c") }) public void testIgnoreValidationXml() { Validator validator = TestUtil.getValidatorUnderTest(); Order order = new Order(); Set<ConstraintViolation<Order>> constraintViolations = validator.validate( order ); assertCorrectNumberOfViolations( constraintViolations, 0 ); } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) public class PropertyDescriptorTest extends AbstractTest { @Test @SpecAssertion(section = "5.4", id = "a") public void testIsNotCascaded() { PropertyDescriptor descriptor = getPropertyDescriptor( Order.class, "orderNumber" ); assertFalse( descriptor.isCascaded(), "Should not be cascaded" ); } @Test @SpecAssertion(section = "5.4", id = "a") public void testIsCascaded() { PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class, "orderList" ); assertTrue( descriptor.isCascaded(), "Should be cascaded" ); } @Test @SpecAssertion(section = "5.4", id = "b") public void testPropertyName() { String propertyName = "orderList"; PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class, propertyName ); assertEquals( descriptor.getPropertyName(), propertyName, "Wrong property name" ); } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class, TCKValidationProvider.class, TCKValidatorConfiguration.class, TCKValidationProvider.DummyValidatorFactory.class }) @ValidationXml(value = "validation-InvalidXmlConfigurationTest.xml") public class InvalidXmlConfigurationTest extends AbstractTest { @Test @SpecAssertion(section = "7", id = "a") public void testInvalidValidationXml() { try { TestUtil.getValidatorUnderTest(); fail(); } catch ( ValidationException e ) { // success } } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class, TCKValidationProvider.class, TCKValidatorConfiguration.class, TCKValidationProvider.DummyValidatorFactory.class }) @ValidationXml(value = "validation-BootstrapUnknownCustomProviderTest.xml") public class BootstrapUnknownCustomProviderTest extends AbstractTest { @Test @SpecAssertion(section = "8", id = "a") public void testWrongProviderConfiguredInValidationXml() { try { Validation.buildDefaultValidatorFactory(); fail( "validation.xml contains a invalid provider. Validation.buildDefaultValidatorFactory() should have failed." ); } catch ( ValidationException e ) { // success } } }
@Resource(source = "builtin-constraints-override.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/constraints/builtinconstraints/builtin-constraints-override.xml") @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) public class BuiltinValidatorOverrideTest extends AbstractTest {
@Classes({ TestUtil.class, TestUtil.PathImpl.class,
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-ConfiguredBeanNotInClassPathTest.xml") @Resource(source = "constraints-ConfiguredBeanNotInClassPathTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/constraints-ConfiguredBeanNotInClassPathTest.xml") public class ConfiguredBeanNotInClassPathTest extends AbstractTest { @Test @SpecAssertion(section = "7.1.1", id = "f") public void testExceptionIsThrownForUnknownBeanNameInXml() { try { TestUtil.getValidatorUnderTest(); fail( "Test should have thrown an exception due to wrong class name" ); } catch ( ValidationException e ) { //success } } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class, TCKValidationProvider.class, TCKValidationProvider.DummyValidatorFactory.class, TCKValidatorConfiguration.class }) @Resource(source = "javax.validation.spi.ValidationProvider", destination = "WEB-INF/classes/META-INF/services/javax.validation.spi.ValidationProvider") @IntegrationTest public class UnknownProviderBootstrapTest extends AbstractTest { @Test(expectedExceptions = ValidationException.class) @SpecAssertion(section = "4.4.5", id = "f") public void testUnknownProviderThrowsValidationException() { Validation.byDefaultProvider().configure(); //ValidatorFactory factory = configuration.buildValidatorFactory(); } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-WrongFieldNameTest.xml") @Resource(source = "user-constraints-WrongFieldNameTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-WrongFieldNameTest.xml") public class WrongFieldNameTest extends AbstractTest { @Test @SpecAssertions({ @SpecAssertion(section = "7.1.1.2", id = "f") }) public void testWrongFieldNameThrowsException() { try { Validator validator = TestUtil.getValidatorUnderTest(); validator.getConstraintsForClass( User.class ); } catch ( ValidationException e ) { // success } } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-DefaultSequenceDefinedInXmlTest.xml") @Resource(source = "package-constraints-DefaultSequenceDefinedInXmlTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/package-constraints-DefaultSequenceDefinedInXmlTest.xml") public class DefaultSequenceDefinedInXmlTest extends AbstractTest { @Test @SpecAssertion(section = "7.1.1.1", id = "e") public void testDefaultGroupDefinitionDefinedInEntityApplies() { Validator validator = TestUtil.getValidatorUnderTest(); Package p = new Package(); p.setMaxWeight(30); Set<ConstraintViolation<Package>> violations = validator.validate( p, Default.class ); assertCorrectNumberOfViolations( violations, 1 ); assertCorrectConstraintViolationMessages( violations, "The package is too heavy" ); } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-MandatoryNameAttributeTest.xml") @Resource(source = "constraints-MandatoryNameAttributeTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/constraints-MandatoryNameAttributeTest.xml") public class MandatoryNameAttributeTest extends AbstractTest { @Test @SpecAssertion(section = "7.1.1.4", id = "a") public void testNameAttributeIsMandatory() { try { TestUtil.getValidatorUnderTest(); fail(); } catch ( ValidationException e ) { // success } } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-ExcludeFieldLevelAnnotationsDueToBeanDefaultsTest.xml") @Resource(source = "user-constraints-ExcludeFieldLevelAnnotationsDueToBeanDefaultsTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-ExcludeFieldLevelAnnotationsDueToBeanDefaultsTest.xml") public class ExcludeFieldLevelAnnotationsDueToBeanDefaultsTest extends AbstractTest { @Test @SpecAssertions({ @SpecAssertion(section = "7.1.1.2", id = "b"), @SpecAssertion(section = "7.1.1.2", id = "c") }) public void testIgnoreAnnotations() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class ); assertNotNull( beanDescriptor ); PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstname" ); assertNull( propDescriptor, "The annotation defined constraints should be ignored." ); } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-MissingMandatoryElementTest.xml") @Resource(source = "package-constraints-MissingMandatoryElementTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/package-constraints-MissingMandatoryElementTest.xml") public class MissingMandatoryElementTest extends AbstractTest { @Test @SpecAssertion(section = "7.1.1.4", id = "h") public void testMissingMandatoryElementInConstraintDeclaration() { try { TestUtil.getValidatorUnderTest(); fail( "Creating the validator should have failed since the constraint declaration in xml is incomplete." ); } catch ( ValidationException e ) { // success } } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-ExcludePropertyLevelAnnotationsDueToBeanDefaultsTest.xml") @Resource(source = "user-constraints-ExcludePropertyLevelAnnotationsDueToBeanDefaultsTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-ExcludePropertyLevelAnnotationsDueToBeanDefaultsTest.xml") public class ExcludePropertyLevelAnnotationsDueToBeanDefaultsTest extends AbstractTest { @Test @SpecAssertions({ @SpecAssertion(section = "7.1.1.3", id = "b"), @SpecAssertion(section = "7.1.1.3", id = "c") }) public void testIgnoreAnnotations() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class ); assertNotNull( beanDescriptor ); PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstname" ); assertNull( propDescriptor, "The annotation defined constraints should be ignored." ); } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-WrongPropertyNameTest.xml") @Resource(source = "user-constraints-WrongPropertyNameTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-WrongPropertyNameTest.xml") public class WrongPropertyNameTest extends AbstractTest { @Test @SpecAssertions({ @SpecAssertion(section = "7.1.1.3", id = "f") }) public void testWrongPropertyNameThrowsException() { try { Validator validator = TestUtil.getValidatorUnderTest(); validator.getConstraintsForClass( User.class ); } catch ( ValidationException e ) { // success } } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-IncludePropertyLevelAnnotationsDueToBeanDefaultsTest.xml") @Resource(source = "user-constraints-IncludePropertyLevelAnnotationsDueToBeanDefaultsTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/propertylevel/user-constraints-IncludePropertyLevelAnnotationsDueToBeanDefaultsTest.xml") public class IncludePropertyLevelAnnotationsDueToBeanDefaultsTest extends AbstractTest { @Test @SpecAssertions({ @SpecAssertion(section = "7.1.1.3", id = "b"), @SpecAssertion(section = "7.1.1.3", id = "d") }) public void testAnnotationsIncluded() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class ); assertNotNull( beanDescriptor ); PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstname" ); assertNotNull( propDescriptor ); Set<ConstraintDescriptor<?>> constraintDescriptors = propDescriptor.getConstraintDescriptors(); assertEquals( constraintDescriptors.size(), 1, "There should be two constraints" ); ConstraintDescriptor<?> descriptor = constraintDescriptors.iterator().next(); assertTrue( descriptor.getAnnotation() instanceof NotNull, "Wrong constraint annotation." ); } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-IncludeFieldLevelAnnotationsDueToBeanDefaultsTest.xml") @Resource(source = "user-constraints-IncludeFieldLevelAnnotationsDueToBeanDefaultsTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/fieldlevel/user-constraints-IncludeFieldLevelAnnotationsDueToBeanDefaultsTest.xml") public class IncludeFieldLevelAnnotationsDueToBeanDefaultsTest extends AbstractTest { @Test @SpecAssertions({ @SpecAssertion(section = "7.1.1.2", id = "b"), @SpecAssertion(section = "7.1.1.2", id = "d") }) public void testAnnotationsIncluded() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( User.class ); assertNotNull( beanDescriptor ); PropertyDescriptor propDescriptor = beanDescriptor.getConstraintsForProperty( "firstname" ); assertNotNull( propDescriptor ); Set<ConstraintDescriptor<?>> constraintDescriptors = propDescriptor.getConstraintDescriptors(); assertEquals( constraintDescriptors.size(), 1, "There should be two constraints" ); ConstraintDescriptor<?> descriptor = constraintDescriptors.iterator().next(); assertTrue( descriptor.getAnnotation() instanceof NotNull, "Wrong constraint annotation." ); } }
/** * @author Hardy Ferentschik */ @Artifact(artifactType = ArtifactType.JSR303) @Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class }) @ValidationXml(value = "validation-ConstraintDeclarationTest.xml") @Resource(source = "package-constraints-ConstraintDeclarationTest.xml", destination = "WEB-INF/classes/org/hibernate/jsr303/tck/tests/xmlconfiguration/constraintdeclaration/package-constraints-ConstraintDeclarationTest.xml") public class ConstraintDeclarationTest extends AbstractTest { @Test @SpecAssertion(section = "7.1.1", id = "d") public void testConstraintAnnotationsArePerDefaultIgnoredForXmlConfiguredEntities() { Validator validator = TestUtil.getValidatorUnderTest(); BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Package.class ); assertFalse( beanDescriptor.isBeanConstrained(), "With xml configuration there should be no constraint." ); Configuration<?> config = TestUtil.getConfigurationUnderTest(); config.ignoreXmlConfiguration(); validator = config.buildValidatorFactory().getValidator(); beanDescriptor = validator.getConstraintsForClass( Package.class ); assertTrue( beanDescriptor.isBeanConstrained(), "If xml configuration is ignored Package should have a single constraint." ); } }
@Artifact(addCurrentPackage = false) @Packaging(PackagingType.WAR) @IntegrationTest(runLocally = true) @SpecVersion(spec="cdi", version="20091101") @WebXml("web.xml") @Classes({ Sheep.class, SheepWSEndPoint.class }) public class InjectionIntoWebServiceEndPointTest extends AbstractJSR299Test { @Test(groups = "javaee-full-only") @SpecAssertions({ @SpecAssertion(section = "5.5", id = "ee"), @SpecAssertion(section = "5.5.2", id = "aq"), @SpecAssertion(section = "5.5.2", id = "ar") }) // JBAS-7046 public void testInjectionIntoWebServiceEndpoint() throws Exception { SheepWSEndPointService service = new SheepWSEndPointService(); SheepWS ws = service.getSheepWSPort(); assert ws.isSheepInjected(); } }
/** * @author Nicklas Karlsson */ @Artifact(addCurrentPackage=false) @Classes({Storm.class, ConversationTestPhaseListener.class, ConversationStatusServlet.class, Cloud.class, CloudController.class}) @IntegrationTest(runLocally=true) @Resources({ @Resource(destination="WEB-INF/faces-config.xml", source="faces-config.xml"), @Resource(destination="clouds.jspx", source="clouds.jsf"), @Resource(destination="cloud.jspx", source="cloud.jsf") }) @WebXml("web.xml") @SpecVersion(spec="cdi", version="20091101") public class InvalidatingSessionDestroysConversationTest extends AbstractConversationTest { @Test(groups = { "contexts" }) @SpecAssertion(section = "6.7.4", id = "qa") // TODO this test doesn't precisely probe the boundaries of the service() method public void testInvalidatingSessionDestroysConversation() throws Exception { WebClient webClient = new WebClient(); resetCloud(webClient); webClient.getPage(getPath("clouds.jsf")); assert !isCloudDestroyed(webClient); invalidateSession(webClient); assert isCloudDestroyed(webClient); } }