001 /*
002 * Copyright 1999-2004 The Apache Software Foundation.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.springframework.richclient.command.config;
017
018 import javax.swing.AbstractButton;
019
020 import org.springframework.richclient.command.ActionCommand;
021 import org.springframework.richclient.test.SpringRichTestCase;
022
023 /**
024 * MultiFacedEnablingTests was built to check up on the issue reported as <a
025 * href="http://opensource.atlassian.com/projects/spring/browse/RCP-73">RCP-73 </a>.
026 */
027 public class MultiFacedEnablingTests extends SpringRichTestCase
028 {
029 private static final String ALTERNATE_ID = "otherId";
030 private static final String MAIN_ID = "someid";
031
032 /**
033 * Big idea of the test:
034 * <ol>
035 * <li>create silly command</li>
036 * <li>register additional command face to it, and create a button that uses that.</li>
037 * <li>disable/enable the command --> check if all buttons follow up on the changes</li>
038 * </ol>
039 */
040 public void testMultifacedCommandDisabling()
041 {
042 ActionCommand command = new ActionCommand(MAIN_ID)
043 {
044
045 protected void doExecuteCommand()
046 {
047 // does nothing during this test anyway
048 }
049 };
050
051 AbstractButton standardButton = command.createButton();
052
053 // test this dude's enabling
054 command.setEnabled(false);
055 assertFalse("standard face button didn't follow up on the command's disabling", standardButton
056 .isEnabled());
057 command.setEnabled(true);
058 assertTrue("standard face button didn't follow up on the command's enabling", standardButton
059 .isEnabled());
060
061 // register an alternative face to this command
062 CommandFaceDescriptor face = new CommandFaceDescriptor();
063 command.setFaceDescriptor(ALTERNATE_ID, face);
064
065 // and get us a button with that face
066 AbstractButton otherFacedButton = command.createButton(ALTERNATE_ID);
067
068 // test this newly faced dude
069 command.setEnabled(false);
070 assertFalse("alternative face button didn't follow up on the command's disabling", otherFacedButton
071 .isEnabled());
072 command.setEnabled(true);
073 assertTrue("alternative face button didn't follow up on the command's enabling", otherFacedButton
074 .isEnabled());
075
076 }
077 }