View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: TestSModelAction.java,v 1.1 2002/09/13 17:12:11 ludovicc Exp $ 37 */ 38 package test.view.swing; 39 40 import java.lang.Integer; 41 import junit.framework.TestCase; 42 import org.scopemvc.core.Control; 43 import org.scopemvc.core.Selector; 44 import org.scopemvc.view.swing.SModelAction; 45 import org.scopemvc.view.swing.SPanel; 46 47 /*** 48 * TODO: document the class 49 * 50 * @author <a href="mailto:ludovicc@users.sourceforge.net>;Ludovic Claude</a> 51 * @created 12 September 2002 52 */ 53 public class TestSModelAction extends TestCase { 54 55 private SwingDummyModel model; 56 private SModelAction action; 57 private SwingDummyController controller; 58 private SPanel panel; 59 60 /*** 61 * Constructor for the TestSModelAction object 62 * 63 * @param inName Name of the test 64 */ 65 public TestSModelAction(String inName) { 66 super(inName); 67 } 68 69 /*** 70 * A unit test for JUnit 71 * 72 * @throws Exception Any abnormal exception 73 */ 74 public void testControl() throws Exception { 75 action = new SModelAction("Test", panel, Selector.fromString("stringProperty")); 76 controller.setModel(model); 77 78 assertEquals("Test", action.getName()); 79 SuiteViewSwing.waitForAWT(); 80 assertTrue(action.isEnabled()); 81 82 action.actionPerformed(null); 83 SuiteViewSwing.waitForAWT(); 84 assertEquals(new Control("Test", model.getStringProperty()), controller.lastControl); 85 } 86 87 /*** 88 * A unit test for JUnit 89 * 90 * @throws Exception Any abnormal exception 91 */ 92 public void testDisabledControl() throws Exception { 93 action = new SModelAction("Test", panel, Selector.fromString("stringProperty")); 94 controller.setModel(model); 95 96 model.setStringProperty(null); 97 SuiteViewSwing.waitForAWT(); 98 assertTrue(!action.isEnabled()); 99 100 model.setStringProperty("notnull"); 101 SuiteViewSwing.waitForAWT(); 102 assertTrue(action.isEnabled()); 103 } 104 105 /*** 106 * A unit test for JUnit 107 * 108 * @throws Exception Any abnormal exception 109 */ 110 public void testValueTest() throws Exception { 111 action = new SModelAction("Test", panel, Selector.fromString("intProperty")); 112 controller.setModel(model); 113 114 // should be enabled if the bound value is an integer less than 1 115 action.setValueTest(new Integer(1)); 116 117 model.setIntProperty(0); 118 SuiteViewSwing.waitForAWT(); 119 assertTrue(action.isEnabled()); 120 121 model.setIntProperty(1); 122 SuiteViewSwing.waitForAWT(); 123 assertTrue(!action.isEnabled()); 124 125 model.setIntProperty(2); 126 SuiteViewSwing.waitForAWT(); 127 assertTrue(!action.isEnabled()); 128 129 } 130 131 /*** 132 * The JUnit setup method 133 * 134 * @throws Exception Any abnormal exception 135 */ 136 protected void setUp() throws Exception { 137 138 model = new SwingDummyModel(); 139 panel = new SPanel(); 140 141 controller = new SwingDummyController(); 142 controller.setView(panel); 143 144 controller.startup(); 145 } 146 147 148 /*** 149 * The teardown method for JUnit 150 */ 151 protected void tearDown() { 152 controller.shutdown(); 153 } 154 155 }

This page was automatically generated by Maven