Revision 39242

View differences:

tags/v2_0_0_Build_2058/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
}
tags/v2_0_0_Build_2058/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/resource/spi/AbstractResourceTest.java
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
* 2009 {}  {{Task}}
26
*/
27
package org.gvsig.fmap.dal.resource.spi;
28

  
29
import junit.framework.TestCase;
30

  
31
import org.easymock.MockControl;
32
import org.gvsig.fmap.dal.resource.ResourceAction;
33
import org.gvsig.fmap.dal.resource.ResourceParameters;
34
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException;
35

  
36
/**
37
 * Unit tests for the class {@link AbstractResource}
38
 * 
39
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
40
 */
41
public class AbstractResourceTest extends TestCase {
42

  
43
	private AbstractResource resource;
44
	private MockControl paramsControl;
45
	private ResourceParameters params;
46

  
47
	protected void setUp() throws Exception {
48
		super.setUp();
49
		paramsControl = MockControl.createNiceControl(ResourceParameters.class);
50
		params = (ResourceParameters) paramsControl.getMock();
51
		resource = new TestResource(params);
52
	}
53

  
54
	/**
55
	 * Test method for {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#getLastTimeOpen()}.
56
	 */
57
	public void testGetLastTimeOpen() throws ResourceNotifyOpenException {
58
		long time = resource.getLastTimeOpen();
59
		resource.notifyOpen();
60
		assertTrue("The resource last time open hasn't been updated",
61
				resource.getLastTimeOpen() > time);
62
	}
63

  
64
	/**
65
	 * Test method for {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#getLastTimeUsed()}.
66
	 */
67
	public void testGetLastTimeUsed() throws Exception {
68
		long time = resource.getLastTimeUsed();
69
		resource.execute(new ResourceAction() {
70
			public Object run() throws Exception {
71
				try {
72
					// Wait for 100 milliseconds
73
					Thread.sleep(100);
74
				} catch (InterruptedException e) {
75
					// No problem
76
				}
77
				return null;
78
			}
79
		});
80
		assertTrue("The resource last time used hasn't been updated",
81
				resource.getLastTimeUsed() > time);
82
	}
83

  
84
	/**
85
	 * Test method for {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#openCount()}.
86
	 */
87
	public void testOpenCount() throws Exception {
88
		assertEquals(0, resource.openCount());
89
		resource.notifyOpen();
90
		assertEquals(1, resource.openCount());
91
		resource.notifyOpen();
92
		resource.notifyOpen();
93
		assertEquals(3, resource.openCount());
94
		resource.notifyClose();
95
		assertEquals(2, resource.openCount());
96
	}
97

  
98
	/**
99
	 * Test method for
100
	 * {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
101
	 * .
102
	 */
103
	public void testExecute() throws Exception {
104
		final MutableBoolean testValue = new MutableBoolean();
105
		resource.execute(new ResourceAction() {
106
			public Object run() throws Exception {
107
				testValue.setValue(true);
108
				return null;
109
			}
110
		});
111
		assertTrue("Runnable execution not performed", testValue.isValue());
112
	}
113

  
114
	public class MutableBoolean {
115
		private boolean value = false;
116

  
117
		public void setValue(boolean value) {
118
			this.value = value;
119
		}
120

  
121
		public boolean isValue() {
122
			return value;
123
		}
124
	}
125
}
tags/v2_0_0_Build_2058/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/resource/spi/TestNonBlockingResource.java
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
* 2009 {}  {{Task}}
26
*/
27
package org.gvsig.fmap.dal.resource.spi;
28

  
29
import org.gvsig.fmap.dal.exception.InitializeException;
30
import org.gvsig.fmap.dal.resource.ResourceParameters;
31
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
32
import org.gvsig.fmap.dal.resource.exception.ResourceException;
33

  
34
/**
35
 * Test resource implementation.
36
 * 
37
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
38
 */
39
public class TestNonBlockingResource extends AbstractNonBlockingResource {
40

  
41
	protected TestNonBlockingResource(ResourceParameters parameters)
42
			throws InitializeException {
43
		super(parameters);
44
	}
45

  
46
	public Object get() throws AccessResourceException {
47
		return getName();
48
	}
49

  
50
	public String getName() throws AccessResourceException {
51
		return getClass().getName();
52
	}
53

  
54
	public boolean isThis(ResourceParameters parameters)
55
			throws ResourceException {
56
		return false;
57
	}
58
}
tags/v2_0_0_Build_2058/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/resource/spi/TestAbstractResourcePerformance.java
1
package org.gvsig.fmap.dal.resource.spi;
2

  
3
import junit.framework.TestCase;
4

  
5
import org.easymock.MockControl;
6
import org.gvsig.fmap.dal.resource.Resource;
7
import org.gvsig.fmap.dal.resource.ResourceAction;
8
import org.gvsig.fmap.dal.resource.ResourceParameters;
9

  
10
public class TestAbstractResourcePerformance extends TestCase {
11
	private MockControl paramsControl;
12
	private ResourceParameters params;
13
	private AbstractResource resource;
14
	private MockControl paramsControl2;
15
	private ResourceParameters params2;
16
	private AbstractNonBlockingResource nonBlockingResource;
17

  
18
	protected void setUp() throws Exception {
19
		super.setUp();
20
		paramsControl = MockControl.createNiceControl(ResourceParameters.class);
21
		params = (ResourceParameters) paramsControl.getMock();
22
		resource = new TestResource(params);
23
		paramsControl2 =
24
				MockControl.createNiceControl(ResourceParameters.class);
25
		params2 = (ResourceParameters) paramsControl2.getMock();
26
		nonBlockingResource = new TestNonBlockingResource(params2);
27
	}
28

  
29
	/**
30
	 * Test method for
31
	 * {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
32
	 * .
33
	 */
34
	public void testExecuteBlockingPerformance() throws Exception {
35
		executePerformance(new ResourceAction() {
36
			public Object run() throws Exception {
37
				return null;
38
			}
39
		}, resource);
40
	}
41

  
42
	/**
43
	 * Test method for
44
	 * {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
45
	 * .
46
	 */
47
	public void testExecuteNonBlockingPerformance() throws Exception {
48
		executePerformance(new ResourceAction() {
49
			public Object run() throws Exception {
50
				return null;
51
			}
52
		}, nonBlockingResource);
53
	}
54

  
55
	/**
56
	 * Test method for
57
	 * {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
58
	 * .
59
	 */
60
	public void executePerformance(ResourceAction action, Resource resource)
61
			throws Exception {
62

  
63
		final int executions = 100000;
64
		long time1 = System.currentTimeMillis();
65
		for (int i = 0; i < executions; i++) {
66
			resource.execute(action);
67
		}
68
		long time2 = System.currentTimeMillis();
69

  
70
		System.out.print(resource.getName());
71
		System.out.print(": total time: " + (time2 - time1) + " ms.");
72
		System.out.println(" - time per execution: "
73
				+ ((float) (time2 - time1) / (float) executions) + " ms.");
74
	}
75
}
tags/v2_0_0_Build_2058/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/resource/spi/TestResource.java
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
* 2009 {}  {{Task}}
26
*/
27
package org.gvsig.fmap.dal.resource.spi;
28

  
29
import org.gvsig.fmap.dal.exception.InitializeException;
30
import org.gvsig.fmap.dal.resource.ResourceParameters;
31
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
32
import org.gvsig.fmap.dal.resource.exception.ResourceException;
33

  
34
/**
35
 * Test non blocking resource implementation.
36
 * 
37
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
38
 */
39
public class TestResource extends AbstractResource {
40

  
41
	protected TestResource(ResourceParameters parameters)
42
			throws InitializeException {
43
		super(parameters);
44
	}
45

  
46
	public Object get() throws AccessResourceException {
47
		return getName();
48
	}
49

  
50
	public String getName() throws AccessResourceException {
51
		return getClass().getName();
52
	}
53

  
54
	public boolean isThis(ResourceParameters parameters)
55
			throws ResourceException {
56
		return false;
57
	}
58
}
tags/v2_0_0_Build_2058/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
}
tags/v2_0_0_Build_2058/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/BaseTestFeatureStore.java
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
* 2009 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.feature;
32

  
33
import java.util.ArrayList;
34
import java.util.Collections;
35
import java.util.Iterator;
36
import java.util.List;
37
import java.util.Random;
38
import java.util.TreeSet;
39

  
40
import org.gvsig.fmap.dal.DALLocator;
41
import org.gvsig.fmap.dal.DataManager;
42
import org.gvsig.fmap.dal.DataServerExplorer;
43
import org.gvsig.fmap.dal.DataStoreParameters;
44
import org.gvsig.fmap.dal.DataTypes;
45
import org.gvsig.fmap.dal.exception.DataEvaluatorRuntimeException;
46
import org.gvsig.fmap.dal.exception.DataException;
47
import org.gvsig.fmap.dal.feature.FeatureQueryOrder.FeatureQueryOrderMember;
48
import org.gvsig.fmap.dal.feature.testmulithread.StoreTask;
49
import org.gvsig.fmap.dal.resource.ResourceManager;
50
import org.gvsig.fmap.geom.Geometry;
51
import org.gvsig.tools.ToolsLocator;
52
import org.gvsig.tools.dispose.DisposableIterator;
53
import org.gvsig.tools.dynobject.DynClass;
54
import org.gvsig.tools.dynobject.DynField;
55
import org.gvsig.tools.dynobject.DynObject;
56
import org.gvsig.tools.evaluator.Evaluator;
57
import org.gvsig.tools.evaluator.EvaluatorData;
58
import org.gvsig.tools.evaluator.EvaluatorException;
59
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo;
60
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
61
import org.gvsig.tools.persistence.PersistentState;
62
import org.slf4j.Logger;
63
import org.slf4j.LoggerFactory;
64

  
65
/**
66
 * @author jmvivo
67
 *
68
 */
69
public abstract class BaseTestFeatureStore extends
70
		AbstractLibraryAutoInitTestCase {
71

  
72
	private static Logger logger = null;
73

  
74
	protected DataManager dataManager = null;
75
	private static Random rnd;
76

  
77
	public Logger getLogger() {
78
		if (logger == null) {
79
			logger = LoggerFactory.getLogger(this.getClass());
80
		}
81
		return logger;
82
	}
83

  
84
	public abstract boolean usesResources();
85

  
86
	public abstract boolean hasExplorer();
87

  
88
	public FeatureQuery getDefaultQuery(FeatureStore store)
89
			throws DataException {
90
		FeatureQuery query = store.createFeatureQuery();
91
		FeatureAttributeDescriptor[] key = store.getDefaultFeatureType()
92
				.getPrimaryKey();
93
		for (int i = 0; i < key.length; i++) {
94
			query.getOrder().add(key[i].getName(), true);
95
		}
96

  
97
		return query;
98
	}
99

  
100

  
101
	public abstract DataStoreParameters getDefaultDataStoreParameters()
102
			throws DataException;
103

  
104

  
105
	protected void doSetUp() throws Exception {
106
		dataManager = DALLocator.getDataManager();
107
	}
108

  
109

  
110
	//=================================================
111

  
112

  
113
	public void printFeature(Feature feature, int maxColSize) {
114
		printFeature(feature, true, maxColSize);
115
	}
116

  
117

  
118
	public void printFeature(Feature feature, boolean showColName,int maxColSize) {
119
		FeatureType fType = feature.getType();
120
		if (showColName){
121
			this.printFeatureTypeColNames(feature.getType(), maxColSize);
122
		}
123
		StringBuffer row = new StringBuffer();
124
		Iterator iter = fType.iterator();
125
		FeatureAttributeDescriptor attr;
126

  
127
		while (iter.hasNext()) {
128
			attr = (FeatureAttributeDescriptor) iter.next();
129
			row.append(truncateOrFillString(feature.get(attr.getName()),
130
					maxColSize + 1, ' '));
131
		}
132
		System.out.println(row.toString());
133
	}
134

  
135
	public String truncateOrFillString(Object str, int max, char fillWith) {
136
		if (str == null) {
137
			return truncateOrFillString("{null}", max, fillWith);
138
		}
139
		return truncateOrFillString(str.toString(), max, fillWith);
140
	}
141

  
142
	public String truncateOrFillString(String str, int max, char fillWith) {
143
		if (str.length() > max) {
144
			return str.substring(0, max - 1) + " ";
145
		} else {
146
			StringBuffer strB = new StringBuffer(str);
147
			while (strB.length() < max) {
148
				strB.append(fillWith);
149
			}
150
			return strB.toString();
151
		}
152

  
153
	}
154

  
155
	public void printFeatureTypeColNames(FeatureType fType, int maxColSize) {
156
		Iterator iter = fType.iterator();
157
		FeatureAttributeDescriptor attr;
158
		StringBuffer colNames = new StringBuffer();
159
		StringBuffer typeNames = new StringBuffer();
160
		StringBuffer sep = new StringBuffer();
161
		if (maxColSize < 1){
162
			maxColSize = 15;
163
		}
164
		while (iter.hasNext()) {
165
			attr = (FeatureAttributeDescriptor) iter.next();
166
			colNames.append(truncateOrFillString(attr.getName(), maxColSize + 1, ' '));
167
			typeNames.append(truncateOrFillString("(" + attr.getDataTypeName() + ")",
168
					maxColSize + 1, ' '));
169
			sep.append(truncateOrFillString("", maxColSize, '='));
170
			sep.append(' ');
171
		}
172

  
173
		System.out.println("");
174
		System.out.println("");
175
		System.out.println(colNames.toString());
176
		System.out.println(typeNames.toString());
177
		System.out.println(sep.toString());
178
	}
179

  
180
	protected FeatureAttributeDescriptor getFirstAttributeOfType(
181
			FeatureType ftype, int dataType) {
182
		return getFirstAttributeOfType(ftype, new int[] { dataType });
183
	}
184

  
185
	protected FeatureAttributeDescriptor getFirstAttributeOfType(
186
			FeatureType ftype, int[] dataTypes) {
187
		FeatureAttributeDescriptor attr;
188
		Iterator iter = ftype.iterator();
189
		int i;
190
		while (iter.hasNext()) {
191
			attr = (FeatureAttributeDescriptor) iter.next();
192
			for (i = 0; i < dataTypes.length; i++) {
193
				if (attr.getType() == dataTypes[i]) {
194
					return attr;
195
				}
196
			}
197
		}
198
		return null;
199
	}
200

  
201
	protected boolean compareDynObject(DynObject obj1, DynObject obj2) {
202
		DynClass dynClass = obj1.getDynClass();
203
		if (!dynClass.getName().equals(obj2.getDynClass().getName())) {
204
			return false;
205
		}
206

  
207
		DynField[] fields = dynClass.getDeclaredDynFields();
208
		String fieldName;
209
		Object v1, v2;
210
		for (int i = 0; i < fields.length; i++) {
211
			fieldName = fields[i].getName();
212
			v1 = obj1.getDynValue(fieldName);
213
			v2 = obj2.getDynValue(fieldName);
214
			if (v1 == v2) {
215
				continue;
216
			} else if (v1 != null) {
217
				if (!v1.equals(v2)) {
218
					return false;
219
				}
220
			}
221
		}
222

  
223
		return true;
224
	}
225

  
226
	protected boolean compareStores(FeatureStore store1, FeatureStore store2)
227
			throws DataException {
228
		if (store1.getParameters().getClass() != store2.getParameters()
229
				.getClass()) {
230
			return false;
231
		}
232
		if (!compareDynObject(store1.getParameters(), store2.getParameters())) {
233
			return false;
234
		}
235

  
236
		if (store1.getEnvelope() != store2.getEnvelope()) {
237
			if (store1.getEnvelope() != null) {
238
				return store1.getEnvelope().equals(store2.getEnvelope());
239
			} else {
240
				return false;
241
			}
242
		}
243

  
244
		if (!store1.getName().equals(store2.getName())) {
245
			return false;
246
		}
247
		if (((FeatureSelection) store1.getSelection()).getSize() != ((FeatureSelection) store2
248
				.getSelection()).getSize()) {
249
			return false;
250
		}
251
		DisposableIterator iter1 = ((FeatureSelection) store1.getSelection())
252
				.fastIterator();
253
		DisposableIterator iter2 = ((FeatureSelection) store2.getSelection())
254
				.fastIterator();
255
		if (!compareFeatureIterators(iter1, iter2)) {
256
			return false;
257
		}
258
		iter1.dispose();
259
		iter2.dispose();
260

  
261
		if (store1.getFeatureTypes().size() != store2.getFeatureTypes().size()) {
262
			return false;
263
		}
264
		Iterator iterTypes1 = store1.getFeatureTypes().iterator();
265
		Iterator iterTypes2 = store2.getFeatureTypes().iterator();
266
		while (iterTypes1.hasNext()) {
267
			if (!compareTypes((FeatureType) iterTypes1.next(),
268
					(FeatureType) iterTypes2
269
					.next())) {
270
				return false;
271
			}
272
		}
273
		if (!compareTypes(store1.getDefaultFeatureType(), store2
274
				.getDefaultFeatureType())) {
275
			return false;
276
		}
277

  
278
		if (store1.getLocks() != null) {
279
			if (store1.getLocks().getLocksCount() != store2.getLocks()
280
					.getLocksCount()) {
281
				return false;
282
			}
283
			if (!compareFeatureIterators(store1.getLocks().getLocks(), store2
284
					.getLocks().getLocks())) {
285
				return false;
286
			}
287

  
288
		} else if (store2.getLocks() != null) {
289
			return false;
290
		}
291

  
292
		return true;
293
	}
294

  
295
	protected boolean compareFeatureIterators(Iterator iter1, Iterator iter2) {
296
		Feature feature;
297
		Feature ffeature;
298
		while (iter1.hasNext()) {
299
			feature = (Feature) iter1.next();
300
			ffeature = (Feature) iter2.next();
301
			if (!this.compareFeatures(feature, ffeature)) {
302
				return false;
303
			}
304
		}
305

  
306
		if (!iter2.hasNext()) {
307
			return true;
308
		} else {
309
			getLogger().warn("size !=");
310
			return false;
311
		}
312

  
313
	}
314

  
315
	protected boolean compareFeatureIterators(Iterator iter1, Iterator iter2,
316
			String[] attrNames) {
317
		Feature feature;
318
		Feature ffeature;
319
		while (iter1.hasNext()) {
320
			feature = (Feature) iter1.next();
321
			ffeature = (Feature) iter2.next();
322
			if (!this.compareFeatures(feature, ffeature, attrNames)) {
323
				return false;
324
			}
325
		}
326

  
327
		return !iter2.hasNext();
328

  
329
	}
330

  
331

  
332

  
333
	protected boolean compareTypes(FeatureType ft1, FeatureType ft2) {
334
		if (ft1.size() != ft2.size()) {
335
			getLogger().warn("size !=");
336
			return false;
337
		}
338
		if (ft1.getDefaultGeometryAttributeIndex() != ft2
339
				.getDefaultGeometryAttributeIndex()) {
340
			getLogger().warn(
341
					"getDefaultGeometryAttributeIndex "
342
							+ ft1.getDefaultGeometryAttributeIndex() +
343
					" !="+ ft2.getDefaultGeometryAttributeIndex());
344
			return false;
345
		}
346
		if (ft1.getDefaultGeometryAttributeIndex() > -1) {
347
			if (ft1.getDefaultSRS() != null) {
348
				if (!ft1.getDefaultSRS().equals(ft2.getDefaultSRS())) {
349
					getLogger().warn("getDefaultSRS !=");
350
					return false;
351
				}
352

  
353
			} else {
354
				if (ft2.getDefaultSRS() != null) {
355
					getLogger().warn("getDefaultSRS !=");
356
					return false;
357
				}
358
			}
359
		}
360

  
361
		if (ft1.getDefaultGeometryAttributeName() != null) {
362
			if (!ft1.getDefaultGeometryAttributeName().equals(
363
					ft2.getDefaultGeometryAttributeName())) {
364
				getLogger().warn("getDefaultGeometryAttributeName !=");
365

  
366
				return false;
367
			}
368
		} else {
369
			if (ft2.getDefaultGeometryAttributeName() != null) {
370
				getLogger().warn("getDefaultGeometryAttributeName !=");
371
				return false;
372
			}
373
		}
374

  
375

  
376

  
377
		FeatureAttributeDescriptor attr1, attr2;
378
		for (int i = 0; i < ft1.size(); i++) {
379
			attr1 = ft1.getAttributeDescriptor(i);
380
			attr2 = ft2.getAttributeDescriptor(i);
381

  
382
			if (!compareAttributes(attr1, attr2)) {
383
				return false;
384
			}
385

  
386
		}
387
		return true;
388

  
389
	}
390

  
391
	protected boolean compareAttributes(FeatureAttributeDescriptor attr1,
392
			FeatureAttributeDescriptor attr2) {
393
		if (attr1 == null || attr2 == null) {
394
			getLogger().warn("attr1 == null || attr2 == null");
395
			return false;
396
		}
397
		if (!attr1.getName().equals(attr2.getName())) {
398
			getLogger().warn(
399
					"name '" + attr1.getName() + "' != '" + attr2.getName()
400
							+ "'");
401
			return false;
402
		}
403

  
404
		if (attr1.getDataType() != attr2.getDataType()) {
405
			getLogger().warn(
406
					attr1.getName() + ":" +
407
					"dataType '" + attr1.getDataTypeName() + "'["
408
							+ attr1.getDataType() + "] != '"
409
							+ attr2.getDataTypeName() + "'["
410
							+ attr2.getDataType() + "]");
411
			return false;
412
		}
413

  
414
		if (attr1.getSize() != attr2.getSize()) {
415
			getLogger().warn(
416
					attr1.getName() + ":" +
417
					"size " + attr1.getSize() + " != " + attr2.getSize());
418
			return false;
419
		}
420

  
421
		if (attr1.getPrecision() != attr2.getPrecision()) {
422
			getLogger().warn(
423
					attr1.getName() + ":" +
424
					"precision " + attr1.getPrecision() + " != "
425
							+ attr1.getPrecision());
426
			return false;
427
		}
428

  
429
		if (attr1.getGeometryType() != attr2.getGeometryType()) {
430
			getLogger().warn(
431
					attr1.getName() + ":" +
432
					"GeometryType " + attr1.getGeometryType() + " != "
433
							+ attr2.getGeometryType());
434
			return false;
435
		}
436

  
437
		if (attr1.getGeometrySubType() != attr2.getGeometrySubType()) {
438
			getLogger().warn(
439
					attr1.getName() + ":" +
440
					"GeometrySubType " + attr1.getGeometrySubType() + " != "
441
							+ attr2.getGeometrySubType());
442

  
443
			return false;
444
		}
445

  
446
		if (attr1.getSRS() != null) {
447
			if (!attr1.getSRS().equals(attr2.getSRS())) {
448
				getLogger().warn(
449
						attr1.getName() + ":" +
450
						"srs " + attr1.getSRS() + " != " + attr2.getSRS());
451
				return false;
452
			}
453
		} else {
454
			if (attr2.getSRS() != null) {
455
				getLogger().warn(
456
						attr1.getName() + ":" +
457
						"srs " + attr1.getSRS() + " != " + attr2.getSRS());
458
				return false;
459
			}
460
		}
461

  
462
		return true;
463
	}
464

  
465
	protected boolean compareFeatures(Feature f1, Feature f2,
466
			String[] attrsNames) {
467
		FeatureAttributeDescriptor attr1;
468
		FeatureAttributeDescriptor attr2;
469
		Object v1, v2;
470
		for (int i = 0; i < attrsNames.length; i++) {
471
			attr1 = f1.getType().getAttributeDescriptor(attrsNames[i]);
472
			attr2 = f2.getType().getAttributeDescriptor(attrsNames[i]);
473
			if (attr1 != attr2) {
474
				if (!compareAttributes(attr1, attr1)) {
475
					return false;
476
				}
477
			}
478
			v1 = f1.get(attr1.getName());
479
			v2 = f2.get(attr2.getName());
480
			if (!compareFeatureValue(v1, v2, attr1)) {
481
				return false;
482
			}
483
		}
484

  
485
		return true;
486
	}
487

  
488
	protected boolean compareFeatures(Feature f1, Feature f2) {
489
		if (!compareTypes(f1.getType(), f2.getType())) {
490
			return false;
491
		}
492
		Iterator iter = f1.getType().iterator();
493
		FeatureAttributeDescriptor attr;
494
		Object v1, v2;
495
		while (iter.hasNext()) {
496
			attr = (FeatureAttributeDescriptor) iter.next();
497
			v1 = f1.get(attr.getName());
498
			v2 = f2.get(attr.getName());
499
			if (!compareFeatureValue(v1, v2, attr)) {
500
				return false;
501
			}
502
		}
503

  
504
		return true;
505

  
506
	}
507

  
508
	protected boolean compareFeatureValue(Object v1, Object v2,
509
			FeatureAttributeDescriptor attr) {
510

  
511
		if ((v1 == null || v2 == null) &&  !attr.allowNull() ){
512
			getLogger().warn("null and !allowNull:"
513
							+ attr.getName());
514
			return false;
515
		}
516

  
517
		if (v1 == v2) {
518
			return true;
519
		} else if (v1 == null) {
520
			getLogger().warn(" v1 == null and v2 != null:"
521
							+ attr.getName());
522
			return false;
523
		} else if (v2 == null) {
524
			getLogger().warn("v2 == null and v1 != null:"
525
							+ attr.getName());
526
			return false;
527

  
528
		}
529
		switch (attr.getType()) {
530
		case DataTypes.GEOMETRY:
531
			Geometry geom1 = (Geometry) v1;
532
			Geometry geom2 = (Geometry) v2;
533
			if (!geom1.equals(geom2)) {
534
				getLogger().warn(" v1 != v2 (Geom):" + attr.getName());
535
				return false;
536

  
537
			}
538
			return true;
539
		case DataTypes.DOUBLE:
540
			double diff = ((Double) v1).doubleValue()
541
					- ((Double) v1).doubleValue();
542
			if (!(Math.abs(diff) < 0.000001)) {
543
				getLogger().warn(" v1 != v2 (Dobule):" + attr.getName());
544
				return false;
545

  
546
			}
547
			return true;
548

  
549
		case DataTypes.OBJECT:
550
			if (!v1.equals(v2)) {
551
				getLogger().warn(
552
						" v1 != v2 (object):" + attr.getName() + " [ignored]");
553
				return false;
554
			}
555
			return true;
556

  
557
		default:
558
			if (!v1.equals(v2)) {
559
				getLogger()
560
						.warn(
561
								" v1 != v2:" + attr.getName() + ": " + v1
562
										+ " != " + v2);
563
				return false;
564
			}
565
		}
566
		return true;
567

  
568
	}
569

  
570

  
571
	//------------------------------------------------
572

  
573
	public void testSimpleIteration(FeatureStore store) {
574
		this.testSimpleIteration(store, null);
575
	}
576

  
577
	protected String[] getRandomAttibuteList(FeatureType fType) {
578
		String[] attrNames = new String[fType.size()];
579
		Iterator iter = fType.iterator();
580
		int i = 0;
581
		while (iter.hasNext()) {
582
			attrNames[i] = ((FeatureAttributeDescriptor) iter.next()).getName();
583
			i++;
584
		}
585
		return this.getRandomAttibuteList(attrNames);
586
	}
587

  
588
	protected Random getRandom(){
589
		if (rnd == null){
590
			rnd = new Random();
591
			rnd.setSeed(System.currentTimeMillis());
592
		}
593
		return rnd;
594
	}
595

  
596
	protected String[] getRandomAttibuteList(String[] attrNames) {
597
		int nAttributes = getRandom().nextInt(
598
				attrNames.length + (attrNames.length / 2)) + 1;
599
		TreeSet set = new TreeSet();
600
		for (int i = 0; i < nAttributes; i++) {
601
			set.add(attrNames[getRandom().nextInt(attrNames.length)]);
602
		}
603
		return (String[]) set.toArray(new String[0]);
604
	}
605

  
606
	public void testIterationFastAndStandart(FeatureStore store)
607
			throws Exception {
608
		this.testIterationFastAndStandart(store, null);
609

  
610
		FeatureQuery query = this.getDefaultQuery(store);
611
		// Random Attribute list
612
		query.setAttributeNames(getRandomAttibuteList(store
613
				.getDefaultFeatureType()));
614
		this.testIterationFastAndStandart(store, query);
615

  
616
		// Sorted
617
		FeatureAttributeDescriptor attr = getFirstAttributeOfType(store
618
				.getDefaultFeatureType(), new int[] { DataTypes.INT,
619
				DataTypes.LONG, DataTypes.STRING, DataTypes.DOUBLE, DataTypes.FLOAT });
620
		{
621
			// asure that attr is in query attributes
622
			boolean attrFound = false;
623
			String[] curAttrs = query.getAttributeNames();
624
			for (int i = 0; i < curAttrs.length; i++) {
625
				if (curAttrs[i].equals(attr.getName())) {
626
					attrFound = true;
627
					break;
628

  
629
				}
630
			}
631
			if (!attrFound) {
632
				String[] newAttrs = new String[curAttrs.length + 1];
633
				for (int i = 0; i < curAttrs.length; i++) {
634
					newAttrs[i] = curAttrs[i];
635
				}
636
				newAttrs[curAttrs.length] = attr.getName();
637
				query.setAttributeNames(newAttrs);
638
			}
639
		}
640

  
641

  
642
		query.getOrder().add(attr.getName(), true);
643
		this.testIterationFastAndStandart(store, query);
644

  
645
		// Filter
646
		query = this.getDefaultQuery(store);
647

  
648
		query.setFilter(new Evaluator(){
649
		    private EvaluatorFieldsInfo evaluatorFieldsInfo = new EvaluatorFieldsInfo();
650
		    
651
			public Object evaluate(EvaluatorData data)
652
					throws EvaluatorException {
653
				// TODO Auto-generated method stub
654
				return Boolean.TRUE;
655
			}
656

  
657
			public String getSQL() {
658
				return "true = true";
659
			}
660

  
661
			public String getDescription() {
662
				// TODO Auto-generated method stub
663
				return null;
664
			}
665

  
666
			public String getName() {
667
				return "AlwaysTrue";
668
			}
669

  
670
			public EvaluatorFieldsInfo getFieldsInfo() {				
671
				return evaluatorFieldsInfo;
672
			}
673

  
674
		});
675
		this.testIterationFastAndStandart(store, query);
676

  
677
		// Filter + Sorted
678
		query.getOrder().add(attr.getName(), true);
679
		this.testIterationFastAndStandart(store, query);
680
	}
681

  
682
	public void testSimpleIteration(FeatureStore store, FeatureQuery query) {
683
		FeatureSet set;
684
		try {
685

  
686
			if (query == null) {
687
				query = this.getDefaultQuery(store);
688
			}
689
			set = store.getFeatureSet(query);
690
			FeatureType type = set.getDefaultFeatureType();
691

  
692
			DisposableIterator it = set.iterator();
693
			Feature feature;
694
			printFeatureTypeColNames(type, 15);
695
			while (it.hasNext()) {
696

  
697
				feature = (Feature) it.next();
698
				printFeature(feature, false, 15);
699
			}
700

  
701
			it.dispose();
702
			set.dispose();
703

  
704
		} catch (DataException e3) {
705
			e3.printStackTrace();
706
			fail();
707
			return;
708
		}
709

  
710
	}
711

  
712
	public void testIterationFastAndStandart(FeatureStore store,
713
			FeatureQuery query) {
714
		FeatureSet set;
715
		try {
716

  
717
			if (query == null) {
718
				query = this.getDefaultQuery(store);
719
			}
720
			set = store.getFeatureSet(query);
721

  
722
			DisposableIterator it = set.iterator();
723
			DisposableIterator fit = set.fastIterator();
724

  
725
			assertTrue(this.compareFeatureIterators(it, fit));
726

  
727
			it.dispose();
728
			fit.dispose();
729
			set.dispose();
730

  
731
		} catch (DataException e3) {
732
			e3.printStackTrace();
733
			fail();
734
			return;
735
		}
736

  
737
	}
738

  
739
	public void testSimpleIteration(DataStoreParameters parameters)
740
			throws Exception {
741
		FeatureStore store = null;
742
		store = (FeatureStore) dataManager.openStore(parameters
743
				.getDataStoreName(), parameters);
744

  
745
		this.testSimpleIteration(store);
746

  
747
		store.dispose();
748

  
749
	}
750

  
751
	public void testIterationFastAndStandart(DataStoreParameters parameters)
752
			throws Exception {
753
		FeatureStore store = null;
754
		store = (FeatureStore) dataManager.openStore(parameters
755
				.getDataStoreName(), parameters);
756

  
757
		this.testIterationFastAndStandart(store);
758

  
759
		store.dispose();
760

  
761
	}
762

  
763
	/**
764
	 *
765
	 * @param count
766
	 *            if (< 0) list.size() >= 1 else list.size() == count
767
	 * @throws Exception
768
	 */
769
	public void testExplorerList(int count) throws Exception {
770
		FeatureStore store = null;
771
		DataStoreParameters params = getDefaultDataStoreParameters();
772
		store = (FeatureStore) dataManager.openStore(params.getDataStoreName(),
773
				params);
774

  
775
		DataServerExplorer explorer;
776
		explorer = store.getExplorer();
777

  
778
		if (count < 0) {
779
			assertTrue(explorer.list().size() >= 1);
780
		} else {
781
			assertTrue(explorer.list().size() == count);
782
		}
783

  
784
		store.dispose();
785

  
786
		explorer.dispose();
787
	}
788

  
789
	//=================================================
790
	//=================================================
791

  
792

  
793

  
794

  
795
	public void testIterationFastAndStandart() throws Exception {
796
		this.testIterationFastAndStandart(this.getDefaultDataStoreParameters());
797
	}
798

  
799
	public void testSimpleIteration() throws Exception {
800
		this.testSimpleIteration(this.getDefaultDataStoreParameters());
801
	}
802

  
803
	public void testInitializeStore() throws Exception {
804
		DataStoreParameters params = getDefaultDataStoreParameters();
805
		FeatureStore store = (FeatureStore) dataManager.openStore(params
806
				.getDataStoreName(), params);
807

  
808
		assertNotNull(store.getMetadataID());
809
		assertNotNull(store.getName());
810
		assertEquals(store.getEnvelope(), store.getDynValue("Envelope"));
811
		assertTrue("Feature count not > 0", store.getFeatureCount() > 0);
812
		if (store.isLocksSupported()) {
813
			assertNotNull(store.getLocks());
814
		} else {
815
			assertNull(store.getLocks());
816
		}
817
		store.dispose();
818
	}
819

  
820

  
821
	public void testExplorer() throws Exception {
822
		if (!this.hasExplorer()) {
823
			return;
824
		}
825
		this.testExplorerList(-1);
826

  
827
	}
828

  
829
	public void testSelection() throws Exception {
830
		DataStoreParameters parameters = this.getDefaultDataStoreParameters();
831

  
832
		FeatureStore store = (FeatureStore) dataManager.openStore(parameters
833
				.getDataStoreName(), parameters);
834
		FeatureSet set = store.getFeatureSet();
835

  
836
		assertTrue(store.getFeatureSelection().isEmpty());
837
		store.setSelection(set);
838
		assertFalse(store.getFeatureSelection().isEmpty());
839

  
840
		assertEquals(set.getSize(), store.getFeatureSelection().getSize());
841

  
842
		DisposableIterator iter = set.iterator();
843
		while (iter.hasNext()) {
844
			assertTrue(store.getFeatureSelection().isSelected(
845
					(Feature) iter.next()));
846
		}
847
		iter.dispose();
848

  
849
		store.getFeatureSelection().reverse();
850
		assertTrue(store.getFeatureSelection().isEmpty());
851
		assertEquals(0, store.getFeatureSelection().getSize());
852
		iter = set.iterator();
853
		while (iter.hasNext()) {
854
			assertFalse(store.getFeatureSelection().isSelected(
855
					(Feature) iter.next()));
856
		}
857
		iter.dispose();
858

  
859
		store.getFeatureSelection().reverse();
860
		assertEquals(set.getSize(), store.getFeatureSelection().getSize());
861
		assertFalse(store.getFeatureSelection().isEmpty());
862

  
863
		set.dispose();
864

  
865
	}
866

  
867
	public void testCustomFTypeSet() throws Exception {
868
		DataStoreParameters dbfParameters = this
869
				.getDefaultDataStoreParameters();
870

  
871
		FeatureStore store = (FeatureStore) dataManager.openStore(dbfParameters
872
				.getDataStoreName(), dbfParameters);
873

  
874
		testCustomFTypeSet(store);
875

  
876
		store.dispose();
877
	}
878

  
879
	public void testCustomFTypeSet(FeatureStore store) throws Exception{
880

  
881
		FeatureSet set, set1;
882
		FeatureQuery query;
883
		DisposableIterator iter, iter1;
884
		Iterator attrIter;
885
		FeatureAttributeDescriptor attr;
886

  
887
		set = store.getFeatureSet(this.getDefaultQuery(store));
888
		attrIter = store.getDefaultFeatureType().iterator();
889

  
890
		String[] names;
891
		while (attrIter.hasNext()) {
892
			attr = (FeatureAttributeDescriptor) attrIter.next();
893
			int fieldIndex = attr.getIndex();
894

  
895
			query = this.getDefaultQuery(store);
896
			String fieldName = store.getDefaultFeatureType()
897
			.getAttributeDescriptor(fieldIndex).getName();
898

  
899
			names = new String[] { fieldName };
900
			query.setAttributeNames(names);
901
			set1 = store.getFeatureSet(query);
902

  
903
			if (getRandom().nextBoolean()) {
904
				iter = set.fastIterator();
905
			} else {
906
				iter = set.iterator();
907
			}
908
			if (getRandom().nextBoolean()) {
909
				iter1 = set1.fastIterator();
910
			} else {
911
				iter1 = set1.iterator();
912
			}
913

  
914
			assertTrue(compareFeatureIterators(iter, iter1, names));
915

  
916
			iter.dispose();
917
			iter1.dispose();
918
			set1.dispose();
919
		}
920

  
921
		int ntimes = getRandom().nextInt(10) + 5;
922
		FeatureType type = store.getDefaultFeatureType();
923
		query = this.getDefaultQuery(store);
924
		for (int i = 0; i < ntimes; i++) {
925
			names = getRandomAttibuteList(type);
926

  
927
			query.setAttributeNames(names);
928
			set1 = store.getFeatureSet(query);
929

  
930
			if (getRandom().nextBoolean()) {
931
				iter = set.fastIterator();
932
			} else {
933
				iter = set.iterator();
934
			}
935
			if (getRandom().nextBoolean()) {
936
				iter1 = set1.fastIterator();
937
			} else {
938
				iter1 = set1.iterator();
939
			}
940

  
941
			assertTrue(compareFeatureIterators(iter, iter1, names));
942

  
943
			iter.dispose();
944
			iter1.dispose();
945

  
946
			iter1 = set1.fastIterator();
947
			assertTrue(checksAttributesPositions(iter1, names));
948
			iter1.dispose();
949

  
950
			iter1 = set1.iterator();
951
			assertTrue(checksAttributesPositions(iter1, names));
952
			iter1.dispose();
953

  
954
			set1.dispose();
955

  
956

  
957
		}
958

  
959

  
960

  
961
		set.dispose();
962

  
963
	}
964

  
965
	protected boolean checksAttributesPositions(DisposableIterator iter,
966
			String[] names) {
967
		Feature feature;
968
		FeatureType type;
969
		FeatureAttributeDescriptor attr;
970
		while (iter.hasNext()) {
971
			feature = (Feature) iter.next();
972
			type = feature.getType();
973
			for (int i = 0; i < names.length; i++) {
974
				attr = type.getAttributeDescriptor(i);
975
				if (!names[i].equals(attr.getName())) {
976
					getLogger().error(
977
							"Error in attribute {} (expected: '{}' have: '{}'",
978
							new Object[] { new Integer(i), names[i],
979
									attr.getName() });
980
					return false;
981
				}
982
			}
983
		}
984
		return true;
985
	}
986

  
987
	 public void testPersistence() throws Exception {
988
		if (ToolsLocator.getPersistenceManager() == null) {
989
			fail("Default Persistence Manager not register");
990
		}
991
		DataStoreParameters params = this.getDefaultDataStoreParameters();
992

  
993
		FeatureStore store = (FeatureStore) dataManager.openStore(params
994
				.getDataStoreName(), params);
995

  
996
		testSimpleIteration(store);
997

  
998
		PersistentState state = ToolsLocator.getPersistenceManager().getState(
999
				store);
1000

  
1001
		FeatureStore store2 = (FeatureStore) ToolsLocator
1002
				.getPersistenceManager().create(state);
1003

  
1004
		testSimpleIteration(store2);
1005

  
1006
		assertTrue(compareStores(store, store2));
1007

  
1008
		store.dispose();
1009
		store2.dispose();
1010

  
1011
	}
1012

  
1013

  
1014
	public void testSort() throws Exception {
1015
		DataStoreParameters dbfParameters = this
1016
				.getDefaultDataStoreParameters();
1017

  
1018
		FeatureStore store = (FeatureStore) dataManager.openStore(dbfParameters
1019
				.getDataStoreName(), dbfParameters);
1020

  
1021
		testSort(store);
1022

  
1023
		store.dispose();
1024

  
1025
	}
1026

  
1027
	public void testSort(FeatureStore store) throws Exception{
1028
		FeatureSet set1;
1029
		FeatureQuery query;
1030
		DisposableIterator iter1;
1031
		Iterator attrIter;
1032
		FeatureAttributeDescriptor attr;
1033

  
1034
		attrIter = store.getDefaultFeatureType().iterator();
1035

  
1036
		String[] names;
1037
		while (attrIter.hasNext()) {
1038
			attr = (FeatureAttributeDescriptor) attrIter.next();
1039

  
1040
			if (attr.getType() == DataTypes.GEOMETRY) {
1041
				continue;
1042
			}
1043
			query = this.getDefaultQuery(store);
1044
			String fieldName = attr.getName();
1045

  
1046

  
1047

  
1048
			names = new String[] { fieldName };
1049
			query.setAttributeNames(names);
1050
			query.getOrder().add(fieldName, getRandom().nextBoolean());
1051

  
1052
			set1 = store.getFeatureSet(query);
1053
			if (getRandom().nextBoolean()) {
1054
				iter1 = set1.fastIterator();
1055
			} else {
1056
				iter1 = set1.iterator();
1057
			}
1058

  
1059
			assertTrue(checkSort(iter1, query));
1060

  
1061
			iter1.dispose();
1062
			set1.dispose();
1063
		}
1064

  
1065
		int ntimes = getRandom().nextInt(10) + 5;
1066
		FeatureType type = store.getDefaultFeatureType();
1067
		query = this.getDefaultQuery(store);
1068
		for (int i = 0; i < ntimes; i++) {
1069
			names = getRandomAttibuteList(type);
1070

  
1071
			int nShortFields = getRandom().nextInt(names.length) + 1;
1072
			query.getOrder().clear();
1073
			for (int j = 0; j < nShortFields; j++) {
1074
				attr = store.getDefaultFeatureType().getAttributeDescriptor(names[getRandom().nextInt(names.length)]);
1075
				if (attr.getType() == DataTypes.INT
1076
						|| attr.getType() == DataTypes.LONG
1077
						|| attr.getType() == DataTypes.DOUBLE
1078
						|| attr.getType() == DataTypes.STRING
1079
						|| attr.getType() == DataTypes.DATE
1080
						|| attr.getType() == DataTypes.BOOLEAN
1081
						|| attr.getType() == DataTypes.BYTE
1082
						|| attr.getType() == DataTypes.FLOAT) {
1083

  
1084
					query.getOrder().add(attr.getName(),
1085
							getRandom().nextBoolean());
1086
				}
1087
			}
1088

  
1089
			query.setAttributeNames(names);
1090
			set1 = store.getFeatureSet(query);
1091

  
1092
			// if (getRandom().nextBoolean()) {
1093
				iter1 = set1.fastIterator();
1094
				// } else {
1095
				// iter1 = set1.iterator();
1096
				// }
1097

  
1098
				assertTrue(checkSort(iter1, query));
1099

  
1100
				iter1.dispose();
1101
				set1.dispose();
1102

  
1103
		}
1104

  
1105
	}
1106

  
1107

  
1108
	public boolean checkSort(Iterator iter, FeatureQuery query) {
1109

  
1110
		FeatureQueryOrderMember order;
1111
		Feature prevFeature = null;
1112
		Feature currFeature = null;
1113
		boolean isFirst = true;
1114
		Comparable v1, v2;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff