Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/InvalidRedefinedDefaultGroupAddress.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/InvalidRedefinedDefaultGroupAddress.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/InvalidRedefinedDefaultGroupAddress.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/InvalidRedefinedDefaultGroupAddress.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bval.jsr.groups.redefining; + +import javax.validation.GroupSequence; +import javax.validation.constraints.NotNull; + + +/** + * If a @GroupSequence redefining the Default group for a class A does not + * contain the group A, a GroupDefinitionException is raised when the class is + * validated or when its metadata is requested. + */ +@GroupSequence({Address.class, Address.HighLevelCoherence.class}) +public class InvalidRedefinedDefaultGroupAddress { + @SuppressWarnings("unused") + @NotNull(groups = Address.HighLevelCoherence.class) + private String street; + + @SuppressWarnings("unused") + @NotNull + private String city; + + /** + * check coherence on the overall object + * Needs basic checking to be green first + */ + public interface HighLevelCoherence {} + +}
Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/RedefiningDefaultGroupTest.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/RedefiningDefaultGroupTest.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/RedefiningDefaultGroupTest.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/RedefiningDefaultGroupTest.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bval.jsr.groups.redefining; + +import junit.framework.TestCase; +import org.apache.bval.jsr.ApacheValidatorFactory; +import org.apache.bval.jsr.util.TestUtils; + +import javax.validation.ConstraintViolation; +import javax.validation.GroupDefinitionException; +import javax.validation.Validator; +import java.util.Set; + +/** + * Description: test Redefining the Default group for a class (spec. chapter 3.4.3)<br/> + */ +public class RedefiningDefaultGroupTest extends TestCase { + private Validator validator; + + protected void setUp() { + validator = ApacheValidatorFactory.getDefault().getValidator(); + } + + /** + * when an address object is validated for the group Default, + * all constraints belonging to the group Default and hosted on Address are evaluated + */ + public void testValidateDefaultGroup() { + Address address = new Address(); + Set<ConstraintViolation<Address>> violations = validator.validate(address); + assertEquals(3, violations.size()); + assertNotNull(TestUtils.getViolation(violations, "street1")); + assertNotNull(TestUtils.getViolation(violations, "zipCode")); + assertNotNull(TestUtils.getViolation(violations, "city")); + + address.setStreet1("Elmstreet"); + address.setZipCode("1234"); + address.setCity("Gotham City"); + violations = validator.validate(address); + assertTrue(violations.isEmpty()); + + violations = validator.validate(address, Address.HighLevelCoherence.class); + assertEquals(0, violations.size()); + + address.setCity("error"); + violations = validator.validate(address, Address.HighLevelCoherence.class); + assertEquals(1, violations.size()); + + /** + * If none fails, all HighLevelCoherence constraints present on Address are evaluated. + * + * In other words, when validating the Default group for Address, + * the group sequence defined on the Address class is used. + */ + violations = validator.validate(address); + assertEquals( + "redefined default group for Address must also validate HighLevelCoherence", + 1, violations.size()); + } + + public void testValidateProperty() { + Address address = new Address(); + address.setStreet1(""); + Set<ConstraintViolation<Address>> violations = validator.validateProperty(address, "street1"); + //prove that ExtraCareful group was validated: + assertEquals(1, violations.size()); + assertNotNull(TestUtils.getViolation(violations, "street1")); + } + + public void testValidateValue() { + Set<ConstraintViolation<Address>> violations = validator.validateValue(Address.class, "street1", ""); + //prove that ExtraCareful group was validated: + assertEquals(1, violations.size()); + assertNotNull(TestUtils.getViolation(violations, "street1")); + } + + public void testRaiseGroupDefinitionException() { + InvalidRedefinedDefaultGroupAddress address = + new InvalidRedefinedDefaultGroupAddress(); + try { + validator.validate(address); + fail(); + } catch (GroupDefinitionException ex) { + + } + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/EnumerationConverterTestCase.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/EnumerationConverterTestCase.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/EnumerationConverterTestCase.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/EnumerationConverterTestCase.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bval.jsr.util; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import org.apache.commons.beanutils.Converter; + +/** + * EnumerationConverter tester. + * + * $Id: EnumerationConverterTestCase.java 1161648 2011-08-25 17:14:15Z romanstumm $ + */ +public final class EnumerationConverterTestCase extends TestCase { + + public EnumerationConverterTestCase(String name) { + super(name); + } + + public void testEnum() { + Converter converter = EnumerationConverter.getInstance(); + + Thread.State expected = Thread.State.TERMINATED; + Thread.State actual = (Thread.State) converter.convert(Thread.State.class, + Thread.State.TERMINATED.name()); + assertEquals(expected, actual); + } + + public static Test suite() { + return new TestSuite(EnumerationConverterTestCase.class); + } + +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/PathImplTest.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/PathImplTest.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/PathImplTest.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/PathImplTest.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bval.jsr.util; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import javax.validation.Path; +import javax.validation.ValidationException; +import java.util.Iterator; + +/** + * PathImpl Tester. + * + * @version 1.0 + * @since <pre>10/01/2009</pre> + */ +public class PathImplTest extends TestCase { + public PathImplTest(String name) { + super(name); + } + + public void testParsing() { + String property = "order[3].deliveryAddress.addressline[1]"; + Path path = PathImpl.createPathFromString(property); + assertEquals(property, path.toString()); + + Iterator<Path.Node> propIter = path.iterator(); + + assertTrue(propIter.hasNext()); + Path.Node elem = propIter.next(); + assertFalse(elem.isInIterable()); + assertEquals("order", elem.getName()); + + assertTrue(propIter.hasNext()); + elem = propIter.next(); + assertTrue(elem.isInIterable()); + assertEquals(new Integer(3), elem.getIndex()); + assertEquals("deliveryAddress", elem.getName()); + + assertTrue(propIter.hasNext()); + elem = propIter.next(); + assertFalse(elem.isInIterable()); + assertEquals(null, elem.getIndex()); + assertEquals("addressline", elem.getName()); + + assertTrue(propIter.hasNext()); + elem = propIter.next(); + assertTrue(elem.isInIterable()); + assertEquals(new Integer(1), elem.getIndex()); + assertNull(elem.getName()); + + assertFalse(propIter.hasNext()); + } + + public void testParseMapBasedProperty() { + String property = "order[foo].deliveryAddress"; + Path path = PathImpl.createPathFromString(property); + Iterator<Path.Node> propIter = path.iterator(); + + assertTrue(propIter.hasNext()); + Path.Node elem = propIter.next(); + assertFalse(elem.isInIterable()); + assertEquals("order", elem.getName()); + + assertTrue(propIter.hasNext()); + elem = propIter.next(); + assertTrue(elem.isInIterable()); + assertEquals("foo", elem.getKey()); + assertEquals("deliveryAddress", elem.getName()); + + assertFalse(propIter.hasNext()); + } + + //some of the examples from the 1.0 bean validation spec, section 4.2 + public void testSpecExamples() { + String fourthAuthor = "authors[3]"; + Path path = PathImpl.createPathFromString(fourthAuthor); + Iterator<Path.Node> propIter = path.iterator(); + + assertTrue(propIter.hasNext()); + Path.Node elem = propIter.next(); + assertFalse(elem.isInIterable()); + assertEquals("authors", elem.getName()); + + assertTrue(propIter.hasNext()); + elem = propIter.next(); + assertTrue(elem.isInIterable()); + assertEquals(3, elem.getIndex().intValue()); + assertNull(elem.getName()); + assertFalse(propIter.hasNext()); + + String firstAuthorCompany = "authors[0].company"; + path = PathImpl.createPathFromString(firstAuthorCompany); + propIter = path.iterator(); + + assertTrue(propIter.hasNext()); + elem = propIter.next(); + assertFalse(elem.isInIterable()); + assertEquals("authors", elem.getName()); + + assertTrue(propIter.hasNext()); + elem = propIter.next(); + assertTrue(elem.isInIterable()); + assertEquals(0, elem.getIndex().intValue()); + assertEquals("company", elem.getName()); + assertFalse(propIter.hasNext()); + } + + public void testNull() { + assertEquals(PathImpl.createPathFromString(null), PathImpl.create()); + + assertEquals("", PathImpl.create().toString()); + Path path = PathImpl.create(); + Path.Node node = path.iterator().next(); + assertEquals(null, node.getName()); + } + + public void testUnbalancedBraces() { + try { + PathImpl.createPathFromString("foo[.bar"); + fail(); + } catch (ValidationException ex) { + } + } + + public void testIndexInMiddleOfProperty() { + try { + PathImpl.createPathFromString("f[1]oo.bar"); + fail(); + } catch (ValidationException ex) { + } + } + + public void testTrailingPathSeparator() { + try { + PathImpl.createPathFromString("foo.bar."); + fail(); + } catch (ValidationException ex) { + } + } + + public void testLeadingPathSeparator() { + try { + PathImpl.createPathFromString(".foo.bar"); + fail(); + } catch (ValidationException ex) { + } + } + + public void testEmptyString() { + Path path = PathImpl.createPathFromString(""); + assertEquals(null, path.iterator().next().getName()); + } + + public void testToString() { + PathImpl path = PathImpl.create(); + path.addNode(new NodeImpl("firstName")); + assertEquals("firstName", path.toString()); + + path = PathImpl.create(); + path.getLeafNode().setIndex(2); + assertEquals("[2]", path.toString()); + path.addNode(new NodeImpl("firstName")); + assertEquals("[2].firstName", path.toString()); + } + + public void testAddRemoveNodes() { + PathImpl path = PathImpl.createPathFromString(""); + assertTrue(path.isRootPath()); + assertEquals(1, countNodes(path)); + path.addNode(new NodeImpl("foo")); + assertFalse(path.isRootPath()); + assertEquals(1, countNodes(path)); + path.removeLeafNode(); + assertTrue(path.isRootPath()); + assertEquals(1, countNodes(path)); + } + + private int countNodes(Path path) { + int result = 0; + for (Iterator<Path.Node> iter = path.iterator(); iter.hasNext();) { + iter.next(); + result++; + } + return result; + } + + public static Test suite() { + return new TestSuite(PathImplTest.class); + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/TestUtils.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/TestUtils.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/TestUtils.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/util/TestUtils.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bval.jsr.util; + +import junit.framework.Assert; + +import javax.validation.ConstraintViolation; +import javax.validation.metadata.ConstraintDescriptor; +import javax.validation.metadata.ElementDescriptor.ConstraintFinder; +import java.lang.annotation.Annotation; +import java.util.Collection; +import java.util.Set; + +/** + * Description: <br/> + */ +public class TestUtils { + /** + * @param violations + * @param propertyPath + * - string format of a propertyPath + * @return the constraintViolation with the propertyPath's string + * representation given + */ + public static <T> ConstraintViolation<T> getViolation(Set<ConstraintViolation<T>> violations, String propertyPath) { + for (ConstraintViolation<T> each : violations) { + if (each.getPropertyPath().toString().equals(propertyPath)) + return each; + } + return null; + } + + /** + * @param violations + * @param propertyPath + * @return count of violations + */ + public static <T> int countViolations(Set<ConstraintViolation<T>> violations, String propertyPath) { + int result = 0; + for (ConstraintViolation<T> each : violations) { + if (each.getPropertyPath().toString().equals(propertyPath)) { + result++; + } + } + return result; + } + + /** + * @param <T> + * @param violations + * @param message + * @return the constraint violation with the specified message found, if any + */ + public static <T> ConstraintViolation<T> getViolationWithMessage(Set<ConstraintViolation<T>> violations, + String message) { + for (ConstraintViolation<T> each : violations) { + if (each.getMessage().equals(message)) + return each; + } + return null; + } + + /** + * assume set addition either does nothing, returning false per collection + * contract, or throws an Exception; in either case size should remain + * unchanged + * + * @param collection + */ + public static void failOnModifiable(Collection<?> collection, String description) { + int size = collection.size(); + try { + Assert + .assertFalse(String.format("should not permit modification to %s", description), collection.add(null)); + } catch (Exception e) { + // okay + } + Assert.assertEquals("constraint descriptor set size changed", size, collection.size()); + } + + /** + * Assert that the specified ConstraintFinder provides constraints of each of the specified types. + * @param constraintFinder + * @param types + */ + public static void assertConstraintTypesFound(ConstraintFinder constraintFinder, Class<? extends Annotation>... types) { + outer: for (Class<? extends Annotation> type : types) { + for (ConstraintDescriptor<?> descriptor : constraintFinder.getConstraintDescriptors()) { + if (descriptor.getAnnotation().annotationType().equals(type)) { + continue outer; + } + } + Assert.fail(String.format("Missing expected constraint descriptor of type %s", type)); + } + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/TestConstraintValidatorFactory.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/TestConstraintValidatorFactory.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/TestConstraintValidatorFactory.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/TestConstraintValidatorFactory.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bval.jsr.xml; + +import org.apache.bval.jsr.DefaultConstraintValidatorFactory; + +/** + * Description: <br/> + */ +public class TestConstraintValidatorFactory extends DefaultConstraintValidatorFactory { +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/TestMessageInterpolator.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/TestMessageInterpolator.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/TestMessageInterpolator.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/TestMessageInterpolator.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bval.jsr.xml; + +import org.apache.bval.jsr.DefaultMessageInterpolator; + +/** + * Description: <br/> + */ +public class TestMessageInterpolator extends DefaultMessageInterpolator { +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bval.jsr.xml; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import org.apache.bval.jsr.ApacheValidationProvider; +import org.apache.bval.jsr.ApacheValidatorConfiguration; +import org.apache.bval.jsr.ConfigurationImpl; +import org.apache.bval.jsr.example.XmlEntitySampleBean; +import org.apache.bval.jsr.resolver.SimpleTraversableResolver; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.ValidationException; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import java.io.IOException; +import java.util.Set; + +/** + * ValidationParser Tester. + * + * @author <Authors name> + * @version 1.0 + * @since <pre>11/25/2009</pre> + */ +public class ValidationParserTest extends TestCase + implements ApacheValidatorConfiguration.Properties { + public ValidationParserTest(String name) { + super(name); + } + + public void testGetInputStream() throws IOException { + assertNotNull(ValidationParser.getInputStream("sample-validation.xml")); + + try { + ValidationParser.getInputStream("META-INF/MANIFEST.MF"); // this is available in multiple jars hopefully + fail("exception not thrown"); + } catch(ValidationException vex) { + assertTrue(vex.getMessage().startsWith("More than ")); + } + } + + public void testParse() { + ConfigurationImpl config = new ConfigurationImpl(null, new ApacheValidationProvider()); + ValidationParser.processValidationConfig("sample-validation.xml", config, false); + } + + public void testConfigureFromXml() { + ValidatorFactory factory = getFactory(); + assertTrue(factory.getMessageInterpolator() instanceof TestMessageInterpolator); + assertTrue(factory + .getConstraintValidatorFactory() instanceof TestConstraintValidatorFactory); + assertTrue(factory.getTraversableResolver() instanceof SimpleTraversableResolver); + Validator validator = factory.getValidator(); + assertNotNull(validator); + } + + private ValidatorFactory getFactory() { + ApacheValidatorConfiguration config = + Validation.byProvider(ApacheValidationProvider.class).configure(); + config.addProperty(VALIDATION_XML_PATH, "sample-validation.xml"); + return config.buildValidatorFactory(); + } + + public void testXmlEntitySample() { + XmlEntitySampleBean bean = new XmlEntitySampleBean(); + bean.setFirstName("tooooooooooooooooooooooooooo long"); + bean.setValueCode("illegal"); + Validator validator = getFactory().getValidator(); + Set<ConstraintViolation<XmlEntitySampleBean>> results = validator.validate(bean); + assertTrue(!results.isEmpty()); + assertTrue(results.size() == 3); + + bean.setZipCode("123"); + bean.setValueCode("20"); + bean.setFirstName("valid"); + results = validator.validate(bean); + assertTrue(results.isEmpty()); + } + + public static Test suite() { + return new TestSuite(ValidationParserTest.class); + } +} Added: bval/branches/bval-11/bval-jsr/src/test/resources/ValidationMessages.properties URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/resources/ValidationMessages.properties?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/resources/ValidationMessages.properties (added) +++ bval/branches/bval-11/bval-jsr/src/test/resources/ValidationMessages.properties Mon Aug 26 13:59:15 2013 @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# standard messages +javax.validation.constraints.Pattern.message=must match "{regexp}" + +# custom messages (examples) for validation-api-1.0.Beta4 +test.validator.creditcard=credit card is not valid + +# custom messages (examples) for validation-api-1.0.CR1 +validator.creditcard=credit card is not valid + Added: bval/branches/bval-11/bval-jsr/src/test/resources/java.policy URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/resources/java.policy?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/resources/java.policy (added) +++ bval/branches/bval-11/bval-jsr/src/test/resources/java.policy Mon Aug 26 13:59:15 2013 @@ -0,0 +1,76 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// +// $Id$ +// +// Allows unit tests to run with a Java Security Manager +// +// Cloned from https://svn.apache.org/repos/asf/commons/proper/lang/trunk/src/test/resources/java.policy +// +// <argLine>-Djava.security.manager -Djava.security.policy=${basedir}/src/test/resources/java.policy</argLine> +// + +grant +{ + // let everyone read target dir + permission java.io.FilePermission "${user.dir}/target/-", "read"; +}; + +// we don't care about the permissions of the testing infrastructure, +// including maven; +grant codeBase "file://${user.home}/.m2/repository/org/apache/maven/-" +{ + permission java.security.AllPermission; +}; + +// junit; +grant codeBase "file://${user.home}/.m2/repository/junit/-" +{ + permission java.security.AllPermission; +}; + +// mockito; +grant codeBase "file://${user.home}/.m2/repository/org/mockito/-" +{ + permission java.security.AllPermission; +}; + +// objenesis (via mockito); +grant codeBase "file://${user.home}/.m2/repository/org/objenesis/-" +{ + permission java.security.AllPermission; +}; + +// and our own testcases +grant codeBase "file://${user.dir}/target/test-classes/-" +{ + permission java.security.AllPermission; +}; + +grant codeBase "file://${user.home}/.m2/repository/org/apache/bval/-" +{ + permission java.lang.RuntimePermission "accessDeclaredMembers"; + permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; +}; + +grant codeBase "file://${user.dir}/target/classes/-" +{ + permission java.lang.RuntimePermission "accessDeclaredMembers"; + permission java.lang.reflect.ReflectPermission "suppressAccessChecks"; + permission java.io.FilePermission "${user.home}/.m2/repository/-", "read"; +}; Added: bval/branches/bval-11/bval-jsr/src/test/resources/sample-constraints.xml URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/resources/sample-constraints.xml?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/resources/sample-constraints.xml (added) +++ bval/branches/bval-11/bval-jsr/src/test/resources/sample-constraints.xml Mon Aug 26 13:59:15 2013 @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<constraint-mappings + xmlns="http://jboss.org/xml/ns/javax/validation/mapping" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation= + "http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd"> + <default-package>org.apache.bval.jsr.example</default-package> + + <bean class="XmlEntitySampleBean" ignore-annotations="false"> + <class ignore-annotations="true"/> + <field name="zipCode"> + <!--@FrenchZipCode(size=3)--> + <constraint annotation="org.apache.bval.constraints.FrenchZipCode"> + <element name="size"> + <value>3</value> + </element> + </constraint> + + </field> + <field name="valueCode"> + <!--<valid/>--> + <!-- @HasValue({ 0, 20 }) --> + <constraint annotation="org.apache.bval.constraints.HasValue"> + <element name="value"> + <value>0</value> + <value>20</value> + </element> + </constraint> + + </field> + <getter name="firstName"> + <!--<valid/>--> + <!-- @Size(message="Size is limited", + groups={First.class, Default.class}, + max=10 + ) + --> + <constraint annotation="javax.validation.constraints.Size"> + <message>Size is limited</message> + <groups> + <value>org.apache.bval.jsr.example.First</value> + <value>javax.validation.groups.Default</value> + </groups> + <element name="max">10</element> + </constraint> + + </getter> + + </bean> + + <constraint-definition annotation="javax.validation.constraints.Size"> + <validated-by include-existing-validators="false"> + <value>org.apache.bval.constraints.SizeValidatorForCharSequence</value> + </validated-by> + </constraint-definition> + +</constraint-mappings> Added: bval/branches/bval-11/bval-jsr/src/test/resources/sample-validation.xml URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/resources/sample-validation.xml?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/resources/sample-validation.xml (added) +++ bval/branches/bval-11/bval-jsr/src/test/resources/sample-validation.xml Mon Aug 26 13:59:15 2013 @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<validation-config + xmlns="http://jboss.org/xml/ns/javax/validation/configuration" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation= + "http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd"> + <default-provider>org.apache.bval.jsr.ApacheValidationProvider</default-provider> + <message-interpolator>org.apache.bval.jsr.xml.TestMessageInterpolator</message-interpolator> + <traversable-resolver>org.apache.bval.jsr.resolver.SimpleTraversableResolver</traversable-resolver> + <constraint-validator-factory>org.apache.bval.jsr.xml.TestConstraintValidatorFactory</constraint-validator-factory> + <constraint-mapping>sample-constraints.xml</constraint-mapping> + <property name="test-prop">test-prop-value</property> +</validation-config>
