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