KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > adwt > action > ActionTest


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package test.adwt.action;
8
9 import java.awt.event.ActionEvent JavaDoc;
10 import java.util.Locale JavaDoc;
11
12 import javax.swing.JMenuItem JavaDoc;
13 import javax.swing.JRadioButtonMenuItem JavaDoc;
14
15 import org.ejtools.adwt.action.Command;
16 import org.ejtools.adwt.action.CommandAction;
17 import org.ejtools.adwt.action.action.RefreshAction;
18 import org.ejtools.adwt.action.edit.CopyAction;
19 import org.ejtools.adwt.action.edit.CutAction;
20 import org.ejtools.adwt.action.edit.DeleteAction;
21 import org.ejtools.adwt.action.edit.DeselectAllAction;
22 import org.ejtools.adwt.action.edit.PasteAction;
23 import org.ejtools.adwt.action.edit.SelectAllAction;
24 import org.ejtools.adwt.action.file.ExitAction;
25 import org.ejtools.adwt.action.file.FileHistoryAction;
26 import org.ejtools.adwt.action.file.FileHistoryActionTop;
27 import org.ejtools.adwt.action.file.NewAction;
28 import org.ejtools.adwt.action.file.OpenAction;
29 import org.ejtools.adwt.action.file.OpenWorkspaceAction;
30 import org.ejtools.adwt.action.file.PrintAction;
31 import org.ejtools.adwt.action.file.SaveAction;
32 import org.ejtools.adwt.action.file.SaveAsAction;
33 import org.ejtools.adwt.action.file.SaveAsWorkspaceAction;
34 import org.ejtools.adwt.action.file.SaveWorkspaceAction;
35 import org.ejtools.adwt.action.help.AboutAction;
36 import org.ejtools.adwt.action.help.HelpOnLineAction;
37 import org.ejtools.adwt.action.help.TOTDAction;
38 import org.ejtools.adwt.action.tools.ExportAction;
39 import org.ejtools.adwt.action.tools.ImportAction;
40 import org.ejtools.adwt.action.view.ShowConsoleAction;
41 import org.ejtools.adwt.action.window.CascadeAction;
42 import org.ejtools.adwt.action.window.CloseAction;
43 import org.ejtools.adwt.action.window.CloseAllAction;
44 import org.ejtools.adwt.action.window.InternalFrameAction;
45 import org.ejtools.adwt.action.window.TileAction;
46 import org.ejtools.adwt.service.MenuBarService;
47
48 import junit.framework.TestCase;
49
50 /**
51  * @author Laurent Etiemble
52  * @version $Revision: 1.4 $
53  */

54 public class ActionTest extends TestCase
55 {
56    /** Description of the Field */
57    protected int value = 0;
58
59
60    /** Constructor for the ActionTest object */
61    public ActionTest()
62    {
63       super();
64    }
65
66
67    /**
68     * Constructor for the ActionTest object
69     *
70     * @param name Description of the Parameter
71     */

72    public ActionTest(String JavaDoc name)
73    {
74       super(name);
75    }
76
77
78    /** A unit test for JUnit */
79    public void testCommandAction()
80    {
81       CommandAction action = null;
82       CommandAction childAction = null;
83
84       Command command =
85          new Command()
86          {
87             public void execute()
88             {
89                value = 99;
90             }
91          };
92
93       action = new NewAction(command);
94       childAction = new NewAction(command);
95
96       assertEquals("Must contains no child", action.size(), 0);
97       action.add(childAction);
98       assertEquals("Must contains one child", action.size(), 1);
99       action.remove(childAction);
100       assertEquals("Must contains no child", action.size(), 0);
101
102       assertEquals("Values must be equal", value, 0);
103       action.actionPerformed(new ActionEvent JavaDoc(this, 0, "TEST"));
104       assertEquals("Values must be equal", value, 99);
105
106       assertEquals("ToolBar presence must be the same", action.getToolBar(), true);
107       assertEquals("Menu must be the same", action.getMenu(), "action.file");
108       assertEquals("Menu layout must be the same", action.getMenuLayout(), MenuBarService.NO_LAYOUT);
109       assertEquals("Item classes must be the same", action.getMenuItem().getClass(), JMenuItem JavaDoc.class);
110    }
111
112
113    /**
114     * Description of the Method
115     *
116     * @param locale Description of the Parameter
117     */

118    protected void doTestInstantiation(Locale JavaDoc locale)
119    {
120       Locale.setDefault(locale);
121
122       CommandAction action = null;
123       Command command =
124          new Command()
125          {
126             public void execute()
127             {
128                // Do nothing
129
}
130          };
131
132       // Package org.ejtools.adwt.action.action
133
action = new RefreshAction(command);
134       assertNotNull("Action must be not null", action);
135       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
136
137       // Package org.ejtools.adwt.action.edit
138
action = new CopyAction(command);
139       assertNotNull("Action must be not null", action);
140       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
141       action = new CutAction(command);
142       assertNotNull("Action must be not null", action);
143       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
144       action = new DeleteAction(command);
145       assertNotNull("Action must be not null", action);
146       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
147       action = new DeselectAllAction(command);
148       assertNotNull("Action must be not null", action);
149       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
150       action = new PasteAction(command);
151       assertNotNull("Action must be not null", action);
152       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
153       action = new SelectAllAction(command);
154       assertNotNull("Action must be not null", action);
155       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
156
157       // Package org.ejtools.adwt.action.file
158
action = new ExitAction(command);
159       assertNotNull("Action must be not null", action);
160       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
161       action = new FileHistoryAction(command);
162       assertNotNull("Action must be not null", action);
163       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
164       action = new FileHistoryActionTop(command);
165       assertNotNull("Action must be not null", action);
166       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
167       action = new NewAction(command);
168       assertNotNull("Action must be not null", action);
169       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
170       action = new OpenAction(command);
171       assertNotNull("Action must be not null", action);
172       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
173       action = new OpenWorkspaceAction(command);
174       assertNotNull("Action must be not null", action);
175       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
176       action = new PrintAction(command);
177       assertNotNull("Action must be not null", action);
178       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
179       action = new SaveAction(command);
180       assertNotNull("Action must be not null", action);
181       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
182       action = new SaveAsAction(command);
183       assertNotNull("Action must be not null", action);
184       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
185       action = new SaveAsWorkspaceAction(command);
186       assertNotNull("Action must be not null", action);
187       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
188       action = new SaveWorkspaceAction(command);
189       assertNotNull("Action must be not null", action);
190       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
191
192       // Package org.ejtools.adwt.action.help
193
action = new AboutAction(command);
194       assertNotNull("Action must be not null", action);
195       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
196       action = new HelpOnLineAction(command);
197       assertNotNull("Action must be not null", action);
198       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
199       action = new TOTDAction(command);
200       assertNotNull("Action must be not null", action);
201       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
202
203       // Package org.ejtools.adwt.action.tools
204
action = new ExportAction(command);
205       assertNotNull("Action must be not null", action);
206       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
207       action = new ImportAction(command);
208       assertNotNull("Action must be not null", action);
209       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
210
211       // Package org.ejtools.adwt.action.view
212
action = new ShowConsoleAction(command);
213       assertNotNull("Action must be not null", action);
214       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
215
216       // Package org.ejtools.adwt.action.help
217
action = new CascadeAction(command);
218       assertNotNull("Action must be not null", action);
219       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
220       action = new CloseAction(command);
221       assertNotNull("Action must be not null", action);
222       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
223       action = new CloseAllAction(command);
224       assertNotNull("Action must be not null", action);
225       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
226       action = new InternalFrameAction(command);
227       assertNotNull("Action must be not null", action);
228       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
229       assertEquals("Action must have a JRadioButtonMenuItem item", action.getMenuItem().getClass(), JRadioButtonMenuItem JavaDoc.class);
230       assertEquals("Action must have a JRadioButtonMenuItem item", action.getMenuItem().getClass(), JRadioButtonMenuItem JavaDoc.class);
231       action = new TileAction(command);
232       assertNotNull("Action must be not null", action);
233       assertEquals("Locale must be the same", action.getResourceBundle().getLocale(), locale);
234    }
235 }
236
Popular Tags