svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / test / java / org / gvsig / fmap / dal / feature / impl / DefaultFeatureReferenceSelectionTest.java @ 40559
History | View | Annotate | Download (7.41 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /*
|
||
25 | * AUTHORS (In addition to CIT):
|
||
26 | * 2008 {DiSiD Technologies} {{Task}}
|
||
27 | */
|
||
28 | package org.gvsig.fmap.dal.feature.impl; |
||
29 | |||
30 | import java.util.Iterator; |
||
31 | |||
32 | import junit.framework.TestCase; |
||
33 | |||
34 | import org.easymock.MockControl; |
||
35 | import org.gvsig.fmap.dal.exception.DataException; |
||
36 | import org.gvsig.fmap.dal.feature.FeatureReference; |
||
37 | import org.gvsig.fmap.dal.feature.FeatureReferenceSelection; |
||
38 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
39 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
40 | import org.gvsig.tools.exception.BaseException; |
||
41 | import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
||
42 | import org.gvsig.tools.visitor.Visitor; |
||
43 | |||
44 | /**
|
||
45 | * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
||
46 | */
|
||
47 | public class DefaultFeatureReferenceSelectionTest extends AbstractLibraryAutoInitTestCase { |
||
48 | |||
49 | private FeatureReferenceSelection selection;
|
||
50 | private MockControl refControl1;
|
||
51 | private FeatureReference ref1;
|
||
52 | private MockControl refControl2;
|
||
53 | private FeatureReference ref2;
|
||
54 | private MockControl storeControl;
|
||
55 | private FeatureStore store;
|
||
56 | private MockControl fsetControl;
|
||
57 | private FeatureSet featureSet;
|
||
58 | private MockControl helperControl;
|
||
59 | private FeatureSelectionHelper helper;
|
||
60 | |||
61 | private int total = 10; |
||
62 | |||
63 | protected void doSetUp() throws Exception { |
||
64 | refControl1 = MockControl.createNiceControl(FeatureReference.class); |
||
65 | ref1 = (FeatureReference) refControl1.getMock(); |
||
66 | refControl2 = MockControl.createNiceControl(FeatureReference.class); |
||
67 | ref2 = (FeatureReference) refControl2.getMock(); |
||
68 | |||
69 | storeControl = MockControl.createNiceControl(FeatureStore.class); |
||
70 | store = (FeatureStore) storeControl.getMock(); |
||
71 | storeControl.expectAndReturn(store.getFeatureCount(), total); |
||
72 | |||
73 | helperControl = MockControl |
||
74 | .createNiceControl(FeatureSelectionHelper.class); |
||
75 | helper = (FeatureSelectionHelper) helperControl.getMock(); |
||
76 | helperControl.expectAndDefaultReturn(helper.getFeatureStoreDeltaSize(), |
||
77 | 0);
|
||
78 | |||
79 | fsetControl = MockControl.createNiceControl(FeatureSet.class); |
||
80 | featureSet = (FeatureSet) fsetControl.getMock(); |
||
81 | |||
82 | storeControl.expectAndReturn(store.getFeatureSet(), featureSet); |
||
83 | fsetControl.expectAndReturn(featureSet.getSize(), total); |
||
84 | |||
85 | |||
86 | |||
87 | storeControl.replay(); |
||
88 | fsetControl.replay(); |
||
89 | helperControl.replay(); |
||
90 | |||
91 | selection = new DefaultFeatureReferenceSelection(store, helper);
|
||
92 | } |
||
93 | |||
94 | protected void tearDown() throws Exception { |
||
95 | super.tearDown();
|
||
96 | } |
||
97 | |||
98 | public void testSelect() throws Exception { |
||
99 | // Add a feature
|
||
100 | selection.select(ref1); |
||
101 | assertTrue(selection.isSelected(ref1)); |
||
102 | assertFalse(selection.isSelected(ref2)); |
||
103 | |||
104 | selection.select(ref2); |
||
105 | assertTrue(selection.isSelected(ref2)); |
||
106 | } |
||
107 | |||
108 | public void testSelectAll() throws Exception { |
||
109 | selection.selectAll(); |
||
110 | assertTrue(selection.isSelected(ref1)); |
||
111 | assertTrue(selection.isSelected(ref2)); |
||
112 | } |
||
113 | |||
114 | public void testDeselect() throws Exception { |
||
115 | // Remove a feature
|
||
116 | selection.select(ref1); |
||
117 | selection.select(ref2); |
||
118 | assertTrue(selection.isSelected(ref2)); |
||
119 | selection.deselect(ref2); |
||
120 | assertFalse(selection.isSelected(ref2)); |
||
121 | selection.deselect(ref1); |
||
122 | assertFalse(selection.isSelected(ref1)); |
||
123 | } |
||
124 | |||
125 | public void testDeselectAll() throws Exception { |
||
126 | selection.select(ref1); |
||
127 | selection.select(ref2); |
||
128 | selection.deselectAll(); |
||
129 | assertFalse(selection.isSelected(ref1)); |
||
130 | assertFalse(selection.isSelected(ref2)); |
||
131 | } |
||
132 | |||
133 | public void testReverse() throws Exception { |
||
134 | // Reverse selection
|
||
135 | selection.select(ref1); |
||
136 | selection.reverse(); |
||
137 | assertFalse(selection.isSelected(ref1)); |
||
138 | assertTrue(selection.isSelected(ref2)); |
||
139 | } |
||
140 | |||
141 | public void testGetSelectedCount() throws Exception { |
||
142 | // None selected
|
||
143 | assertEquals(0, selection.getSelectedCount());
|
||
144 | selection.select(ref1); |
||
145 | selection.select(ref2); |
||
146 | // Two selected
|
||
147 | assertEquals(2, selection.getSelectedCount());
|
||
148 | // Deselect one, so one left selected
|
||
149 | selection.deselect(ref2); |
||
150 | assertEquals(1, selection.getSelectedCount());
|
||
151 | // Reverse the selection, so all buy one selected
|
||
152 | selection.reverse(); |
||
153 | assertEquals(total - 1, selection.getSelectedCount());
|
||
154 | // Deselect another one, so all but two selected
|
||
155 | selection.deselect(ref2); |
||
156 | assertEquals(total - 2, selection.getSelectedCount());
|
||
157 | // Deselect an already deselected one, nothing changes
|
||
158 | selection.deselect(ref2); |
||
159 | assertEquals(total - 2, selection.getSelectedCount());
|
||
160 | } |
||
161 | |||
162 | public void testGetSelectedValues() throws DataException { |
||
163 | selection.deselectAll(); |
||
164 | selection.select(ref1); |
||
165 | selection.select(ref2); |
||
166 | |||
167 | boolean ref1Pending = true; |
||
168 | boolean ref2Pending = true; |
||
169 | |||
170 | for (Iterator references = selection.referenceIterator(); references |
||
171 | .hasNext();) { |
||
172 | FeatureReference reference = (FeatureReference) references.next(); |
||
173 | if (reference.equals(ref1)) {
|
||
174 | if (ref1Pending) {
|
||
175 | ref1Pending = false;
|
||
176 | } else {
|
||
177 | fail("FeatureReference 1 was already obtained");
|
||
178 | } |
||
179 | } else if (reference.equals(ref2)) { |
||
180 | if (ref2Pending) {
|
||
181 | ref2Pending = false;
|
||
182 | } else {
|
||
183 | fail("FeatureReference 2 was already obtained");
|
||
184 | } |
||
185 | } else {
|
||
186 | fail("A reference not selected was obtained: " + reference);
|
||
187 | } |
||
188 | } |
||
189 | } |
||
190 | |||
191 | public void testDispose() { |
||
192 | selection.select(ref1); |
||
193 | selection.select(ref2); |
||
194 | selection.dispose(); |
||
195 | assertFalse(selection.isSelected(ref1)); |
||
196 | assertFalse(selection.isSelected(ref2)); |
||
197 | } |
||
198 | |||
199 | public void testAccept() throws BaseException { |
||
200 | // Create a Mopck Visitor and add expected usage
|
||
201 | MockControl visitorControl = MockControl |
||
202 | .createNiceControl(Visitor.class); |
||
203 | Visitor visitor = (Visitor) visitorControl.getMock(); |
||
204 | |||
205 | visitor.visit(ref1); |
||
206 | visitor.visit(ref2); |
||
207 | visitorControl.replay(); |
||
208 | |||
209 | // Add selected references
|
||
210 | selection.select(ref1); |
||
211 | selection.select(ref2); |
||
212 | |||
213 | // Use visitor
|
||
214 | selection.accept(visitor); |
||
215 | |||
216 | // check correct visitor usage
|
||
217 | visitorControl.verify(); |
||
218 | } |
||
219 | } |