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 @ 40435
History | View | Annotate | Download (4.19 KB)
1 | 40435 | jjdelcerro | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (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.dal.feature; |
||
28 | |||
29 | import junit.framework.TestCase; |
||
30 | |||
31 | import org.gvsig.fmap.dal.DALLocator; |
||
32 | import org.gvsig.fmap.dal.DataManager; |
||
33 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
34 | import org.gvsig.fmap.dal.exception.DataException; |
||
35 | import org.gvsig.tools.dispose.DisposableIterator; |
||
36 | |||
37 | /**
|
||
38 | * Unit tests for the {@link AbstractFeatureCollection} class.
|
||
39 | *
|
||
40 | * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
||
41 | */
|
||
42 | public abstract class FeatureSetTestParent extends TestCase { |
||
43 | |||
44 | |||
45 | protected void setUp() throws Exception { |
||
46 | super.setUp();
|
||
47 | register(); |
||
48 | } |
||
49 | |||
50 | protected void tearDown() throws Exception { |
||
51 | super.tearDown();
|
||
52 | } |
||
53 | |||
54 | /**
|
||
55 | * Test method for
|
||
56 | * {@link org.gvsig.fmap.dal.feature.AbstractFeatureCollection#iterator(int)}
|
||
57 | * .
|
||
58 | *
|
||
59 | * @throws Exception
|
||
60 | */
|
||
61 | public void testIteratorInt() throws Exception { |
||
62 | FeatureSet featureSet = createFeatureCollection(); |
||
63 | testIteratorInt(featureSet); |
||
64 | featureSet.dispose(); |
||
65 | } |
||
66 | |||
67 | public void testIteratorInt(FeatureSet featureSet) throws DataException { |
||
68 | |||
69 | if (featureSet.getSize() < 3) { |
||
70 | fail("The Collection to create for the test must contain "
|
||
71 | + "at least 3 values");
|
||
72 | } |
||
73 | |||
74 | try {
|
||
75 | featureSet.iterator(-5);
|
||
76 | fail("Iterator index accepted with a value < 0");
|
||
77 | } catch (Exception ex) { |
||
78 | // Good
|
||
79 | } |
||
80 | |||
81 | try {
|
||
82 | featureSet.iterator(featureSet.getSize() + 2);
|
||
83 | fail("Iterator index accepted with a value > collection size");
|
||
84 | } catch (Exception ex) { |
||
85 | // Good
|
||
86 | } |
||
87 | |||
88 | long index = featureSet.getSize() - 3l; |
||
89 | DisposableIterator iter = featureSet.iterator(index); |
||
90 | int iterations = 0; |
||
91 | while (iter.hasNext()) {
|
||
92 | iter.next(); |
||
93 | iterations++; |
||
94 | } |
||
95 | assertEquals("The number of iterations remaining is not correct", 3, |
||
96 | iterations); |
||
97 | iter.dispose(); |
||
98 | |||
99 | iter = featureSet.iterator(0);
|
||
100 | iterations = 0;
|
||
101 | while (iter.hasNext()) {
|
||
102 | iter.next(); |
||
103 | iterations++; |
||
104 | } |
||
105 | assertEquals("The number of iterations is not the "
|
||
106 | + "total size of the collection", featureSet.getSize(),
|
||
107 | iterations); |
||
108 | iter.dispose(); |
||
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, |
||
135 | FeatureType ft) throws DataException;
|
||
136 | } |