incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romanst...@apache.org
Subject svn commit: r949685 - in /incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions: ExampleMethodService.java MethodValidatorImplTest.java
Date Mon, 31 May 2010 08:17:55 GMT
Author: romanstumm
Date: Mon May 31 08:17:55 2010
New Revision: 949685

URL: http://svn.apache.org/viewvc?rev=949685&view=rev
Log:
BVAL-66 committing 2 new tests from Carlos Vara for point 1 and 2

Modified:
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/ExampleMethodService.java
    incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/ExampleMethodService.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/ExampleMethodService.java?rev=949685&r1=949684&r2=949685&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/ExampleMethodService.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/ExampleMethodService.java
Mon May 31 08:17:55 2010
@@ -21,6 +21,7 @@ package org.apache.bval.jsr303.extension
 
 import org.apache.bval.constraints.NotEmpty;
 
+import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
 import javax.validation.constraints.Size;
@@ -51,4 +52,18 @@ public class ExampleMethodService {
     public String echo(@NotNull @Size(min=3,max=10) String str) {
     	return str;
     }
+    
+    public void personOp1(@Valid Person p) {
+        return;
+    }
+    
+    public void personOp2(@NotNull @Valid Person p) {
+        return;
+    }
+    
+    public static class Person {
+        @NotNull
+        String name;
+    }
+    
 }

Modified: incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java?rev=949685&r1=949684&r2=949685&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/test/java/org/apache/bval/jsr303/extensions/MethodValidatorImplTest.java
Mon May 31 08:17:55 2010
@@ -21,6 +21,7 @@ import junit.framework.TestCase;
 import junit.framework.TestSuite;
 import org.apache.bval.jsr303.ApacheValidatorFactory;
 import org.apache.bval.jsr303.ClassValidator;
+import org.apache.bval.jsr303.extensions.ExampleMethodService.Person;
 
 import javax.validation.Validator;
 import java.lang.reflect.Constructor;
@@ -156,7 +157,6 @@ public class MethodValidatorImplTest ext
     }
     
     public void testValidateMoreReturnValue() throws NoSuchMethodException {
-    	
     	ExampleMethodService service = new ExampleMethodService();
     	MethodValidator mv = getValidator().unwrap(MethodValidator.class);
     	Method echoMethod = service.getClass().getMethod("echo", new Class[]{String.class});
@@ -172,8 +172,48 @@ public class MethodValidatorImplTest ext
     	returnedValue = "valid";
     	results = mv.validateReturnedValue(service.getClass(), echoMethod, returnedValue);
     	assertTrue(results.isEmpty());
-    	
-    	
+    }
+    
+    public void testValidateValidParam() throws NoSuchMethodException {
+        ExampleMethodService service = new ExampleMethodService();
+        MethodValidator mv = getValidator().unwrap(MethodValidator.class);
+        
+        Method personOp1 = service.getClass().getMethod("personOp1", new Class[]{Person.class});
+        
+        // Validate with invalid person
+        Person p = new ExampleMethodService.Person();
+        Set<?> results = mv.validateParameters(service.getClass(), personOp1, new Object[]{p});
+        assertEquals("Expected 1 violation", 1, results.size());
+        
+        // validate with valid person
+        p.name = "valid name";
+        results = mv.validateParameters(service.getClass(), personOp1, new Object[]{p});
+        assertTrue("No violations expected", results.isEmpty());
+        
+        // validate with null person
+        results = mv.validateParameters(service.getClass(), personOp1, new Object[]{null});
+        assertTrue("No violations expected", results.isEmpty());
+    }
+    
+    public void testValidateNotNullValidParam() throws NoSuchMethodException {
+        ExampleMethodService service = new ExampleMethodService();
+        MethodValidator mv = getValidator().unwrap(MethodValidator.class);
+        
+        Method personOp2 = service.getClass().getMethod("personOp2", new Class[]{Person.class});
+        
+        // Validate with null person
+        Set<?> results = mv.validateParameters(service.getClass(), personOp2, new Object[]{null});
+        assertEquals("Expected 1 violation", 1, results.size());
+        
+        // Validate with invalid person
+        Person p = new ExampleMethodService.Person();
+        results = mv.validateParameters(service.getClass(), personOp2, new Object[]{p});
+        assertEquals("Expected 1 violation", 1, results.size());
+        
+        // validate with valid person
+        p.name = "valid name";
+        results = mv.validateParameters(service.getClass(), personOp2, new Object[]{p});
+        assertTrue("No violations expected", results.isEmpty());
     }
 
     private Validator getValidator() {



Mime
View raw message