svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_data / src-test / org / gvsig / fmap / data / feature / paging / FeatureCollectionPagingHelperTest.java @ 23842
History | View | Annotate | Download (8.27 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Gobernment (CIT)
|
5 |
*
|
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 |
* as published by the Free Software Foundation; either version 2
|
9 |
* 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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 {DiSiD Technologies} {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.fmap.data.feature.paging; |
28 |
|
29 |
import java.util.Iterator; |
30 |
|
31 |
import junit.framework.TestCase; |
32 |
|
33 |
import org.easymock.MockControl; |
34 |
import org.gvsig.fmap.data.feature.Feature; |
35 |
import org.gvsig.fmap.data.feature.FeatureSet; |
36 |
import org.gvsig.fmap.data.feature.FeatureStore; |
37 |
import org.gvsig.fmap.data.feature.impl.FeatureIterator; |
38 |
|
39 |
/**
|
40 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
41 |
*/
|
42 |
public class FeatureCollectionPagingHelperTest extends TestCase { |
43 |
|
44 |
private FeaturePagingHelper helper;
|
45 |
private MockControl collectionControl;
|
46 |
private FeatureSet collectionMock;
|
47 |
private MockControl storeControl;
|
48 |
private FeatureStore storeMock;
|
49 |
|
50 |
protected void setUp() throws Exception { |
51 |
super.setUp();
|
52 |
collectionControl = MockControl |
53 |
.createNiceControl(FeatureSet.class); |
54 |
collectionMock = (FeatureSet) collectionControl.getMock(); |
55 |
storeControl = MockControl.createNiceControl(FeatureStore.class); |
56 |
storeMock = (FeatureStore) storeControl.getMock(); |
57 |
} |
58 |
|
59 |
protected void tearDown() throws Exception { |
60 |
super.tearDown();
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* Test method for
|
65 |
* {@link org.gvsig.fmap.data.feature.paging.FeaturePagingHelper#getMaxPageSize()}
|
66 |
*/
|
67 |
public void testGetMaxPageSize() throws Exception { |
68 |
storeControl.expectAndReturn(storeMock.getFeatureSet(), |
69 |
collectionMock, 2);
|
70 |
storeControl.replay(); |
71 |
collectionControl.expectAndReturn(collectionMock.size(), 10, 2); |
72 |
collectionControl.replay(); |
73 |
|
74 |
helper = new FeaturePagingHelperImpl(storeMock);
|
75 |
assertEquals( |
76 |
"El tama?o m?ximo de p?gina no es el establecido en el helper",
|
77 |
FeaturePagingHelper.DEFAULT_PAGE_SIZE, helper |
78 |
.getMaxPageSize()); |
79 |
|
80 |
helper = new FeaturePagingHelperImpl(storeMock, 5); |
81 |
assertEquals( |
82 |
"El tama?o m?ximo de p?gina no es el establecido en el helper",
|
83 |
5, helper.getMaxPageSize());
|
84 |
|
85 |
storeControl.verify(); |
86 |
collectionControl.verify(); |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Test method for
|
91 |
* {@link org.gvsig.fmap.data.feature.paging.FeaturePagingHelper#getNumPages()}
|
92 |
* .
|
93 |
*/
|
94 |
public void testGetNumPages() throws Exception { |
95 |
storeControl.expectAndReturn(storeMock.getFeatureSet(), |
96 |
collectionMock); |
97 |
storeControl.replay(); |
98 |
collectionControl.expectAndReturn(collectionMock.size(), 10);
|
99 |
collectionControl.replay(); |
100 |
|
101 |
helper = new FeaturePagingHelperImpl(storeMock);
|
102 |
|
103 |
assertEquals("El n? de p?ginas calculadas no es correcto", 1, helper |
104 |
.getNumPages()); |
105 |
|
106 |
storeControl.verify(); |
107 |
collectionControl.verify(); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Test method for
|
112 |
* {@link org.gvsig.fmap.data.feature.paging.FeaturePagingHelper#getTotalSize()}
|
113 |
* .
|
114 |
*/
|
115 |
public void testGetTotalSize() throws Exception { |
116 |
storeControl.expectAndReturn(storeMock.getFeatureSet(), |
117 |
collectionMock); |
118 |
storeControl.replay(); |
119 |
collectionControl.expectAndReturn(collectionMock.size(), 10, 2); |
120 |
collectionControl.replay(); |
121 |
|
122 |
helper = new FeaturePagingHelperImpl(storeMock);
|
123 |
|
124 |
assertEquals("El n? total de features no es el de la Colecci?n", 10, |
125 |
helper.getTotalSize()); |
126 |
|
127 |
storeControl.verify(); |
128 |
collectionControl.verify(); |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Test method for
|
133 |
* {@link org.gvsig.fmap.data.feature.paging.FeaturePagingHelper#getFeatureAt(int)}
|
134 |
* .
|
135 |
*/
|
136 |
public void testGetFeatureAt() throws Exception { |
137 |
// Create two mock features for the test.
|
138 |
MockControl featureControl = MockControl.createControl(Feature.class); |
139 |
Feature mockFeature1 = (Feature) featureControl.getMock(); |
140 |
Feature mockFeature2 = (Feature) featureControl.getMock(); |
141 |
|
142 |
// Create a mock Iterator to return the Features.
|
143 |
MockControl iteratorControl = MockControl |
144 |
.createControl(FeatureIterator.class); |
145 |
Iterator mockIterator = (Iterator) iteratorControl.getMock(); |
146 |
|
147 |
// Values 0 and 1
|
148 |
mockIterator.hasNext(); |
149 |
iteratorControl.setReturnValue(true);
|
150 |
mockIterator.next(); |
151 |
iteratorControl.setReturnValue(mockFeature1); |
152 |
mockIterator.hasNext(); |
153 |
iteratorControl.setReturnValue(true);
|
154 |
mockIterator.next(); |
155 |
iteratorControl.setReturnValue(mockFeature2); |
156 |
mockIterator.hasNext(); |
157 |
iteratorControl.setReturnValue(false);
|
158 |
|
159 |
// Values 4 and 5
|
160 |
mockIterator.hasNext(); |
161 |
iteratorControl.setReturnValue(true);
|
162 |
mockIterator.next(); |
163 |
iteratorControl.setReturnValue(mockFeature2); |
164 |
mockIterator.hasNext(); |
165 |
iteratorControl.setReturnValue(true);
|
166 |
mockIterator.next(); |
167 |
iteratorControl.setReturnValue(mockFeature1); |
168 |
mockIterator.hasNext(); |
169 |
iteratorControl.setReturnValue(false);
|
170 |
|
171 |
iteratorControl.replay(); |
172 |
|
173 |
// Define the mock Collection operations.
|
174 |
storeControl.expectAndReturn(storeMock.getFeatureSet(), |
175 |
collectionMock); |
176 |
storeControl.replay(); |
177 |
|
178 |
collectionControl.expectAndReturn(collectionMock.size(), 11);
|
179 |
collectionControl.expectAndReturn(collectionMock.iterator(0),
|
180 |
mockIterator); |
181 |
collectionControl.expectAndReturn(collectionMock.iterator(4),
|
182 |
mockIterator); |
183 |
collectionControl.replay(); |
184 |
|
185 |
helper = new FeaturePagingHelperImpl(storeMock, 2); |
186 |
|
187 |
// Check the returned Features are the correct ones
|
188 |
Feature feature = helper.getFeatureAt(0);
|
189 |
assertEquals("La Feature devuelta no es la que corresponde "
|
190 |
+ "al ?ndice solicitado: 0", mockFeature1, feature);
|
191 |
|
192 |
feature = helper.getFeatureAt(1);
|
193 |
assertEquals("La Feature devuelta no es la que corresponde "
|
194 |
+ "al ?ndice solicitado: 1", mockFeature2, feature);
|
195 |
|
196 |
feature = helper.getFeatureAt(5);
|
197 |
assertEquals("La Feature devuelta no es la que corresponde "
|
198 |
+ "al ?ndice solicitado: 5", mockFeature1, feature);
|
199 |
|
200 |
try {
|
201 |
feature = helper.getFeatureAt(9999);
|
202 |
fail("Returned a value for a non existent Feature position");
|
203 |
} catch (Exception ex) { |
204 |
// Good
|
205 |
} |
206 |
|
207 |
storeControl.verify(); |
208 |
collectionControl.verify(); |
209 |
iteratorControl.verify(); |
210 |
} |
211 |
|
212 |
/**
|
213 |
* Test method for
|
214 |
* {@link org.gvsig.fmap.data.feature.paging.FeaturePagingHelper#setCurrentPage(int)}
|
215 |
* .
|
216 |
*/
|
217 |
public void testSetCurrentPage() throws Exception { |
218 |
storeControl.expectAndReturn(storeMock.getFeatureSet(), |
219 |
collectionMock); |
220 |
storeControl.replay(); |
221 |
collectionControl.expectAndReturn(collectionMock.size(), 10);
|
222 |
collectionControl.replay(); |
223 |
|
224 |
helper = new FeaturePagingHelperImpl(storeMock);
|
225 |
|
226 |
try {
|
227 |
helper.setCurrentPage(-4);
|
228 |
fail("Allowed to set a negative number as the current page");
|
229 |
} catch (Exception ex) { |
230 |
// Good
|
231 |
} |
232 |
|
233 |
try {
|
234 |
helper.setCurrentPage(99999);
|
235 |
fail("Allowed to set a current page greater than the number "
|
236 |
+ "of available pages");
|
237 |
} catch (Exception ex) { |
238 |
// Good
|
239 |
} |
240 |
|
241 |
storeControl.verify(); |
242 |
collectionControl.verify(); |
243 |
} |
244 |
|
245 |
} |