incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r924153 [9/13] - in /incubator/bval/trunk: ./ agimatec-jsr303/ agimatec-jsr303/src/ agimatec-jsr303/src/main/ agimatec-jsr303/src/main/java/ agimatec-jsr303/src/main/java/com/ agimatec-jsr303/src/main/java/com/agimatec/ agimatec-jsr303/src/...
Date Wed, 17 Mar 2010 04:39:14 GMT
Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/Second.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/Second.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/Second.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/Second.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.example;
+
+/**
+ * Description: <br/>
+ * User: roman.stumm <br/>
+ * Date: 08.12.2008 <br/>
+ * Time: 10:25:24 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface Second {
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/SizeTestEntity.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/SizeTestEntity.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/SizeTestEntity.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/SizeTestEntity.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,60 @@
+/*
+ * 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 com.agimatec.validation.jsr303.example;
+
+import javax.validation.constraints.Size;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 18.11.2009 <br/>
+ * Time: 11:58:46 <br/>
+ * Copyright: Agimatec GmbH
+ */
+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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/XmlEntitySampleBean.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/XmlEntitySampleBean.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/XmlEntitySampleBean.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/XmlEntitySampleBean.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,57 @@
+/*
+ * 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 com.agimatec.validation.jsr303.example;
+
+/**
+ * Description: bean used to test constraints described in XML<br/>
+ * User: roman <br/>
+ * Date: 25.11.2009 <br/>
+ * Time: 09:00:45 <br/>
+ * Copyright: Agimatec GmbH
+ */
+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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/ZipCodeCityCarrier.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/ZipCodeCityCarrier.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/ZipCodeCityCarrier.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/example/ZipCodeCityCarrier.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.example;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 05.10.2009 <br/>
+ * Time: 12:40:35 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public interface ZipCodeCityCarrier {
+    String getZipCode();
+    String getCity();
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/extensions/ExampleMethodService.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/extensions/ExampleMethodService.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/extensions/ExampleMethodService.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/extensions/ExampleMethodService.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,45 @@
+/*
+ * 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 com.agimatec.validation.jsr303.extensions;
+
+import com.agimatec.validation.constraints.NotEmpty;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * Description: class with annotated methods to demonstrate
+ * method-level-validation<br/>
+ * User: roman <br/>
+ * Date: 01.02.2010 <br/>
+ * Time: 10:05:12 <br/>
+ * Copyright: Agimatec GmbH
+ */
+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;
+    }
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/extensions/MethodValidatorImplTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/extensions/MethodValidatorImplTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/extensions/MethodValidatorImplTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/extensions/MethodValidatorImplTest.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.extensions;
+
+import com.agimatec.validation.jsr303.AgimatecValidatorFactory;
+import com.agimatec.validation.jsr303.ClassValidator;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import javax.validation.Validator;
+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>
+ */
+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));
+        MethodValidatorImpl mvi = v.unwrap(MethodValidatorImpl.class);
+        assertNotNull(mvi);
+        MethodValidator mv = v.unwrap(MethodValidator.class);
+        assertNotNull(mv);
+        assertTrue(mv == mv.unwrap(MethodValidatorImpl.class));
+        assertTrue(mv == mv.unwrap(ClassValidator.class));
+    }
+
+    public void testValidateMethodParameters() throws NoSuchMethodException {
+        ExampleMethodService service = new ExampleMethodService();
+        MethodValidator mv = getValidator().unwrap(MethodValidator.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.getClass(), method, params);
+        assertEquals(true, results.isEmpty());
+
+        params[0] = "";
+        results = mv.validateParameters(service.getClass(), method, params);
+        assertEquals(1, results.size());
+
+        params[1] = null;
+        results = mv.validateParameters(service.getClass(), method, params);
+        assertEquals(2, results.size());
+
+        results = mv.validateParameter(service.getClass(), method,  params[0], 0);
+        assertEquals(1, results.size());
+
+        results = mv.validateParameter(service.getClass(), method,  "ok", 0);
+        assertEquals(0, results.size());
+    }
+
+    public void testValidateConstructorParameters() throws NoSuchMethodException {
+        ExampleMethodService service = new ExampleMethodService();
+        MethodValidator mv = getValidator().unwrap(MethodValidator.class);
+        Constructor constructor =
+              service.getClass().getConstructor(String.class, String.class);
+        String[] params = new String[2];
+        params[0] = "Hello ";
+        params[1] = "world";
+        Set results = mv.validateParameters(service.getClass(), constructor, params);
+        assertEquals(true, results.isEmpty());
+
+        params[0] = "";
+        results = mv.validateParameters(service.getClass(), constructor, params);
+        assertEquals(1, results.size());
+
+        params[1] = null;
+        results = mv.validateParameters(service.getClass(), constructor, params);
+        assertEquals(2, results.size());
+
+        results = mv.validateParameter(service.getClass(), constructor,  params[0], 0);
+        assertEquals(1, results.size());
+
+        results = mv.validateParameter(service.getClass(), constructor,  "ok", 0);
+        assertEquals(0, results.size());
+    }
+
+    public void testValidateReturnValue() throws NoSuchMethodException {
+        ExampleMethodService service = new ExampleMethodService();
+        MethodValidator mv = getValidator().unwrap(MethodValidator.class);
+        Method method =
+              service.getClass().getMethod("concat", new Class[]{String.class, String.class});
+        Set results;
+        results = mv.validateReturnedValue(service.getClass(), method, "test");
+        assertEquals(true, results.isEmpty());
+
+        results = mv.validateReturnedValue(service.getClass(), method, "");
+        assertEquals(1, results.size());
+    }
+
+    private Validator getValidator() {
+        return AgimatecValidatorFactory.getDefault().getValidator();
+    }
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/Billable.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/Billable.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/Billable.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/Billable.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.groups;
+
+/**
+ * Validation group checking a user is billable.
+ * Example 3.1. Definition of groups
+ */
+public interface Billable {
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BillableCreditCard.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BillableCreditCard.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BillableCreditCard.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BillableCreditCard.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.groups;
+
+/**
+ * Example 3.2. Assign groups to constraints.
+ */
+public class BillableCreditCard {
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BillableUser.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BillableUser.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BillableUser.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BillableUser.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BuyInOneClick.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BuyInOneClick.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BuyInOneClick.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/BuyInOneClick.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.groups;
+
+/**
+ * customer can buy without any harrassing checking process.
+ * Example 3.1. Definition of groups
+ */
+public interface BuyInOneClick {
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CollectionValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CollectionValidationTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CollectionValidationTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CollectionValidationTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,169 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups;
+
+import com.agimatec.validation.jsr303.AgimatecValidatorFactory;
+import com.agimatec.validation.jsr303.example.*;
+import com.agimatec.validation.jsr303.util.TestUtils;
+import junit.framework.TestCase;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.util.ArrayList;
+import java.util.Set;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 06.10.2009 <br/>
+ * Time: 12:47:30 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class CollectionValidationTest extends TestCase {
+    private Validator validator;
+
+    protected void setUp() {
+        validator = AgimatecValidatorFactory.getDefault().getValidator();
+    }
+
+    public void testValidateList() {
+        Author author = new Author();
+        author.setFirstName("Peter");
+        author.setLastName("Ford");
+        author.setCompany("IBM");
+        author.setAddresses(new ArrayList());
+
+        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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,32 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 09.04.2009 <br/>
+ * Time: 09:33:10 <br/>
+ * Copyright: Agimatec GmbH
+ */
+@GroupSequence(value = CyclicGroupSequence.class)
+public interface CyclicGroupSequence {
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence1.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence1.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence1.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence1.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,32 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 09.04.2009 <br/>
+ * Time: 09:33:46 <br/>
+ * Copyright: Agimatec GmbH
+ */
+@GroupSequence(value = CyclicGroupSequence2.class)
+public interface CyclicGroupSequence1 {
+}
\ No newline at end of file

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence2.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence2.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence2.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/CyclicGroupSequence2.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 09.04.2009 <br/>
+ * Time: 09:33:52 <br/>
+ * Copyright: Agimatec GmbH
+ */
+@GroupSequence( value = CyclicGroupSequence1.class)
+public interface CyclicGroupSequence2 {
+
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/DefaultGroupSequenceTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/DefaultGroupSequenceTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/DefaultGroupSequenceTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/DefaultGroupSequenceTest.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass1.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass1.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass1.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass1.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.groups;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 25.02.2009 <br/>
+ * Time: 16:44:41 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class GClass1 implements GInterface1 {
+
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass2.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass2.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass2.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass2.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,32 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 25.02.2009 <br/>
+ * Time: 16:44:48 <br/>
+ * Copyright: Agimatec GmbH
+ */
+@GroupSequence({GClass1.class, GClass2.class})
+public class GClass2 extends GClass1 {
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass3.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass3.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass3.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GClass3.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,32 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 25.02.2009 <br/>
+ * Time: 17:37:04 <br/>
+ * Copyright: Agimatec GmbH
+ */
+@GroupSequence({GClass3.class, GClass1.class})
+public class GClass3 {
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GInterface1.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GInterface1.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GInterface1.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GInterface1.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.groups;
+
+import javax.validation.GroupSequence;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 25.02.2009 <br/>
+ * Time: 16:44:56 <br/>
+ * Copyright: Agimatec GmbH
+ */
+@GroupSequence(GInterface1.class)
+public interface GInterface1 {
+
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupSequenceTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupSequenceTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupSequenceTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupSequenceTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,174 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups;
+
+import com.agimatec.validation.jsr303.AgimatecValidatorFactory;
+import com.agimatec.validation.jsr303.Jsr303Features;
+import com.agimatec.validation.jsr303.example.*;
+import com.agimatec.validation.jsr303.util.TestUtils;
+import com.agimatec.validation.model.MetaBean;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Description: test of group sequence behavior<br/>
+ * User: roman <br/>
+ * Date: 25.02.2009 <br/>
+ * Time: 16:47:06 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class GroupSequenceTest extends TestCase {
+    public void testGroupSequence1() {
+        MetaBean metaBean =
+              AgimatecValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
+                    .findForClass(GInterface1.class);
+        List<Group> gseq = metaBean.getFeature(Jsr303Features.Bean.GROUP_SEQUENCE);
+        Assert.assertNotNull(gseq);
+        Assert.assertEquals(1, gseq.size());
+        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
+    }
+
+    public void testGroupSequence2() {
+        MetaBean metaBean =
+              AgimatecValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
+                    .findForClass(GClass1.class);
+        List<Group> gseq = metaBean.getFeature(Jsr303Features.Bean.GROUP_SEQUENCE);
+        Assert.assertNotNull(gseq);
+        Assert.assertEquals(1, gseq.size());
+        Assert.assertEquals(Group.DEFAULT, gseq.get(0));
+    }
+
+    public void testGroupSequence3() {
+        MetaBean metaBean =
+              AgimatecValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
+                    .findForClass(GClass2.class);
+        List<Group> gseq = metaBean.getFeature(Jsr303Features.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 =
+              AgimatecValidatorFactory.getDefault().usingContext().getMetaBeanFinder()
+                    .findForClass(GClass3.class);
+        List<Group> gseq = metaBean.getFeature(Jsr303Features.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("agimatec");
+
+        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());
+    }
+
+    public Validator getValidator() {
+        return AgimatecValidatorFactory.getDefault().getValidator();
+    }
+}

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupValidationTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupValidationTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupValidationTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupValidationTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,87 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups;
+
+import com.agimatec.validation.jsr303.AgimatecValidatorFactory;
+import com.agimatec.validation.jsr303.util.TestUtils;
+import junit.framework.TestCase;
+
+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/>
+ * User: roman <br/>
+ * Date: 05.10.2009 <br/>
+ * Time: 11:29:53 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class GroupValidationTest extends TestCase {
+    private Validator validator;
+
+    protected void setUp() {
+        validator = AgimatecValidatorFactory.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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupsComputerTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupsComputerTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupsComputerTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/GroupsComputerTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,147 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups;
+
+import com.agimatec.validation.jsr303.example.Address;
+import com.agimatec.validation.jsr303.example.First;
+import com.agimatec.validation.jsr303.example.Last;
+import com.agimatec.validation.jsr303.example.Second;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+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 (ValidationException ex) {
+
+        }
+    }
+
+    public void testCyclicGroupSequence() {
+        try {
+            Set<Class<?>> groups = new HashSet<Class<?>>();
+            groups.add(CyclicGroupSequence.class);
+            groupsComputer.computeGroups(groups);
+            fail();
+        } catch (ValidationException 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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/Auditable.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/Auditable.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/Auditable.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/Auditable.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/ImplicitGroupingTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/ImplicitGroupingTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/ImplicitGroupingTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/ImplicitGroupingTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,66 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups.implicit;
+
+import com.agimatec.validation.jsr303.AgimatecValidatorFactory;
+import com.agimatec.validation.jsr303.util.TestUtils;
+import junit.framework.TestCase;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.util.Set;
+
+/**
+ * Description: test spec chapter 3.4.4. Implicit grouping<br/>
+ * User: roman <br/>
+ * Date: 05.10.2009 <br/>
+ * Time: 12:45:24 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class ImplicitGroupingTest extends TestCase {
+    private Validator validator;
+
+    protected void setUp() {
+        validator = AgimatecValidatorFactory.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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/Order.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/Order.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/Order.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/implicit/Order.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/BillableUser.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/BillableUser.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/BillableUser.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/BillableUser.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,67 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups.inheritance;
+
+import com.agimatec.validation.jsr303.groups.Billable;
+import com.agimatec.validation.jsr303.groups.BillableCreditCard;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 05.10.2009 <br/>
+ * Time: 12:18:31 <br/>
+ * Copyright: Agimatec GmbH
+ */
+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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/BuyInOneClick.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/BuyInOneClick.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/BuyInOneClick.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/BuyInOneClick.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.groups.inheritance;
+
+import com.agimatec.validation.jsr303.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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/GroupInheritanceTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/GroupInheritanceTest.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/GroupInheritanceTest.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/inheritance/GroupInheritanceTest.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,60 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups.inheritance;
+
+import com.agimatec.validation.jsr303.AgimatecValidatorFactory;
+import com.agimatec.validation.jsr303.util.TestUtils;
+import junit.framework.TestCase;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import java.util.Set;
+
+/**
+ * Description: <br/>
+ * User: roman <br/>
+ * Date: 05.10.2009 <br/>
+ * Time: 12:19:40 <br/>
+ * Copyright: Agimatec GmbH
+ */
+public class GroupInheritanceTest extends TestCase {
+    private Validator validator;
+
+    protected void setUp() {
+        validator = AgimatecValidatorFactory.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: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/redefining/Address.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/redefining/Address.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/redefining/Address.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/redefining/Address.java Wed Mar 17 04:39:07 2010
@@ -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 com.agimatec.validation.jsr303.groups.redefining;
+
+import com.agimatec.validation.constraints.ZipCodeCityCoherence;
+import com.agimatec.validation.jsr303.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})
+@ZipCodeCityCoherence(groups = Address.HighLevelCoherence.class)
+public class Address implements ZipCodeCityCarrier {
+    @NotNull @Size(max = 50)
+    private String street1;
+
+    @NotNull 
+    private String zipCode;
+
+    @NotNull
+    @Size(max = 30)
+    private String city;
+
+    /**
+     * check coherence on the overall object
+     * Needs basic checking to be green first
+     */
+    public interface HighLevelCoherence {}
+
+    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

Added: incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/redefining/InvalidRedefinedDefaultGroupAddress.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/redefining/InvalidRedefinedDefaultGroupAddress.java?rev=924153&view=auto
==============================================================================
--- incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/redefining/InvalidRedefinedDefaultGroupAddress.java (added)
+++ incubator/bval/trunk/agimatec-jsr303/src/test/java/com/agimatec/validation/jsr303/groups/redefining/InvalidRedefinedDefaultGroupAddress.java Wed Mar 17 04:39:07 2010
@@ -0,0 +1,44 @@
+/*
+ * 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 com.agimatec.validation.jsr303.groups.redefining;
+
+import javax.validation.GroupSequence;
+import javax.validation.constraints.NotNull;
+
+
+/**
+ * If a @GroupSequence redefining the Default group for a class A does not
+ * contain the group A, a GroupDefinitionException is raised when the class is
+ * validated or when its metadata is requested.
+ */
+@GroupSequence({Address.class, Address.HighLevelCoherence.class})
+public class InvalidRedefinedDefaultGroupAddress {
+    @NotNull(groups = Address.HighLevelCoherence.class)
+    private String street;
+
+    @NotNull
+    private String city;
+
+    /**
+     * check coherence on the overall object
+     * Needs basic checking to be green first
+     */
+    public interface HighLevelCoherence {}
+
+}



Mime
View raw message