Revision 24497

View differences:

branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/DataStoreTest.java
1
package org.gvsig.fmap.dal;
2

  
3
import junit.framework.TestCase;
4

  
5
public class DataStoreTest extends TestCase {
6
    
7
    public void testVoid() {
8

  
9
    }
10
}
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/AllTests.java
1
package org.gvsig.fmap.dal;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestCase;
5
import junit.framework.TestSuite;
6

  
7
import org.gvsig.fmap.dal.commands.CommandTest;
8
import org.gvsig.fmap.dal.feature.FeatureTest;
9

  
10
public class AllTests extends TestCase{
11
	public static Test suite() {
12
		TestSuite suite = new TestSuite("Test for libDataSource");
13
		//$JUnit-BEGIN$
14
		suite.addTestSuite(CommandTest.class);
15
		suite.addTestSuite(DataStoreTest.class);
16
		suite.addTestSuite(FeatureTest.class);
17

  
18
		//$JUnit-END$
19
		return suite;
20
	}
21
}
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/FeatureTest.java
1
package org.gvsig.fmap.dal.feature;
2

  
3
import junit.framework.TestCase;
4

  
5
public class FeatureTest extends TestCase {
6

  
7
    public void testVoid() {
8

  
9
    }
10

  
11
}
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/FeatureSetTestParent.java
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
}
0 139

  
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/impl/DefaultFeatureReferenceSelectionTest.java
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}  {{Task}}
26
 */
27
package org.gvsig.fmap.dal.feature.impl;
28

  
29
import java.util.Iterator;
30

  
31
import junit.framework.TestCase;
32

  
33
import org.easymock.MockControl;
34
import org.gvsig.fmap.dal.exceptions.DataException;
35
import org.gvsig.fmap.dal.feature.FeatureReference;
36
import org.gvsig.fmap.dal.feature.FeatureReferenceSelection;
37
import org.gvsig.fmap.dal.feature.FeatureSet;
38
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection;
39
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
40
import org.gvsig.tools.exception.BaseException;
41
import org.gvsig.tools.visitor.Visitor;
42

  
43
/**
44
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
45
 */
46
public class DefaultFeatureReferenceSelectionTest extends TestCase {
47

  
48
    private FeatureReferenceSelection selection;
49
    private MockControl refControl1;
50
    private FeatureReference ref1;
51
    private MockControl refControl2;
52
    private FeatureReference ref2;
53
    private MockControl storeControl;
54
    private DefaultFeatureStore store;
55
    private MockControl fsetControl;
56
    private FeatureSet featureSet;
57

  
58
    private int total = 10;
59

  
60
    protected void setUp() throws Exception {
61
        super.setUp();
62
        refControl1 = MockControl.createNiceControl(FeatureReference.class);
63
        ref1 = (FeatureReference) refControl1.getMock();
64
        refControl2 = MockControl.createNiceControl(FeatureReference.class);
65
        ref2 = (FeatureReference) refControl2.getMock();
66

  
67
        storeControl = MockControl.createNiceControl(DefaultFeatureStore.class);
68
        store = (DefaultFeatureStore) storeControl.getMock();
69

  
70
        fsetControl = MockControl.createNiceControl(FeatureSet.class);
71
        featureSet = (FeatureSet) fsetControl.getMock();
72

  
73
        storeControl.expectAndReturn(store.getFeatureSet(), featureSet);
74
        fsetControl.expectAndReturn(featureSet.getSize(), total);
75

  
76
        storeControl.replay();
77
        fsetControl.replay();
78

  
79
        selection = new DefaultFeatureReferenceSelection(store);
80
    }
81

  
82
    protected void tearDown() throws Exception {
83
        super.tearDown();
84
    }
85

  
86
    public void testSelect() throws Exception {
87
        // Add a feature
88
        selection.select(ref1);
89
        assertTrue(selection.isSelected(ref1));
90
        assertFalse(selection.isSelected(ref2));
91

  
92
        selection.select(ref2);
93
        assertTrue(selection.isSelected(ref2));
94
    }
95

  
96
    public void testSelectAll() throws Exception {
97
        selection.selectAll();
98
        assertTrue(selection.isSelected(ref1));
99
        assertTrue(selection.isSelected(ref2));
100
    }
101

  
102
    public void testDeselect() throws Exception {
103
        // Remove a feature
104
        selection.select(ref1);
105
        selection.select(ref2);
106
        assertTrue(selection.isSelected(ref2));
107
        selection.deselect(ref2);
108
        assertFalse(selection.isSelected(ref2));
109
        selection.deselect(ref1);
110
        assertFalse(selection.isSelected(ref1));
111
    }
112

  
113
    public void testDeselectAll() throws Exception {
114
        selection.select(ref1);
115
        selection.select(ref2);
116
        selection.deselectAll();
117
        assertFalse(selection.isSelected(ref1));
118
        assertFalse(selection.isSelected(ref2));
119
    }
120

  
121
    public void testReverse() throws Exception {
122
        // Reverse selection
123
        selection.select(ref1);
124
        selection.reverse();
125
        assertFalse(selection.isSelected(ref1));
126
        assertTrue(selection.isSelected(ref2));
127
    }
128

  
129
    public void testGetSelectedCount() throws Exception {
130
        // None selected
131
        assertEquals(0, selection.getSelectedCount());
132
        selection.select(ref1);
133
        selection.select(ref2);
134
        // Two selected
135
        assertEquals(2, selection.getSelectedCount());
136
        // Deselect one, so one left selected
137
        selection.deselect(ref2);
138
        assertEquals(1, selection.getSelectedCount());
139
        // Reverse the selection, so all buy one selected
140
        selection.reverse();
141
        assertEquals(total - 1, selection.getSelectedCount());
142
        // Deselect another one, so all but two selected
143
        selection.deselect(ref2);
144
        assertEquals(total - 2, selection.getSelectedCount());
145
        // Deselect an already deselected one, nothing changes
146
        selection.deselect(ref2);
147
        assertEquals(total - 2, selection.getSelectedCount());
148
    }
149

  
150
    public void testGetSelectedValues() throws DataException {
151
        selection.deselectAll();
152
        selection.select(ref1);
153
        selection.select(ref2);
154

  
155
        boolean ref1Pending = true;
156
        boolean ref2Pending = true;
157

  
158
        for (Iterator references = selection.referenceIterator(); references
159
                .hasNext();) {
160
            FeatureReference reference = (FeatureReference) references.next();
161
            if (reference.equals(ref1)) {
162
                if (ref1Pending) {
163
                    ref1Pending = false;
164
                } else {
165
                    fail("FeatureReference 1 was already obtained");
166
                }
167
            } else if (reference.equals(ref2)) {
168
                if (ref2Pending) {
169
                    ref2Pending = false;
170
                } else {
171
                    fail("FeatureReference 2 was already obtained");
172
                }
173
            } else {
174
                fail("A reference not selected was obtained: " + reference);
175
            }
176
        }
177
    }
178

  
179
    public void testDispose() {
180
        selection.select(ref1);
181
        selection.select(ref2);
182
        selection.dispose();
183
        assertFalse(selection.isSelected(ref1));
184
        assertFalse(selection.isSelected(ref2));
185
    }
186

  
187
    public void testAccept() throws BaseException {
188
        // Create a Mopck Visitor and add expected usage
189
        MockControl visitorControl = MockControl
190
                .createNiceControl(Visitor.class);
191
        Visitor visitor = (Visitor) visitorControl.getMock();
192

  
193
        visitor.visit(ref1);
194
        visitor.visit(ref2);
195
        visitorControl.replay();
196

  
197
        // Add selected references
198
        selection.select(ref1);
199
        selection.select(ref2);
200

  
201
        // Use visitor
202
        selection.accept(visitor);
203

  
204
        // check correct visitor usage
205
        visitorControl.verify();
206
    }
207
}
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/impl/DefaultFeatureSelectionTest.java
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}  {{Task}}
26
 */
27
package org.gvsig.fmap.dal.feature.impl;
28

  
29
import junit.framework.TestCase;
30

  
31
import org.easymock.MockControl;
32
import org.gvsig.fmap.dal.feature.*;
33
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection;
34
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore;
35

  
36
/**
37
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
38
 */
39
public class DefaultFeatureSelectionTest extends TestCase {
40
    private FeatureSelection selection;
41
    private MockControl refControl1;
42
    private FeatureReference ref1;
43
    private MockControl refControl2;
44
    private FeatureReference ref2;
45
    private MockControl fControl1;
46
    private Feature feature1;
47
    private MockControl fControl2;
48
    private Feature feature2;
49
    private MockControl storeControl;
50
    private DefaultFeatureStore store;
51
    private MockControl fsetControl;
52
    private FeatureSet featureSet;
53

  
54
    private int total = 10;
55

  
56
    protected void setUp() throws Exception {
57
        super.setUp();
58
        refControl1 = MockControl.createNiceControl(FeatureReference.class);
59
        ref1 = (FeatureReference) refControl1.getMock();
60
        refControl2 = MockControl.createNiceControl(FeatureReference.class);
61
        ref2 = (FeatureReference) refControl2.getMock();
62

  
63
        fControl1 = MockControl.createControl(Feature.class);
64
        feature1 = (Feature) fControl1.getMock();
65
        fControl2 = MockControl.createControl(Feature.class);
66
        feature2 = (Feature) fControl2.getMock();
67

  
68
        storeControl = MockControl.createNiceControl(DefaultFeatureStore.class);
69
        store = (DefaultFeatureStore) storeControl.getMock();
70

  
71
        fsetControl = MockControl.createNiceControl(FeatureSet.class);
72
        featureSet = (FeatureSet) fsetControl.getMock();
73

  
74
        storeControl.expectAndReturn(store.getFeatureSet(), featureSet);
75
        fsetControl.expectAndReturn(featureSet.getSize(), total);
76

  
77
        storeControl.replay();
78
        fsetControl.replay();
79

  
80
        selection = new DefaultFeatureSelection(store);
81
    }
82

  
83
    protected void tearDown() throws Exception {
84
        super.tearDown();
85
    }
86

  
87
    /**
88
     * Test method for
89
     * {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#select(org.gvsig.fmap.dal.feature.Feature)}
90
     * .
91
     */
92
    public void testSelectFeature() {
93
        fControl1.expectAndReturn(feature1.getReference(), ref1, 2);
94
        fControl2.expectAndReturn(feature2.getReference(), ref2, 3);
95
        fControl1.replay();
96
        fControl2.replay();
97

  
98
        // Add a feature
99
        selection.select(feature1);
100
        assertTrue("Selected feature1 is not recognized as selected", selection
101
                .isSelected(feature1));
102
        assertFalse("Selected feature2 is recognized as selected", selection
103
                .isSelected(feature2));
104

  
105
        selection.select(feature2);
106
        assertTrue(selection.isSelected(feature2));
107
    }
108

  
109
    /**
110
     * Test method for
111
     * {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#deselect(org.gvsig.fmap.dal.feature.Feature)}
112
     * .
113
     */
114
    public void testDeselectFeature() {
115
        fControl1.expectAndReturn(feature1.getReference(), ref1, 3);
116
        fControl2.expectAndReturn(feature2.getReference(), ref2, 4);
117
        fControl1.replay();
118
        fControl2.replay();
119

  
120
        // Remove a feature
121
        selection.select(feature1);
122
        selection.select(feature2);
123
        assertTrue(selection.isSelected(feature2));
124
        selection.deselect(feature2);
125
        assertFalse(selection.isSelected(feature2));
126
        selection.deselect(feature1);
127
        assertFalse(selection.isSelected(feature1));
128
    }
129

  
130
    /**
131
     * Test method for
132
     * {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#getSize()}
133
     * .
134
     */
135
    public void testGetSize() throws Exception {
136
        fControl1.expectAndReturn(feature1.getReference(), ref1, 1);
137
        fControl2.expectAndReturn(feature2.getReference(), ref2, 4);
138
        fControl1.replay();
139
        fControl2.replay();
140

  
141
        // None selected
142
        assertEquals(0, selection.getSize());
143
        selection.select(feature1);
144
        selection.select(feature2);
145
        // Two selected
146
        assertEquals(2, selection.getSize());
147
        // Deselect one, so one left selected
148
        selection.deselect(feature2);
149
        assertEquals(1, selection.getSize());
150
        // Reverse the selection, so all buy one selected
151
        selection.reverse();
152
        assertEquals(total - 1, selection.getSize());
153
        // Deselect another one, so all but two selected
154
        selection.deselect(feature2);
155
        assertEquals(total - 2, selection.getSize());
156
        // Deselect an already deselected one, nothing changes
157
        selection.deselect(feature2);
158
        assertEquals(total - 2, selection.getSize());
159
    }
160

  
161
    /**
162
     * Test method for
163
     * {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#isEmpty()}
164
     * .
165
     */
166
    public void testIsEmpty() throws Exception {
167
        fControl1.expectAndReturn(feature1.getReference(), ref1, 1);
168
        fControl2.expectAndReturn(feature2.getReference(), ref2, 4);
169
        fControl1.replay();
170
        fControl2.replay();
171

  
172
        // None selected
173
        assertTrue(selection.isEmpty());
174
        
175
        // One selected
176
        selection.select(feature1);
177
        assertFalse(selection.isEmpty());
178

  
179
        // Deselect all
180
        selection.deselectAll();
181
        assertTrue(selection.isEmpty());
182
        
183
        // Reverse
184
        selection.reverse();
185
        assertFalse(selection.isEmpty());
186
    }
187

  
188
}
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/paging/FeaturePagingHelperTest.java
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}  {{Task}}
26
 */
27
package org.gvsig.fmap.dal.feature.paging;
28

  
29
import java.util.Iterator;
30

  
31
import junit.framework.TestCase;
32

  
33
import org.easymock.MockControl;
34
import org.gvsig.fmap.dal.feature.Feature;
35
import org.gvsig.fmap.dal.feature.FeatureSet;
36
import org.gvsig.fmap.dal.feature.FeatureStore;
37
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper;
38
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelperImpl;
39

  
40
/**
41
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
42
 */
43
public class FeaturePagingHelperTest extends TestCase {
44

  
45
    private FeaturePagingHelper helper;
46
    private MockControl fsetControl;
47
    private FeatureSet fsetMock;
48
    private MockControl storeControl;
49
    private FeatureStore storeMock;
50

  
51
    protected void setUp() throws Exception {
52
        super.setUp();
53
        fsetControl = MockControl.createNiceControl(FeatureSet.class);
54
        fsetMock = (FeatureSet) fsetControl.getMock();
55
        storeControl = MockControl.createNiceControl(FeatureStore.class);
56
        storeMock = (FeatureStore) storeControl.getMock();
57
    }
58

  
59
    protected void tearDown() throws Exception {
60
        super.tearDown();
61
    }
62

  
63
    /**
64
     * Test method for
65
     * {@link org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper#getMaxPageSize()}
66
     */
67
    public void testGetMaxPageSize() throws Exception {
68
        storeControl.expectAndReturn(storeMock.getFeatureSet(), fsetMock, 2);
69
        storeControl.replay();
70
        fsetControl.expectAndReturn(fsetMock.getSize(), 10, 2);
71
        fsetControl.replay();
72

  
73
        helper = new FeaturePagingHelperImpl(storeMock);
74
        assertEquals(
75
                "El tama?o m?ximo de p?gina no es el establecido en el helper",
76
                FeaturePagingHelper.DEFAULT_PAGE_SIZE, helper.getMaxPageSize());
77

  
78
        helper = new FeaturePagingHelperImpl(storeMock, 5);
79
        assertEquals(
80
                "El tama?o m?ximo de p?gina no es el establecido en el helper",
81
                5, helper.getMaxPageSize());
82

  
83
        storeControl.verify();
84
        fsetControl.verify();
85
    }
86

  
87
    /**
88
     * Test method for
89
     * {@link org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper#getNumPages()}
90
     * .
91
     */
92
    public void testGetNumPages() throws Exception {
93
        storeControl.expectAndReturn(storeMock.getFeatureSet(), fsetMock);
94
        storeControl.replay();
95
        fsetControl.expectAndReturn(fsetMock.getSize(), 10);
96
        fsetControl.replay();
97

  
98
        helper = new FeaturePagingHelperImpl(storeMock);
99

  
100
        assertEquals("El n? de p?ginas calculadas no es correcto", 1, helper
101
                .getNumPages());
102

  
103
        storeControl.verify();
104
        fsetControl.verify();
105
    }
106

  
107
    /**
108
     * Test method for
109
     * {@link org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper#getTotalSize()}
110
     * .
111
     */
112
    public void testGetTotalSize() throws Exception {
113
        storeControl.expectAndReturn(storeMock.getFeatureSet(), fsetMock);
114
        storeControl.replay();
115
        fsetControl.expectAndReturn(fsetMock.getSize(), 10, 2);
116
        fsetControl.replay();
117

  
118
        helper = new FeaturePagingHelperImpl(storeMock);
119

  
120
        assertEquals("El n? total de features no es el de la Colecci?n", 10,
121
                helper.getTotalSize());
122

  
123
        storeControl.verify();
124
        fsetControl.verify();
125
    }
126

  
127
    /**
128
     * Test method for
129
     * {@link org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper#getFeatureAt(int)}
130
     * .
131
     */
132
    public void testGetFeatureAt() throws Exception {
133
        // Create two mock features for the test.
134
        MockControl featureControl = MockControl.createControl(Feature.class);
135
        Feature mockFeature1 = (Feature) featureControl.getMock();
136
        Feature mockFeature2 = (Feature) featureControl.getMock();
137

  
138
        // Create a mock Iterator to return the Features.
139
        MockControl iteratorControl = MockControl.createControl(Iterator.class);
140
        Iterator mockIterator = (Iterator) iteratorControl.getMock();
141

  
142
        // Values 0 and 1
143
        mockIterator.hasNext();
144
        iteratorControl.setReturnValue(true);
145
        mockIterator.next();
146
        iteratorControl.setReturnValue(mockFeature1);
147
        mockIterator.hasNext();
148
        iteratorControl.setReturnValue(true);
149
        mockIterator.next();
150
        iteratorControl.setReturnValue(mockFeature2);
151
        mockIterator.hasNext();
152
        iteratorControl.setReturnValue(false);
153

  
154
        // Values 4 and 5
155
        mockIterator.hasNext();
156
        iteratorControl.setReturnValue(true);
157
        mockIterator.next();
158
        iteratorControl.setReturnValue(mockFeature2);
159
        mockIterator.hasNext();
160
        iteratorControl.setReturnValue(true);
161
        mockIterator.next();
162
        iteratorControl.setReturnValue(mockFeature1);
163
        mockIterator.hasNext();
164
        iteratorControl.setReturnValue(false);
165

  
166
        iteratorControl.replay();
167

  
168
        // Define the mock Collection operations.
169
        storeControl.expectAndReturn(storeMock.getFeatureSet(), fsetMock);
170
        storeControl.replay();
171

  
172
        fsetControl.expectAndReturn(fsetMock.getSize(), 11);
173
        fsetControl.expectAndReturn(fsetMock.iterator(0), mockIterator);
174
        fsetControl.expectAndReturn(fsetMock.iterator(4), mockIterator);
175
        fsetControl.replay();
176

  
177
        helper = new FeaturePagingHelperImpl(storeMock, 2);
178

  
179
        // Check the returned Features are the correct ones
180
        Feature feature = helper.getFeatureAt(0);
181
        assertEquals("La Feature devuelta no es la que corresponde "
182
                + "al ?ndice solicitado: 0", mockFeature1, feature);
183

  
184
        feature = helper.getFeatureAt(1);
185
        assertEquals("La Feature devuelta no es la que corresponde "
186
                + "al ?ndice solicitado: 1", mockFeature2, feature);
187

  
188
        feature = helper.getFeatureAt(5);
189
        assertEquals("La Feature devuelta no es la que corresponde "
190
                + "al ?ndice solicitado: 5", mockFeature1, feature);
191

  
192
        try {
193
            feature = helper.getFeatureAt(9999);
194
            fail("Returned a value for a non existent Feature position");
195
        } catch (Exception ex) {
196
            // Good
197
        }
198

  
199
        storeControl.verify();
200
        fsetControl.verify();
201
        iteratorControl.verify();
202
    }
203

  
204
    /**
205
     * Test method for
206
     * {@link org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper#setCurrentPage(int)}
207
     * .
208
     */
209
    public void testSetCurrentPage() throws Exception {
210
        storeControl.expectAndReturn(storeMock.getFeatureSet(), fsetMock);
211
        storeControl.replay();
212
        fsetControl.expectAndReturn(fsetMock.getSize(), 10);
213
        fsetControl.replay();
214

  
215
        helper = new FeaturePagingHelperImpl(storeMock);
216

  
217
        try {
218
            helper.setCurrentPage(-4);
219
            fail("Allowed to set a negative number as the current page");
220
        } catch (Exception ex) {
221
            // Good
222
        }
223

  
224
        try {
225
            helper.setCurrentPage(99999);
226
            fail("Allowed to set a current page greater than the number "
227
                    + "of available pages");
228
        } catch (Exception ex) {
229
            // Good
230
        }
231

  
232
        storeControl.verify();
233
        fsetControl.verify();
234
    }
235

  
236
}
0 237

  
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/commands/CommandTest.java
1
package org.gvsig.fmap.dal.commands;
2

  
3
import junit.framework.TestCase;
4

  
5
public class CommandTest extends TestCase {
6

  
7
	public static void main(String[] args) {
8
		junit.textui.TestRunner.run(CommandTest.class);
9
	}
10

  
11
	protected void setUp() throws Exception {
12
		super.setUp();
13
	}
14

  
15
	public void testInitialize() {
16

  
17
	}
18
}

Also available in: Unified diff