1 package org.jboss.portal.test.core.theme.strategy; 2 3 import junit.framework.Test; 4 import junit.framework.TestCase; 5 import junit.framework.TestSuite; 6 import org.jboss.portal.common.MediaType; 7 import org.jboss.portal.core.theme.strategy.impl.DefaultStrategyImpl; 8 import org.jboss.portal.core.theme.strategy.impl.StrategyContextImpl; 9 import org.jboss.portal.server.theme.PortalLayout; 10 import org.jboss.portal.server.theme.strategy.PortletContext; 11 import org.jboss.portal.server.theme.strategy.StrategyContext; 12 import org.jboss.portal.server.theme.strategy.StrategyException; 13 import org.jboss.portal.server.theme.strategy.StrategyResponse; 14 15 import javax.servlet.RequestDispatcher ; 16 import javax.servlet.ServletInputStream ; 17 import javax.servlet.http.Cookie ; 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpSession ; 20 import java.io.BufferedReader ; 21 import java.io.IOException ; 22 import java.io.UnsupportedEncodingException ; 23 import java.security.Principal ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.Enumeration ; 27 import java.util.Locale ; 28 import java.util.Map ; 29 30 32 36 public class DefaultStrategyImplTest extends TestCase 37 { 38 private static final String appName = "testApp"; 39 private static final String strategyName = "testStrategy"; 40 private static final MediaType mediaType = MediaType.HTML; 41 private DefaultStrategyImpl strategy = null; 42 43 private HttpServletRequest request = new Request (); 44 private PortalLayout layout = null; 45 private Collection portlets = Collections.EMPTY_LIST; 46 private PortletContext targetPortlet = null; 47 private String portalName = "TestPortal"; 48 private String pageName = "TestPage"; 49 private String [] regionNames = {"testRegion"}; 50 51 StrategyContext context = null; 52 53 56 public DefaultStrategyImplTest(String testName) 57 { 58 super(testName); 59 } 60 61 64 public static Test suite() 65 { 66 return new TestSuite(DefaultStrategyImplTest.class); 67 } 68 69 73 public void setUp() 74 { 75 strategy = new DefaultStrategyImpl(); 76 strategy.setAppName(appName); 77 strategy.setName(strategyName); 78 strategy.setMediaType(mediaType); 79 } 80 81 85 public void tearDown() 86 { 87 strategy = null; 88 } 89 90 91 98 public void testProperties() 99 { 100 assertEquals(appName, strategy.getAppName()); 101 assertEquals(strategyName, strategy.getName()); 102 assertEquals(mediaType, strategy.getMediaType()); 103 } 104 105 public void testContextCreate1() 106 { 107 try 108 { 109 new StrategyContextImpl(null, layout, portlets, targetPortlet, portalName, pageName, regionNames); 110 } 111 catch (NullPointerException e) 112 { 113 assertTrue(true); 114 return; 115 } 116 assertTrue(false); 117 } 118 119 public void testContextCreate2() 120 { 121 try 122 { 123 new StrategyContextImpl(request, layout, portlets, targetPortlet, null, pageName, regionNames); 124 } 125 catch (NullPointerException e) 126 { 127 assertTrue(true); 128 return; 129 } 130 assertTrue(false); 131 } 132 133 public void testContextCreate3() 134 { 135 try 136 { 137 new StrategyContextImpl(request, layout, portlets, targetPortlet, portalName, null, regionNames); 138 } 139 catch (NullPointerException e) 140 { 141 assertTrue(true); 142 return; 143 } 144 assertTrue(false); 145 } 146 147 public void testContextCreate4() 148 { 149 try 150 { 151 new StrategyContextImpl(request, layout, portlets, targetPortlet, portalName, pageName, regionNames); 152 } 153 catch (NullPointerException e) 154 { 155 assertTrue(false); 156 return; 157 } 158 assertTrue(true); 159 } 160 161 public void testContext() 162 { 163 try 164 { 165 context = new StrategyContextImpl(request, null, portlets, null, portalName, pageName, regionNames); 166 assertTrue(context.getHttpServletRequest() != null); 167 assertTrue(context.getLayout() == null); 168 assertTrue(context.getPageName().equals(pageName)); 169 assertTrue(context.getPortalName().equals(portalName)); 170 assertTrue(context.getPortletList() != null); 171 assertTrue(context.getPortletList().isEmpty()); 172 assertTrue(context.getRegions() != null); 173 assertTrue(context.getRegions().length == 1); 174 assertTrue(context.getRegions()[0].equals(regionNames[0])); 175 assertTrue(context.getTargetPortlet() == null); 176 } 177 catch (NullPointerException e) 178 { 179 assertTrue(false); 180 return; 181 } 182 assertTrue(true); 183 } 184 185 public void testEvaluate() 186 { 187 StrategyContext context = null; 188 try 189 { 190 strategy.evaluate(context); 191 } 192 catch (NullPointerException e) 193 { 194 assertTrue(true); 196 return; 197 } 198 catch (StrategyException e) 199 { 200 assertTrue(false); 202 return; 203 } 204 205 assertTrue(false); 207 } 208 209 public void testEvaluate2() 210 { 211 context = new StrategyContextImpl(request, layout, portlets, targetPortlet, portalName, pageName, regionNames); 212 StrategyResponse response = null; 213 try 214 { 215 response = strategy.evaluate(context); 216 217 assertTrue(response != null); 218 assertTrue(response.getExcludedList() != null); 219 assertTrue(response.getExcludedList().isEmpty()); 220 assertTrue(response.getModifiedPortletContextList() != null); 221 assertTrue(response.getModifiedPortletContextList().isEmpty()); 222 assertTrue(response.getWindowStateChangeMap() != null); 223 assertTrue(response.getWindowStateChangeMap().isEmpty()); 224 assertTrue(response.getState() == null); 225 assertTrue(response.getLayoutURI() == null); 226 } 227 catch (NullPointerException e) 228 { 229 assertTrue(false); 230 return; 231 } 232 catch (StrategyException e) 233 { 234 assertTrue(false); 236 return; 237 } 238 assertTrue(true); 240 } 241 242 public void testEvaluate3() 243 { 244 } 246 247 248 private static class Request implements HttpServletRequest 250 { 251 252 public String getAuthType() 253 { 254 return null; } 256 257 public Cookie [] getCookies() 258 { 259 return new Cookie [0]; } 261 262 public long getDateHeader(String s) 263 { 264 return 0; } 266 267 public String getHeader(String s) 268 { 269 return null; } 271 272 public Enumeration getHeaders(String s) 273 { 274 return null; } 276 277 public Enumeration getHeaderNames() 278 { 279 return null; } 281 282 public int getIntHeader(String s) 283 { 284 return 0; } 286 287 public String getMethod() 288 { 289 return null; } 291 292 public String getPathInfo() 293 { 294 return null; } 296 297 public String getPathTranslated() 298 { 299 return null; } 301 302 public String getContextPath() 303 { 304 return null; } 306 307 public String getQueryString() 308 { 309 return null; } 311 312 public String getRemoteUser() 313 { 314 return null; } 316 317 public boolean isUserInRole(String s) 318 { 319 return false; } 321 322 public Principal getUserPrincipal() 323 { 324 return null; } 326 327 public String getRequestedSessionId() 328 { 329 return null; } 331 332 public String getRequestURI() 333 { 334 return null; } 336 337 public StringBuffer getRequestURL() 338 { 339 return null; } 341 342 public String getServletPath() 343 { 344 return null; } 346 347 public HttpSession getSession(boolean b) 348 { 349 return null; } 351 352 public HttpSession getSession() 353 { 354 return null; } 356 357 public boolean isRequestedSessionIdValid() 358 { 359 return false; } 361 362 public boolean isRequestedSessionIdFromCookie() 363 { 364 return false; } 366 367 public boolean isRequestedSessionIdFromURL() 368 { 369 return false; } 371 372 375 public boolean isRequestedSessionIdFromUrl() 376 { 377 return false; } 379 380 public Object getAttribute(String s) 381 { 382 return null; } 384 385 public Enumeration getAttributeNames() 386 { 387 return null; } 389 390 public String getCharacterEncoding() 391 { 392 return null; } 394 395 public void setCharacterEncoding(String s) throws UnsupportedEncodingException 396 { 397 } 399 400 public int getContentLength() 401 { 402 return 0; } 404 405 public String getContentType() 406 { 407 return null; } 409 410 public ServletInputStream getInputStream() throws IOException 411 { 412 return null; } 414 415 public String getParameter(String s) 416 { 417 return null; } 419 420 public Enumeration getParameterNames() 421 { 422 return null; } 424 425 public String [] getParameterValues(String s) 426 { 427 return new String [0]; } 429 430 public Map getParameterMap() 431 { 432 return null; } 434 435 public String getProtocol() 436 { 437 return null; } 439 440 public String getScheme() 441 { 442 return null; } 444 445 public String getServerName() 446 { 447 return null; } 449 450 public int getServerPort() 451 { 452 return 0; } 454 455 public BufferedReader getReader() throws IOException 456 { 457 return null; } 459 460 public String getRemoteAddr() 461 { 462 return null; } 464 465 public String getRemoteHost() 466 { 467 return null; } 469 470 public void setAttribute(String s, Object o) 471 { 472 } 474 475 public void removeAttribute(String s) 476 { 477 } 479 480 public Locale getLocale() 481 { 482 return null; } 484 485 public Enumeration getLocales() 486 { 487 return null; } 489 490 public boolean isSecure() 491 { 492 return false; } 494 495 public RequestDispatcher getRequestDispatcher(String s) 496 { 497 return null; } 499 500 503 public String getRealPath(String s) 504 { 505 return null; } 507 508 public int getRemotePort() 509 { 510 return 0; } 512 513 public String getLocalName() 514 { 515 return null; } 517 518 public String getLocalAddr() 519 { 520 return null; } 522 523 public int getLocalPort() 524 { 525 return 0; } 527 } 528 } 529 | Popular Tags |