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 com.tirsen.angkor.ApplicationFactory;
|
10
|
|
import com.tirsen.angkor.ComponentServlet;
|
11
|
|
import com.tirsen.angkor.View;
|
12
|
|
import com.tirsen.angkor.ViewFactory;
|
13
|
|
import com.tirsen.angkor.test.unit.mock.MockServletRequest;
|
14
|
|
import com.tirsen.angkor.test.unit.mock.MockServletResponse;
|
15
|
|
import com.tirsen.angkor.test.unit.mock.MockComponent;
|
16
|
|
import com.tirsen.angkor.widget.TextLabel;
|
17
|
|
import junit.framework.TestCase;
|
18
|
|
import org.w3c.dom.Document;
|
19
|
|
|
20
|
|
import javax.servlet.ServletException;
|
21
|
|
import java.io.IOException;
|
22
|
|
|
23
|
|
|
24
|
|
/**
|
25
|
|
* TODO document ComponentServletTest
|
26
|
|
*
|
27
|
|
* <!-- $Id: ComponentServletTest.java,v 1.3 2002/10/13 19:59:23 tirsen Exp $ -->
|
28
|
|
*
|
29
|
|
* @author $Author: tirsen $
|
30
|
|
* @version $Revision: 1.3 $
|
31
|
|
*/
|
32
|
|
public class ComponentServletTest extends TestCase
|
33
|
|
{
|
34
|
1
|
public void testComponentServlet() throws ServletException, IOException
|
35
|
|
{
|
36
|
1
|
ComponentServlet componentServlet = new ComponentServlet();
|
37
|
|
|
38
|
1
|
MockServletRequest servletRequest = new MockServletRequest();
|
39
|
1
|
ApplicationFactory applicationFactory = new ApplicationFactory(servletRequest.getSession());
|
40
|
1
|
applicationFactory.ensureApplicationInit(MockApplication.class);
|
41
|
|
|
42
|
1
|
String componentName = "comp";
|
43
|
1
|
servletRequest.setRequestURI("/app/" + componentName);
|
44
|
|
|
45
|
1
|
final TextLabel textLabel = new TextLabel("test");
|
46
|
1
|
textLabel.setId(componentName);
|
47
|
|
|
48
|
1
|
MockApplication application = (MockApplication) applicationFactory.getApplication();
|
49
|
1
|
application.registerComponent(componentName, new ViewFactory()
|
50
|
|
{
|
51
|
1
|
public View getView()
|
52
|
|
{
|
53
|
1
|
return textLabel;
|
54
|
|
}
|
55
|
|
});
|
56
|
|
|
57
|
1
|
MockServletResponse servletResponse = new MockServletResponse();
|
58
|
1
|
componentServlet.service(servletRequest, servletResponse);
|
59
|
|
|
60
|
1
|
org.jdom.Document document = servletResponse.getResultingDocument();
|
61
|
1
|
assertNotNull(TestUtility.selectElement(document, "//*[@id='" + componentName + "']"));
|
62
|
|
}
|
63
|
|
}
|
64
|
|
|