01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library 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 GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.caching;
17:
18: import junit.framework.Test;
19: import junit.framework.TestCase;
20: import junit.framework.TestSuite;
21:
22: import org.geotools.caching.Generator;
23: import org.geotools.caching.InternalStore;
24: import org.geotools.caching.impl.HashMapInternalStore;
25: import org.geotools.caching.impl.SimpleHashMapInternalStore;
26:
27: import org.geotools.feature.Feature;
28:
29: import java.util.ArrayList;
30: import java.util.List;
31: import java.util.Random;
32:
33: public class InternalStoreTest extends TestCase {
34: public static Test suite() {
35: return new TestSuite(InternalStoreTest.class);
36: }
37:
38: public void testSimpleHashMapInternalStore() {
39: SimpleHashMapInternalStore simple = new SimpleHashMapInternalStore();
40: testStore(simple);
41: }
42:
43: public void testHashMapInternalStore() {
44: SimpleHashMapInternalStore simple = new SimpleHashMapInternalStore();
45: HashMapInternalStore hash = new HashMapInternalStore(100,
46: simple);
47: testStore(hash);
48: }
49:
50: protected void testStore(InternalStore tested) {
51: Random rand = new Random();
52: List features = new ArrayList();
53: Generator gen = new Generator(1000, 1000);
54:
55: for (int i = 0; i < 1000; i++) {
56: Feature f = gen.createFeature(i);
57: features.add(f);
58: tested.put(f);
59: }
60:
61: for (int i = 0; i < 10000; i++) {
62: int e = rand.nextInt(1000);
63: Feature f = (Feature) features.get(e);
64: Feature retrieved = tested.get(f.getID());
65: assertTrue(f.equals(retrieved));
66: }
67: }
68: }
|