View Javadoc

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  
17  package org.apache.pluto.portalImpl.portlet.test;
18  
19  import java.util.Map;
20  
21  import javax.portlet.PortletContext;
22  import javax.portlet.ActionRequest;
23  import javax.portlet.ActionResponse;
24  import javax.portlet.PortletSession;
25  
26  /***
27   * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
28   */
29  public class ComplexAttributeTest extends AbstractReflectivePortletTest {
30  
31      private static final String BOGUS_KEY = "org.apache.pluto.testsuite.BOGUS_KEY";
32      private static final String KEY = "org.apache.pluto.testsuite.KEY";
33      private static final String VAL = "VALUE";
34  
35      public String getTestSuiteName() {
36          return "Complex Attribute Test";
37      }
38  
39      public Map doPrerequisiteAction(PortletContext context, ActionRequest req,
40                                      ActionResponse res) {
41          return new java.util.HashMap();
42      }
43  
44      protected TestResult checkGetEmptyApplicationScopedAttribute(PortletSession session) {
45          TestResult res = new TestResult();
46          res.setName("Get Empty Application Scoped Attribute Test");
47          res.setDesc("Retrieve an attribute that has not been set in the session's application scope and ensure it's value is null.");
48  
49          Object val = session.getAttribute(BOGUS_KEY, PortletSession.APPLICATION_SCOPE);
50          if(val == null) {
51              res.setReturnCode(TestResult.PASSED);
52          }
53          else {
54              res.setReturnCode(TestResult.FAILED);
55              res.setResults("Retrieved attribute value '"+val+"'; expected null.");
56          }
57          return res;
58      }
59  
60      protected TestResult checkSetApplicationScopedAttribute(PortletSession session) {
61          TestResult res = new TestResult();
62          res.setName("Set Application Scoped Attribute Test");
63          res.setDesc("Set an application scoped session attribute and ensure it's retrievable");
64  
65          session.setAttribute(KEY, VAL, PortletSession.APPLICATION_SCOPE);
66  
67          Object val = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE);
68          if(VAL.equals(val)) {
69              res.setReturnCode(TestResult.PASSED);
70          }
71          else {
72              res.setReturnCode(TestResult.FAILED);
73              res.setResults("Retrieved attribute value '"+val+"'; expected '"+VAL+"'");
74          }
75          return res;
76      }
77  
78      protected TestResult checkRemoveApplicationScopedAttribute(PortletSession session) {
79          TestResult res = new TestResult();
80          res.setName("Remove Application Scoped Attribute Test");
81          res.setDesc("Remove an application scoped session attribute and ensure it's null.");
82  
83          session.setAttribute(KEY, VAL, PortletSession.APPLICATION_SCOPE);
84          session.removeAttribute(KEY, PortletSession.APPLICATION_SCOPE);
85          Object val = session.getAttribute(KEY, PortletSession.APPLICATION_SCOPE);
86          if(null == val) {
87              res.setReturnCode(TestResult.PASSED);
88          }
89          else {
90              res.setReturnCode(TestResult.FAILED);
91              res.setResults("Retrieved attribute value '"+val+"'; expected null.");
92          }
93          return res;
94      }
95  }