Author: musachy
Date: Fri Jul 27 10:57:41 2007
New Revision: 560339

URL: http://svn.apache.org/viewvc?view=rev&rev=560339
Log:
WW-2050 Separate JSONValidationInterceptor from AnnotationValidationInterceptor
Patch provided by Lukasz Racon

Modified:
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptorTest.java

Modified: 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptorTest.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptorTest.java?view=diff&rev=560339&r1=560338&r2=560339
==============================================================================
--- 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptorTest.java
 (original)
+++ 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/validation/JSONValidationInterceptorTest.java
 Fri Jul 27 10:57:41 2007
@@ -53,10 +53,17 @@
     private StrutsMockHttpServletResponse response;
     private JSONValidationInterceptor interceptor;
     private StrutsMockHttpServletRequest request;
+    private AnnotationValidationInterceptor validationInterceptor;
 
     public void testValidationFails() throws Exception {
-
+        
         action.addActionError("General error");
+        
+        Map parameters = new HashMap();
+        parameters.put("struts.enableJSONValidation", "true");
+        request.setParameterMap(parameters);
+        
+        validationInterceptor.intercept(invocation);
         
interceptor.setValidationFailedStatus(HttpServletResponse.SC_BAD_REQUEST);
         interceptor.intercept(invocation);
 
@@ -68,7 +75,7 @@
         //json
         assertEquals(normalizedExpected, normalizedActual);
         //execution
-        assertFalse(invocation.isExecuted());
+        assertFalse(action.isExecuted());
         //http status
         assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
     }
@@ -78,14 +85,18 @@
 
         action.setText("[EMAIL PROTECTED]");
         action.setValue(10);
+        
+        Map parameters = new HashMap();
+        parameters.put("struts.enableJSONValidation", "true");
+        request.setParameterMap(parameters);
 
+        validationInterceptor.intercept(invocation);
         interceptor.intercept(invocation);
 
         String json = stringWriter.toString();
 
         String normalizedActual = TestUtils.normalize(json, true);
         assertEquals("", normalizedActual);
-        assertTrue(invocation.isExecuted());
     }
     
     public void testValidationSucceedsValidateOnly() throws Exception {
@@ -97,22 +108,24 @@
         //just validate
         Map parameters = new HashMap();
         parameters.put("struts.validateOnly", "true");
+        parameters.put("struts.enableJSONValidation", "true");
         request.setParameterMap(parameters);
         
+        validationInterceptor.intercept(invocation);
         interceptor.intercept(invocation);
 
         String json = stringWriter.toString();
 
         String normalizedActual = TestUtils.normalize(json, true);
         assertEquals("/*{}*/", normalizedActual);
-        assertFalse(invocation.isExecuted());
+        assertFalse(action.isExecuted());
     }
 
     protected void setUp() throws Exception {
         super.setUp();
         this.action = new TestAction();
         this.interceptor = new JSONValidationInterceptor();
-        
+        this.validationInterceptor = new AnnotationValidationInterceptor();
         this.request = new StrutsMockHttpServletRequest();
         stringWriter = new StringWriter();
         PrintWriter writer = new PrintWriter(stringWriter);
@@ -129,21 +142,11 @@
         StrutsMockServletContext servletContext = new 
StrutsMockServletContext();
 
         context.put(StrutsStatics.SERVLET_CONTEXT, servletContext);
-        invocation = new MockActionInvocation() {
-            private boolean executed;
-
-            public String invoke() throws Exception {
-                executed = true;
-                return "success";
-            }
-
-            public boolean isExecuted() {
-                return executed;
-            }
-        };
+        invocation = new MockActionInvocation(); 
         invocation.setAction(action);
         invocation.setInvocationContext(context);
         MockActionProxy proxy = new MockActionProxy();
+        proxy.setMethod("execute");
         proxy.setAction(action);
         invocation.setProxy(proxy);
     }
@@ -152,8 +155,10 @@
     public static class TestAction extends ActionSupport {
         private String text = "x";
         private int value = -10;
-
+        private boolean executed = false;
+        
         public String execute() {
+            executed = true;
             return Action.SUCCESS;
         }
 
@@ -179,6 +184,10 @@
         @IntRangeFieldValidator(min = "-1", message = "Min value is -1")
         public void setValue(int value) {
             this.value = value;
+        }
+
+        public boolean isExecuted() {
+            return executed;
         }
     }
 }


Reply via email to