Statistics
| Revision:

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 @ 40559

History | View | Annotate | Download (4.24 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
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 {DiSiD Technologies}   {{Test indexed iterator retrieval}}
27
 */
28
package org.gvsig.fmap.dal.feature;
29

    
30
import junit.framework.TestCase;
31

    
32
import org.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.DataManager;
34
import org.gvsig.fmap.dal.DataStoreParameters;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.tools.dispose.DisposableIterator;
37

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

    
45

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

    
51
    protected void tearDown() throws Exception {
52
        super.tearDown();
53
    }
54

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

    
68
    public void testIteratorInt(FeatureSet featureSet) throws DataException {
69

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

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

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

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

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

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

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

    
124
    protected abstract void register();
125

    
126
    protected abstract DataStoreParameters createStoreParameters(
127
            DataManager manager)
128
            throws Exception;
129

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