View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, Steve Meyfroidt 4 * All rights reserved. 5 * Email: smeyfroi@users.sourceforge.net 6 * 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * Neither the name "Scope" nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 * 36 * 37 * $Id: TestSPanel.java,v 1.5 2002/08/05 13:19:26 ludovicc Exp $ 38 */ 39 40 41 package test.view.swing; 42 43 44 import javax.swing.JPanel; 45 import junit.framework.TestCase; 46 import org.apache.commons.logging.LogFactory;import org.apache.commons.logging.Log; 47 import org.scopemvc.core.Selector; 48 import org.scopemvc.view.swing.SCheckBox; 49 import org.scopemvc.view.swing.SPanel; 50 51 52 /*** 53 * 54 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>;Steve Meyfroidt</A> 55 * @version $Revision: 1.5 $ $Date: 2002/08/05 13:19:26 $ 56 */ 57 public final class TestSPanel extends TestCase { 58 59 60 private static final Log LOG = LogFactory.getLog(TestSPanel.class); 61 62 63 private SCheckBox checkbox1; 64 private SCheckBox checkbox2; 65 private SwingDummyController controller; 66 private SPanel view; 67 private SPanel view2; 68 private SwingDummyModel model; 69 70 71 public TestSPanel(String inName) { 72 super(inName); 73 } 74 75 76 protected void setUp() throws Exception { 77 78 checkbox1 = new SCheckBox(); 79 checkbox2 = new SCheckBox(); 80 81 view = new SPanel(); 82 view.add(checkbox1); 83 JPanel p = new JPanel(); 84 p.add(checkbox2); 85 view.add(p); 86 87 view2 = new SPanel(); 88 view.add(view2); 89 90 controller = new SwingDummyController(); 91 controller.setView(view); 92 controller.startup(); // does showView() 93 94 model = new SwingDummyModel(); 95 } 96 97 98 protected void tearDown() { 99 controller.shutdown(); 100 } 101 102 103 public void testUnbound() throws Exception { 104 SuiteViewSwing.waitForAWT(); 105 assertNull(view.getBoundModel()); 106 assertNull(view.getShownModel()); 107 } 108 109 110 public void testSelector() throws Exception { 111 view.setSelector(Selector.fromString("any")); 112 SuiteViewSwing.waitForAWT(); 113 assertEquals(Selector.fromString("any"), view.getSelector()); 114 assertNull(view.getBoundModel()); 115 assertNull(view.getShownModel()); 116 } 117 118 119 public void testConvenience() throws Exception { 120 view.setSelectorString("any"); 121 SuiteViewSwing.waitForAWT(); 122 assertEquals(Selector.fromString("any"), view.getSelector()); 123 assertNull(view.getBoundModel()); 124 assertNull(view.getShownModel()); 125 } 126 127 128 public void testBind1() throws Exception { 129 checkbox1.setSelector(Selector.fromString("booleanProperty")); 130 assertEquals(Selector.fromString("booleanProperty"), checkbox1.getSelector()); 131 checkbox2.setSelector(Selector.fromString("booleanProperty")); 132 assertEquals(Selector.fromString("booleanProperty"), checkbox2.getSelector()); 133 134 controller.setModel(model); 135 SuiteViewSwing.waitForAWT(); 136 assertSame(model, view.getBoundModel()); 137 assertSame(model, view.getShownModel()); 138 assertSame(model, checkbox1.getBoundModel()); 139 assertSame(model, checkbox2.getBoundModel()); 140 } 141 142 143 public void testBind2() throws Exception { 144 SwingDummyModel submodel = new SwingDummyModel(); 145 model.setSubModel(submodel); 146 view2.setSelector(Selector.fromString("subModel")); 147 148 controller.setModel(model); 149 SuiteViewSwing.waitForAWT(); 150 assertSame("is: " + view2.getBoundModel(), model, view2.getBoundModel()); 151 assertSame(submodel, view2.getShownModel()); 152 } 153 154 155 public void testControlIssueAndSync() throws Exception { 156 SwingDummyModel submodel = new SwingDummyModel(); 157 model.setSubModel(submodel); 158 view2.setSelector(Selector.fromString("subModel")); 159 160 SwingDummyController c = new SwingDummyController(); 161 c.setView(view2); 162 c.setModel(submodel); 163 164 controller.setModel(model); 165 SuiteViewSwing.waitForAWT(); 166 assertSame(view2.getBoundModel(), model); 167 assertSame(view2.getShownModel(), submodel); 168 assertSame("submodel: " + submodel + " getModel: " + c.getModel(), submodel, c.getModel()); 169 170 submodel = new SwingDummyModel(); 171 model.setSubModel(submodel); 172 SuiteViewSwing.waitForAWT(); 173 assertSame("submodel: " + submodel + " getModel: " + c.getModel(), submodel, c.getModel()); 174 } 175 176 177 public void testControlIssueAndSyncNoMCE() throws Exception { 178 SwingDummyModelNoMCE model = new SwingDummyModelNoMCE(); 179 SwingDummyModelNoMCE submodel = new SwingDummyModelNoMCE(); 180 model.setSubModel(submodel); 181 view2.setSelector(Selector.fromString("subModel")); 182 183 SwingDummyController c = new SwingDummyController(); 184 c.setView(view2); 185 c.setModel(submodel); 186 187 controller.setModel(model); 188 SuiteViewSwing.waitForAWT(); 189 assertSame(view.getBoundModel(), model); 190 assertSame(view2.getBoundModel(), model); 191 assertSame(view2.getShownModel(), submodel); 192 assertSame("submodel: " + submodel + " getModel: " + c.getModel(), submodel, c.getModel()); 193 194 SwingDummyModelNoMCE submodel2 = new SwingDummyModelNoMCE(); 195 model.setSubModel(submodel2); 196 assertSame(submodel, c.getModel()); 197 198 view.refresh(); 199 assertSame(view.getBoundModel(), model); 200 assertSame(view2.getBoundModel(), model); 201 assertSame(view2.getShownModel(), submodel2); 202 assertSame("submodel: " + submodel2 + " getModel: " + c.getModel(), submodel2, c.getModel()); 203 } 204 }

This page was automatically generated by Maven