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