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: TestSComboBoxModel.java,v 1.9 2002/09/12 19:09:37 ludovicc Exp $
37 */
38 package test.view.swing;
39
40
41 import javax.swing.JComboBox;
42 import org.apache.commons.logging.Log;
43 import org.apache.commons.logging.LogFactory;
44 import junit.framework.TestCase;
45 import org.scopemvc.core.Selector;
46 import org.scopemvc.model.basic.BasicModel;
47 import org.scopemvc.util.convertor.*;
48 import org.scopemvc.view.swing.*;
49
50 /***
51 * @author <A HREF="mailto:daniel.michalik@autel.cz">Daniel Michalik</A>
52 * @created 12 September 2002
53 * @version $Revision: 1.9 $ $Date: 2002/09/12 19:09:37 $
54 */
55 public class TestSComboBoxModel extends TestCase {
56
57 /***
58 * TODO: describe of the Field
59 */
60 protected SComboBoxModel comboModel;
61 /***
62 * TODO: describe of the Field
63 */
64 protected SwingDummyModel model;
65
66
67 /***
68 * Constructor for the TestSComboBoxModel object
69 *
70 * @param inName Name of the test
71 */
72 public TestSComboBoxModel(String inName) {
73 super(inName);
74 }
75
76
77 /***
78 * A unit test for JUnit
79 *
80 * @throws Exception Any abnormal exception
81 */
82 public void testUnbound() throws Exception {
83 assertNull(comboModel.getBoundModel());
84 assertTrue(comboModel.getSize() == 0);
85 assertNull(comboModel.getElementAt(0));
86 assertNull(comboModel.getBoundSelectionModel());
87 assertNull(comboModel.getSelectedItem());
88 }
89
90
91 /***
92 * A unit test for JUnit
93 *
94 * @throws Exception Any abnormal exception
95 */
96 public void testSetup() throws Exception {
97 Selector s = Selector.fromString("xyz");
98
99 assertNull(comboModel.getSelectionSelector());
100 comboModel.setSelectionSelector(s);
101 assertSame(s, comboModel.getSelectionSelector());
102 }
103
104
105 /***
106 * A unit test for JUnit
107 *
108 * @throws Exception Any abnormal exception
109 */
110 public void testSetup2() throws Exception {
111 Selector s = Selector.fromString("xyz");
112
113 assertNull(comboModel.getSelectionSelector());
114 comboModel.setSelectionSelectorString("xyz");
115 assertEquals(s, comboModel.getSelectionSelector());
116 }
117
118
119 /***
120 * A unit test for JUnit
121 *
122 * @throws Exception Any abnormal exception
123 */
124 public void testBind() throws Exception {
125 comboModel.setSelectionSelectorString("stringProperty");
126 comboModel.setSelectorString("stringNonIndexedProperty");
127 comboModel.setBoundModel(model);
128 SuiteViewSwing.waitForAWT();
129
130 assertEquals(model.getStringProperty(), comboModel.getSelectedItem());
131 comboModel.setSelectedItem(model.getStringNonIndexedProperty(0));
132 SuiteViewSwing.waitForAWT();
133
134 assertEquals(model.getStringNonIndexedProperty(0), comboModel.getSelectedItem());
135 assertEquals(model.getStringNonIndexedProperty(0), model.getStringProperty());
136
137 model.setStringProperty((String) model.getStringNonIndexedProperty(1));
138 SuiteViewSwing.waitForAWT();
139
140 assertEquals(model.getStringNonIndexedProperty(1), comboModel.getSelectedItem());
141 assertEquals(model.getStringNonIndexedProperty(1), model.getStringProperty());
142 }
143
144
145 /***
146 * A unit test for JUnit
147 *
148 * @throws Exception Any abnormal exception
149 */
150 public void testBindNoMCE() throws Exception {
151 SwingDummyModelNoMCE noMceModel = new SwingDummyModelNoMCE();
152 noMceModel.setStringProperty(noMceModel.getStringNonIndexedProperty(0));
153
154 comboModel.setSelectionSelectorString("stringProperty");
155 comboModel.setSelectorString("stringNonIndexedProperty");
156 comboModel.setBoundModel(noMceModel);
157 SuiteViewSwing.waitForAWT();
158
159 assertEquals(noMceModel.getStringProperty(), comboModel.getSelectedItem());
160 comboModel.setSelectedItem(model.getStringNonIndexedProperty(0));
161 SuiteViewSwing.waitForAWT();
162
163 assertEquals(noMceModel.getStringNonIndexedProperty(0), comboModel.getSelectedItem());
164 assertEquals(noMceModel.getStringNonIndexedProperty(0), noMceModel.getStringProperty());
165
166 noMceModel.setStringProperty((String) noMceModel.getStringNonIndexedProperty(1));
167 SuiteViewSwing.waitForAWT();
168
169 assertEquals(noMceModel.getStringNonIndexedProperty(0), comboModel.getSelectedItem());
170
171 comboModel.refresh();
172 SuiteViewSwing.waitForAWT();
173
174 assertEquals(noMceModel.getStringNonIndexedProperty(1), comboModel.getSelectedItem());
175 assertEquals(noMceModel.getStringNonIndexedProperty(1), noMceModel.getStringProperty());
176 }
177
178
179 /***
180 * The JUnit setup method
181 *
182 * @throws Exception Any abnormal exception
183 */
184 protected void setUp() throws Exception {
185 comboModel = new SComboBoxModel(new JComboBox());
186 model = new SwingDummyModel();
187 model.setStringProperty(model.getStringNonIndexedProperty(0));
188 }
189
190
191 /***
192 * The teardown method for JUnit
193 */
194 protected void tearDown() { }
195 }
This page was automatically generated by Maven