KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > portlet > test > SimpleRenderParameterTest


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.pluto.portalImpl.portlet.test;
17
18 import java.util.Enumeration JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import javax.portlet.PortletRequest;
23
24 /**
25  * @author <a HREF="ddewolf@apache.org">David H. DeWolf</a>
26  */

27 public class SimpleRenderParameterTest extends AbstractReflectivePortletTest {
28
29     public static final String JavaDoc KEY = "org.apache.pluto.testsuite.PARAM_TEST_KEY";
30     public static final String JavaDoc VALUE = "org.apache.pluto.testsuite.PARAM_TEST_VALUE";
31
32     private static final String JavaDoc IKEY = "org.apache.pluto.testsuite.PARAM_TEST_KEY_I";
33
34     public String JavaDoc getTestSuiteName() {
35         return "Simple Parameter Test";
36     }
37
38     // Unlike other tests, we DON'T want to include anything but the test id.
39
public Map JavaDoc getRenderParameters(PortletRequest req) {
40         Map JavaDoc map = new HashMap JavaDoc();
41         map.put(IKEY, new String JavaDoc[] {VALUE});
42         return map;
43     }
44
45     protected TestResult checkActionParametersNotHere(PortletRequest req) {
46         TestResult res = new TestResult();
47         res.setName("No Action Parameters Test");
48         res.setDesc("Ensure that parameters sent through the action query stream have NOT made it.");
49
50         String JavaDoc val = req.getParameter(KEY);
51         if(val != null) {
52             res.setReturnCode(TestResult.FAILED);
53             res.setResults("Retrieved action parameter ("+KEY+"="+VALUE+" inappropriately");
54         }
55         else {
56             res.setReturnCode(TestResult.PASSED);
57         }
58         return res;
59     }
60
61
62     protected TestResult checkInternalRenderParameter(PortletRequest req) {
63         TestResult res = new TestResult();
64         res.setName("Render Parameter Test");
65         res.setDesc("Validate the appropriate render parameters");
66
67         String JavaDoc val = req.getParameter(IKEY);
68         if(val == null || !VALUE.equals(val)) {
69             res.setReturnCode(TestResult.FAILED);
70             res.setResults("Expected : "+VALUE+" retrieved "+val);
71         }
72         else {
73             res.setReturnCode(TestResult.PASSED);
74         }
75         return res;
76     }
77
78     protected TestResult checkInternalRenderParameterValues(PortletRequest req) {
79         TestResult res = new TestResult();
80         res.setName("Render Parameter Values Test");
81         res.setDesc("Validate the appropriate render parameter values");
82
83         String JavaDoc[] val = req.getParameterValues(IKEY);
84         if(val == null || val.length<1 || !VALUE.equals(val[0])) {
85             res.setReturnCode(TestResult.FAILED);
86             res.setResults("Expected : "+VALUE+" retrieved "+val);
87         }
88         else {
89             res.setReturnCode(TestResult.PASSED);
90         }
91         return res;
92     }
93
94     protected TestResult checkParameterMap(PortletRequest req) {
95         TestResult res = new TestResult();
96         res.setName("Render Parameter Map Test");
97         res.setName("Check the contents of the render parameter map");
98
99         Map JavaDoc map = req.getParameterMap();
100         String JavaDoc[] val = (String JavaDoc[])map.get(IKEY);
101         if(map.containsKey(KEY) || val==null || val.length < 1 || !VALUE.equals(val[0])) {
102             res.setReturnCode(TestResult.FAILED);
103             if(map.containsKey(KEY)) {
104                 res.setResults("Found Action Parameter: "+KEY+"="+map.get(KEY));
105             }
106             if(!map.containsKey(IKEY) || val.length <1 || !VALUE.equals(val[0])) {
107                 res.setResults("Render Parameter: "+IKEY+"="+(val.length<1?"null":val[0])+" does not contain the expected value: "+VALUE);
108             }
109             return res;
110         }
111         res.setReturnCode(TestResult.PASSED);
112         return res;
113     }
114
115     protected TestResult checkParameterNames(PortletRequest req) {
116         TestResult res = new TestResult();
117         res.setName("Test Parameter Names Enumeration.");
118         res.setDesc("Enumerate through all expected names.");
119
120         boolean hasExternal = false;
121         boolean hasInternal = false;
122         Enumeration JavaDoc enumerator= req.getParameterNames();
123         while(enumerator.hasMoreElements()) {
124             String JavaDoc val = enumerator.nextElement().toString();
125             if(KEY.equals(val)) {
126                 hasExternal = true;
127             }
128             if(IKEY.equals(val)) {
129                 hasInternal = true;
130             }
131         }
132         if(!hasInternal || hasExternal) {
133             res.setReturnCode(TestResult.FAILED);
134             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
135             if(!hasInternal) {
136                 sb.append("Render Parameter Not Found. ");
137             }
138             if(!hasExternal) {
139                 sb.append("Action Parameter Found. ");
140             }
141             res.setResults(sb.toString());
142         }
143         else {
144             res.setReturnCode(TestResult.PASSED);
145         }
146         return res;
147     }
148 }
149
Popular Tags