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  package org.apache.pluto.portalImpl.portlet.test;
17  
18  import java.util.Properties;
19  import java.util.Enumeration;
20  
21  import javax.portlet.PortletRequest;
22  import javax.portlet.PortletMode;
23  import javax.portlet.WindowState;
24  import javax.portlet.PortletContext;
25  
26  import org.apache.pluto.testsuite.ExpectedResults;
27  
28  /***
29   * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
30   */
31  public class MiscTest extends AbstractReflectivePortletTest {
32  
33  
34      public String getTestSuiteName() {
35          return "Misc Test";
36      }
37  
38      protected TestResult checkContextMajorVersion(PortletContext ctx) {
39          TestResult res = new TestResult();
40          res.setName("Major Version Test");
41          res.setDesc("Make sure that the expected major version number is returned.");
42          Properties props = ExpectedResults.getExpectedProperties();
43          String major = String.valueOf(ctx.getMajorVersion());
44          if(major.equals(props.getProperty("expected.version.major"))) {
45              res.setReturnCode(TestResult.PASSED);
46          }
47          else {
48              res.setReturnCode(TestResult.FAILED);
49              res.setResults("Major Version: "+major+". Expected: "+props.getProperty("expected.version.major"));
50          }
51          return res;
52      }
53  
54      protected TestResult checkContextMinorVersion(PortletContext ctx) {
55          TestResult res = new TestResult();
56          res.setName("Minor Version Test");
57          res.setDesc("Make sure that the expected minor version number is returned.");
58          Properties props = ExpectedResults.getExpectedProperties();
59          String minor = String.valueOf(ctx.getMinorVersion());
60          if(minor.equals(props.getProperty("expected.version.minor"))) {
61              res.setReturnCode(TestResult.PASSED);
62          }
63          else {
64              res.setReturnCode(TestResult.FAILED);
65              res.setResults("Minor Version: "+minor+". Expected: "+props.getProperty("expected.version.minor"));
66          }
67          return res;
68      }
69  
70  
71  
72      protected TestResult checkContextServerInfo(PortletContext ctx) {
73          TestResult res = new TestResult();
74          res.setName("Server Info Test");
75          res.setDesc("Make sure that the expected server info is returned.");
76          Properties props = ExpectedResults.getExpectedProperties();
77          if(ctx.getServerInfo().equals(props.getProperty("expected.serverInfo"))) {
78              res.setReturnCode(TestResult.PASSED);
79          }
80          else {
81              res.setReturnCode(TestResult.FAILED);
82              res.setResults("Server info: "+ctx.getServerInfo()+". Expected: "+props.getProperty("expected.serverInfo"));
83          }
84          return res;
85      }
86  
87      protected TestResult checkPortalInfo(PortletRequest req) {
88          TestResult res = new TestResult();
89          res.setName("Portal Info Test");
90          res.setDesc("Make sure that the expected portal info is returned.");
91          Properties props = ExpectedResults.getExpectedProperties();
92          if(req.getPortalContext().getPortalInfo().equals(props.getProperty("expected.portalInfo"))) {
93              res.setReturnCode(TestResult.PASSED);
94          }
95          else {
96              res.setReturnCode(TestResult.FAILED);
97              res.setResults("Portal info: "+req.getPortalContext().getPortalInfo()+". Expected: "+props.getProperty("expected.portalInfo"));
98          }
99          return res;
100     }
101 
102     /***
103      * Test to ensure that the basic modes are supported.
104      * @todo Enhance to check for custom modes.
105      * @param req
106      * @return
107      */
108     protected TestResult checkSupportedModes(PortletRequest req)  {
109         TestResult res = new TestResult();
110         res.setName("Supported Modes Test");
111         res.setDesc("Make sure that the expected modes are returned.");
112 
113         boolean hasView = false;
114         boolean hasEdit = false;
115         boolean hasHelp = false;
116 
117         Enumeration enum = req.getPortalContext().getSupportedPortletModes();
118         while(enum.hasMoreElements()) {
119             PortletMode mode = (PortletMode)enum.nextElement();
120             if(mode.equals(PortletMode.VIEW)) {
121                 hasView  = true;
122             }
123             else if(mode.equals(PortletMode.EDIT)) {
124                 hasEdit  = true;
125             }
126             else if(mode.equals(PortletMode.HELP)) {
127                 hasHelp  = true;
128             }
129         }
130 
131         if(hasView && hasEdit &&  hasHelp) {
132             res.setReturnCode(TestResult.PASSED);
133         }
134         else {
135             res.setReturnCode(TestResult.FAILED);
136             StringBuffer sb = new StringBuffer();
137             if(!hasView) {
138                 sb.append("'View' mode not found. ");
139             }
140             if(!hasEdit) {
141                 sb.append("'Edit' mode not found. ");
142             }
143             if(!hasHelp) {
144                 sb.append("'Help' mode not found. ");
145             }
146         }
147         return res;
148     }
149 
150     protected TestResult checkSupportedWindowSates(PortletRequest req) {
151         TestResult res = new TestResult();
152         res.setName("Supported Window States Test");
153         res.setDesc("Make sure that the expected states are returned.");
154 
155         boolean hasMin = false;
156         boolean hasMax = false;
157         boolean hasNor = false;
158 
159         Enumeration enum = req.getPortalContext().getSupportedWindowStates();
160         while(enum.hasMoreElements()) {
161             WindowState mode = (WindowState)enum.nextElement();
162             if(mode.equals(WindowState.MINIMIZED)) {
163                 hasMin  = true;
164             }
165             else if(mode.equals(WindowState.MAXIMIZED)) {
166                 hasMax  = true;
167             }
168             else if(mode.equals(WindowState.NORMAL)) {
169                 hasNor  = true;
170             }
171         }
172 
173         if(hasMin && hasMax &&  hasNor) {
174             res.setReturnCode(TestResult.PASSED);
175         }
176         else {
177             res.setReturnCode(TestResult.FAILED);
178             StringBuffer sb = new StringBuffer();
179             if(!hasMin) {
180                 sb.append("'Minimized' state not found. ");
181             }
182             if(!hasMax) {
183                 sb.append("'Maximized' state not found. ");
184             }
185             if(!hasNor) {
186                 sb.append("'Normal' state not found. ");
187             }
188         }
189         return res;
190     }
191 
192 }