KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > validator > test > DefaultValidatorParserTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.validator.test;
8
9
10 import com.inversoft.junit.Request;
11 import com.inversoft.junit.WebTestCase;
12 import com.inversoft.verge.mvc.MVCException;
13 import com.inversoft.verge.mvc.MVCRequest;
14 import com.inversoft.verge.mvc.validator.DefaultValidatorParser;
15 import com.inversoft.verge.mvc.validator.ValidatorConstants;
16
17
18 /**
19  * <p>
20  * Test the default validator parser.
21  * </p>
22  *
23  * @author Brian Pontarelli
24  * @since 2.0
25  * @version 2.0
26  */

27 public class DefaultValidatorParserTest extends WebTestCase {
28
29     /**
30      * Constructs a new <code>DefaultValidatorParserTest</code>
31      *
32      * @param name The name of the test case being run
33      */

34     public DefaultValidatorParserTest(String JavaDoc name) {
35         super(name);
36         setLocal(true);
37     }
38
39
40     /**
41      * Tests that the overall DefaultValidatorParser correctly creates and then
42      * calls the Validator
43      */

44     public void beginOverallValidation(Request request) {
45         request.addParameter(ValidatorConstants.VALIDATOR_PARAMETER,
46             "com.inversoft.verge.mvc.validator.test.TestValidator1");
47     }
48     public void testOverallValidation() {
49         TestValidator1.validated = false;
50         DefaultValidatorParser mp = new DefaultValidatorParser();
51         MVCRequest mvcRequest = new MVCRequest(request, response);
52         try {
53             mp.preExecute(mvcRequest);
54             mp.execute(mvcRequest);
55             assertTrue("Should have validated", TestValidator1.validated);
56         } catch (MVCException mvce) {
57             fail(mvce.toString());
58         }
59     }
60
61     /**
62      * Tests that the overall DefaultValidatorParser correctly does not call the
63      * Validator
64      */

65     public void beginNoOverallValidation(Request request) {
66     }
67     public void testNoOverallValidation() {
68         DefaultValidatorParser mp = new DefaultValidatorParser();
69         TestValidator1.validated = false;
70         MVCRequest mvcRequest = new MVCRequest(request, response);
71         try {
72             mp.preExecute(mvcRequest);
73             mp.execute(mvcRequest);
74             assertFalse("Should NOT have validated", TestValidator1.validated);
75         } catch (MVCException mvce) {
76             fail(mvce.toString());
77         }
78     }
79
80     /**
81      * Tests that the overall DefaultModelParser correctly skips the call to the
82      * validator even if it was specified, but if the meta data has it turned
83      * off
84      */

85     public void beginValidationDisabled(Request request) {
86         request.addParameter(ValidatorConstants.VALIDATOR_PARAMETER,
87             "com.inversoft.verge.mvc.validator.test.TestValidator1");
88     }
89     public void testValidationDisabled() {
90         DefaultValidatorParser mp = new DefaultValidatorParser();
91         TestValidator1.validated = false;
92         MVCRequest mvcRequest = new MVCRequest(request, response);
93         mvcRequest.setValidationEnabled(false);
94         try {
95             mp.preExecute(mvcRequest);
96             mp.execute(mvcRequest);
97             assertFalse("Should NOT have validated", TestValidator1.validated);
98         } catch (MVCException mvce) {
99             fail(mvce.toString());
100         }
101     }
102 }
Popular Tags