1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.renderer.impl;
17
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.Shell;
20 import org.seasar.eclipse.common.util.SWTUtil;
21 import org.seasar.framework.container.S2Container;
22 import org.seasar.framework.container.factory.S2ContainerFactory;
23 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
24 import org.seasar.framework.exception.ResourceNotFoundRuntimeException;
25 import org.seasar.framework.unit.S2FrameworkTestCase;
26 import org.seasar.framework.util.StringUtil;
27 import org.seasar.uruma.annotation.EventListener;
28 import org.seasar.uruma.annotation.PostOpenMethod;
29 import org.seasar.uruma.core.StandAloneUrumaStarter;
30
31
32
33
34
35
36
37
38
39 public abstract class AbstractGUITest extends S2FrameworkTestCase {
40 protected StandAloneUrumaStarter uruma;
41
42 public Shell shell;
43
44 protected boolean result;
45
46
47
48
49 @Override
50 protected void setUp() throws Exception {
51 uruma = StandAloneUrumaStarter.getInstance();
52 S2Container container = SingletonS2ContainerFactory.getContainer();
53 String componentName = StringUtil.decapitalize(getClass()
54 .getSimpleName())
55 + "Action";
56 container.register(this, componentName);
57
58
59 try {
60 S2Container child = S2ContainerFactory
61 .create(convertPath(getClass().getSimpleName() + ".dicon"));
62 container.include(child);
63 } catch (ResourceNotFoundRuntimeException ex) {
64
65 }
66
67 result = false;
68 }
69
70
71
72
73 @Override
74 protected void tearDown() throws Exception {
75 StandAloneUrumaStarter.destroy();
76 }
77
78
79
80
81 public void testRender() {
82 String path = convertPath(getClass().getSimpleName() + ".xml");
83 uruma.openWindow(path);
84 assertTrue(path, result);
85 }
86
87
88
89
90 @PostOpenMethod
91 public void postOpen() {
92 captureScreen();
93
94 if (isAutoTestMode()) {
95 try {
96 autoOK();
97 } catch (Exception ex) {
98 ex.printStackTrace();
99 fail(ex.getMessage());
100 }
101 }
102 }
103
104 protected void captureScreen() {
105 String path = "log/" + getClass().getSimpleName() + ".png";
106 SWTUtil.saveWindowImage(shell, path, SWT.IMAGE_PNG);
107 }
108
109 protected boolean isAutoTestMode() {
110 return Boolean.getBoolean("autoTest");
111 }
112
113 protected void autoOK() throws Exception {
114 okButtonAction();
115 }
116
117
118
119
120 @EventListener(id = "okButton")
121 public void okButtonAction() {
122 shell.close();
123
124 result = true;
125 }
126
127
128
129
130 @EventListener(id = "ngButton")
131 public void ngButtonAction() {
132 shell.close();
133 result = false;
134 }
135 }