bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1517540 [14/15] - in /bval/branches/bval-11/bval-jsr: ./ src/ src/main/ src/main/appended-resources/ src/main/appended-resources/META-INF/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/bval/ src/main/...
Date Mon, 26 Aug 2013 13:59:20 GMT
Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/ExampleMethodService.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/ExampleMethodService.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/ExampleMethodService.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/ExampleMethodService.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,69 @@
+/*
+ * 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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/extensions/MethodValidatorImplTest.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,256 @@
+/*
+ *  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 junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.bval.jsr.ApacheValidationProvider;
+import org.apache.bval.jsr.ClassValidator;
+import org.apache.bval.jsr.extensions.ExampleMethodService.Person;
+import org.junit.Ignore;
+
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+import javax.validation.executable.ExecutableValidator;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Set;
+
+/**
+ * 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();
+        ClassValidator cv = v.unwrap(ClassValidator.class);
+        assertTrue(v == cv);
+        assertTrue(v == v.unwrap(Validator.class));
+        ExecutableValidator mv = v.forExecutables();
+        assertNotNull(mv);
+    }
+
+    public void testValidateMethodParameters() throws NoSuchMethodException {
+        ExampleMethodService service = new ExampleMethodService();
+        ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+        Method method =
+              service.getClass().getMethod("concat", new Class[]{String.class, String.class});
+        String[] params = new String[2];
+        params[0] = "Hello ";
+        params[1] = "world";
+        Set results = mv.validateParameters(service, method, params);
+        assertEquals(true, results.isEmpty());
+
+        params[0] = "";
+        results = mv.validateParameters(service, method, params);
+        assertEquals(1, results.size());
+
+        params[1] = null;
+        results = mv.validateParameters(service, method, params);
+        assertEquals(2, results.size());
+    }
+    
+    public void testValidateMoreMethodParameters() throws NoSuchMethodException {
+    	
+    	ExampleMethodService service = new ExampleMethodService();
+        ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+    	Method saveMethod = service.getClass().getMethod("save", new Class[]{String.class});
+    	
+    	String[] saveParams = new String[1];
+    	saveParams[0] = "abcd";
+    	
+    	Set results = mv.validateParameters(service, saveMethod, saveParams);
+    	assertTrue(results.isEmpty());
+    	
+    	saveParams[0] = "zzzz";
+    	results = mv.validateParameters(service, saveMethod, saveParams);
+    	assertEquals(1, results.size());
+    	
+    	Method echoMethod = service.getClass().getMethod("echo", new Class[]{String.class});
+    	
+    	String[] echoParams = new String[1];
+    	echoParams[0] = "hello";
+    	
+    	results = mv.validateParameters(service, echoMethod, echoParams);
+    	assertTrue(results.isEmpty());
+    	
+    	echoParams[0] = "h";
+    	results = mv.validateParameters(service, echoMethod, echoParams);
+    	assertEquals(1, results.size());
+    	
+    	echoParams[0] = null;
+    	results = mv.validateParameters(service, echoMethod, echoParams);
+    	assertEquals(1, results.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[2];
+        params[0] = "Hello ";
+        params[1] = "world";
+        Set results = mv.validateConstructorParameters(constructor, params);
+        assertEquals(true, results.isEmpty());
+
+        params[0] = "";
+        results = mv.validateConstructorParameters(constructor, params);
+        assertEquals(1, results.size());
+
+        params[1] = null;
+        results = mv.validateConstructorParameters(constructor, params);
+        assertEquals(2, results.size());
+    }
+
+    public void testValidateReturnValue() throws NoSuchMethodException {
+        ExampleMethodService service = new ExampleMethodService();
+        ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+        Method method = service.getClass().getMethod("concat", new Class[]{String.class, String.class});
+
+        Set results;
+
+        results = mv.validateReturnValue(service, method, "test");
+        assertEquals(true, results.isEmpty());
+
+        results = mv.validateReturnValue(service, method, "");
+        assertEquals(1, results.size());
+    }
+    
+    public void testValidateMoreReturnValue() throws NoSuchMethodException {
+    	ExampleMethodService service = new ExampleMethodService();
+        ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+    	Method echoMethod = service.getClass().getMethod("echo", new Class[]{String.class});
+    	
+    	String returnedValue = "a too long string";
+    	Set results = mv.validateReturnValue(service, echoMethod, returnedValue);
+    	assertEquals(1, results.size());
+
+    	returnedValue = null;
+        results = mv.validateReturnValue(service, echoMethod, returnedValue);
+        assertEquals(1, results.size());
+    	
+    	returnedValue = "valid";
+        results = mv.validateReturnValue(service, echoMethod, returnedValue);
+    	assertTrue(results.isEmpty());
+    }
+    
+    public void testValidateValidParam() throws NoSuchMethodException {
+        ExampleMethodService service = new ExampleMethodService();
+        ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+        
+        Method personOp1 = service.getClass().getMethod("personOp1", new Class[]{Person.class});
+        
+        // Validate with invalid person
+        Person p = new ExampleMethodService.Person();
+        Set<?> results = mv.validateParameters(service, personOp1, new Object[]{p});
+        assertEquals("Expected 1 violation", 1, results.size());
+        
+        // validate with valid person
+        p.name = "valid name";
+        results = mv.validateParameters(service, personOp1, new Object[]{p});
+        assertTrue("No violations expected", results.isEmpty());
+        
+        // validate with null person
+        results = mv.validateParameters(service, personOp1, new Object[]{null});
+        assertTrue("No violations expected", results.isEmpty());
+    }
+    
+    public void testValidateNotNullValidParam() throws NoSuchMethodException {
+        ExampleMethodService service = new ExampleMethodService();
+        ExecutableValidator mv = getValidator().unwrap(ExecutableValidator.class);
+        
+        Method personOp2 = service.getClass().getMethod("personOp2", new Class[]{Person.class});
+        
+        // Validate with null person
+        Set<?> results = mv.validateParameters(service, personOp2, new Object[]{null});
+        assertEquals("Expected 1 violation", 1, results.size());
+        
+        // Validate with invalid person
+        Person p = new ExampleMethodService.Person();
+        results = mv.validateParameters(service, personOp2, new Object[]{p});
+        assertEquals("Expected 1 violation", 1, results.size());
+        
+        // validate with valid person
+        p.name = "valid name";
+        results = mv.validateParameters(service, personOp2, new Object[]{p});
+        assertTrue("No violations expected", results.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", new Class[]{String.class, String.class, Integer.class});
+        Method ifaceMethod = UserMethods.class.getMethod("findUser", new Class[]{String.class, String.class, Integer.class});
+        
+        Set<?> results;
+        
+        // Validate from class (should create violations)
+        results = mv.validateParameters(um, classMethod, new Object[]{"", "valid", null });
+        assertEquals("Invalid number of violations", 2, results.size());
+    }
+    
+    public static interface UserMethods {
+        void findUser(String param1, String param2, Integer param3);
+    }
+    
+    public static class UserMethodsImpl implements UserMethods {
+        // @Override - not allowed in 1.5 for Interface methods
+        public void findUser( @Size( min=1 ) String param1, @NotNull String param2, @NotNull Integer param3) {
+            return;
+        }        
+    }
+    
+
+    private Validator getValidator() {
+        return Validation
+            .byProvider(ApacheValidationProvider.class)
+            .configure()
+                /*
+            .addProperty(ApacheValidatorConfiguration.Properties.METABEAN_FACTORY_CLASSNAMES,
+                MethodValidatorMetaBeanFactory.class.getName())*/
+                .buildValidatorFactory().getValidator();
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/Billable.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/Billable.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/Billable.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/Billable.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.jsr.groups;
+
+/**
+ * Validation group checking a user is billable.
+ * Example 3.1. Definition of groups
+ */
+public interface Billable {
+}

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableCreditCard.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableCreditCard.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableCreditCard.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableCreditCard.java Mon Aug 26 13:59:15 2013
@@ -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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableUser.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableUser.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableUser.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BillableUser.java Mon Aug 26 13:59:15 2013
@@ -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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BuyInOneClick.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BuyInOneClick.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BuyInOneClick.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/BuyInOneClick.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.jsr.groups;
+
+/**
+ * customer can buy without any harrassing checking process.
+ * Example 3.1. Definition of groups
+ */
+public interface BuyInOneClick {
+}

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CollectionValidationTest.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CollectionValidationTest.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CollectionValidationTest.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CollectionValidationTest.java Mon Aug 26 13:59:15 2013
@@ -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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence.java Mon Aug 26 13:59:15 2013
@@ -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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence1.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence1.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence1.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence1.java Mon Aug 26 13:59:15 2013
@@ -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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence2.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence2.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence2.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/CyclicGroupSequence2.java Mon Aug 26 13:59:15 2013
@@ -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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/DefaultGroupSequenceTest.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/DefaultGroupSequenceTest.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/DefaultGroupSequenceTest.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/DefaultGroupSequenceTest.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,150 @@
+/*
+ * 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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass1.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass1.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass1.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass1.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.bval.jsr.groups;
+
+/**
+ * Description: <br/>
+ */
+public class GClass1 implements GInterface1 {
+
+}

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass2.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass2.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass2.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass2.java Mon Aug 26 13:59:15 2013
@@ -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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass3.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass3.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass3.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GClass3.java Mon Aug 26 13:59:15 2013
@@ -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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GInterface1.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GInterface1.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GInterface1.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GInterface1.java Mon Aug 26 13:59:15 2013
@@ -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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceIsolationTest.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,170 @@
+/*
+ * 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.Assert;
+import junit.framework.TestCase;
+import org.apache.bval.jsr.DefaultMessageInterpolator;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.GroupSequence;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Additional tests to check the correct processing of {@link GroupSequence}s
+ * by the validator.
+ * 
+ * @author Carlos Vara
+ */
+public class GroupSequenceIsolationTest extends TestCase {
+    
+    static ValidatorFactory factory;
+
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator)factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    private Validator getValidator() {
+        return factory.getValidator();
+    }
+
+    
+    /**
+     * 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.
+     */
+    public void testGroupSequencesInHierarchyClasses() {
+        Validator validator = getValidator();
+        
+        HolderWithNoGS h = new HolderWithNoGS();
+        Set<ConstraintViolation<HolderWithNoGS>> violations;
+        
+        violations = validator.validate(h);
+        Assert.assertEquals("Unexpected number of violations", 2, violations.size());
+        for ( ConstraintViolation<HolderWithNoGS> violation : violations ) {
+            boolean good = violation.getPropertyPath().toString().equals("a1");
+            good |= violation.getPropertyPath().toString().equals("b2");
+            Assert.assertTrue("Wrong constraint", good);
+        }
+
+        h.a1 = "good";
+        violations = validator.validate(h);
+        Assert.assertEquals("Unexpected number of violations", 2, violations.size());
+        for ( ConstraintViolation<HolderWithNoGS> violation : violations ) {
+            boolean good = violation.getPropertyPath().toString().equals("a2");
+            good |= violation.getPropertyPath().toString().equals("b2");
+            Assert.assertTrue("Wrong constraint", good);
+        }
+        
+        h.b2 = "good";
+        violations = validator.validate(h);
+        Assert.assertEquals("Unexpected number of violations", 2, violations.size());
+        for ( ConstraintViolation<HolderWithNoGS> violation : violations ) {
+            boolean good = violation.getPropertyPath().toString().equals("a2");
+            good |= violation.getPropertyPath().toString().equals("b1");
+            Assert.assertTrue("Wrong constraint", good);
+        }
+        
+        h.b1 = "good";
+        violations = validator.validate(h);
+        Assert.assertEquals("Unexpected number of violations", 1, violations.size());
+        for ( ConstraintViolation<HolderWithNoGS> violation : violations ) {
+            boolean good = violation.getPropertyPath().toString().equals("a2");
+            Assert.assertTrue("Wrong constraint", good);
+        }
+    }
+    
+    /**
+     * When validating the {@link Default} group in a bean whose class defines
+     * a group sequence, that group sequence is used for all the constraints.
+     */
+    public void testGroupSequenceOfBeanClass() {
+        Validator validator = getValidator();
+        
+        HolderWithGS h = new HolderWithGS();
+        Set<ConstraintViolation<HolderWithGS>> violations;
+        
+        violations = validator.validate(h);
+        Assert.assertEquals("Unexpected number of violations", 1, violations.size());
+        for ( ConstraintViolation<HolderWithGS> violation : violations ) {
+            boolean good = violation.getPropertyPath().toString().equals("a1");
+            Assert.assertTrue("Wrong constraint", good);
+        }
+        
+        h.a1 = "good";
+        violations = validator.validate(h);
+        Assert.assertEquals("Unexpected number of violations", 2, violations.size());
+        for ( ConstraintViolation<HolderWithGS> violation : violations ) {
+            boolean good = violation.getPropertyPath().toString().equals("a2");
+            good |= violation.getPropertyPath().toString().equals("b2");
+            Assert.assertTrue("Wrong constraint", good);
+        }
+        
+        h.a2 = "good";
+        h.b2 = "good";
+        violations = validator.validate(h);
+        Assert.assertEquals("Unexpected number of violations", 1, violations.size());
+        for ( ConstraintViolation<HolderWithGS> violation : violations ) {
+            boolean good = violation.getPropertyPath().toString().equals("b1");
+            Assert.assertTrue("Wrong constraint", good);
+        }
+    }
+    
+    @GroupSequence({GroupA1.class, A.class})
+    public static class A {
+        @NotNull(groups={GroupA1.class})
+        public String a1;
+        @NotNull
+        public String a2;
+    }
+    
+    public static 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 static 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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupSequenceTest.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,219 @@
+/*
+ * 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.Assert;
+import junit.framework.TestCase;
+import org.apache.bval.jsr.ApacheValidatorFactory;
+import org.apache.bval.jsr.DefaultMessageInterpolator;
+import org.apache.bval.jsr.JsrFeatures;
+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.apache.bval.model.MetaBean;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.GroupSequence;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Description: test of group sequence behavior<br/>
+ */
+public class GroupSequenceTest extends TestCase {
+
+    static ValidatorFactory factory;
+
+    static {
+        factory = Validation.buildDefaultValidatorFactory();
+        ((DefaultMessageInterpolator)factory.getMessageInterpolator()).setLocale(Locale.ENGLISH);
+    }
+
+    private Validator getValidator() {
+        return factory.getValidator();
+    }
+
+
+    public void testGroupSequence1() {
+        MetaBean metaBean =
+              ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
+                    .findForClass(GInterface1.class);
+        List<Group> gseq = metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE);
+        Assert.assertNotNull(gseq);
+        Assert.assertEquals(1, gseq.size());
+        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
+    }
+
+    public void testGroupSequence2() {
+        MetaBean metaBean =
+              ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
+                    .findForClass(GClass1.class);
+        List<Group> gseq = metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE);
+        Assert.assertNotNull(gseq);
+        Assert.assertEquals(1, gseq.size());
+        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
+    }
+
+    public void testGroupSequence3() {
+        MetaBean metaBean =
+              ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
+                    .findForClass(GClass2.class);
+        List<Group> gseq = metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE);
+        Assert.assertNotNull(gseq);
+        Assert.assertEquals(2, gseq.size());
+        Assert.assertEquals(new Group(GClass1.class), gseq.get(0));
+        Assert.assertEquals(Group.DEFAULT, gseq.get(1));
+    }
+
+    public void testGroupSequence4() {
+        MetaBean metaBean =
+              ApacheValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
+                    .findForClass(GClass3.class);
+        List<Group> gseq = metaBean.getFeature(JsrFeatures.Bean.GROUP_SEQUENCE);
+        Assert.assertNotNull(gseq);
+        Assert.assertEquals(2, gseq.size());
+        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
+        Assert.assertEquals(new Group(GClass1.class), gseq.get(1));
+    }
+
+    public void testGroups() {
+        Validator validator = getValidator();
+
+        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());
+    }
+
+    public void testGroupSequence() {
+        Validator validator = getValidator();
+
+        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
+     */
+    public void testValidationStopsWhenFailuresOnGroup() {
+        Validator validator = getValidator();
+        
+        // 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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupValidationTest.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupValidationTest.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupValidationTest.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupValidationTest.java Mon Aug 26 13:59:15 2013
@@ -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 junit.framework.TestCase;
+import org.apache.bval.jsr.ApacheValidatorFactory;
+import org.apache.bval.jsr.util.TestUtils;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.util.Set;
+
+/**
+ * Description: test features from spec chapter 3.4 group and group sequence<br/>
+ */
+public class GroupValidationTest extends TestCase {
+    private Validator validator;
+
+    protected void setUp() {
+        validator = ApacheValidatorFactory.getDefault().getValidator();
+    }
+
+    /**
+     * test spec: @NotNull on firstname and on lastname are validated when
+     * the Default group is validated.
+     */
+    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.
+     */
+  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());
+    }
+
+  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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/GroupsComputerTest.java Mon Aug 26 13:59:15 2013
@@ -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.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 javax.validation.GroupDefinitionException;
+import javax.validation.ValidationException;
+import javax.validation.groups.Default;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * GroupListComputer Tester.
+ *
+ * @author <Authors name>
+ * @version 1.0
+ * @since <pre>04/09/2009</pre>
+ */
+public class GroupsComputerTest extends TestCase {
+    GroupsComputer groupsComputer;
+
+    public GroupsComputerTest(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        super.setUp();
+        groupsComputer = new GroupsComputer();
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public static Test suite() {
+        return new TestSuite(GroupsComputerTest.class);
+    }
+
+    public void testComputeGroupsNotAnInterface() {
+        Set<Class<?>> groups = new HashSet<Class<?>>();
+        groups.add(String.class);
+        try {
+            groupsComputer.computeGroups(groups);
+            fail();
+        } catch (ValidationException ex) {
+
+        }
+    }
+
+    public void testGroupChainForNull() {
+        try {
+            groupsComputer.computeGroups((Class<?>[]) null);
+            fail();
+        } catch (IllegalArgumentException ex) {
+
+        }
+    }
+
+    public void testGroupChainForEmptySet() {
+        try {
+            groupsComputer.computeGroups(new HashSet<Class<?>>());
+            fail();
+        } catch (IllegalArgumentException ex) {
+
+        }
+    }
+
+    public void testCyclicGroupSequences() {
+        try {
+            Set<Class<?>> groups = new HashSet<Class<?>>();
+            groups.add(CyclicGroupSequence1.class);
+            groupsComputer.computeGroups(groups);
+            fail();
+        } catch (GroupDefinitionException ex) {
+
+        }
+    }
+
+    public void testCyclicGroupSequence() {
+        try {
+            Set<Class<?>> groups = new HashSet<Class<?>>();
+            groups.add(CyclicGroupSequence.class);
+            groupsComputer.computeGroups(groups);
+            fail();
+        } catch (GroupDefinitionException ex) {
+
+        }
+    }
+
+    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.groups.size());
+
+        groups.clear();
+        groups.add(First.class);
+        groups.add(First.class);
+        chain = groupsComputer.computeGroups(groups);
+        assertEquals(1, chain.groups.size());
+
+        groups.clear();
+        groups.add(First.class);
+        groups.add(Last.class);
+        groups.add(First.class);
+        chain = groupsComputer.computeGroups(groups);
+        assertEquals(2, chain.groups.size());
+    }
+
+
+    public void testSequenceResolution() {
+        Set<Class<?>> groups = new HashSet<Class<?>>();
+        groups.add(Address.Complete.class);
+        Groups chain = groupsComputer.computeGroups(groups);
+        Iterator<List<Group>> sequences = chain.getSequences().iterator();
+        List<Group> sequence = sequences.next();
+
+        assertEquals(Default.class, sequence.get(0).getGroup());
+        assertEquals(Address.HighLevelCoherence.class, sequence.get(1).getGroup());
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Auditable.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Auditable.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Auditable.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Auditable.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,33 @@
+/*
+ * 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();
+}

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/ImplicitGroupingTest.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/ImplicitGroupingTest.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/ImplicitGroupingTest.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/ImplicitGroupingTest.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,62 @@
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.bval.jsr.ApacheValidatorFactory;
+import org.apache.bval.jsr.util.TestUtils;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.util.Set;
+
+/**
+ * Description: test spec chapter 3.4.4. Implicit grouping<br/>
+ */
+public class ImplicitGroupingTest extends TestCase {
+    private Validator validator;
+
+    protected void setUp() {
+        validator = ApacheValidatorFactory.getDefault().getValidator();
+    }
+
+    public void testValidateImplicitGrouping() {
+        Order order = new Order();
+        // When an Order object is validated on the Default group, ...
+        Set<ConstraintViolation<Order>> violations = validator.validate(order);
+        assertNotNull(TestUtils.getViolation(violations, "creationDate"));
+        assertNotNull(TestUtils.getViolation(violations, "lastUpdate"));
+        assertNotNull(TestUtils.getViolation(violations, "lastModifier"));
+        assertNotNull(TestUtils.getViolation(violations, "lastReader"));
+        assertNotNull(TestUtils.getViolation(violations, "orderNumber"));
+        assertEquals(5, violations.size());
+
+        // When an Order object is validated on the Auditable group, ...
+
+        /* Only the constraints present on Auditable (and any of its super interfaces)
+           and belonging to the Default group are validated
+           when the group Auditable is requested. */
+        violations = validator.validate(order, Auditable.class);
+        assertEquals("Implicit grouping not correctly implemented", 4, violations.size());
+        assertNotNull(TestUtils.getViolation(violations, "creationDate"));
+        assertNotNull(TestUtils.getViolation(violations, "lastUpdate"));
+        assertNotNull(TestUtils.getViolation(violations, "lastModifier"));
+        assertNotNull(TestUtils.getViolation(violations, "lastReader"));
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Order.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Order.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Order.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/implicit/Order.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.jsr.groups.implicit;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * Represents an order in the system
+ */
+public class Order implements Auditable {
+    private String creationDate;
+    private String lastUpdate;
+    private String lastModifier;
+    private String lastReader;
+
+    private String orderNumber;
+
+    public String getCreationDate() {
+        return this.creationDate;
+    }
+
+    public String getLastUpdate() {
+        return this.lastUpdate;
+    }
+
+    public String getLastModifier() {
+        return this.lastModifier;
+    }
+
+    public String getLastReader() {
+        return this.lastReader;
+    }
+
+    @NotNull
+    @Size(min=10, max=10)
+    public String getOrderNumber() {
+        return this.orderNumber;
+    }
+
+    public void setCreationDate(String creationDate) {
+        this.creationDate = creationDate;
+    }
+
+    public void setLastUpdate(String lastUpdate) {
+        this.lastUpdate = lastUpdate;
+    }
+
+    public void setLastModifier(String lastModifier) {
+        this.lastModifier = lastModifier;
+    }
+
+    public void setLastReader(String lastReader) {
+        this.lastReader = lastReader;
+    }
+
+    public void setOrderNumber(String orderNumber) {
+        this.orderNumber = orderNumber;
+    }
+}
\ No newline at end of file

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/BillableUser.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/BillableUser.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/BillableUser.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/BillableUser.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.inheritance;
+
+
+import org.apache.bval.jsr.groups.Billable;
+import org.apache.bval.jsr.groups.BillableCreditCard;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+
+/**
+ * Description: <br/>
+ */
+public class BillableUser {
+    @NotNull
+    private String firstname;
+
+    @NotNull(groups = Default.class)
+    private String lastname;
+
+    @NotNull(groups = {Billable.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: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/BuyInOneClick.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/BuyInOneClick.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/BuyInOneClick.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/BuyInOneClick.java Mon Aug 26 13:59:15 2013
@@ -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.groups.inheritance;
+
+
+import org.apache.bval.jsr.groups.Billable;
+
+import javax.validation.groups.Default;
+
+/**
+ * Customer can buy without harrassing checking process.
+ * spec: Example 3.3. Groups can inherit other groups
+ */
+public interface BuyInOneClick extends Default, Billable {
+}

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/GroupInheritanceTest.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/GroupInheritanceTest.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/GroupInheritanceTest.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/inheritance/GroupInheritanceTest.java Mon Aug 26 13:59:15 2013
@@ -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.groups.inheritance;
+
+import junit.framework.TestCase;
+import org.apache.bval.jsr.ApacheValidatorFactory;
+import org.apache.bval.jsr.util.TestUtils;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.util.Set;
+
+/**
+ * Description: <br/>
+ */
+public class GroupInheritanceTest extends TestCase {
+    private Validator validator;
+
+    protected void setUp() {
+        validator = ApacheValidatorFactory.getDefault().getValidator();
+    }
+
+    /**
+     * validating the group BuyInOneClick will lead to the following constraints checking:
+     *<pre>
+     *  * @NotNull on firstname and lastname
+     *  * @NotNull on defaultCreditCard</pre>
+     * because Default and Billable are superinterfaces of BuyInOneClick.
+     */
+    public void testValidGroupBuyInOneClick() {
+        BillableUser user = new BillableUser();
+
+        Set<ConstraintViolation<BillableUser>> violations =
+              validator.validate(user, BuyInOneClick.class);
+        assertEquals(3, violations.size());
+        assertNotNull(TestUtils.getViolation(violations, "firstname"));
+        assertNotNull(TestUtils.getViolation(violations, "lastname"));
+        assertNotNull(TestUtils.getViolation(violations, "defaultCreditCard"));
+    }
+}

Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/Address.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/Address.java?rev=1517540&view=auto
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/Address.java (added)
+++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/groups/redefining/Address.java Mon Aug 26 13:59:15 2013
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bval.jsr.groups.redefining;
+
+
+import org.apache.bval.constraints.ZipCodeCityCoherence;
+import org.apache.bval.jsr.example.ZipCodeCityCarrier;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * Example 3.6. Redefining Default group for Address:
+ * To redefine Default for a class, place a @GroupSequence annotation on the class ; 
+ * this sequence expresses the sequence of groups that does
+ * substitute Default for this class.
+ */
+@GroupSequence({Address.class, Address.HighLevelCoherence.class, Address.ExtraCareful.class })
+@ZipCodeCityCoherence(groups = Address.HighLevelCoherence.class)
+public class Address implements ZipCodeCityCarrier {
+    
+    /**
+     * check coherence on the overall object
+     * Needs basic checking to be green first
+     */
+    public interface HighLevelCoherence {}
+    
+    /**
+     * Extra-careful validation group.
+     */
+    public interface ExtraCareful {}
+
+    @NotNull
+    @Size(max = 50, min = 1, groups = ExtraCareful.class)
+    private String street1;
+
+    @NotNull 
+    private String zipCode;
+    
+    @NotNull
+    @Size(max = 30)
+    private String city;
+
+    public String getStreet1() {
+        return street1;
+    }
+
+    public void setStreet1(String street1) {
+        this.street1 = street1;
+    }
+
+    public String getZipCode() {
+        return zipCode;
+    }
+
+    public void setZipCode(String zipCode) {
+        this.zipCode = zipCode;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+}
\ No newline at end of file



Mime
View raw message