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
|
4
|
protected void setUp()
|
33
|
|
{
|
34
|
4
|
application = new MockApplication();
|
35
|
|
|
36
|
4
|
page = new Page();
|
37
|
4
|
application.registerPage("page", page);
|
38
|
|
}
|
39
|
|
|
40
|
1
|
public void testAdd()
|
41
|
|
{
|
42
|
1
|
MockComponent child = new MockComponent();
|
43
|
1
|
page.add(child);
|
44
|
1
|
assertTrue("add() failed", page.getChildren().contains(child));
|
45
|
|
}
|
46
|
|
|
47
|
1
|
public void testPage() throws Exception
|
48
|
|
{
|
49
|
1
|
System.out.println(logger.isDebugEnabled());
|
50
|
|
|
51
|
1
|
setUp();
|
52
|
|
|
53
|
1
|
MockComponent mockComponent = new MockComponent();
|
54
|
1
|
page.add(mockComponent);
|
55
|
|
|
56
|
1
|
MockServletRequest mockServletRequest = new MockServletRequest(application, "application/" + "page");
|
57
|
1
|
MockServletResponse mockServletResponse = new MockServletResponse();
|
58
|
1
|
application.process(mockServletRequest, mockServletResponse);
|
59
|
|
|
60
|
1
|
mockComponent.assertRenderedCorrectly(mockServletResponse);
|
61
|
|
}
|
62
|
|
|
63
|
1
|
public void testGetPage()
|
64
|
|
{
|
65
|
1
|
Page testPage = new Page();
|
66
|
1
|
application.registerPage("testPage", testPage);
|
67
|
1
|
assertSame(testPage, application.getPage("testPage"));
|
68
|
1
|
assertSame(application, testPage.getApplication());
|
69
|
|
|
70
|
|
// should be able to register same page twice
|
71
|
1
|
application.registerPage("testPage", testPage);
|
72
|
|
|
73
|
1
|
Application application2 = new Application();
|
74
|
1
|
try
|
75
|
|
{
|
76
|
1
|
application2.registerPage("testPage", testPage);
|
77
|
0
|
fail("Should not be able to register same page to two applications.");
|
78
|
|
}
|
79
|
|
catch (IllegalArgumentException shouldHappen)
|
80
|
|
{
|
81
|
|
}
|
82
|
|
|
83
|
1
|
try
|
84
|
|
{
|
85
|
1
|
application.getPage("no-page-here");
|
86
|
0
|
fail("Should not find non-existent page.");
|
87
|
|
}
|
88
|
|
catch (IllegalArgumentException shouldHappen)
|
89
|
|
{
|
90
|
|
}
|
91
|
|
}
|
92
|
|
}
|
93
|
|
|