1 16 17 package org.apache.pluto.portalImpl.portlet.test; 18 19 import java.util.Map ; 20 21 import javax.portlet.ActionRequest; 22 import javax.portlet.ActionResponse; 23 import javax.portlet.PortletContext; 24 import javax.portlet.PortletSession; 25 26 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 } 96 | Popular Tags |