1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.pluto.portalImpl.portlet.test;
17
18 import java.util.Map;
19 import java.util.HashMap;
20 import java.util.Enumeration;
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 KEY = "org.apache.pluto.testsuite.PARAM_TEST_KEY";
29 public static final String VALUE = "org.apache.pluto.testsuite.PARAM_TEST_VALUE";
30
31 private static final String IKEY = "org.apache.pluto.testsuite.PARAM_TEST_KEY";
32
33 public String getTestSuiteName() {
34 return "Simple Parameter Test";
35 }
36
37 public Map getRenderParameters(PortletRequest req) {
38 Map map = new HashMap(req.getParameterMap());
39 map.put(IKEY, new String[] {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 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 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 enum = req.getParameterNames();
84 while(enum.hasMoreElements()) {
85 String val = enum.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 sb = new StringBuffer();
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 }