1 /*
2 * Copyright 1999-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.springframework.richclient.command.config;
17
18 import javax.swing.AbstractButton;
19
20 import org.springframework.richclient.command.ActionCommand;
21 import org.springframework.richclient.test.SpringRichTestCase;
22
23 /**
24 * MultiFacedEnablingTests was built to check up on the issue reported as <a
25 * href="http://opensource.atlassian.com/projects/spring/browse/RCP-73">RCP-73 </a>.
26 */
27 public class MultiFacedEnablingTests extends SpringRichTestCase
28 {
29 private static final String ALTERNATE_ID = "otherId";
30 private static final String MAIN_ID = "someid";
31
32 /**
33 * Big idea of the test:
34 * <ol>
35 * <li>create silly command</li>
36 * <li>register additional command face to it, and create a button that uses that.</li>
37 * <li>disable/enable the command --> check if all buttons follow up on the changes</li>
38 * </ol>
39 */
40 public void testMultifacedCommandDisabling()
41 {
42 ActionCommand command = new ActionCommand(MAIN_ID)
43 {
44
45 protected void doExecuteCommand()
46 {
47 // does nothing during this test anyway
48 }
49 };
50
51 AbstractButton standardButton = command.createButton();
52
53 // test this dude's enabling
54 command.setEnabled(false);
55 assertFalse("standard face button didn't follow up on the command's disabling", standardButton
56 .isEnabled());
57 command.setEnabled(true);
58 assertTrue("standard face button didn't follow up on the command's enabling", standardButton
59 .isEnabled());
60
61 // register an alternative face to this command
62 CommandFaceDescriptor face = new CommandFaceDescriptor();
63 command.setFaceDescriptor(ALTERNATE_ID, face);
64
65 // and get us a button with that face
66 AbstractButton otherFacedButton = command.createButton(ALTERNATE_ID);
67
68 // test this newly faced dude
69 command.setEnabled(false);
70 assertFalse("alternative face button didn't follow up on the command's disabling", otherFacedButton
71 .isEnabled());
72 command.setEnabled(true);
73 assertTrue("alternative face button didn't follow up on the command's enabling", otherFacedButton
74 .isEnabled());
75
76 }
77 }