1 15 package org.apache.tapestry.portlet; 16 17 import java.net.MalformedURLException ; 18 import java.net.URL ; 19 import java.util.List ; 20 21 import javax.portlet.PortletContext; 22 23 import org.apache.tapestry.web.WebContext; 24 import org.easymock.MockControl; 25 26 29 public class TestPortletWebContext extends BasePortletWebTestCase 30 { 31 32 public void testGetInitParameterNames() 33 { 34 MockControl control = newControl(PortletContext.class); 35 PortletContext context = (PortletContext) control.getMock(); 36 37 context.getInitParameterNames(); 38 control.setReturnValue(newEnumeration()); 39 40 replayControls(); 41 42 WebContext wc = new PortletWebContext(context); 43 44 List l = wc.getInitParameterNames(); 45 46 checkList(l); 47 48 verifyControls(); 49 } 50 51 public void testGetInitParameterValue() 52 { 53 String value = "William Orbit"; 54 55 MockControl control = newControl(PortletContext.class); 56 PortletContext context = (PortletContext) control.getMock(); 57 58 context.getInitParameter("artist"); 59 control.setReturnValue(value); 60 61 replayControls(); 62 63 WebContext wc = new PortletWebContext(context); 64 65 assertSame(value, wc.getInitParameterValue("artist")); 66 67 verifyControls(); 68 } 69 70 public void testGetAttributeNames() 71 { 72 MockControl control = newControl(PortletContext.class); 73 PortletContext context = (PortletContext) control.getMock(); 74 75 context.getAttributeNames(); 76 control.setReturnValue(newEnumeration()); 77 78 replayControls(); 79 80 WebContext wc = new PortletWebContext(context); 81 82 List l = wc.getAttributeNames(); 83 84 checkList(l); 85 86 verifyControls(); 87 } 88 89 public void testGetAttribute() 90 { 91 Object attribute = new Object (); 92 93 MockControl control = newControl(PortletContext.class); 94 PortletContext context = (PortletContext) control.getMock(); 95 96 context.getAttribute("attr"); 97 control.setReturnValue(attribute); 98 99 replayControls(); 100 101 WebContext wc = new PortletWebContext(context); 102 103 assertSame(attribute, wc.getAttribute("attr")); 104 105 verifyControls(); 106 } 107 108 public void testSetAttribute() 109 { 110 Object attribute = new Object (); 111 112 MockControl control = newControl(PortletContext.class); 113 PortletContext context = (PortletContext) control.getMock(); 114 115 context.setAttribute("name", attribute); 116 117 replayControls(); 118 119 WebContext wc = new PortletWebContext(context); 120 121 wc.setAttribute("name", attribute); 122 123 verifyControls(); 124 } 125 126 public void testSetAttributeToNull() 127 { 128 MockControl control = newControl(PortletContext.class); 129 PortletContext context = (PortletContext) control.getMock(); 130 131 context.removeAttribute("tonull"); 132 133 replayControls(); 134 135 WebContext wc = new PortletWebContext(context); 136 137 wc.setAttribute("tonull", null); 138 139 verifyControls(); 140 } 141 142 public void testGetResource() throws Exception 143 { 144 URL url = new URL ("http://jakarta.apache.org/tapestry"); 145 146 MockControl control = newControl(PortletContext.class); 147 PortletContext context = (PortletContext) control.getMock(); 148 149 context.getResource("/tapestry"); 150 control.setReturnValue(url); 151 152 replayControls(); 153 154 WebContext wc = new PortletWebContext(context); 155 156 assertSame(url, wc.getResource("/tapestry")); 157 158 verifyControls(); 159 } 160 161 public void testGetResourceFailure() throws Exception 162 { 163 Throwable t = new MalformedURLException ("Like this ever happens."); 164 165 MockControl control = newControl(PortletContext.class); 166 PortletContext context = (PortletContext) control.getMock(); 167 168 context.getResource("/tapestry"); 169 control.setThrowable(t); 170 171 replayControls(); 172 173 interceptLogging(PortletWebContext.class.getName()); 174 175 WebContext wc = new PortletWebContext(context); 176 177 assertNull(wc.getResource("/tapestry")); 178 179 verifyControls(); 180 181 assertLoggedMessage("Error getting portlet context resource '/tapestry': Like this ever happens."); 182 } 183 } | Popular Tags |