01: package simpleorm.simplewebapp.eg.database;
02:
03: import simpleorm.simplewebapp.eg.WAllTests;
04: import simpleorm.simplewebapp.core.WPageStructure;
05: import simpleorm.simplewebapp.core.WButton;
06: import simpleorm.simplewebapp.context.WPageContextTest;
07:
08: import java.util.Map;
09: import java.util.LinkedHashMap;
10:
11: /**
12: * Simple Demonstration of the Unit test infrastructure.
13: * This tests WGenericCrudPagelet independently of the webserver
14: */
15: public class WUserTest {
16: static Map<String, String> interFields;
17:
18: public static void main(String[] args) throws Exception {
19: initDb();
20: unsubmitted();
21: submitted();
22: unsubmitted2();
23: }
24:
25: static void initDb() throws Exception {
26: Map<String, String> params = new LinkedHashMap();
27: params.put(WButton.BUTTONS_NAME, "Initialize");
28: WInitPage page = new WInitPage();
29: page.setPageContext(new WPageContextTest(page, params));
30: WPageStructure struct = page.getPageStructure();
31: struct.doMain();
32: struct.doFinalize();
33: }
34:
35: static void unsubmitted() throws Exception {
36: Map<String, String> fields = new LinkedHashMap();
37: fields.put("userId", "3");
38:
39: WUserAutoCrudPage page = WAllTests.MENUS.database.userAutoCrud
40: .newPage();
41: page.setPageContext(new WPageContextTest(page, fields));
42: WPageStructure struct = page.getPageStructure();
43: struct.doMain();
44: WAllTests.assertEquals("Charley Smith", page.getField("name")
45: .getText());
46: interFields = struct.browserParameters();
47: struct.doFinalize();
48: }
49:
50: static void submitted() throws Exception {
51: interFields.put("name", "Christeen");
52: interFields.put(WButton.BUTTONS_NAME, "Update");
53:
54: WUserAutoCrudPage page = WAllTests.MENUS.database.userAutoCrud
55: .newPage();
56: page.setPageContext(new WPageContextTest(page, interFields));
57: WPageStructure struct = page.getPageStructure();
58: struct.doMain();
59: WAllTests.assertEquals("Christeen", page.getField("name")
60: .getText());
61: struct.doFinalize();
62: }
63:
64: static void unsubmitted2() throws Exception {
65: Map<String, String> fields = new LinkedHashMap();
66: fields.put("userId", "3");
67:
68: WUserAutoCrudPage page = WAllTests.MENUS.database.userAutoCrud
69: .newPage();
70: page.setPageContext(new WPageContextTest(page, fields));
71: WPageStructure struct = page.getPageStructure();
72: struct.doMain();
73: WAllTests.assertEquals("Christeen", page.getField("name")
74: .getText());
75: struct.doFinalize();
76: }
77:
78: }
|