sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1661954 - /sling/trunk/contrib/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java
Date Tue, 24 Feb 2015 13:58:14 GMT
Author: kwin
Date: Tue Feb 24 13:58:14 2015
New Revision: 1661954

URL: http://svn.apache.org/r1661954
Log:
add test for arguments parameter of the validate to never be null

Modified:
    sling/trunk/contrib/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java

Modified: sling/trunk/contrib/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java?rev=1661954&r1=1661953&r2=1661954&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java
(original)
+++ sling/trunk/contrib/extensions/validation/core/src/test/java/org/apache/sling/validation/impl/ValidationServiceImplTest.java
Tue Feb 24 13:58:14 2015
@@ -44,6 +44,7 @@ import org.apache.sling.jcr.resource.Jcr
 import org.apache.sling.validation.api.ValidationModel;
 import org.apache.sling.validation.api.ValidationResult;
 import org.apache.sling.validation.api.Validator;
+import org.apache.sling.validation.api.exceptions.SlingValidationException;
 import org.apache.sling.validation.impl.setup.MockedResourceResolver;
 import org.apache.sling.validation.impl.util.examplevalidators.DateValidator;
 import org.apache.sling.validation.impl.validators.RegexValidator;
@@ -54,6 +55,7 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.powermock.reflect.Whitebox;
@@ -258,6 +260,46 @@ public class ValidationServiceImplTest {
         } finally {
             if (model1 != null) {
                 rr.delete(model1);
+            }
+        }
+    }
+    
+    @Test
+    public void testValidateNeverCalledWithNullValues() throws Exception {
+        
+        Validator<String> myValidator = new Validator<String>() {
+            @Override
+            public String validate(String data, ValueMap valueMap, ValueMap arguments)
+                    throws SlingValidationException {
+                Assert.assertNotNull("ValueMap parameter for validate should never be null",
valueMap);
+                Assert.assertNotNull("arguments parameter for validate should never be null",
arguments);
+                return null;
+            }
+            
+        };
+        
+        validationService.validators.put("testvalidator",
+                myValidator);
+
+        TestProperty property = new TestProperty("field1");
+        property.addValidator("testvalidator");
+        Resource model1 = null;
+        try {
+            model1 = createValidationModelResource(rr, libsValidatorsRoot.getPath(), "testValidationModel1",
+                    "sling/validation/test", new String[] { "/apps/validation" }, property);
+
+            ValidationModel vm = validationService.getValidationModel("sling/validation/test",
+                    "/apps/validation/1/resource");
+            HashMap<String, Object> hashMap = new HashMap<String, Object>() {
+                {
+                    put("field1", "1");
+                }
+            };
+            ValueMap map = new ValueMapDecorator(hashMap);
+            validationService.validate(map, vm);
+        } finally {
+            if (model1 != null) {
+                rr.delete(model1);
             }
         }
     }



Mime
View raw message