KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > test > core > theme > strategy > DefaultStrategyImplTest


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 JavaDoc;
16 import javax.servlet.ServletInputStream JavaDoc;
17 import javax.servlet.http.Cookie JavaDoc;
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpSession JavaDoc;
20 import java.io.BufferedReader JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.UnsupportedEncodingException JavaDoc;
23 import java.security.Principal JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.Enumeration JavaDoc;
27 import java.util.Locale JavaDoc;
28 import java.util.Map JavaDoc;
29
30 // todo: add any other packages needed for test
31

32 /**
33  * Typically you will have one of these classes for every
34  * class in the package you want to test named ClassNameTest
35  */

36 public class DefaultStrategyImplTest extends TestCase
37 {
38    private static final String JavaDoc appName = "testApp";
39    private static final String JavaDoc strategyName = "testStrategy";
40    private static final MediaType mediaType = MediaType.HTML;
41    private DefaultStrategyImpl strategy = null;
42
43    private HttpServletRequest JavaDoc request = new Request JavaDoc();
44    private PortalLayout layout = null;
45    private Collection JavaDoc portlets = Collections.EMPTY_LIST;
46    private PortletContext targetPortlet = null;
47    private String JavaDoc portalName = "TestPortal";
48    private String JavaDoc pageName = "TestPage";
49    private String JavaDoc[] regionNames = {"testRegion"};
50
51    StrategyContext context = null;
52
53    /**
54     * Creates the test with a given name.
55     */

56    public DefaultStrategyImplTest(String JavaDoc testName)
57    {
58       super(testName);
59    }
60
61    /**
62     * Static method used to lauch this suite of tests.
63     */

64    public static Test suite()
65    {
66       return new TestSuite(DefaultStrategyImplTest.class);
67    }
68
69    /**
70     * Put and initialization code here. Gets called for every test
71     * in this suite class (so before every testMethod gets called.
72     */

73    public void setUp()
74    {
75       strategy = new DefaultStrategyImpl();
76       strategy.setAppName(appName);
77       strategy.setName(strategyName);
78       strategy.setMediaType(mediaType);
79    }
80
81    /**
82     * Put and clean up code here. Gets called for every test
83     * in this suite class (so after every testMethod gets called.
84     */

85    public void tearDown()
86    {
87       strategy = null;
88    }
89
90
91    /**
92     * This is an example testMethod. Any method
93     * named testXXX that takes no args and returns
94     * void will be called by the testing framework.
95     * Typically, you would have one of these for every
96     * method you wanted to test on your class.
97     */

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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc e)
193       {
194          // this is expected
195
assertTrue(true);
196          return;
197       }
198       catch (StrategyException e)
199       {
200          // not expected
201
assertTrue(false);
202          return;
203       }
204
205       // if we get here, then fail
206
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 JavaDoc e)
228       {
229          assertTrue(false);
230          return;
231       }
232       catch (StrategyException e)
233       {
234          // not expected
235
assertTrue(false);
236          return;
237       }
238       //expected to get here
239
assertTrue(true);
240    }
241
242    public void testEvaluate3()
243    {
244       //+++TODO
245
}
246
247
248    // ----------------- helpers from here on ------------------------------------------------
249
private static class Request implements HttpServletRequest JavaDoc
250    {
251
252       public String JavaDoc getAuthType()
253       {
254          return null; //+++TODO
255
}
256
257       public Cookie JavaDoc[] getCookies()
258       {
259          return new Cookie JavaDoc[0]; //+++TODO
260
}
261
262       public long getDateHeader(String JavaDoc s)
263       {
264          return 0; //+++TODO
265
}
266
267       public String JavaDoc getHeader(String JavaDoc s)
268       {
269          return null; //+++TODO
270
}
271
272       public Enumeration JavaDoc getHeaders(String JavaDoc s)
273       {
274          return null; //+++TODO
275
}
276
277       public Enumeration JavaDoc getHeaderNames()
278       {
279          return null; //+++TODO
280
}
281
282       public int getIntHeader(String JavaDoc s)
283       {
284          return 0; //+++TODO
285
}
286
287       public String JavaDoc getMethod()
288       {
289          return null; //+++TODO
290
}
291
292       public String JavaDoc getPathInfo()
293       {
294          return null; //+++TODO
295
}
296
297       public String JavaDoc getPathTranslated()
298       {
299          return null; //+++TODO
300
}
301
302       public String JavaDoc getContextPath()
303       {
304          return null; //+++TODO
305
}
306
307       public String JavaDoc getQueryString()
308       {
309          return null; //+++TODO
310
}
311
312       public String JavaDoc getRemoteUser()
313       {
314          return null; //+++TODO
315
}
316
317       public boolean isUserInRole(String JavaDoc s)
318       {
319          return false; //+++TODO
320
}
321
322       public Principal JavaDoc getUserPrincipal()
323       {
324          return null; //+++TODO
325
}
326
327       public String JavaDoc getRequestedSessionId()
328       {
329          return null; //+++TODO
330
}
331
332       public String JavaDoc getRequestURI()
333       {
334          return null; //+++TODO
335
}
336
337       public StringBuffer JavaDoc getRequestURL()
338       {
339          return null; //+++TODO
340
}
341
342       public String JavaDoc getServletPath()
343       {
344          return null; //+++TODO
345
}
346
347       public HttpSession JavaDoc getSession(boolean b)
348       {
349          return null; //+++TODO
350
}
351
352       public HttpSession JavaDoc getSession()
353       {
354          return null; //+++TODO
355
}
356
357       public boolean isRequestedSessionIdValid()
358       {
359          return false; //+++TODO
360
}
361
362       public boolean isRequestedSessionIdFromCookie()
363       {
364          return false; //+++TODO
365
}
366
367       public boolean isRequestedSessionIdFromURL()
368       {
369          return false; //+++TODO
370
}
371
372       /**
373        * @deprecated
374        */

375       public boolean isRequestedSessionIdFromUrl()
376       {
377          return false; //+++TODO
378
}
379
380       public Object JavaDoc getAttribute(String JavaDoc s)
381       {
382          return null; //+++TODO
383
}
384
385       public Enumeration JavaDoc getAttributeNames()
386       {
387          return null; //+++TODO
388
}
389
390       public String JavaDoc getCharacterEncoding()
391       {
392          return null; //+++TODO
393
}
394
395       public void setCharacterEncoding(String JavaDoc s) throws UnsupportedEncodingException JavaDoc
396       {
397          //+++TODO
398
}
399
400       public int getContentLength()
401       {
402          return 0; //+++TODO
403
}
404
405       public String JavaDoc getContentType()
406       {
407          return null; //+++TODO
408
}
409
410       public ServletInputStream JavaDoc getInputStream() throws IOException JavaDoc
411       {
412          return null; //+++TODO
413
}
414
415       public String JavaDoc getParameter(String JavaDoc s)
416       {
417          return null; //+++TODO
418
}
419
420       public Enumeration JavaDoc getParameterNames()
421       {
422          return null; //+++TODO
423
}
424
425       public String JavaDoc[] getParameterValues(String JavaDoc s)
426       {
427          return new String JavaDoc[0]; //+++TODO
428
}
429
430       public Map JavaDoc getParameterMap()
431       {
432          return null; //+++TODO
433
}
434
435       public String JavaDoc getProtocol()
436       {
437          return null; //+++TODO
438
}
439
440       public String JavaDoc getScheme()
441       {
442          return null; //+++TODO
443
}
444
445       public String JavaDoc getServerName()
446       {
447          return null; //+++TODO
448
}
449
450       public int getServerPort()
451       {
452          return 0; //+++TODO
453
}
454
455       public BufferedReader JavaDoc getReader() throws IOException JavaDoc
456       {
457          return null; //+++TODO
458
}
459
460       public String JavaDoc getRemoteAddr()
461       {
462          return null; //+++TODO
463
}
464
465       public String JavaDoc getRemoteHost()
466       {
467          return null; //+++TODO
468
}
469
470       public void setAttribute(String JavaDoc s, Object JavaDoc o)
471       {
472          //+++TODO
473
}
474
475       public void removeAttribute(String JavaDoc s)
476       {
477          //+++TODO
478
}
479
480       public Locale JavaDoc getLocale()
481       {
482          return null; //+++TODO
483
}
484
485       public Enumeration JavaDoc getLocales()
486       {
487          return null; //+++TODO
488
}
489
490       public boolean isSecure()
491       {
492          return false; //+++TODO
493
}
494
495       public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc s)
496       {
497          return null; //+++TODO
498
}
499
500       /**
501        * @deprecated
502        */

503       public String JavaDoc getRealPath(String JavaDoc s)
504       {
505          return null; //+++TODO
506
}
507
508       public int getRemotePort()
509       {
510          return 0; //+++TODO
511
}
512
513       public String JavaDoc getLocalName()
514       {
515          return null; //+++TODO
516
}
517
518       public String JavaDoc getLocalAddr()
519       {
520          return null; //+++TODO
521
}
522
523       public int getLocalPort()
524       {
525          return 0; //+++TODO
526
}
527    }
528 }
529
Popular Tags