myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1131283 - in /myfaces/extensions/cdi/trunk/jee-modules/bv-module: api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ impl/ impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/ impl/src/test/ impl/src/test/java/ impl/src/t...
Date Fri, 03 Jun 2011 23:07:13 GMT
Author: gpetracek
Date: Fri Jun  3 23:07:12 2011
New Revision: 1131283

URL: http://svn.apache.org/viewvc?rev=1131283&view=rev
Log:
EXTCDI-195 and EXTCDI-196 bv-module improvements and tests

Added:
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelConstraintValidator.java
      - copied, changed from r1130646, myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelValidator.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/AdvancedValidatorContext.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectionAwareConstraintValidatorFactory.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/SimpleBeanValidationTest.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentName.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentNameValidator.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/TestBean.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/ValidationService.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/LICENSE.txt
      - copied unchanged from r1130646, myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/resources/META-INF/LICENSE.txt
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/META-INF/
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/META-INF/beans.xml
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/NOTICE.txt
      - copied, changed from r1130646, myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/resources/META-INF/NOTICE.txt
Removed:
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelValidator.java
Modified:
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/pom.xml
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java

Copied: myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelConstraintValidator.java
(from r1130646, myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelValidator.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelConstraintValidator.java?p2=myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelConstraintValidator.java&p1=myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelValidator.java&r1=1130646&r2=1131283&rev=1131283&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelValidator.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/api/src/main/java/org/apache/myfaces/extensions/cdi/bv/api/ClassLevelConstraintValidator.java
Fri Jun  3 23:07:12 2011
@@ -31,7 +31,8 @@ import java.lang.reflect.Method;
  *
  * @author Gerhard Petracek
  */
-public abstract class ClassLevelValidator<A extends Annotation, T> implements ConstraintValidator<A,
T>, Serializable
+public abstract class ClassLevelConstraintValidator<A extends Annotation, T>
+        implements ConstraintValidator<A, T>, Serializable
 {
     protected A constraint;
 

Modified: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/pom.xml?rev=1131283&r1=1131282&r2=1131283&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/pom.xml (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/pom.xml Fri Jun  3 23:07:12 2011
@@ -46,6 +46,70 @@
             <groupId>org.apache.myfaces.extensions.cdi.core</groupId>
             <artifactId>myfaces-extcdi-core-impl</artifactId>
         </dependency>
+
+        <!-- test dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.myfaces.extensions.cdi.test</groupId>
+            <artifactId>myfaces-extcdi-owb-support-module</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.myfaces.extensions.cdi.test</groupId>
+            <artifactId>myfaces-extcdi-junit-support-module</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.5</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.bval</groupId>
+            <artifactId>bval-core</artifactId>
+            <version>0.2-incubating</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.bval</groupId>
+            <artifactId>bval-jsr303</artifactId>
+            <version>0.2-incubating</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-impl</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-spi</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.openwebbeans.test</groupId>
+            <artifactId>cditest</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.openwebbeans.test</groupId>
+            <artifactId>cditest-owb</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>

Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/AdvancedValidatorContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/AdvancedValidatorContext.java?rev=1131283&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/AdvancedValidatorContext.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/AdvancedValidatorContext.java
Fri Jun  3 23:07:12 2011
@@ -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 org.apache.myfaces.extensions.cdi.bv.impl;
+
+import javax.enterprise.inject.Typed;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import javax.validation.ValidatorFactory;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Typed()
+class AdvancedValidatorContext implements ValidatorContext
+{
+    private ValidatorContext wrapped;
+    private ValidatorFactory validatorFactory;
+
+    protected AdvancedValidatorContext()
+    {
+    }
+
+    AdvancedValidatorContext(ValidatorFactory validatorFactory, ValidatorContext validatorContext)
+    {
+        this.validatorFactory = validatorFactory;
+        this.wrapped = validatorContext;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValidatorContext messageInterpolator(MessageInterpolator messageInterpolator)
+    {
+        wrapped.messageInterpolator(messageInterpolator);
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValidatorContext traversableResolver(TraversableResolver traversableResolver)
+    {
+        wrapped.traversableResolver(traversableResolver);
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ValidatorContext constraintValidatorFactory(ConstraintValidatorFactory factory)
+    {
+        wrapped.constraintValidatorFactory(factory);
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Validator getValidator()
+    {
+        ConstraintValidatorFactory constraintValidatorFactory =
+                this.validatorFactory.getConstraintValidatorFactory();
+
+        this.wrapped.constraintValidatorFactory(
+                new InjectionAwareConstraintValidatorFactory(constraintValidatorFactory));
+        return this.wrapped.getValidator();
+    }
+}

Modified: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java?rev=1131283&r1=1131282&r2=1131283&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableValidatorFactory.java
Fri Jun  3 23:07:12 2011
@@ -71,7 +71,7 @@ class InjectableValidatorFactory impleme
      */
     public ValidatorContext usingContext()
     {
-        return getValidatorFactory().usingContext();
+        return new AdvancedValidatorContext(this, getValidatorFactory().usingContext());
     }
 
     /**

Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectionAwareConstraintValidatorFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectionAwareConstraintValidatorFactory.java?rev=1131283&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectionAwareConstraintValidatorFactory.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectionAwareConstraintValidatorFactory.java
Fri Jun  3 23:07:12 2011
@@ -0,0 +1,54 @@
+/*
+ * 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.myfaces.extensions.cdi.bv.impl;
+
+import javax.enterprise.inject.Typed;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorFactory;
+
+import static org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils.injectFields;
+
+/**
+ * @author Gerhard Petracek
+ */
+@Typed()
+class InjectionAwareConstraintValidatorFactory implements ConstraintValidatorFactory
+{
+    private ConstraintValidatorFactory wrapped;
+
+    protected InjectionAwareConstraintValidatorFactory()
+    {
+    }
+
+    InjectionAwareConstraintValidatorFactory(ConstraintValidatorFactory wrapped)
+    {
+        this.wrapped = wrapped;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @SuppressWarnings({"unchecked"})
+    public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T>
targetClass)
+    {
+        T validator = this.wrapped.getInstance(targetClass);
+
+        return injectFields(validator, false);
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/SimpleBeanValidationTest.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/SimpleBeanValidationTest.java?rev=1131283&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/SimpleBeanValidationTest.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/SimpleBeanValidationTest.java
Fri Jun  3 23:07:12 2011
@@ -0,0 +1,89 @@
+/*
+ * 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.myfaces.extensions.cdi.bv.test.impl;
+
+import org.apache.myfaces.extensions.cdi.bv.test.impl.validation.TestBean;
+import org.apache.myfaces.extensions.cdi.core.api.Advanced;
+import org.apache.myfaces.extensions.cdi.test.junit4.AbstractCdiAwareTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import javax.inject.Inject;
+import javax.validation.ConstraintViolation;
+import javax.validation.MessageInterpolator;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+import java.util.Locale;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test impl
+ */
+@RunWith(JUnit4.class)
+public class SimpleBeanValidationTest extends AbstractCdiAwareTest
+{
+    @Inject
+    @Advanced
+    private Validator validator;
+
+    @Inject
+    @Advanced
+    private ValidatorFactory validatorFactory;
+
+    /**
+     */
+    @Test
+    public void testConstraintValidatorInjection()
+    {
+        Set<ConstraintViolation<TestBean>> violations = this.validator.validate(new
TestBean("Tester", "Tester"));
+
+        assertEquals(1, violations.size());
+    }
+
+    /**
+     */
+    @Test
+    public void testInvalidValueInMessage()
+    {
+        Validator validator = this.validatorFactory.usingContext().messageInterpolator(new
MessageInterpolator()
+        {
+            public String interpolate(String messageTemplate, Context context)
+            {
+                return interpolate(messageTemplate, context, null);
+            }
+
+            public String interpolate(String messageTemplate, Context context, Locale locale)
+            {
+                //simplified version of the interpolator provided by the jsf module
+                String invalidValue = messageTemplate.substring(0, messageTemplate.indexOf("$"));
+                String message = messageTemplate.substring(messageTemplate.lastIndexOf("$")
+ 1);
+
+                return message.replace("{invalidValue}", invalidValue);
+            }
+        }).getValidator();
+        Set<ConstraintViolation<TestBean>> violations = validator.validate(new
TestBean("Tester", "Tester"));
+
+        assertEquals(1, violations.size());
+
+        assertEquals("The same name 'Tester' isn't allowed.", violations.iterator().next().getMessage());
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentName.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentName.java?rev=1131283&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentName.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentName.java
Fri Jun  3 23:07:12 2011
@@ -0,0 +1,48 @@
+/*
+ * 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.myfaces.extensions.cdi.bv.test.impl.validation;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Test impl
+ */
+@Constraint(validatedBy = DifferentNameValidator.class)
+@Target(TYPE)
+@Retention(RUNTIME)
+public @interface DifferentName
+{
+    /**
+     */
+    String message() default "The same name '{invalidValue}' isn't allowed.";
+
+    /**
+     */
+    Class<?>[] groups() default {};
+
+    /**
+     */
+    Class<? extends Payload>[] payload() default {};
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentNameValidator.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentNameValidator.java?rev=1131283&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentNameValidator.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/DifferentNameValidator.java
Fri Jun  3 23:07:12 2011
@@ -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 org.apache.myfaces.extensions.cdi.bv.test.impl.validation;
+
+import org.apache.myfaces.extensions.cdi.bv.api.ClassLevelConstraintValidator;
+
+import javax.inject.Inject;
+import javax.validation.ConstraintValidatorContext;
+import java.io.Serializable;
+
+/**
+ * Test impl
+ */
+public class DifferentNameValidator extends ClassLevelConstraintValidator<DifferentName,
TestBean>
+{
+    private static final long serialVersionUID = 3851988368625335444L;
+
+    @Inject
+    private ValidationService validationService;
+
+    private String invalidValue;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected boolean isValidInstance(TestBean testBean, ConstraintValidatorContext constraintValidatorContext)
+    {
+        boolean result = this.validationService.isValid(testBean);
+
+        if(result)
+        {
+            this.invalidValue = null;
+        }
+        else
+        {
+            this.invalidValue = testBean.getFirstName();
+        }
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Serializable getInvalidValue()
+    {
+        return this.invalidValue;
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/TestBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/TestBean.java?rev=1131283&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/TestBean.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/TestBean.java
Fri Jun  3 23:07:12 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.myfaces.extensions.cdi.bv.test.impl.validation;
+
+/**
+ * Test impl
+ */
+@DifferentName
+public class TestBean
+{
+    private String firstName;
+
+    private String lastName;
+
+    /**
+     */
+    public TestBean(String firstName, String lastName)
+    {
+        this.firstName = firstName;
+        this.lastName = lastName;
+    }
+
+    /**
+     */
+    public String getFirstName()
+    {
+        return firstName;
+    }
+
+    /**
+     */
+    public String getLastName()
+    {
+        return lastName;
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/ValidationService.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/ValidationService.java?rev=1131283&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/ValidationService.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/validation/ValidationService.java
Fri Jun  3 23:07:12 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.myfaces.extensions.cdi.bv.test.impl.validation;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * Test impl
+ */
+@ApplicationScoped
+public class ValidationService
+{
+    /**
+     */
+    public boolean isValid(TestBean testBean)
+    {
+        return !testBean.getFirstName().equals(testBean.getLastName());
+    }
+}

Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/META-INF/beans.xml?rev=1131283&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/META-INF/beans.xml
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/META-INF/beans.xml
Fri Jun  3 23:07:12 2011
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>

Copied: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/NOTICE.txt
(from r1130646, myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/resources/META-INF/NOTICE.txt)
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/NOTICE.txt?p2=myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/NOTICE.txt&p1=myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/resources/META-INF/NOTICE.txt&r1=1130646&r2=1131283&rev=1131283&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/resources/META-INF/NOTICE.txt
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/resources/NOTICE.txt
Fri Jun  3 23:07:12 2011
@@ -1,5 +1,5 @@
 Apache MyFaces Extensions CDI (aka MyFaces CODI)
-Copyright 2010 The Apache Software Foundation
+Copyright 2011 The Apache Software Foundation
 
 This product includes software developed by
 The Apache Software Foundation (http://www.apache.org/).



Mime
View raw message