KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
20
21 import javax.portlet.PortletRequest;
22
23 /**
24  * @author <a HREF="ddewolf@apache.org">David H. DeWolf</a>
25  */

26 public class SimpleActionParameterTest
27     extends ActionAbstractReflectivePortletTest {
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     public String JavaDoc getTestSuiteName() {
33         return "Simple Action Parameter Test";
34     }
35
36     protected TestResult checkSentActionParameter(PortletRequest req) {
37         TestResult res = new TestResult();
38         res.setName("Sent Action Parameter Test");
39         res.setDesc("Ensure that parameters sent through the action query stream have made it to the action reqest.");
40
41         String JavaDoc val = req.getParameter(KEY);
42         if(val == null || !VALUE.equals(val)) {
43             res.setReturnCode(TestResult.FAILED);
44             res.setResults("Expected : "+VALUE+" retrieved "+val);
45         }
46         else {
47             res.setReturnCode(TestResult.PASSED);
48         }
49         return res;
50     }
51
52     protected TestResult checkSentActionParamerMap(PortletRequest req) {
53         TestResult res = new TestResult();
54         res.setName("Sent Action Parameter Map");
55         res.setDesc("Ensure that parameters sent through the action query stream have made it to the action parameter map");
56
57         Map JavaDoc map = req.getParameterMap();
58         String JavaDoc[] val = (String JavaDoc[])map.get(KEY);
59         if(val!=null) {
60             for(int i=0;i<val.length;i++) {
61                 if(val[i].equals(VALUE)) {
62                     res.setReturnCode(TestResult.PASSED);
63                     return res;
64                 }
65             }
66         }
67
68         res.setReturnCode(TestResult.FAILED);
69         res.setResults("Unable to retrieve key "+KEY+" with value of "+VALUE);
70         return res;
71     }
72
73     protected TestResult checkParameterNames(PortletRequest req) {
74         TestResult res = new TestResult();
75         res.setName("Test Parameter Names Enumeration.");
76         res.setDesc("Enumerate through all expected names.");
77
78         boolean hasExternal = false;
79         Enumeration JavaDoc enumerator= req.getParameterNames();
80         while(enumerator.hasMoreElements()) {
81             String JavaDoc val = enumerator.nextElement().toString();
82             if(KEY.equals(val)) {
83                 hasExternal = true;
84             }
85         }
86         if(!hasExternal) {
87             res.setReturnCode(TestResult.FAILED);
88             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
89             if(!hasExternal) {
90                 sb.append("External Parameter Not Found. ");
91             }
92             res.setResults(sb.toString());
93         }
94         else {
95             res.setReturnCode(TestResult.PASSED);
96         }
97         return res;
98     }
99 }
100
Popular Tags