Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dal / src-test / org / gvsig / fmap / dal / feature / FeatureSetTestParent.java @ 31544

History | View | Annotate | Download (4.14 KB)

1
/* 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

    
36
/**
37
 * Unit tests for the {@link AbstractFeatureCollection} class.
38
 *
39
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
40
 */
41
public abstract class FeatureSetTestParent extends TestCase {
42

    
43

    
44
    protected void setUp() throws Exception {
45
        super.setUp();
46
        register();
47
    }
48

    
49
    protected void tearDown() throws Exception {
50
        super.tearDown();
51
    }
52

    
53
    /**
54
     * Test method for
55
     * {@link org.gvsig.fmap.dal.feature.AbstractFeatureCollection#iterator(int)}
56
     * .
57
     *
58
     * @throws Exception
59
     */
60
    public void testIteratorInt() throws Exception {
61
        FeatureSet featureSet = createFeatureCollection();
62
        testIteratorInt(featureSet);
63
        featureSet.dispose();
64
    }
65

    
66
    public void testIteratorInt(FeatureSet featureSet) throws DataException {
67

    
68
        if (featureSet.getSize() < 3) {
69
            fail("The Collection to create for the test must contain "
70
                    + "at least 3 values");
71
        }
72

    
73
        try {
74
            featureSet.iterator(-5);
75
            fail("Iterator index accepted with a value < 0");
76
        } catch (Exception ex) {
77
            // Good
78
        }
79

    
80
        try {
81
            featureSet.iterator(featureSet.getSize() + 2);
82
            fail("Iterator index accepted with a value > collection size");
83
        } catch (Exception ex) {
84
            // Good
85
        }
86

    
87
        long index = featureSet.getSize() - 3l;
88
        DisposableIterator iter = featureSet.iterator(index);
89
        int iterations = 0;
90
        while (iter.hasNext()) {
91
            iter.next();
92
            iterations++;
93
        }
94
        assertEquals("The number of iterations remaining is not correct", 3,
95
                iterations);
96
        iter.dispose();
97

    
98
        iter = featureSet.iterator(0);
99
        iterations = 0;
100
        while (iter.hasNext()) {
101
            iter.next();
102
            iterations++;
103
        }
104
        assertEquals("The number of iterations is not the "
105
                + "total size of the collection", featureSet.getSize(),
106
                iterations);
107
        iter.dispose();
108
    }
109

    
110
    protected FeatureSet createFeatureCollection() throws Exception {
111
        FeatureStore store = createFeatureStore();
112
        FeatureType ft = store.getDefaultFeatureType();
113
        return createFeatureCollection(store, ft);
114
    }
115

    
116
    protected FeatureStore createFeatureStore() throws Exception {
117
        DataManager manager = DALLocator.getDataManager();
118
        return (FeatureStore) manager
119
                .createStore(createStoreParameters(manager));
120
    }
121

    
122
    protected abstract void register();
123

    
124
    protected abstract DataStoreParameters createStoreParameters(
125
            DataManager manager)
126
            throws Exception;
127

    
128
    /**
129
     * If this method is rewritten, the returned FeatureCollection must have at
130
     * least 3 values.
131
     */
132
    protected abstract FeatureSet createFeatureCollection(
133
            FeatureStore store,
134
            FeatureType ft) throws DataException;
135
}