Statistics
| Revision:

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

History | View | Annotate | Download (4.27 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.dal.feature;
28

    
29
import java.util.Iterator;
30

    
31
import junit.framework.TestCase;
32

    
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataManager;
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.exceptions.DataException;
37
import org.gvsig.fmap.dal.feature.FeatureSet;
38
import org.gvsig.fmap.dal.feature.FeatureStore;
39
import org.gvsig.fmap.dal.feature.FeatureType;
40

    
41
/**
42
 * Unit tests for the {@link AbstractFeatureCollection} class.
43
 * 
44
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
45
 */
46
public abstract class FeatureSetTestParent extends TestCase {
47

    
48

    
49
    protected void setUp() throws Exception {
50
        super.setUp();
51
        register();
52
    }
53

    
54
    protected void tearDown() throws Exception {
55
        super.tearDown();
56
    }
57

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

    
71
    public void testIteratorInt(FeatureSet featureSet) throws DataException {
72
        
73
        if (featureSet.getSize() < 3) {
74
            fail("The Collection to create for the test must contain "
75
                    + "at least 3 values");
76
        }
77

    
78
        try {
79
            featureSet.iterator(-5);
80
            fail("Iterator index accepted with a value < 0");
81
        } catch (Exception ex) {
82
            // Good
83
        }
84

    
85
        try {
86
            featureSet.iterator(featureSet.getSize() + 2);
87
            fail("Iterator index accepted with a value > collection size");
88
        } catch (Exception ex) {
89
            // Good
90
        }
91

    
92
        long index = featureSet.getSize() - 3l;
93
        Iterator iter = featureSet.iterator(index);
94
        int iterations = 0;
95
        while (iter.hasNext()) {
96
            iter.next();
97
            iterations++;
98
        }
99
        assertEquals("The number of iterations remaining is not correct", 3,
100
                iterations);
101

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

    
113
    protected FeatureSet createFeatureCollection() throws Exception {
114
        FeatureStore store = createFeatureStore();
115
        FeatureType ft = store.getDefaultFeatureType();
116
        return createFeatureCollection(store, ft);
117
    }
118
    
119
    protected FeatureStore createFeatureStore() throws Exception {
120
        DataManager manager = DALLocator.getDataManager();
121
        return (FeatureStore) manager
122
                .createStore(createStoreParameters(manager));
123
    }
124

    
125
    protected abstract void register();
126
    
127
    protected abstract DataStoreParameters createStoreParameters(
128
            DataManager manager)
129
            throws Exception;
130

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