myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1131300 - /myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/test/java/org/apache/myfaces/extensions/cdi/bv/test/impl/SimpleBeanValidationTest.java
Date Sat, 04 Jun 2011 01:08:56 GMT
Author: gpetracek
Date: Sat Jun  4 01:08:55 2011
New Revision: 1131300

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

Modified:
    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/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=1131300&r1=1131299&r2=1131300&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 01:08:55 2011
@@ -24,16 +24,25 @@ import org.apache.myfaces.extensions.cdi
 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.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
 import javax.inject.Inject;
-import javax.validation.*;
+import javax.inject.Named;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+import javax.validation.ConstraintValidatorFactory;
+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;
+import static org.junit.Assert.assertNotNull;
 
 /**
  * Test impl
@@ -50,9 +59,17 @@ public class SimpleBeanValidationTest ex
     private ValidatorFactory validatorFactory;
 
     @Inject
+    @Named("contextAwareValidatorFactory")
+    private ValidatorFactory namedValidatorFactory;
+
+    @Inject
     @Advanced
     private ConstraintValidatorFactory constraintValidatorFactory;
 
+    @Inject
+    @Advanced
+    private MessageInterpolator messageInterpolator;
+
     /**
      */
     @Test
@@ -107,6 +124,14 @@ public class SimpleBeanValidationTest ex
     /**
      */
     @Test
+    public void testMessageInterpolatorInjection()
+    {
+        assertNotNull(this.messageInterpolator);
+    }
+
+    /**
+     */
+    @Test
     public void testInvalidValueInMessage()
     {
         Validator validator = this.validatorFactory.usingContext().messageInterpolator(new
MessageInterpolator()
@@ -131,4 +156,32 @@ public class SimpleBeanValidationTest ex
 
         assertEquals("The same name 'Tester' isn't allowed.", violations.iterator().next().getMessage());
     }
+
+    /**
+     */
+    @Test
+    public void testNamedValidatorFactory()
+    {
+        Validator validator = this.namedValidatorFactory.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());
+    }
 }



Mime
View raw message