Repository: bval Updated Branches: refs/heads/bv2 a43c0b0c7 -> 3f287a7af (forced update)
http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd ---------------------------------------------------------------------- diff --git a/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd b/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd new file mode 100644 index 0000000..9d16bf3 --- /dev/null +++ b/bval-jsr/src/main/xsd/validation-mapping-2.0.xsd @@ -0,0 +1,297 @@ +<?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. +--> +<xs:schema attributeFormDefault="unqualified" + elementFormDefault="qualified" + targetNamespace="http://xmlns.jcp.org/xml/ns/javax/validation/mapping" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:map="http://xmlns.jcp.org/xml/ns/javax/validation/mapping" + version="2.0"> + <xs:element name="constraint-mappings" type="map:constraint-mappingsType" /> + + <xs:complexType name="payloadType"> + <xs:sequence> + <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0" /> + </xs:sequence> + </xs:complexType> + <xs:complexType name="groupsType"> + <xs:sequence> + <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0" /> + </xs:sequence> + </xs:complexType> + <xs:complexType name="groupSequenceType"> + <xs:sequence> + <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0" /> + </xs:sequence> + </xs:complexType> + <xs:complexType name="groupConversionType"> + <xs:attribute type="xs:string" name="from" use="required" /> + <xs:attribute type="xs:string" name="to" use="required" /> + </xs:complexType> + <xs:complexType name="constraint-mappingsType"> + <xs:sequence> + <xs:element type="xs:string" name="default-package" minOccurs="0" /> + <xs:element type="map:beanType" + name="bean" + maxOccurs="unbounded" + minOccurs="0" /> + <xs:element type="map:constraint-definitionType" + name="constraint-definition" + maxOccurs="unbounded" + minOccurs="0" /> + </xs:sequence> + <xs:attribute name="version" type="map:versionType" fixed="2.0" /> <!-- use="required" --> + </xs:complexType> + <xs:simpleType name="versionType"> + <xs:restriction base="xs:token"> + <xs:pattern value="[0-9]+(\.[0-9]+)*" /> + </xs:restriction> + </xs:simpleType> + <xs:complexType name="validated-byType"> + <xs:sequence> + <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0" /> + </xs:sequence> + <xs:attribute type="xs:boolean" name="include-existing-validators" use="optional" /> + </xs:complexType> + <xs:complexType name="constraintType"> + <xs:sequence> + <xs:element type="xs:string" name="message" minOccurs="0" /> + <xs:element type="map:groupsType" + name="groups" + minOccurs="0" /> + <xs:element type="map:payloadType" + name="payload" + minOccurs="0" /> + <xs:element type="map:elementType" + name="element" + maxOccurs="unbounded" + minOccurs="0" /> + </xs:sequence> + <xs:attribute type="xs:string" name="annotation" use="required" /> + </xs:complexType> + <xs:complexType name="elementType" mixed="true"> + <xs:sequence> + <xs:element type="xs:string" name="value" maxOccurs="unbounded" minOccurs="0" /> + <xs:element type="map:annotationType" + name="annotation" + maxOccurs="unbounded" + minOccurs="0" /> + </xs:sequence> + <xs:attribute type="xs:string" name="name" use="required" /> + </xs:complexType> + <xs:complexType name="containerElementTypeType"> + <xs:sequence> + <xs:element type="xs:string" + name="valid" + minOccurs="0" + fixed="" /> + <xs:element type="map:groupConversionType" + name="convert-group" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:containerElementTypeType" + name="container-element-type" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:constraintType" + name="constraint" + minOccurs="0" + maxOccurs="unbounded" /> + </xs:sequence> + <xs:attribute name="type-argument-index" use="optional"> + <xs:simpleType> + <xs:restriction base="xs:int"> + <xs:minInclusive value="0" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:complexType> + <xs:complexType name="classType"> + <xs:sequence> + <xs:element type="map:groupSequenceType" + name="group-sequence" + minOccurs="0" /> + <xs:element type="map:constraintType" + name="constraint" + maxOccurs="unbounded" + minOccurs="0" /> + </xs:sequence> + <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" /> + </xs:complexType> + <xs:complexType name="beanType"> + <xs:sequence> + <xs:element type="map:classType" + name="class" + minOccurs="0"> + </xs:element> + <xs:element type="map:fieldType" + name="field" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:getterType" + name="getter" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:constructorType" + name="constructor" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:methodType" + name="method" + minOccurs="0" + maxOccurs="unbounded" /> + </xs:sequence> + <xs:attribute type="xs:string" name="class" use="required" /> + <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" default="true" /> + </xs:complexType> + <xs:complexType name="annotationType"> + <xs:sequence> + <xs:element type="map:elementType" + name="element" + maxOccurs="unbounded" + minOccurs="0" /> + </xs:sequence> + </xs:complexType> + <xs:complexType name="getterType"> + <xs:sequence> + <xs:element type="xs:string" name="valid" minOccurs="0" fixed="" /> + <xs:element type="map:groupConversionType" + name="convert-group" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:containerElementTypeType" + name="container-element-type" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:constraintType" + name="constraint" + minOccurs="0" + maxOccurs="unbounded" /> + </xs:sequence> + <xs:attribute type="xs:string" name="name" use="required" /> + <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" /> + </xs:complexType> + <xs:complexType name="methodType"> + <xs:sequence> + <xs:element type="map:parameterType" + name="parameter" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:crossParameterType" + name="cross-parameter" + minOccurs="0" + maxOccurs="1" /> + <xs:element type="map:returnValueType" + name="return-value" + minOccurs="0" + maxOccurs="1" /> + </xs:sequence> + <xs:attribute type="xs:string" name="name" use="required" /> + <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" /> + </xs:complexType> + <xs:complexType name="constructorType"> + <xs:sequence> + <xs:element type="map:parameterType" + name="parameter" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:crossParameterType" + name="cross-parameter" + minOccurs="0" + maxOccurs="1" /> + <xs:element type="map:returnValueType" + name="return-value" + minOccurs="0" + maxOccurs="1" /> + </xs:sequence> + <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" /> + </xs:complexType> + <xs:complexType name="parameterType"> + <xs:sequence> + <xs:element type="xs:string" name="valid" minOccurs="0" fixed="" /> + <xs:element type="map:groupConversionType" + name="convert-group" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:containerElementTypeType" + name="container-element-type" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:constraintType" + name="constraint" + minOccurs="0" + maxOccurs="unbounded" /> + </xs:sequence> + <xs:attribute type="xs:string" name="type" use="required" /> + <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" /> + </xs:complexType> + <xs:complexType name="returnValueType"> + <xs:sequence> + <xs:element type="xs:string" name="valid" minOccurs="0" fixed="" /> + <xs:element type="map:groupConversionType" + name="convert-group" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:containerElementTypeType" + name="container-element-type" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:constraintType" + name="constraint" + minOccurs="0" + maxOccurs="unbounded" /> + </xs:sequence> + <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" /> + </xs:complexType> + <xs:complexType name="crossParameterType"> + <xs:sequence> + <xs:element type="map:constraintType" + name="constraint" + minOccurs="0" + maxOccurs="unbounded" /> + </xs:sequence> + <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" /> + </xs:complexType> + <xs:complexType name="constraint-definitionType"> + <xs:sequence> + <xs:element type="map:validated-byType" + name="validated-by" /> + </xs:sequence> + <xs:attribute type="xs:string" name="annotation" use="required" /> + </xs:complexType> + <xs:complexType name="fieldType"> + <xs:sequence> + <xs:element type="xs:string" name="valid" minOccurs="0" fixed="" /> + <xs:element type="map:groupConversionType" + name="convert-group" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:containerElementTypeType" + name="container-element-type" + minOccurs="0" + maxOccurs="unbounded" /> + <xs:element type="map:constraintType" + name="constraint" + minOccurs="0" + maxOccurs="unbounded" /> + </xs:sequence> + <xs:attribute type="xs:string" name="name" use="required" /> + <xs:attribute type="xs:boolean" name="ignore-annotations" use="optional" /> + </xs:complexType> +</xs:schema> http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/BeanDescriptorTest.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/BeanDescriptorTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/BeanDescriptorTest.java index d81f90a..5c949c1 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/BeanDescriptorTest.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/BeanDescriptorTest.java @@ -42,6 +42,7 @@ import javax.validation.metadata.PropertyDescriptor; import javax.validation.metadata.Scope; import org.apache.bval.jsr.util.TestUtils; +import org.junit.Ignore; import org.junit.Test; /** @@ -120,6 +121,8 @@ public class BeanDescriptorTest extends ValidationTestBase { * interface group when querying the interface directly. */ @Test + // spec does not dictate this + @Ignore public void testNoImplicitGroupWhenQueryingInterfaceDirectly() { Set<ConstraintDescriptor<?>> nameDescriptors = validator.getConstraintsForClass(Person.class).getConstraintsForProperty("name").getConstraintDescriptors(); http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java index 355d676..fca45d1 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/CustomValidatorFactoryTest.java @@ -20,6 +20,7 @@ package org.apache.bval.jsr; import static org.hamcrest.CoreMatchers.isA; +import javax.validation.ClockProvider; import javax.validation.ConstraintValidatorFactory; import javax.validation.MessageInterpolator; import javax.validation.ParameterNameProvider; @@ -95,6 +96,11 @@ public class CustomValidatorFactoryTest { return null; } + @Override + public ClockProvider getClockProvider() { + return null; + } + } public static class NotAValidatorFactory { http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java b/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java index 83f2427..2dfe493 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/Jsr303Test.java @@ -31,8 +31,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import javax.validation.ConstraintValidator; import javax.validation.ConstraintViolation; import javax.validation.UnexpectedTypeException; +import javax.validation.constraints.Max; import javax.validation.metadata.BeanDescriptor; import javax.validation.metadata.ConstraintDescriptor; import javax.validation.metadata.ElementDescriptor; @@ -48,6 +50,7 @@ import org.apache.bval.jsr.example.NoValidatorTestEntity; import org.apache.bval.jsr.example.Second; import org.apache.bval.jsr.example.SizeTestEntity; import org.apache.bval.jsr.util.TestUtils; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -65,8 +68,10 @@ public class Jsr303Test extends ValidationTestBase { assertTrue(cons.getConstraintsForProperty("author").hasConstraints()); assertTrue(cons.getConstraintsForProperty("title").hasConstraints()); assertTrue(cons.getConstraintsForProperty("uselessField").hasConstraints()); - // cons.getConstraintsForProperty("unconstraintField") == null without Introspector - // cons.getConstraintsForProperty("unconstraintField") != null with Introspector + // cons.getConstraintsForProperty("unconstraintField") == null without + // Introspector + // cons.getConstraintsForProperty("unconstraintField") != null with + // Introspector assertTrue(cons.getConstraintsForProperty("unconstraintField") == null || !cons.getConstraintsForProperty("unconstraintField").hasConstraints()); assertNull(cons.getConstraintsForProperty("unknownField")); @@ -83,11 +88,13 @@ public class Jsr303Test extends ValidationTestBase { @Test(expected = IllegalArgumentException.class) public void testUnknownProperty() { - // tests for issue 22: validation of unknown field cause ValidationException + // tests for issue 22: validation of unknown field cause + // ValidationException validator.validateValue(Book.class, "unknownProperty", 4); } @Test(expected = IllegalArgumentException.class) + @Ignore public void testValidateNonCascadedRealNestedProperty() { validator.validateValue(IllustratedBook.class, "illustrator.firstName", "Edgar"); } @@ -95,7 +102,8 @@ public class Jsr303Test extends ValidationTestBase { @Test public void testMetadataAPI_Book() { assertNotNull(validator.getConstraintsForClass(Book.class)); - // not necessary for implementation correctness, but we'll test nevertheless: + // not necessary for implementation correctness, but we'll test + // nevertheless: assertSame(validator.getConstraintsForClass(Book.class), validator.getConstraintsForClass(Book.class)); BeanDescriptor bc = validator.getConstraintsForClass(Book.class); assertEquals(Book.class, bc.getElementClass()); @@ -135,8 +143,9 @@ public class Jsr303Test extends ValidationTestBase { validator.getConstraintsForClass(Address.class).getConstraintsForProperty("addressline1"); assertNotNull(desc); boolean found = false; + for (ConstraintDescriptor<?> each : desc.getConstraintDescriptors()) { - if (SizeValidatorForCharSequence.class.equals(each.getConstraintValidatorClasses().get(0))) { + if (each.getConstraintValidatorClasses().contains(SizeValidatorForCharSequence.class)) { assertTrue(each.getAttributes().containsKey("max")); assertEquals(30, each.getAttributes().get("max")); found = true; @@ -175,9 +184,8 @@ public class Jsr303Test extends ValidationTestBase { @Test public void testConstraintValidatorResolutionAlgorithm2() { thrown.expect(UnexpectedTypeException.class); - thrown.expectMessage("No validator could be found for type java.lang.Object. " - + "See: @Max at private java.lang.Object org.apache.bval.jsr.example." + "NoValidatorTestEntity.anything"); - + thrown.expectMessage(String.format("No compliant %s %s found for annotated element of type %s", + Max.class.getName(), ConstraintValidator.class.getSimpleName(), Object.class.getName())); NoValidatorTestEntity entity2 = new NoValidatorTestEntity(); validator.validate(entity2); } http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/ValidationTest.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/ValidationTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/ValidationTest.java index f6c7a4f..b696627 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/ValidationTest.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/ValidationTest.java @@ -59,6 +59,7 @@ import org.apache.bval.jsr.example.Last; import org.apache.bval.jsr.example.RecursiveFoo; import org.apache.bval.jsr.util.TestUtils; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; /** @@ -73,6 +74,7 @@ public class ValidationTest extends ValidationTestBase { } @Test + @Ignore // per spec, fields should after all be validated on subclasses public void testAccessStrategies_field_method() { AccessTestBusinessObject o1 = new AccessTestBusinessObject("1"); assertTrue(validator.validate(o1).isEmpty()); http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/example/Engine.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/example/Engine.java b/bval-jsr/src/test/java/org/apache/bval/jsr/example/Engine.java index 4ee8101..b65d091 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/example/Engine.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/example/Engine.java @@ -21,9 +21,11 @@ package org.apache.bval.jsr.example; import javax.validation.constraints.Pattern; public class Engine { - @Pattern.List({ - @Pattern(regexp = "^[A-Z0-9-]+$", flags = Pattern.Flag.CASE_INSENSITIVE, message = "must contain alphabetical characters only"), - @Pattern(regexp = "^....-....-....$", message = "must match ....-....-....") }) + // TODO See about Windows bug with container @ Field#getAnnotatedType() +// @Pattern.List({ + @Pattern(regexp = "^[A-Z0-9-]+$", flags = Pattern.Flag.CASE_INSENSITIVE, message = "must contain alphabetical characters only")//, + @Pattern(regexp = "^....-....-....$", message = "must match ....-....-....") +// }) public String serialNumber; } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java index 4740f5b..d05b47d 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java @@ -26,7 +26,7 @@ import javax.validation.constraints.Size; import javax.validation.executable.ExecutableValidator; import org.apache.bval.jsr.ApacheValidationProvider; -import org.apache.bval.jsr.ClassValidator; +import org.apache.bval.jsr.ValidatorImpl; import org.apache.bval.jsr.extensions.ExampleMethodService.Person; import org.junit.Ignore; @@ -53,7 +53,7 @@ public class MethodValidatorImplTest extends TestCase { public void testUnwrap() { Validator v = getValidator(); - ClassValidator cv = v.unwrap(ClassValidator.class); + ValidatorImpl cv = v.unwrap(ValidatorImpl.class); assertSame(v, cv); assertSame(v, v.unwrap(Validator.class)); assertNotNull(v.forExecutables()); http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java index 89489fb..17d6dba 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java @@ -52,16 +52,13 @@ public class GroupSequenceIsolationTest extends ValidationTestBase { public void testGroupSequencesInHierarchyClasses() { HolderWithNoGS h = new HolderWithNoGS(); - assertEquals(set("a1", "b2"), violationPaths(validator.validate(h))); - - h.a1 = "good"; assertEquals(set("a2", "b2"), violationPaths(validator.validate(h))); h.b2 = "good"; - assertEquals(set("a2", "b1"), violationPaths(validator.validate(h))); - - h.b1 = "good"; assertEquals(set("a2"), violationPaths(validator.validate(h))); + + h.a2 = "good"; + assertEquals(set("b1"), violationPaths(validator.validate(h))); } /** @@ -82,6 +79,7 @@ public class GroupSequenceIsolationTest extends ValidationTestBase { assertEquals(Collections.singleton("b1"), violationPaths(validator.validate(h))); } + @SafeVarargs private static <T> Set<T> set(T... elements) { return new HashSet<T>(Arrays.asList(elements)); } http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java index 13a49e1..4222339 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java @@ -18,22 +18,25 @@ */ package org.apache.bval.jsr.groups; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.apache.bval.jsr.example.Address; -import org.apache.bval.jsr.example.First; -import org.apache.bval.jsr.example.Last; -import org.apache.bval.jsr.example.Second; +import static org.junit.Assert.assertEquals; -import javax.validation.GroupDefinitionException; -import javax.validation.ValidationException; -import javax.validation.groups.Default; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; +import javax.validation.GroupDefinitionException; +import javax.validation.ValidationException; +import javax.validation.groups.Default; + +import org.apache.bval.jsr.example.Address; +import org.apache.bval.jsr.example.First; +import org.apache.bval.jsr.example.Last; +import org.apache.bval.jsr.example.Second; +import org.junit.Before; +import org.junit.Test; + /** * GroupListComputer Tester. * @@ -41,79 +44,41 @@ import java.util.Set; * @version 1.0 * @since <pre>04/09/2009</pre> */ -public class GroupsComputerTest extends TestCase { +public class GroupsComputerTest { GroupsComputer groupsComputer; - public GroupsComputerTest(String name) { - super(name); - } - - @Override + @Before public void setUp() throws Exception { - super.setUp(); groupsComputer = new GroupsComputer(); } - @Override - public void tearDown() throws Exception { - super.tearDown(); - } - - public static Test suite() { - return new TestSuite(GroupsComputerTest.class); - } - + @Test(expected = ValidationException.class) public void testComputeGroupsNotAnInterface() { - Set<Class<?>> groups = new HashSet<Class<?>>(); - groups.add(String.class); - try { - groupsComputer.computeGroups(groups); - fail(); - } catch (ValidationException ex) { - - } + groupsComputer.computeGroups(Collections.singleton(String.class)); } + @Test(expected = IllegalArgumentException.class) public void testGroupChainForNull() { - try { groupsComputer.computeGroups((Class<?>[]) null); - fail(); - } catch (IllegalArgumentException ex) { - - } } + @Test public void testGroupChainForEmptySet() { - try { - groupsComputer.computeGroups(new HashSet<Class<?>>()); - fail(); - } catch (IllegalArgumentException ex) { - - } + assertEquals(Collections.singletonList(Group.DEFAULT), + groupsComputer.computeGroups(new HashSet<Class<?>>()).getGroups()); } + @Test(expected = GroupDefinitionException.class) public void testCyclicGroupSequences() { - try { - Set<Class<?>> groups = new HashSet<Class<?>>(); - groups.add(CyclicGroupSequence1.class); - groupsComputer.computeGroups(groups); - fail(); - } catch (GroupDefinitionException ex) { - - } + groupsComputer.computeGroups(Collections.singleton(CyclicGroupSequence1.class)); } + @Test(expected = GroupDefinitionException.class) public void testCyclicGroupSequence() { - try { - Set<Class<?>> groups = new HashSet<Class<?>>(); - groups.add(CyclicGroupSequence.class); - groupsComputer.computeGroups(groups); - fail(); - } catch (GroupDefinitionException ex) { - - } + groupsComputer.computeGroups(Collections.singleton(CyclicGroupSequence.class)); } + @Test public void testGroupDuplicates() { Set<Class<?>> groups = new HashSet<Class<?>>(); groups.add(First.class); @@ -136,6 +101,7 @@ public class GroupsComputerTest extends TestCase { assertEquals(2, chain.groups.size()); } + @Test public void testSequenceResolution() { Set<Class<?>> groups = new HashSet<Class<?>>(); groups.add(Address.Complete.class); http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java new file mode 100644 index 0000000..02a07a8 --- /dev/null +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/Demo.java @@ -0,0 +1,40 @@ +package org.apache.bval.jsr.xml; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.UnmarshallerHandler; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.junit.Test; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; + +public class Demo { + + @Test + public void test1() throws Exception { + JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class); + + // Set the parent XMLReader on the XMLFilter + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + SAXParser sp = spf.newSAXParser(); + XMLReader xr = sp.getXMLReader(); + + // Set UnmarshallerHandler as ContentHandler on XMLFilter + + Unmarshaller unmarshaller = jc.createUnmarshaller(); + + UnmarshallerHandler unmarshallerHandler = unmarshaller.getUnmarshallerHandler(); + xr.setContentHandler(unmarshallerHandler); + + // Parse the XML + InputSource xml = new InputSource(getClass().getResourceAsStream("/sample-validation2.xml")); + xr.parse(xml); + JAXBElement<ValidationConfigType> result = (JAXBElement<ValidationConfigType>) unmarshallerHandler.getResult(); + System.out.println(ToStringBuilder.reflectionToString(result.getValue())); + } +} http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java index 827abae..41d4f13 100644 --- a/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java +++ b/bval-jsr/src/test/java/org/apache/bval/jsr/xml/ValidationParserTest.java @@ -19,6 +19,8 @@ package org.apache.bval.jsr.xml; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -84,6 +86,18 @@ public class ValidationParserTest implements ApacheValidatorConfiguration.Proper } @Test + public void testParseV11() { + ConfigurationImpl config = new ConfigurationImpl(null, new ApacheValidationProvider()); + ValidationParser.processValidationConfig("sample-validation11.xml", config, false); + } + + @Test + public void testParseV20() { + ConfigurationImpl config = new ConfigurationImpl(null, new ApacheValidationProvider()); + ValidationParser.processValidationConfig("sample-validation2.xml", config, false); + } + + @Test public void testConfigureFromXml() { ValidatorFactory factory = getFactory(); assertThat(factory.getMessageInterpolator(), instanceOf(TestMessageInterpolator.class)); @@ -105,8 +119,8 @@ public class ValidationParserTest implements ApacheValidatorConfiguration.Proper bean.setValueCode("illegal"); Validator validator = getFactory().getValidator(); Set<ConstraintViolation<XmlEntitySampleBean>> results = validator.validate(bean); - assertTrue(!results.isEmpty()); - assertTrue(results.size() == 3); + assertFalse(results.isEmpty()); + assertEquals(3, results.size()); bean.setZipCode("123"); bean.setValueCode("20"); http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/resources/sample-validation11.xml ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/resources/sample-validation11.xml b/bval-jsr/src/test/resources/sample-validation11.xml new file mode 100644 index 0000000..648ba1c --- /dev/null +++ b/bval-jsr/src/test/resources/sample-validation11.xml @@ -0,0 +1,30 @@ +<?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" + version="1.1"> + <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> http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-jsr/src/test/resources/sample-validation2.xml ---------------------------------------------------------------------- diff --git a/bval-jsr/src/test/resources/sample-validation2.xml b/bval-jsr/src/test/resources/sample-validation2.xml new file mode 100644 index 0000000..4758454 --- /dev/null +++ b/bval-jsr/src/test/resources/sample-validation2.xml @@ -0,0 +1,30 @@ +<?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://xmlns.jcp.org/xml/ns/javax/validation/configuration" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation= + "http://xmlns.jcp.org/xml/ns/javax/validation/configuration validation-configuration-2.0.xsd" + version="2.0"> + <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> http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-tck11/pom.xml ---------------------------------------------------------------------- diff --git a/bval-tck11/pom.xml b/bval-tck11/pom.xml index fb2ae65..63611b9 100644 --- a/bval-tck11/pom.xml +++ b/bval-tck11/pom.xml @@ -23,7 +23,7 @@ under the License. <parent> <artifactId>bval-parent</artifactId> <groupId>org.apache.bval</groupId> - <version>1.1.3-SNAPSHOT</version> + <version>2.0.0-SNAPSHOT</version> </parent> <artifactId>bval-tck11-runner</artifactId> @@ -32,15 +32,15 @@ under the License. <properties> <tck.version>1.1.4.Final</tck.version> - <owb.version>1.7.2</owb.version> - <arquillian.version>1.1.13.Final</arquillian.version> + <owb.version>1.6.0</owb.version> + <arquillian.version>1.1.8.Final</arquillian.version> <validation.provider>org.apache.bval.jsr.ApacheValidationProvider</validation.provider> </properties> <dependencies> <dependency> <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-validation_1.1_spec</artifactId> + <artifactId>geronimo-validation_2.0_spec</artifactId> <scope>provided</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/bval-xstream/pom.xml ---------------------------------------------------------------------- diff --git a/bval-xstream/pom.xml b/bval-xstream/pom.xml index 67ac48d..bf90180 100644 --- a/bval-xstream/pom.xml +++ b/bval-xstream/pom.xml @@ -27,7 +27,7 @@ <parent> <groupId>org.apache.bval</groupId> <artifactId>bval-parent</artifactId> - <version>1.1.3-SNAPSHOT</version> + <version>2.0.0-SNAPSHOT</version> </parent> <artifactId>bval-xstream</artifactId> http://git-wip-us.apache.org/repos/asf/bval/blob/3f287a7a/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 470ddd0..42e8d80 100644 --- a/pom.xml +++ b/pom.xml @@ -35,14 +35,16 @@ <artifactId>bval-parent</artifactId> <name>Apache BVal :: bval-parent (Parent POM)</name> <packaging>pom</packaging> - <version>1.1.3-SNAPSHOT</version> + <version>2.0.0-SNAPSHOT</version> <description>Apache BVal parent pom</description> <properties> <site.deploy.url>sftp://people.apache.org/home/${user.name}/public_html/bval/${project.version}/staging-site</site.deploy.url> <commons.weaver.version>1.3</commons.weaver.version> - <privilizer.policy>DYNAMIC</privilizer.policy> +<!-- temporarily disable privilizer due to Java 8 incompatibility --> +<!-- <privilizer.policy>DYNAMIC</privilizer.policy> --> + <privilizer.policy>NEVER</privilizer.policy> </properties> <inceptionYear>2010</inceptionYear> @@ -257,10 +259,10 @@ <configuration> <show>package</show> <quiet>true</quiet> - <source>1.6</source> + <source>1.8</source> <links> - <link>http://docs.oracle.com/javase/6/docs/api</link> - <link>http://docs.oracle.com/javaee/7/api</link> + <link>http://docs.oracle.com/javase/8/docs/api</link> +<!-- <link>http://docs.oracle.com/javaee/7/api</link> --> </links> </configuration> <reportSets> @@ -292,8 +294,8 @@ <dependencies> <dependency> <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-validation_1.1_spec</artifactId> - <version>1.0</version> + <artifactId>geronimo-validation_2.0_spec</artifactId> + <version>1.0-SNAPSHOT</version> </dependency> <!-- Optional profile to use Spec RI API --> <dependency> @@ -367,6 +369,13 @@ <version>7.0.72</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>com.oracle</groupId> + <artifactId>javafx</artifactId> + <version>8.0</version> + <systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath> + <scope>system</scope> + </dependency> </dependencies> </dependencyManagement> @@ -391,8 +400,8 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> - <source>1.6</source> - <target>1.6</target> + <source>1.8</source> + <target>1.8</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> @@ -406,9 +415,9 @@ </manifest> <manifestEntries> <Implementation-Build>${buildNumber}</Implementation-Build> - <Specification-Title>JSR-349 Bean Validation</Specification-Title> + <Specification-Title>JSR-380 Bean Validation</Specification-Title> <Specification-Vendor>Sun Microsystems, Inc.</Specification-Vendor> - <Specification-Version>1.1</Specification-Version> + <Specification-Version>2.0</Specification-Version> </manifestEntries> </archive> </configuration> @@ -424,8 +433,8 @@ <verbose>false</verbose> <maxmemory>512m</maxmemory> <links> - <link>http://docs.oracle.com/javase/6/docs/api</link> - <link>http://docs.oracle.com/javaee/7/api</link> + <link>http://docs.oracle.com/javase/8/docs/api</link> +<!-- <link>http://docs.oracle.com/javaee/7/api</link> --> </links> </configuration> </plugin> @@ -459,7 +468,7 @@ <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> - <version>2.0.1</version> + <version>3.3.0</version> <extensions>true</extensions> <configuration> <instructions> @@ -626,7 +635,7 @@ <version>[2.2.1,)</version> </requireMavenVersion> <requireJavaVersion> - <version>[1.6,)</version> + <version>[1.8,)</version> </requireJavaVersion> </rules> </configuration>
