Index: src/test/java/org/jboss/arquillian/impl/XmlConfigurationBuilderTestCase.java =================================================================== --- src/test/java/org/jboss/arquillian/impl/XmlConfigurationBuilderTestCase.java (revision 4510) +++ src/test/java/org/jboss/arquillian/impl/XmlConfigurationBuilderTestCase.java (working copy) @@ -18,6 +18,8 @@ import java.util.Collection; import java.util.Collections; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import org.jboss.arquillian.spi.Configuration; import org.jboss.arquillian.spi.ConfigurationException; @@ -84,7 +86,22 @@ Assert.assertEquals("char", containerConfig.getC()); } - + + @Test(expected = ConfigurationException.class) + public void testConfigurationWithInvalidValues() throws Exception + { + // create a mock ServiceLoader that returns our MockContainerConfiguration + ServiceLoader serviceLoader = new MockServiceLoader(); + + // build the configuration + ConfigurationBuilder builder = new XmlConfigurationBuilder("arquillian_invalid.xml", serviceLoader); + Configuration configuration = builder.build(); + Assert.assertNotNull(configuration); + + // retrieve the container configuration + configuration.getContainerConfig(MockContainerConfiguration.class); + } + /** * Should throw a ConfigurationException if * @throws Exception @@ -136,7 +153,7 @@ } } - class AbstractMockContainerConfiguration + public class AbstractMockContainerConfiguration { private String propertyInherited; @@ -156,7 +173,7 @@ * * @author German Escobar */ - class MockContainerConfiguration extends AbstractMockContainerConfiguration implements ContainerConfiguration + public class MockContainerConfiguration extends AbstractMockContainerConfiguration implements ContainerConfiguration { private String propertyString; @@ -174,7 +191,8 @@ { return ContainerProfile.STANDALONE; } - + + @Size(min = 1, max = 5) public String getPropertyString() { return propertyString; @@ -225,6 +243,7 @@ this.propertyBoolean = propertyBoolean; } + @NotNull public String getC() { return c; Index: src/test/resources/arquillian_invalid.xml =================================================================== --- src/test/resources/arquillian_invalid.xml (revision 0) +++ src/test/resources/arquillian_invalid.xml (revision 0) @@ -0,0 +1,10 @@ + + + + + too long + + + Index: src/main/java/org/jboss/arquillian/impl/XmlConfigurationBuilder.java =================================================================== --- src/main/java/org/jboss/arquillian/impl/XmlConfigurationBuilder.java (revision 4510) +++ src/main/java/org/jboss/arquillian/impl/XmlConfigurationBuilder.java (working copy) @@ -20,8 +20,14 @@ import java.lang.reflect.Method; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Logger; +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -62,6 +68,8 @@ private ServiceLoader serviceLoader; + private Validator validator; + /** * Constructor. Initializes with the default resource path and service loader. */ @@ -89,6 +97,7 @@ { this.resourcePath = resourcePath; this.serviceLoader = serviceLoader; + this.validator = Validation.buildDefaultValidatorFactory().getValidator(); } /* (non-Javadoc) @@ -113,6 +122,7 @@ if(arquillianConfiguration != null) { populateConfiguration(arquillianConfiguration, containersConfigurations); + validationContainerConfigurations(containersConfigurations); populateConfiguration(arquillianConfiguration, configuration); } } @@ -239,6 +249,45 @@ } } } + + private void validationContainerConfigurations(Collection configs) + { + boolean violationsFound = false; + StringBuilder builder = new StringBuilder(); + for (ContainerConfiguration config : configs) + { + Set> violations = validator.validate(config); + if (!violations.isEmpty()) + { + if (violationsFound) + { + builder.append("\n"); + } + else + { + violationsFound = true; + } + builder.append("Invalid values applied to configuration in namespace "); + builder.append(config.getClass().getPackage().getName()); + builder.append("\n{"); + for (ConstraintViolation violation : violations) + { + builder.append("\n ") + .append("") + .append(violation.getPropertyPath()) + .append(" = \"") + .append(violation.getInvalidValue()) + .append("\" => ") + .append(violation.getMessage()); + } + builder.append("\n}"); + } + } + if (violationsFound) + { + throw new IllegalArgumentException(builder.toString()); + } + } /** * Creates all the properties from a single Node element. The element must be a child of the Index: pom.xml =================================================================== --- pom.xml (revision 4464) +++ pom.xml (working copy) @@ -54,6 +54,12 @@ shrinkwrap-spi + + org.hibernate + hibernate-validator + 4.0.0.GA + + @@ -69,6 +75,13 @@ test + + org.slf4j + slf4j-simple + 1.5.10 + test + +