myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1131298 - in /myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src: main/java/org/apache/myfaces/extensions/cdi/bv/impl/ test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/
Date Sat, 04 Jun 2011 00:50:26 GMT
Author: gpetracek
Date: Sat Jun  4 00:50:25 2011
New Revision: 1131298

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

Modified:
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableConstraintValidatorFactory.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/SimpleBeanValidationTest.java

Modified: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableConstraintValidatorFactory.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/InjectableConstraintValidatorFactory.java?rev=1131298&r1=1131297&r2=1131298&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableConstraintValidatorFactory.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/InjectableConstraintValidatorFactory.java
Sat Jun  4 00:50:25 2011
@@ -24,6 +24,8 @@ import java.io.Serializable;
 import java.io.ObjectInputStream;
 import java.io.IOException;
 
+import static org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils.injectFields;
+
 /**
  * @author Gerhard Petracek
  */
@@ -54,8 +56,10 @@ class InjectableConstraintValidatorFacto
      */
     public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T>
tClass)
     {
-        return this.injectableValidatorFactory.getValidatorFactory()
+        T validator = this.injectableValidatorFactory.getValidatorFactory()
                 .getConstraintValidatorFactory().getInstance(tClass);
+
+        return injectFields(validator, false);
     }
 
     @SuppressWarnings({"UnusedDeclaration"})

Modified: 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=1131298&r1=1131297&r2=1131298&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/SimpleBeanValidationTest.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/SimpleBeanValidationTest.java
Sat Jun  4 00:50:25 2011
@@ -18,18 +18,18 @@
  */
 package org.apache.myfaces.extensions.cdi.bv.test.impl;
 
+import org.apache.myfaces.extensions.cdi.bv.test.impl.validation.DifferentName;
+import org.apache.myfaces.extensions.cdi.bv.test.impl.validation.DifferentNameValidator;
 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.core.api.tools.DefaultAnnotation;
 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 javax.validation.*;
 import java.util.Locale;
 import java.util.Set;
 
@@ -49,6 +49,10 @@ public class SimpleBeanValidationTest ex
     @Advanced
     private ValidatorFactory validatorFactory;
 
+    @Inject
+    @Advanced
+    private ConstraintValidatorFactory constraintValidatorFactory;
+
     /**
      */
     @Test
@@ -62,6 +66,47 @@ public class SimpleBeanValidationTest ex
     /**
      */
     @Test
+    public void testInjectionAwareConstraintValidatorFactory()
+    {
+        ConstraintValidator<DifferentName, TestBean> constraintValidator =
+                this.constraintValidatorFactory.getInstance(DifferentNameValidator.class);
+
+        constraintValidator.initialize(DefaultAnnotation.of(DifferentName.class));
+        boolean result = constraintValidator.isValid(new TestBean("Tester", "Tester"),
+                        new ConstraintValidatorContext()
+                        {
+                            public void disableDefaultConstraintViolation()
+                            {
+                                //
+                            }
+
+                            public String getDefaultConstraintMessageTemplate()
+                            {
+                                return "";
+                            }
+
+                            public ConstraintViolationBuilder buildConstraintViolationWithTemplate(String
msgTemplate)
+                            {
+                                return new ConstraintViolationBuilder()
+                                {
+                                    public NodeBuilderDefinedContext addNode(String name)
+                                    {
+                                        return null;
+                                    }
+
+                                    public ConstraintValidatorContext addConstraintViolation()
+                                    {
+                                        return null;
+                                    }
+                                };
+                            }
+                        });
+        assertEquals(false, result);
+    }
+
+    /**
+     */
+    @Test
     public void testInvalidValueInMessage()
     {
         Validator validator = this.validatorFactory.usingContext().messageInterpolator(new
MessageInterpolator()



Mime
View raw message