KickJava   Java API By Example, From Geeks To Geeks.

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


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 SimpleParameterTest extends AbstractReflectivePortletTest {
28     public static final String JavaDoc KEY = "org.apache.pluto.testsuite.PARAM_TEST_KEY";
29     public static final String JavaDoc VALUE = "org.apache.pluto.testsuite.PARAM_TEST_VALUE";
30
31     private static final String JavaDoc IKEY = "org.apache.pluto.testsuite.PARAM_TEST_KEY_I";
32
33     public String JavaDoc getTestSuiteName() {
34         return "Simple Parameter Test";
35     }
36
37     public Map JavaDoc getRenderParameters(PortletRequest req) {
38         Map JavaDoc map = new HashMap JavaDoc(req.getParameterMap());
39         map.put(IKEY, new String JavaDoc[] {VALUE});
40         return map;
41     }
42
43     protected TestResult checkSentParameters(PortletRequest req) {
44         TestResult res = new TestResult();
45         res.setName("Sent Parameter Test");
46         res.setDesc("Ensure that parameters sent through the action query stream have made it all the way through");
47
48         String JavaDoc val = req.getParameter(KEY);
49         if(val == null || !VALUE.equals(val)) {
50             res.setReturnCode(TestResult.FAILED);
51             res.setResults("Expected : "+VALUE+" retrieved "+val);
52         }
53         else {
54             res.setReturnCode(TestResult.PASSED);
55         }
56         return res;
57     }
58
59
60     protected TestResult checkInternalRenderParameters(PortletRequest req) {
61         TestResult res = new TestResult();
62         res.setName("Render Parameters Test");
63         res.setDesc("Enumerate through all render parameters sent in the action");
64
65         String JavaDoc val = req.getParameter(IKEY);
66         if(val == null || !VALUE.equals(val)) {
67             res.setReturnCode(TestResult.FAILED);
68             res.setResults("Expected : "+VALUE+" retrieved "+val);
69         }
70         else {
71             res.setReturnCode(TestResult.PASSED);
72         }
73         return res;
74     }
75
76     protected TestResult checkParameterNames(PortletRequest req) {
77         TestResult res = new TestResult();
78         res.setName("Test Parameter Names Enumeration.");
79         res.setDesc("Enumerate through all expected names.");
80
81         boolean hasExternal = false;
82         boolean hasInternal = false;
83         Enumeration JavaDoc enumerator= req.getParameterNames();
84         while(enumerator.hasMoreElements()) {
85             String JavaDoc val = enumerator.nextElement().toString();
86             if(KEY.equals(val)) {
87                 hasExternal = true;
88             }
89             if(IKEY.equals(val)) {
90                 hasInternal = true;
91             }
92         }
93         if(!hasInternal || !hasExternal) {
94             res.setReturnCode(TestResult.FAILED);
95             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
96             if(!hasInternal) {
97                 sb.append("Internal Parameter Not Found. ");
98             }
99             if(!hasExternal) {
100                 sb.append("External Parameter Not Found. ");
101             }
102             res.setResults(sb.toString());
103         }
104         else {
105             res.setReturnCode(TestResult.PASSED);
106         }
107         return res;
108     }
109 }
110
Popular Tags