1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7 package com.tirsen.angkor.test.unit;
8
9 import junit.framework.TestCase;
10 import com.tirsen.angkor.Application;
11 import com.tirsen.angkor.Page;
12 import com.tirsen.angkor.test.unit.mock.MockServletRequest;
13 import com.tirsen.angkor.test.unit.mock.MockServletResponse;
14 import com.tirsen.angkor.test.unit.mock.MockComponent;
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17
18 /***
19 * TODO document PageTest
20 *
21 * <!-- $Id: PageTest.java,v 1.1 2002/10/13 19:59:23 tirsen Exp $ -->
22 *
23 * @author $Author: tirsen $
24 * @version $Revision: 1.1 $
25 */
26 public class PageTest extends TestCase
27 {
28 private static final Log logger = LogFactory.getLog(PageTest.class);
29 public Application application;
30 public Page page;
31
32 protected void setUp()
33 {
34 application = new MockApplication();
35
36 page = new Page();
37 application.registerPage("page", page);
38 }
39
40 public void testAdd()
41 {
42 MockComponent child = new MockComponent();
43 page.add(child);
44 assertTrue("add() failed", page.getChildren().contains(child));
45 }
46
47 public void testPage() throws Exception
48 {
49 System.out.println(logger.isDebugEnabled());
50
51 setUp();
52
53 MockComponent mockComponent = new MockComponent();
54 page.add(mockComponent);
55
56 MockServletRequest mockServletRequest = new MockServletRequest(application, "application/" + "page");
57 MockServletResponse mockServletResponse = new MockServletResponse();
58 application.process(mockServletRequest, mockServletResponse);
59
60 mockComponent.assertRenderedCorrectly(mockServletResponse);
61 }
62
63 public void testGetPage()
64 {
65 Page testPage = new Page();
66 application.registerPage("testPage", testPage);
67 assertSame(testPage, application.getPage("testPage"));
68 assertSame(application, testPage.getApplication());
69
70 // should be able to register same page twice
71 application.registerPage("testPage", testPage);
72
73 Application application2 = new Application();
74 try
75 {
76 application2.registerPage("testPage", testPage);
77 fail("Should not be able to register same page to two applications.");
78 }
79 catch (IllegalArgumentException shouldHappen)
80 {
81 }
82
83 try
84 {
85 application.getPage("no-page-here");
86 fail("Should not find non-existent page.");
87 }
88 catch (IllegalArgumentException shouldHappen)
89 {
90 }
91 }
92 }
This page was automatically generated by Maven