root / branches / v2_0_0_prep / libraries / libFMap_data / src-test / org / gvsig / fmap / data / feature / FeatureSetTestParent.java @ 24079
History | View | Annotate | Download (4.18 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} {{Test indexed iterator retrieval}}
|
26 |
*/
|
27 |
package org.gvsig.fmap.data.feature; |
28 |
|
29 |
import java.util.Iterator; |
30 |
|
31 |
import junit.framework.TestCase; |
32 |
|
33 |
import org.gvsig.fmap.data.DALLocator; |
34 |
import org.gvsig.fmap.data.DataManager; |
35 |
import org.gvsig.fmap.data.DataStoreParameters; |
36 |
import org.gvsig.fmap.data.exceptions.DataException; |
37 |
import org.gvsig.fmap.data.exceptions.ReadException; |
38 |
|
39 |
/**
|
40 |
* Unit tests for the {@link AbstractFeatureCollection} class.
|
41 |
*
|
42 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
43 |
*/
|
44 |
public abstract class FeatureSetTestParent extends TestCase { |
45 |
|
46 |
|
47 |
protected void setUp() throws Exception { |
48 |
super.setUp();
|
49 |
register(); |
50 |
} |
51 |
|
52 |
protected void tearDown() throws Exception { |
53 |
super.tearDown();
|
54 |
} |
55 |
|
56 |
/**
|
57 |
* Test method for
|
58 |
* {@link org.gvsig.fmap.data.feature.AbstractFeatureCollection#iterator(int)}
|
59 |
* .
|
60 |
*
|
61 |
* @throws Exception
|
62 |
*/
|
63 |
public void testIteratorInt() throws Exception { |
64 |
FeatureSet featureSet = createFeatureCollection(); |
65 |
testIteratorInt(featureSet); |
66 |
featureSet.dispose(); |
67 |
} |
68 |
|
69 |
public void testIteratorInt(FeatureSet featureSet) throws DataException { |
70 |
|
71 |
if (featureSet.getSize() < 3) { |
72 |
fail("The Collection to create for the test must contain "
|
73 |
+ "at least 3 values");
|
74 |
} |
75 |
|
76 |
try {
|
77 |
featureSet.iterator(-5);
|
78 |
fail("Iterator index accepted with a value < 0");
|
79 |
} catch (Exception ex) { |
80 |
// Good
|
81 |
} |
82 |
|
83 |
try {
|
84 |
featureSet.iterator(featureSet.getSize() + 2);
|
85 |
fail("Iterator index accepted with a value > collection size");
|
86 |
} catch (Exception ex) { |
87 |
// Good
|
88 |
} |
89 |
|
90 |
long index = featureSet.getSize() - 3l; |
91 |
Iterator iter = featureSet.iterator(index);
|
92 |
int iterations = 0; |
93 |
while (iter.hasNext()) {
|
94 |
iter.next(); |
95 |
iterations++; |
96 |
} |
97 |
assertEquals("The number of iterations remaining is not correct", 3, |
98 |
iterations); |
99 |
|
100 |
iter = featureSet.iterator(0);
|
101 |
iterations = 0;
|
102 |
while (iter.hasNext()) {
|
103 |
iter.next(); |
104 |
iterations++; |
105 |
} |
106 |
assertEquals("The number of iterations is not the "
|
107 |
+ "total size of the collection", featureSet.getSize(),
|
108 |
iterations); |
109 |
} |
110 |
|
111 |
protected FeatureSet createFeatureCollection() throws Exception { |
112 |
FeatureStore store = createFeatureStore(); |
113 |
FeatureType ft = store.getDefaultFeatureType(); |
114 |
return createFeatureCollection(store, ft);
|
115 |
} |
116 |
|
117 |
protected FeatureStore createFeatureStore() throws Exception { |
118 |
DataManager manager = DALLocator.getDataManager(); |
119 |
return (FeatureStore) manager
|
120 |
.createStore(createStoreParameters(manager)); |
121 |
} |
122 |
|
123 |
protected abstract void register(); |
124 |
|
125 |
protected abstract DataStoreParameters createStoreParameters( |
126 |
DataManager manager) |
127 |
throws Exception; |
128 |
|
129 |
/**
|
130 |
* If this method is rewritten, the returned FeatureCollection must have at
|
131 |
* least 3 values.
|
132 |
*/
|
133 |
protected abstract FeatureSet createFeatureCollection( |
134 |
FeatureStore store, FeatureType ft) throws ReadException;
|
135 |
} |