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.Enumeration;
19
20 import javax.portlet.PortletContext;
21 import javax.portlet.PortletSession;
22
23 /***
24 * <B>TODO</B>: Document
25 * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
26 * @version 1.0
27 * @since Sep 15, 2004
28 */
29 public class ContextInitParameterTest extends AbstractReflectivePortletTest {
30 private static final String TEST_PARAM_NAME = "test-parameter-name";
31 private static final String TEST_PARAM_VAL = "test-parameter-val";
32
33 public ContextInitParameterTest() {
34
35 }
36
37 public String getTestSuiteName() {
38 return "Context Init Parameter Test";
39 }
40
41 protected TestResult checkEnumerationContainsElements(PortletContext ctx) {
42 TestResult res = new TestResult();
43 res.setName("Get Init Parameter Enumeration Test");
44 res.setDesc("Test the initialization parameter enumeration.");
45
46 Enumeration enumerator= ctx.getInitParameterNames();
47 if (enumerator.hasMoreElements()) {
48 res.setReturnCode(TestResult.PASSED);
49 }
50 else {
51 res.setReturnCode(TestResult.FAILED);
52 res.setResults("No init parameters found.");
53 }
54 return res;
55 }
56
57 protected TestResult checkEnumerationContainsNames(PortletContext ctx) {
58 TestResult res = new TestResult();
59 res.setName("Init Parameter Names in Enumeration Test");
60 res.setDesc("Test to make sure that the expected init parameters exist.");
61
62 boolean found = false;
63 Enumeration enumerator= ctx.getInitParameterNames();
64 while(enumerator.hasMoreElements()) {
65 String name = (String)enumerator.nextElement();
66 if(TEST_PARAM_NAME.equals(name)) {
67 found = true;
68 }
69 }
70
71 if(found) {
72 res.setReturnCode(TestResult.PASSED);
73 }
74 else {
75 res.setReturnCode(TestResult.FAILED);
76 res.setResults("Expected init parameter '"+TEST_PARAM_NAME+"' no found.");
77 }
78
79 return res;
80 }
81
82 protected TestResult checkGetInitParameter(PortletContext context) {
83 TestResult res = new TestResult();
84 res.setName("Init Parameter Retrieved Test");
85 res.setDesc("Test to make sure that init parameters are successfully retrieved.");
86
87 String val = context.getInitParameter(TEST_PARAM_NAME);
88 if(TEST_PARAM_VAL.equals(val)) {
89 res.setReturnCode(TestResult.PASSED);
90 }
91 else {
92 res.setReturnCode(TestResult.FAILED);
93 res.setResults("Expected value not found for key '"+TEST_PARAM_NAME+"'. Found '"+TEST_PARAM_VAL+"'");
94 }
95 return res;
96 }
97
98 protected TestResult checkGetContextFromSession(PortletSession session) {
99 TestResult res = new TestResult();
100 res.setName("PortletContext Retrieved From Session Test");
101 res.setDesc("Test ensures that the PortletContext can be retrieved from the session.");
102
103 PortletContext ctx = session.getPortletContext();
104 if(ctx != null) {
105 res.setReturnCode(TestResult.PASSED);
106 }
107 else {
108 res.setReturnCode(TestResult.FAILED);
109 res.setResults("Portlet Context is Null");
110 }
111 return res;
112 }
113 }
114