1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to you under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.shale.validator;
19
20 import javax.servlet.ServletContextEvent;
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23 import org.apache.commons.validator.ValidatorAction;
24 import org.apache.shale.test.base.AbstractJsfTestCase;
25 import org.apache.shale.validator.faces.ValidatorLifecycleListener;
26
27 /***
28 * <p>Test case for <code>CommonsValidator</code>.</p>
29 */
30 public class ValidatorDefaultTestCase extends AbstractJsfTestCase {
31
32
33 // ------------------------------------------------------------ Constructors
34
35
36 // Construct a new instance of this test case.
37 public ValidatorDefaultTestCase(String name) {
38 super(name);
39 }
40
41
42 // ---------------------------------------------------- Overall Test Methods
43
44
45 // Set up instance variables required by this test case.
46 protected void setUp() throws Exception {
47
48 super.setUp();
49
50 servletContext.addInitParameter
51 (Globals.VALIDATOR_RULES,
52 Globals.DEFAULT_VALIDATOR_RULES +
53 ", /org/apache/shale/validator/custom-rules.xml");
54 listener = new ValidatorLifecycleListener();
55 listener.contextInitialized(new ServletContextEvent(servletContext));
56
57 }
58
59
60 // Return the tests included in this test case.
61 public static Test suite() {
62
63 return (new TestSuite(ValidatorDefaultTestCase.class));
64
65 }
66
67
68 // Tear down instance variables required by this test case.
69 protected void tearDown() throws Exception {
70
71 listener.contextDestroyed(new ServletContextEvent(servletContext));
72 listener = null;
73
74 super.tearDown();
75
76 }
77
78
79 // ------------------------------------------------------ Instance Variables
80
81
82 // ValidatorLifecycleListener used to load configuration resources
83 ValidatorLifecycleListener listener = null;
84
85
86 // ------------------------------------------------------------ Test Methods
87
88
89 // Test access to the 'required' validation rule with default configuration
90 public void testRequired() {
91
92 ValidatorAction va = CommonsValidator.getValidatorAction( "required" );
93 assertNotNull(va);
94 assertEquals("required",va.getName());
95 assertEquals("org.apache.shale.validator.CommonsValidator",
96 va.getClassname());
97 assertEquals("isSupplied",va.getMethod());
98
99 }
100
101 }