Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_data / src-test / org / gvsig / fmap / data / feature / FeatureCollectionTestParent.java @ 23675

History | View | Annotate | Download (4.17 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.DataManager;
34
import org.gvsig.fmap.data.DataStoreParameters;
35
import org.gvsig.fmap.data.ReadException;
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 FeatureCollectionTestParent 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.data.feature.AbstractFeatureCollection#iterator(int)}
57
     * .
58
     * 
59
     * @throws Exception
60
     */
61
    public void testIteratorInt() throws Exception {
62
        FeatureCollection featureCollection = createFeatureCollection();
63
        testIteratorInt(featureCollection);
64
        featureCollection.dispose();
65
    }
66

    
67
    public void testIteratorInt(FeatureCollection featureCollection) {
68
        
69
        if (featureCollection.size() < 3) {
70
            fail("The Collection to create for the test must contain "
71
                    + "at least 3 values");
72
        }
73

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

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

    
88
        int index = featureCollection.size() - 3;
89
        Iterator iter = featureCollection.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

    
98
        iter = featureCollection.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", featureCollection.size(),
106
                iterations);
107
    }
108

    
109
    protected FeatureCollection createFeatureCollection() throws Exception {
110
        FeatureStore store = createFeatureStore();
111
        FeatureType ft = store.getDefaultFeatureType();
112
        return createFeatureCollection(store, ft);
113
    }
114
    
115
    protected FeatureStore createFeatureStore() throws Exception {
116
        DataManager manager = DataManager.getManager();
117
        return (FeatureStore) manager
118
                .createDataStore(createStoreParameters(manager));
119
    }
120

    
121
    protected abstract void register();
122
    
123
    protected abstract DataStoreParameters createStoreParameters(
124
            DataManager manager)
125
            throws Exception;
126
    
127
    /**
128
     * If this method is rewritten, the returned FeatureCollection must have at
129
     * least 3 values.
130
     */
131
    protected abstract FeatureCollection createFeatureCollection(
132
            FeatureStore store, FeatureType ft) throws ReadException;
133
}