1 16 package org.apache.pluto.portalImpl.portlet.test; 17 18 import java.util.Enumeration ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import javax.portlet.PortletRequest; 23 24 27 public class SimpleRenderParameterTest extends AbstractReflectivePortletTest { 28 29 public static final String KEY = "org.apache.pluto.testsuite.PARAM_TEST_KEY"; 30 public static final String VALUE = "org.apache.pluto.testsuite.PARAM_TEST_VALUE"; 31 32 private static final String IKEY = "org.apache.pluto.testsuite.PARAM_TEST_KEY_I"; 33 34 public String getTestSuiteName() { 35 return "Simple Parameter Test"; 36 } 37 38 public Map getRenderParameters(PortletRequest req) { 40 Map map = new HashMap (); 41 map.put(IKEY, new String [] {VALUE}); 42 return map; 43 } 44 45 protected TestResult checkActionParametersNotHere(PortletRequest req) { 46 TestResult res = new TestResult(); 47 res.setName("No Action Parameters Test"); 48 res.setDesc("Ensure that parameters sent through the action query stream have NOT made it."); 49 50 String val = req.getParameter(KEY); 51 if(val != null) { 52 res.setReturnCode(TestResult.FAILED); 53 res.setResults("Retrieved action parameter ("+KEY+"="+VALUE+" inappropriately"); 54 } 55 else { 56 res.setReturnCode(TestResult.PASSED); 57 } 58 return res; 59 } 60 61 62 protected TestResult checkInternalRenderParameter(PortletRequest req) { 63 TestResult res = new TestResult(); 64 res.setName("Render Parameter Test"); 65 res.setDesc("Validate the appropriate render parameters"); 66 67 String val = req.getParameter(IKEY); 68 if(val == null || !VALUE.equals(val)) { 69 res.setReturnCode(TestResult.FAILED); 70 res.setResults("Expected : "+VALUE+" retrieved "+val); 71 } 72 else { 73 res.setReturnCode(TestResult.PASSED); 74 } 75 return res; 76 } 77 78 protected TestResult checkInternalRenderParameterValues(PortletRequest req) { 79 TestResult res = new TestResult(); 80 res.setName("Render Parameter Values Test"); 81 res.setDesc("Validate the appropriate render parameter values"); 82 83 String [] val = req.getParameterValues(IKEY); 84 if(val == null || val.length<1 || !VALUE.equals(val[0])) { 85 res.setReturnCode(TestResult.FAILED); 86 res.setResults("Expected : "+VALUE+" retrieved "+val); 87 } 88 else { 89 res.setReturnCode(TestResult.PASSED); 90 } 91 return res; 92 } 93 94 protected TestResult checkParameterMap(PortletRequest req) { 95 TestResult res = new TestResult(); 96 res.setName("Render Parameter Map Test"); 97 res.setName("Check the contents of the render parameter map"); 98 99 Map map = req.getParameterMap(); 100 String [] val = (String [])map.get(IKEY); 101 if(map.containsKey(KEY) || val==null || val.length < 1 || !VALUE.equals(val[0])) { 102 res.setReturnCode(TestResult.FAILED); 103 if(map.containsKey(KEY)) { 104 res.setResults("Found Action Parameter: "+KEY+"="+map.get(KEY)); 105 } 106 if(!map.containsKey(IKEY) || val.length <1 || !VALUE.equals(val[0])) { 107 res.setResults("Render Parameter: "+IKEY+"="+(val.length<1?"null":val[0])+" does not contain the expected value: "+VALUE); 108 } 109 return res; 110 } 111 res.setReturnCode(TestResult.PASSED); 112 return res; 113 } 114 115 protected TestResult checkParameterNames(PortletRequest req) { 116 TestResult res = new TestResult(); 117 res.setName("Test Parameter Names Enumeration."); 118 res.setDesc("Enumerate through all expected names."); 119 120 boolean hasExternal = false; 121 boolean hasInternal = false; 122 Enumeration enumerator= req.getParameterNames(); 123 while(enumerator.hasMoreElements()) { 124 String val = enumerator.nextElement().toString(); 125 if(KEY.equals(val)) { 126 hasExternal = true; 127 } 128 if(IKEY.equals(val)) { 129 hasInternal = true; 130 } 131 } 132 if(!hasInternal || hasExternal) { 133 res.setReturnCode(TestResult.FAILED); 134 StringBuffer sb = new StringBuffer (); 135 if(!hasInternal) { 136 sb.append("Render Parameter Not Found. "); 137 } 138 if(!hasExternal) { 139 sb.append("Action Parameter Found. "); 140 } 141 res.setResults(sb.toString()); 142 } 143 else { 144 res.setReturnCode(TestResult.PASSED); 145 } 146 return res; 147 } 148 } 149 | Popular Tags |