View Javadoc

1   /*
2    * Copyright 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;
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