You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ra...@apache.org on 2018/10/12 15:00:51 UTC
svn commit: r1843674 [20/22] - in /tomee/deps/branches/bval-2: ./ bundle/
bundle/src/ bundle/src/main/ bundle/src/main/appended-resources/
bundle/src/main/appended-resources/META-INF/ bval-extras/ bval-extras/src/
bval-extras/src/main/ bval-extras/src/...
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Library.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Library.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Library.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Library.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,72 @@
+/*
+ * 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.example;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Description: <br/>
+ */
+public class Library {
+ @NotNull
+ private String libraryName;
+ @Valid
+ private final Map<String, Book> taggedBooks = new HashMap<String, Book>();
+
+ private Person[] persons;
+
+ public String getLibraryName() {
+ return libraryName;
+ }
+
+ public void setLibraryName(String libraryName) {
+ this.libraryName = libraryName;
+ }
+
+ public Map<String, Book> getTaggedBooks() {
+ return taggedBooks;
+ }
+
+ public Person[] getPersons() {
+ return persons;
+ }
+
+ public void setPersons(Person[] persons) {
+ this.persons = persons;
+ }
+
+ @Valid
+ public List<Employee> getEmployees() {
+ if (persons == null)
+ return Collections.emptyList();
+
+ ArrayList<Employee> emps = new ArrayList<Employee>(persons.length);
+ for (Person each : persons) {
+ if (each instanceof Employee)
+ emps.add((Employee) each);
+ }
+ return emps;
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/MaxTestEntity.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/MaxTestEntity.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/MaxTestEntity.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/MaxTestEntity.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,70 @@
+/*
+ * 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.example;
+
+import javax.validation.constraints.Max;
+import java.math.BigDecimal;
+
+/**
+ * Description: <br/>
+ */
+public class MaxTestEntity {
+ @Max(100)
+ private String text;
+ private String property;
+
+ @Max(300)
+ private long longValue;
+
+ private BigDecimal decimalValue;
+
+ public String getText() {
+ return text;
+ }
+
+ @Max(200)
+ public String getProperty() {
+ return property;
+ }
+
+ public long getLongValue() {
+ return longValue;
+ }
+
+ @Max(400)
+ public BigDecimal getDecimalValue() {
+ return decimalValue;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public void setProperty(String property) {
+ this.property = property;
+ }
+
+ public void setLongValue(long longValue) {
+ this.longValue = longValue;
+ }
+
+ public void setDecimalValue(BigDecimal decimalValue) {
+ this.decimalValue = decimalValue;
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/NoValidatorTestEntity.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/NoValidatorTestEntity.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/NoValidatorTestEntity.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/NoValidatorTestEntity.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,30 @@
+/*
+ * 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.example;
+
+import javax.validation.constraints.Max;
+
+/**
+ * Description: <br/>
+ */
+public class NoValidatorTestEntity {
+ @Max(20)
+ private Object anything;
+
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Person.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Person.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Person.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Person.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,31 @@
+/*
+ * 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.example;
+
+import org.apache.bval.constraints.NotEmpty;
+
+public interface Person {
+ @NotEmpty
+ String getFirstName();
+
+ String getMiddleName();
+
+ @NotEmpty
+ String getLastName();
+}
\ No newline at end of file
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/PreferredGuest.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/PreferredGuest.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/PreferredGuest.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/PreferredGuest.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,34 @@
+/*
+ * 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.example;
+
+import javax.validation.constraints.Digits;
+
+public class PreferredGuest extends Customer {
+ @Digits(integer = 10, fraction = 0)
+ private String guestCreditCardNumber;
+
+ public String getGuestCreditCardNumber() {
+ return guestCreditCardNumber;
+ }
+
+ public void setGuestCreditCardNumber(String guestCreditCardNumber) {
+ this.guestCreditCardNumber = guestCreditCardNumber;
+ }
+}
\ No newline at end of file
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/RecursiveFoo.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/RecursiveFoo.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/RecursiveFoo.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/RecursiveFoo.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,42 @@
+/*
+ * 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.example;
+
+import org.apache.bval.constraints.NotEmpty;
+
+import javax.validation.Valid;
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * Description: <br/>
+ */
+public class RecursiveFoo {
+ @NotEmpty
+ @Valid
+ Collection<RecursiveFoo> foos = new ArrayList<RecursiveFoo>();
+
+ public Collection<RecursiveFoo> getFoos() {
+ return foos;
+ }
+
+ public void setFoos(Collection<RecursiveFoo> foos) {
+ this.foos = foos;
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Second.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Second.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Second.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/Second.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,25 @@
+/*
+ * 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.example;
+
+/**
+ * Description: <br/>
+ */
+public interface Second {
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/SizeTestEntity.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/SizeTestEntity.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/SizeTestEntity.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/SizeTestEntity.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,56 @@
+/*
+ * 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.example;
+
+import javax.validation.constraints.Size;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Description: <br/>
+ */
+public class SizeTestEntity {
+ @Size(max = 2)
+ public Map<String, String> map;
+ @Size(max = 2)
+ public Collection<String> coll;
+ @Size(max = 2)
+ public String text;
+
+ @Size(max = 2)
+ public Object[] oa;
+ @Size(max = 2)
+ public byte[] ba;
+ @Size(max = 2)
+ public int[] it;
+ @Size(max = 2)
+ public Integer[] oa2;
+ @Size(max = 2)
+ public boolean[] boa;
+ @Size(max = 2)
+ public char[] ca;
+ @Size(max = 2)
+ public double[] da;
+ @Size(max = 2)
+ public float[] fa;
+ @Size(max = 2)
+ public long[] la;
+ @Size(max = 2)
+ public short[] sa;
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/XmlEntitySampleBean.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/XmlEntitySampleBean.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/XmlEntitySampleBean.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/XmlEntitySampleBean.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,53 @@
+/*
+ * 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.example;
+
+/**
+ * Description: bean used to test constraints described in XML<br/>
+ */
+public class XmlEntitySampleBean {
+ private String zipCode;
+ private String valueCode;
+
+ private String firstName;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getZipCode() {
+ return zipCode;
+ }
+
+ public void setZipCode(String zipCode) {
+ this.zipCode = zipCode;
+ }
+
+ public String getValueCode() {
+ return valueCode;
+ }
+
+ public void setValueCode(String valueCode) {
+ this.valueCode = valueCode;
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/ZipCodeCityCarrier.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/ZipCodeCityCarrier.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/ZipCodeCityCarrier.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/example/ZipCodeCityCarrier.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,28 @@
+/*
+ * 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.example;
+
+/**
+ * Description: <br/>
+ */
+public interface ZipCodeCityCarrier {
+ String getZipCode();
+
+ String getCity();
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/ExampleMethodService.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/ExampleMethodService.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/ExampleMethodService.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/ExampleMethodService.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,68 @@
+/*
+ * 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.extensions;
+
+import org.apache.bval.constraints.NotEmpty;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+/**
+ * Description: class with annotated methods to demonstrate
+ * method-level-validation<br/>
+ */
+public class ExampleMethodService {
+ public ExampleMethodService() {
+ }
+
+ public ExampleMethodService(@NotNull @NotEmpty String s1, @NotNull String s2) {
+ }
+
+ @NotNull
+ @NotEmpty
+ public String concat(@NotNull @NotEmpty String s1, @NotNull String s2) {
+ return s1 + s2;
+ }
+
+ public void save(@Pattern(regexp = "[a-f0-9]{4}") String data) {
+ return;
+ }
+
+ @NotNull
+ @Size(min = 3, max = 10)
+ public String echo(@NotNull @Size(min = 3, max = 10) String str) {
+ return str;
+ }
+
+ public void personOp1(@Valid Person p) {
+ return;
+ }
+
+ public void personOp2(@NotNull @Valid Person p) {
+ return;
+ }
+
+ public static class Person {
+ @NotNull
+ String name;
+ }
+
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,216 @@
+/*
+ * 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.extensions;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.validation.executable.ExecutableValidator;
+
+import org.apache.bval.jsr.ApacheValidationProvider;
+import org.apache.bval.jsr.ValidatorImpl;
+import org.apache.bval.jsr.extensions.ExampleMethodService.Person;
+import org.junit.Ignore;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * MethodValidatorImpl Tester.
+ *
+ * @author <Authors name>
+ * @version 1.0
+ * @since <pre>11/11/2009</pre>
+ */
+@SuppressWarnings({ "unchecked", "rawtypes" })
+public class MethodValidatorImplTest extends TestCase {
+ public MethodValidatorImplTest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new TestSuite(MethodValidatorImplTest.class);
+ }
+
+ public void testUnwrap() {
+ Validator v = getValidator();
+ ValidatorImpl cv = v.unwrap(ValidatorImpl.class);
+ assertSame(v, cv);
+ assertSame(v, v.unwrap(Validator.class));
+ assertNotNull(v.forExecutables());
+ }
+
+ public void testValidateMethodParameters() throws NoSuchMethodException {
+ ExampleMethodService service = new ExampleMethodService();
+ ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+ Method method = service.getClass().getMethod("concat", String.class, String.class);
+ String[] params = new String[] { "Hello ", "world" };
+ assertTrue(mv.validateParameters(service, method, params).isEmpty());
+
+ params[0] = "";
+ assertEquals(1, mv.validateParameters(service, method, params).size());
+
+ params[1] = null;
+ assertEquals(2, mv.validateParameters(service, method, params).size());
+ }
+
+ public void testValidateMoreMethodParameters() throws NoSuchMethodException {
+
+ ExampleMethodService service = new ExampleMethodService();
+ ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+ Method saveMethod = service.getClass().getMethod("save", String.class);
+
+ String[] saveParams = new String[1];
+ saveParams[0] = "abcd";
+ assertTrue(mv.validateParameters(service, saveMethod, saveParams).isEmpty());
+
+ saveParams[0] = "zzzz";
+ assertEquals(1, mv.validateParameters(service, saveMethod, saveParams).size());
+
+ Method echoMethod = service.getClass().getMethod("echo", String.class);
+
+ String[] echoParams = new String[1];
+ echoParams[0] = "hello";
+ assertTrue(mv.validateParameters(service, echoMethod, echoParams).isEmpty());
+
+ echoParams[0] = "h";
+ assertEquals(1, mv.validateParameters(service, echoMethod, echoParams).size());
+
+ echoParams[0] = null;
+ assertEquals(1, mv.validateParameters(service, echoMethod, echoParams).size());
+ }
+
+ public void testValidateConstructorParameters() throws NoSuchMethodException {
+ ExampleMethodService service = new ExampleMethodService();
+ ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+ Constructor constructor = service.getClass().getConstructor(String.class, String.class);
+ String[] params = new String[] { "Hello ", "world" };
+
+ assertTrue(mv.<ExampleMethodService> validateConstructorParameters(constructor, params).isEmpty());
+
+ params[0] = "";
+ assertEquals(1, mv.validateConstructorParameters(constructor, params).size());
+
+ params[1] = null;
+ assertEquals(2, mv.validateConstructorParameters(constructor, params).size());
+ }
+
+ public void testValidateReturnValue() throws NoSuchMethodException {
+ ExampleMethodService service = new ExampleMethodService();
+ ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+ Method method = service.getClass().getMethod("concat", String.class, String.class);
+
+ assertTrue(mv.validateReturnValue(service, method, "test").isEmpty());
+
+ assertEquals(1, mv.validateReturnValue(service, method, "").size());
+ }
+
+ public void testValidateMoreReturnValue() throws NoSuchMethodException {
+ ExampleMethodService service = new ExampleMethodService();
+ ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+ Method echoMethod = service.getClass().getMethod("echo", String.class);
+
+ String returnedValue = "a too long string";
+ assertEquals(1, mv.validateReturnValue(service, echoMethod, returnedValue).size());
+
+ returnedValue = null;
+ assertEquals(1, mv.validateReturnValue(service, echoMethod, returnedValue).size());
+
+ returnedValue = "valid";
+ assertTrue(mv.validateReturnValue(service, echoMethod, returnedValue).isEmpty());
+ }
+
+ public void testValidateValidParam() throws NoSuchMethodException {
+ ExampleMethodService service = new ExampleMethodService();
+ ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+
+ Method personOp1 = service.getClass().getMethod("personOp1", Person.class);
+
+ // Validate with invalid person
+ Person p = new ExampleMethodService.Person();
+ assertEquals("Expected 1 violation", 1, mv.validateParameters(service, personOp1, new Object[] { p }).size());
+
+ // validate with valid person
+ p.name = "valid name";
+ assertTrue("No violations expected", mv.validateParameters(service, personOp1, new Object[] { p }).isEmpty());
+
+ // validate with null person
+ assertTrue("No violations expected",
+ mv.validateParameters(service, personOp1, new Object[] { null }).isEmpty());
+ }
+
+ public void testValidateNotNullValidParam() throws NoSuchMethodException {
+ ExampleMethodService service = new ExampleMethodService();
+ ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+
+ Method personOp2 = service.getClass().getMethod("personOp2", Person.class);
+
+ // Validate with null person
+ assertEquals("Expected 1 violation", 1,
+ mv.validateParameters(service, personOp2, new Object[] { null }).size());
+
+ // Validate with invalid person
+ Person p = new ExampleMethodService.Person();
+ assertEquals("Expected 1 violation", 1, mv.validateParameters(service, personOp2, new Object[] { p }).size());
+
+ // validate with valid person
+ p.name = "valid name";
+ assertTrue("No violations expected", mv.validateParameters(service, personOp2, new Object[] { p }).isEmpty());
+ }
+
+ /**
+ * Validate a method defined in an interface using the following
+ * combinations:
+ * <ul>
+ * <li>impl.class + impl.method</li>
+ * <li>interface.class + interface.method</li>
+ * <li>impl.class + interface.method</li>
+ * <li>interface.class + impl.method</li>
+ * </ul>
+ */
+ @Ignore("violates Liskov principle, forbidden by the spec - 4.5.5")
+ public void validateImplementedMethod() throws NoSuchMethodException {
+ UserMethodsImpl um = new UserMethodsImpl();
+ ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+
+ Method classMethod = um.getClass().getMethod("findUser", String.class, String.class, Integer.class);
+ UserMethods.class.getMethod("findUser", String.class, String.class, Integer.class);
+
+ assertEquals("Invalid number of violations", 2,
+ mv.validateParameters(um, classMethod, new Object[] { "", "valid", null }).size());
+ }
+
+ public static interface UserMethods {
+ void findUser(String param1, String param2, Integer param3);
+ }
+
+ public static class UserMethodsImpl implements UserMethods {
+ @Override
+ public void findUser(@Size(min = 1) String param1, @NotNull String param2, @NotNull Integer param3) {
+ return;
+ }
+ }
+
+ private Validator getValidator() {
+ return Validation.byProvider(ApacheValidationProvider.class).configure().buildValidatorFactory().getValidator();
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/Billable.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/Billable.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/Billable.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/Billable.java Fri Oct 12 15:00:48 2018
@@ -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.
+ */
+package org.apache.bval.jsr.groups;
+
+/**
+ * Validation group checking a user is billable.
+ * Example 3.1. Definition of groups
+ */
+public interface Billable {
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableCreditCard.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableCreditCard.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableCreditCard.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableCreditCard.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+/**
+ * Example 3.2. Assign groups to constraints.
+ */
+public class BillableCreditCard {
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableUser.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableUser.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableUser.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableUser.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+
+/**
+ * User representation
+ * Example 3.2. Assign groups to constraints.
+ */
+public class BillableUser {
+ @NotNull
+ private String firstname;
+
+ @NotNull(groups = Default.class)
+ private String lastname;
+
+ @NotNull(groups = { Billable.class, BuyInOneClick.class })
+ private BillableCreditCard defaultCreditCard;
+
+ public String getFirstname() {
+ return firstname;
+ }
+
+ public void setFirstname(String firstname) {
+ this.firstname = firstname;
+ }
+
+ public String getLastname() {
+ return lastname;
+ }
+
+ public void setLastname(String lastname) {
+ this.lastname = lastname;
+ }
+
+ public BillableCreditCard getDefaultCreditCard() {
+ return defaultCreditCard;
+ }
+
+ public void setDefaultCreditCard(BillableCreditCard defaultCreditCard) {
+ this.defaultCreditCard = defaultCreditCard;
+ }
+}
\ No newline at end of file
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BuyInOneClick.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BuyInOneClick.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BuyInOneClick.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BuyInOneClick.java Fri Oct 12 15:00:48 2018
@@ -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.
+ */
+package org.apache.bval.jsr.groups;
+
+/**
+ * customer can buy without any harrassing checking process.
+ * Example 3.1. Definition of groups
+ */
+public interface BuyInOneClick {
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CollectionValidationTest.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CollectionValidationTest.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CollectionValidationTest.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CollectionValidationTest.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,196 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+import org.apache.bval.jsr.DefaultMessageInterpolator;
+import org.apache.bval.jsr.example.Address;
+import org.apache.bval.jsr.example.Author;
+import org.apache.bval.jsr.example.Book;
+import org.apache.bval.jsr.example.Country;
+import org.apache.bval.jsr.example.Customer;
+import org.apache.bval.jsr.example.Employee;
+import org.apache.bval.jsr.example.Library;
+import org.apache.bval.jsr.example.Person;
+import org.apache.bval.jsr.util.TestUtils;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import java.util.ArrayList;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Description: <br/>
+ */
+public class CollectionValidationTest extends TestCase {
+ static ValidatorFactory factory;
+
+ static {
+ factory = Validation.buildDefaultValidatorFactory();
+ ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+ }
+
+ /**
+ * Validator instance to test
+ */
+ protected Validator validator;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ validator = createValidator();
+ }
+
+ /**
+ * Create the validator instance.
+ *
+ * @return Validator
+ */
+ protected Validator createValidator() {
+ return factory.getValidator();
+ }
+
+ public void testValidateList() {
+ Author author = new Author();
+ author.setFirstName("Peter");
+ author.setLastName("Ford");
+ author.setCompany("IBM");
+ author.setAddresses(new ArrayList<Address>());
+
+ Address adr1, adr2, adr3;
+ adr1 = new Address();
+ adr1.setCountry(new Country());
+ adr1.getCountry().setName("Germany");
+ adr1.setCity("Bonn");
+ adr1.setAddressline1("Strasse 1");
+
+ adr2 = new Address();
+ adr2.setCountry(new Country());
+ adr2.getCountry().setName("Cuba");
+ adr2.setCity("Habana");
+ adr2.setAddressline1("Calle 2");
+
+ adr3 = new Address();
+ adr3.setCountry(new Country());
+ adr3.getCountry().setName("USA");
+ adr3.setCity("San Francisco");
+ adr3.setAddressline1("Street 3");
+
+ author.getAddresses().add(adr1);
+ author.getAddresses().add(adr2);
+ author.getAddresses().add(adr3);
+
+ Set<ConstraintViolation<Author>> violations;
+
+ violations = validator.validate(author);
+ assertEquals(0, violations.size());
+
+ adr2.setCity(null); // violate not null
+ adr3.setAddressline1(null); // violate not null
+
+ violations = validator.validate(author);
+ assertEquals(2, violations.size());
+ assertNotNull(TestUtils.getViolation(violations, "addresses[1].city"));
+ assertNotNull(TestUtils.getViolation(violations, "addresses[2].addressline1"));
+ }
+
+ public void testValidateMapAndRedefinedDefaultGroupOnNonRootBean() {
+ Library lib = new Library();
+ lib.setLibraryName("Leibnitz Bibliothek");
+
+ Book book1, book2, book3;
+
+ book1 = new Book();
+ book1.setTitle("History of time");
+ book1.setSubtitle("How it really works");
+ Author hawking = new Author();
+ hawking.setFirstName("Stephen");
+ hawking.setFirstName("Hawking");
+ hawking.setAddresses(new ArrayList<Address>(1));
+ Address adr = new Address();
+ adr.setAddressline1("Street 1");
+ adr.setCity("London");
+ adr.setCountry(new Country());
+ adr.getCountry().setName("England");
+ hawking.getAddresses().add(adr);
+ book1.setAuthor(hawking);
+
+ book2 = new Book();
+ Author castro = new Author();
+ castro.setFirstName("Fidel");
+ castro.setLastName("Castro Ruz");
+ book2.setAuthor(castro);
+ book2.setTitle("My life");
+
+ book3 = new Book();
+ book3.setTitle("World best jokes");
+ Author someone = new Author();
+ someone.setFirstName("John");
+ someone.setLastName("Do");
+ book3.setAuthor(someone);
+
+ lib.getTaggedBooks().put("science", book1);
+ lib.getTaggedBooks().put("politics", book2);
+ lib.getTaggedBooks().put("humor", book3);
+
+ Set<ConstraintViolation<Library>> violations;
+
+ violations = validator.validate(lib);
+ assertTrue(violations.isEmpty());
+
+ book2.setTitle(null);
+ book3.getAuthor().setFirstName(""); // violate NotEmpty validation
+ book1.getAuthor().getAddresses().get(0).setCity(null);
+ /*
+ * This, by the way, tests redefined default group sequence behavior on
+ * non-root-beans (Library.Book)!!
+ */
+ violations = validator.validate(lib);
+ assertEquals("redefined default group of Book not correctly validated from Library", 3, violations.size());
+ assertNotNull(TestUtils.getViolation(violations, "taggedBooks[politics].title"));
+ assertNotNull(TestUtils.getViolation(violations, "taggedBooks[humor].author.firstName"));
+ assertNotNull(TestUtils.getViolation(violations, "taggedBooks[science].author.addresses[0].city"));
+ }
+
+ public void testValidateArray() {
+ Library lib = new Library();
+ lib.setLibraryName("Unibibliothek");
+ lib.setPersons(new Person[3]);
+ lib.getPersons()[0] = new Employee("Marcel", "Reich-Ranicki");
+ lib.getPersons()[1] = new Employee("Elke", "Heidenreich");
+ lib.getPersons()[2] = new Customer(); // not validated, because only
+ // getEmployees() is @Valid
+
+ Set<ConstraintViolation<Library>> violations;
+ violations = validator.validate(lib);
+ assertTrue(violations.isEmpty());
+
+ ((Employee) lib.getPersons()[1]).setFirstName(""); // violate NotEmpty
+ // constraint
+ violations = validator.validate(lib);
+ assertEquals(1, violations.size());
+ assertNotNull(TestUtils.getViolation(violations, "employees[1].firstName"));
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ */
+@GroupSequence(value = CyclicGroupSequence.class)
+public interface CyclicGroupSequence {
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence1.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence1.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence1.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence1.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ */
+@GroupSequence(value = CyclicGroupSequence2.class)
+public interface CyclicGroupSequence1 {
+}
\ No newline at end of file
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence2.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence2.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence2.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence2.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ */
+@GroupSequence(value = CyclicGroupSequence1.class)
+public interface CyclicGroupSequence2 {
+
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/DefaultGroupSequenceTest.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/DefaultGroupSequenceTest.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/DefaultGroupSequenceTest.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/DefaultGroupSequenceTest.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,148 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+
+import javax.validation.GroupDefinitionException;
+import javax.validation.groups.Default;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Hardy Ferentschik
+ * @author Roman Stumm
+ */
+public class DefaultGroupSequenceTest extends TestCase {
+ public void testAssertDefaultGroupSequenceIsExpandableWithDefaultAtEndOfSequence() {
+ // create a dummy sequence
+ Group a = new Group(GroupA.class);
+ Group b = new Group(GroupB.class);
+ Group c = new Group(GroupC.class);
+ Group defaultGroup = new Group(Default.class);
+ List<Group> sequence = new ArrayList<Group>();
+ sequence.add(a);
+ sequence.add(b);
+ sequence.add(c);
+ sequence.add(defaultGroup);
+
+ Groups chain = new Groups();
+ chain.insertSequence(sequence);
+
+ // create test default sequence
+ List<Group> defaultSequence = new ArrayList<Group>();
+ defaultSequence.add(Group.DEFAULT);
+ defaultSequence.add(new Group(GroupA.class));
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
+ fail();
+ } catch (GroupDefinitionException e) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add(new Group(GroupA.class));
+ defaultSequence.add(new Group(Default.class));
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
+ fail();
+ } catch (GroupDefinitionException e) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add(Group.DEFAULT);
+ defaultSequence.add(new Group(GroupC.class));
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
+ fail();
+ } catch (GroupDefinitionException e) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add(new Group(GroupC.class));
+ defaultSequence.add(Group.DEFAULT);
+ chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
+ }
+
+ public void testAssertDefaulGroupSequenceIsExpandableWithDefaultAtBeginningOfSequence() {
+ // create a dummy sequence
+ Group a = new Group(GroupA.class);
+ Group b = new Group(GroupB.class);
+ Group c = new Group(GroupC.class);
+ Group defaultGroup = new Group(Default.class);
+ List<Group> sequence = new ArrayList<Group>();
+ sequence.add(defaultGroup);
+ sequence.add(a);
+ sequence.add(b);
+ sequence.add(c);
+
+ Groups chain = new Groups();
+ chain.insertSequence(sequence);
+
+ // create test default sequence
+ List<Group> defaultSequence = new ArrayList<Group>();
+ defaultSequence.add(Group.DEFAULT);
+ defaultSequence.add(new Group(GroupA.class));
+ chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
+
+ defaultSequence.clear();
+ defaultSequence.add(new Group(GroupA.class));
+ defaultSequence.add(Group.DEFAULT);
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
+ fail();
+ } catch (GroupDefinitionException e) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add(Group.DEFAULT);
+ defaultSequence.add(new Group(GroupC.class));
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
+ fail();
+ } catch (GroupDefinitionException e) {
+ // success
+ }
+
+ defaultSequence.clear();
+ defaultSequence.add(new Group(GroupC.class));
+ defaultSequence.add(Group.DEFAULT);
+ try {
+ chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
+ fail();
+ } catch (GroupDefinitionException e) {
+ // success
+ }
+ }
+}
+
+interface TestSequence {
+}
+
+interface GroupA {
+}
+
+interface GroupB {
+}
+
+interface GroupC {
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass1.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass1.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass1.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass1.java Fri Oct 12 15:00:48 2018
@@ -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.
+ */
+package org.apache.bval.jsr.groups;
+
+/**
+ * Description: <br/>
+ */
+public class GClass1 implements GInterface1 {
+
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass2.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass2.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass2.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass2.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ */
+@GroupSequence({ GClass1.class, GClass2.class })
+public class GClass2 extends GClass1 {
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass3.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass3.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass3.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass3.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ */
+@GroupSequence({ GClass3.class, GClass1.class })
+public class GClass3 {
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GInterface1.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GInterface1.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GInterface1.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GInterface1.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ */
+@GroupSequence(GInterface1.class)
+public interface GInterface1 {
+
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,127 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+
+import org.apache.bval.jsr.ValidationTestBase;
+import org.junit.Test;
+
+/**
+ * Additional tests to check the correct processing of {@link GroupSequence}s
+ * by the validator.
+ *
+ * @author Carlos Vara
+ */
+public class GroupSequenceIsolationTest extends ValidationTestBase {
+
+ /**
+ * When validating the {@link Default} group in a bean whose class doesn't
+ * define a {@link GroupSequence}, all the classes in the hierarchy must be
+ * checked for group sequence definitions and they must be evaluated in
+ * order for the constraints defined on those classes.
+ */
+ @Test
+ public void testGroupSequencesInHierarchyClasses() {
+ HolderWithNoGS h = new HolderWithNoGS();
+
+ assertEquals(set("a2", "b2"), violationPaths(validator.validate(h)));
+
+ h.b2 = "good";
+ assertEquals(set("a2"), violationPaths(validator.validate(h)));
+
+ h.a2 = "good";
+ assertEquals(set("b1"), violationPaths(validator.validate(h)));
+ }
+
+ /**
+ * When validating the {@link Default} group in a bean whose class defines
+ * a group sequence, that group sequence is used for all the constraints.
+ */
+ @Test
+ public void testGroupSequenceOfBeanClass() {
+ HolderWithGS h = new HolderWithGS();
+
+ assertEquals(Collections.singleton("a1"), violationPaths(validator.validate(h)));
+
+ h.a1 = "good";
+ assertEquals(set("a2", "b2"), violationPaths(validator.validate(h)));
+
+ h.a2 = "good";
+ h.b2 = "good";
+ assertEquals(Collections.singleton("b1"), violationPaths(validator.validate(h)));
+ }
+
+ @SafeVarargs
+ private static <T> Set<T> set(T... elements) {
+ return new HashSet<T>(Arrays.asList(elements));
+ }
+
+ private static Set<String> violationPaths(Set<? extends ConstraintViolation<?>> violations) {
+ if (violations == null || violations.isEmpty()) {
+ return Collections.emptySet();
+ }
+ final Set<String> result = new LinkedHashSet<String>(violations.size());
+ for (ConstraintViolation<?> constraintViolation : violations) {
+ result.add(constraintViolation.getPropertyPath().toString());
+ }
+ return result;
+ }
+
+ @GroupSequence({ GroupA1.class, A.class })
+ public static class A {
+ @NotNull(groups = { GroupA1.class })
+ public String a1;
+ @NotNull
+ public String a2;
+ }
+
+ public interface GroupA1 {
+ }
+
+ @GroupSequence({ B.class, GroupB1.class })
+ public static class B extends A {
+ @NotNull(groups = { GroupB1.class })
+ public String b1;
+ @NotNull
+ public String b2;
+ }
+
+ public interface GroupB1 {
+ }
+
+ // No group sequence definition
+ public static class HolderWithNoGS extends B {
+ }
+
+ @GroupSequence({ GroupA1.class, HolderWithGS.class, GroupB1.class })
+ public static class HolderWithGS extends B {
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,206 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Predicate;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.GroupDefinitionException;
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
+
+import org.apache.bval.jsr.ApacheValidatorFactory;
+import org.apache.bval.jsr.ValidationTestBase;
+import org.apache.bval.jsr.descriptor.BeanD;
+import org.apache.bval.jsr.example.Author;
+import org.apache.bval.jsr.example.Book;
+import org.apache.bval.jsr.example.First;
+import org.apache.bval.jsr.example.Last;
+import org.apache.bval.jsr.example.Second;
+import org.apache.bval.jsr.util.TestUtils;
+import org.junit.Test;
+
+/**
+ * Description: test of group sequence behavior<br/>
+ */
+public class GroupSequenceTest extends ValidationTestBase {
+ @Test(expected = GroupDefinitionException.class)
+ public void testGroupSequence1() {
+ ApacheValidatorFactory.getDefault().usingContext().getValidator().getConstraintsForClass(GInterface1.class);
+ }
+
+ @Test
+ public void testGroupSequence2() {
+ BeanD<?> bean = (BeanD<?>) ApacheValidatorFactory.getDefault().usingContext().getValidator()
+ .getConstraintsForClass(GClass1.class);
+
+ assertEquals(Group.of(GClass1.class), bean.getGroupStrategy());
+ }
+
+ @Test
+ public void testGroupSequence3() {
+ BeanD<?> bean = (BeanD<?>) ApacheValidatorFactory.getDefault().usingContext().getValidator()
+ .getConstraintsForClass(GClass2.class);
+
+ class TestPredicate implements Predicate<GroupStrategy> {
+
+ final List<GroupStrategy> strategies = new ArrayList<>();
+
+ @Override
+ public boolean test(GroupStrategy t) {
+ return strategies.add(t);
+ }
+ }
+
+ final TestPredicate p = new TestPredicate();
+
+ bean.getGroupStrategy().applyTo(p);
+
+ Group g1 = Group.of(GClass1.class);
+ Group g2 = Group.of(GClass2.class);
+
+ assertEquals(Arrays.asList(g1, GroupStrategy.simple(g1, g2)), p.strategies);
+ }
+
+ @Test
+ public void testGroupSequence4() {
+ BeanD<?> bean = (BeanD<?>) ApacheValidatorFactory.getDefault().usingContext().getValidator()
+ .getConstraintsForClass(GClass3.class);
+
+ assertEquals(Group.sequence(Group.of(GClass3.class), Group.of(GClass1.class)), bean.getGroupStrategy());
+ }
+
+ @Test
+ public void testGroups() {
+ Author author = new Author();
+ author.setLastName("");
+ author.setFirstName("");
+ Book book = new Book();
+ book.setTitle("");
+ book.setAuthor(author);
+
+ Set<ConstraintViolation<Book>> constraintViolations =
+ validator.validate(book, First.class, Second.class, Last.class);
+ assertEquals("Wrong number of constraints", 3, constraintViolations.size());
+ assertNotNull(TestUtils.getViolation(constraintViolations, "title"));
+ assertNotNull(TestUtils.getViolation(constraintViolations, "author.firstName"));
+ assertNotNull(TestUtils.getViolation(constraintViolations, "author.lastName"));
+
+ author.setFirstName("Gavin");
+ author.setLastName("King");
+
+ constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
+ ConstraintViolation<?> constraintViolation = constraintViolations.iterator().next();
+ assertEquals(1, constraintViolations.size());
+ assertEquals("may not be empty", constraintViolation.getMessage());
+ assertEquals(book, constraintViolation.getRootBean());
+ assertEquals(book.getTitle(), constraintViolation.getInvalidValue());
+ assertEquals("title", constraintViolation.getPropertyPath().toString());
+
+ book.setTitle("My fault");
+ book.setSubtitle("confessions of a president - a book for a nice price");
+
+ constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
+ assertEquals(1, constraintViolations.size());
+ constraintViolation = constraintViolations.iterator().next();
+ assertEquals("size must be between 0 and 30", constraintViolation.getMessage());
+ assertEquals(book, constraintViolation.getRootBean());
+ assertEquals(book.getSubtitle(), constraintViolation.getInvalidValue());
+ assertEquals("subtitle", constraintViolation.getPropertyPath().toString());
+
+ book.setSubtitle("Capitalism in crisis");
+ author.setCompany("1234567890Ã9876543212578909876542245678987432");
+
+ constraintViolations = validator.validate(book);
+ constraintViolation = constraintViolations.iterator().next();
+ assertEquals(1, constraintViolations.size());
+ assertEquals("size must be between 0 and 40", constraintViolation.getMessage());
+ assertEquals(book, constraintViolation.getRootBean());
+ assertEquals(author.getCompany(), constraintViolation.getInvalidValue());
+ assertEquals("author.company", constraintViolation.getPropertyPath().toString());
+
+ author.setCompany("apache");
+
+ constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
+ assertEquals(0, constraintViolations.size());
+ }
+
+ @Test
+ public void testGroupSequence() {
+ Author author = new Author();
+ author.setLastName("");
+ author.setFirstName("");
+ Book book = new Book();
+ book.setAuthor(author);
+
+ Set<ConstraintViolation<Book>> constraintViolations = validator.validate(book, Book.All.class);
+ assertEquals(2, constraintViolations.size());
+
+ author.setFirstName("Kelvin");
+ author.setLastName("Cline");
+
+ constraintViolations = validator.validate(book, Book.All.class);
+ ConstraintViolation<?> constraintViolation = constraintViolations.iterator().next();
+ assertEquals(1, constraintViolations.size());
+ assertEquals("may not be null", constraintViolation.getMessage());
+ assertEquals(book, constraintViolation.getRootBean());
+ assertEquals(book.getTitle(), constraintViolation.getInvalidValue());
+ assertEquals("title", constraintViolation.getPropertyPath().toString());
+
+ book.setTitle("247307892430798789024389798789");
+ book.setSubtitle("f43u rlök fjöq3liu opiur ölw3kj rölkj d");
+
+ constraintViolations = validator.validate(book, Book.All.class);
+ assertEquals(1, constraintViolations.size());
+ }
+
+ /**
+ * Check that when there is one constraint failure in one of the groups in
+ * a sequence, validation stops.
+ * JSR-303: 3.4.3
+ */
+ @Test
+ public void testValidationStopsWhenFailuresOnGroup() {
+ // Validate Dummy with its redefined Default group
+ Set<ConstraintViolation<Dummy>> violations = validator.validate(new Dummy());
+ assertEquals("Only 1 violation expected", 1, violations.size());
+ ConstraintViolation<Dummy> violation = violations.iterator().next();
+ assertEquals("Group1 should be evaluated first", "field1", violation.getPropertyPath().toString());
+ }
+
+ @GroupSequence({ Dummy.Group1.class, Dummy.class })
+ public static class Dummy {
+
+ @NotNull(groups = Group1.class)
+ public String field1;
+
+ @NotNull
+ public String field2;
+
+ interface Group1 {
+ }
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupValidationTest.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupValidationTest.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupValidationTest.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupValidationTest.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,83 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+
+import org.apache.bval.jsr.ValidationTestBase;
+import org.apache.bval.jsr.util.TestUtils;
+import org.junit.Test;
+
+/**
+ * Description: test features from spec chapter 3.4 group and group sequence
+ * <br/>
+ */
+public class GroupValidationTest extends ValidationTestBase {
+
+ /**
+ * test spec: @NotNull on firstname and on lastname are validated when the
+ * Default group is validated.
+ */
+ @Test
+ public void testValidateFirstNameLastNameWithDefaultGroup() {
+ BillableUser user = new BillableUser();
+
+ Set<ConstraintViolation<BillableUser>> violations = validator.validate(user);
+ assertEquals(2, violations.size());
+ ConstraintViolation<?> violation = TestUtils.getViolation(violations, "firstname");
+ assertNotNull(violation);
+ assertEquals(user, violation.getRootBean());
+ violation = TestUtils.getViolation(violations, "lastname");
+ assertNotNull(violation);
+ assertEquals(user, violation.getRootBean());
+ }
+
+ /**
+ * test spec: @NotNull is checked on defaultCreditCard when either the
+ * Billable or BuyInOneClick group is validated.
+ */
+ @Test
+ public void testValidateDefaultCreditCardInBillableGroup() {
+ BillableUser user = new BillableUser();
+
+ Set<ConstraintViolation<BillableUser>> violations = validator.validate(user, Billable.class);
+ assertEquals(1, violations.size());
+ ConstraintViolation<?> violation = TestUtils.getViolation(violations, "defaultCreditCard");
+ assertNotNull(violation);
+ assertEquals(user, violation.getRootBean());
+ }
+
+ @Test
+ public void testValidateDefaultCreditCardInBillableAndByInOneClickGroup() {
+ BillableUser user = new BillableUser();
+
+ Set<ConstraintViolation<BillableUser>> violations =
+ validator.validate(user, BuyInOneClick.class, Billable.class);
+ assertEquals(1, violations.size());
+ ConstraintViolation<?> violation = TestUtils.getViolation(violations, "defaultCreditCard");
+ assertNotNull(violation);
+ assertEquals(user, violation.getRootBean());
+ }
+
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,114 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+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.
+ *
+ * @author <Authors name>
+ * @version 1.0
+ * @since <pre>04/09/2009</pre>
+ */
+public class GroupsComputerTest {
+ GroupsComputer groupsComputer;
+
+ @Before
+ public void setUp() throws Exception {
+ groupsComputer = new GroupsComputer();
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testComputeGroupsNotAnInterface() {
+ groupsComputer.computeGroups(Collections.singleton(String.class));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGroupChainForNull() {
+ groupsComputer.computeGroups((Class<?>[]) null);
+ }
+
+ @Test
+ public void testGroupChainForEmptySet() {
+ assertEquals(Collections.singleton(Group.DEFAULT),
+ groupsComputer.computeGroups(new HashSet<Class<?>>()).getGroups());
+ }
+
+ @Test(expected = GroupDefinitionException.class)
+ public void testCyclicGroupSequences() {
+ groupsComputer.computeGroups(Collections.singleton(CyclicGroupSequence1.class));
+ }
+
+ @Test(expected = GroupDefinitionException.class)
+ public void testCyclicGroupSequence() {
+ groupsComputer.computeGroups(Collections.singleton(CyclicGroupSequence.class));
+ }
+
+ @Test
+ public void testGroupDuplicates() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add(First.class);
+ groups.add(Second.class);
+ groups.add(Last.class);
+ Groups chain = groupsComputer.computeGroups(groups);
+ assertEquals(3, chain.getGroups().size());
+
+ groups.clear();
+ groups.add(First.class);
+ groups.add(First.class);
+ chain = groupsComputer.computeGroups(groups);
+ assertEquals(1, chain.getGroups().size());
+
+ groups.clear();
+ groups.add(First.class);
+ groups.add(Last.class);
+ groups.add(First.class);
+ chain = groupsComputer.computeGroups(groups);
+ assertEquals(2, chain.getGroups().size());
+ }
+
+ @Test
+ public void testSequenceResolution() {
+ Set<Class<?>> groups = new HashSet<Class<?>>();
+ groups.add(Address.Complete.class);
+ Groups chain = groupsComputer.computeGroups(groups);
+ Iterator<Group.Sequence> sequences = chain.getSequences().iterator();
+ Iterator<Group> sequence = sequences.next().getGroups().iterator();
+
+ assertEquals(Default.class, sequence.next().getGroup());
+ assertEquals(Address.HighLevelCoherence.class, sequence.next().getGroup());
+ }
+}
Added: tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Auditable.java
URL: http://svn.apache.org/viewvc/tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Auditable.java?rev=1843674&view=auto
==============================================================================
--- tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Auditable.java (added)
+++ tomee/deps/branches/bval-2/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Auditable.java Fri Oct 12 15:00:48 2018
@@ -0,0 +1,39 @@
+/*
+ * 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.implicit;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * Auditable object contract.
+ * Example 3.7. Example of interface / group hosting constraints
+ */
+public interface Auditable {
+ @NotNull
+ String getCreationDate();
+
+ @NotNull
+ String getLastUpdate();
+
+ @NotNull
+ String getLastModifier();
+
+ @NotNull
+ String getLastReader();
+}