Revision 36155
tags/v2_0_0_Build_2032/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 |
} |
tags/v2_0_0_Build_2032/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_2032/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_2032/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_2032/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_2032/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_2032/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_2032/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/paging/impl/OneSubsetOneSetPagingCalculatorTest.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 |
* 2010 {} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.dal.feature.paging.impl; |
|
28 |
|
|
29 |
import junit.framework.TestCase; |
|
30 |
|
|
31 |
import org.gvsig.tools.paging.PagingCalculator.Sizeable; |
|
32 |
|
|
33 |
/** |
|
34 |
* Unit tests for the {@link OneSubsetOneSetPagingCalculator} class. |
|
35 |
* |
|
36 |
* @author gvSIG team |
|
37 |
*/ |
|
38 |
public class OneSubsetOneSetPagingCalculatorTest extends |
|
39 |
TestCase { |
|
40 |
|
|
41 |
private static final int MAX_PAGE_SIZE = 4; |
|
42 |
|
|
43 |
private TestSizeable sizeable1 = new TestSizeable(6); |
|
44 |
private TestSizeable sizeable2 = new TestSizeable(17); |
|
45 |
|
|
46 |
private OneSubsetOneSetPagingCalculator calculator; |
|
47 |
|
|
48 |
protected void setUp() throws Exception { |
|
49 |
super.setUp(); |
|
50 |
calculator = |
|
51 |
new OneSubsetOneSetPagingCalculator(sizeable1, sizeable2, |
|
52 |
MAX_PAGE_SIZE); |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Test method for |
|
57 |
* {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getFirstSetSize()} |
|
58 |
* . |
|
59 |
*/ |
|
60 |
public void testGetFirstSetSize() { |
|
61 |
assertEquals(sizeable1.getSize(), calculator.getFirstSetSize()); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Test method for |
|
66 |
* {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getSecondSetSize()} |
|
67 |
* . |
|
68 |
*/ |
|
69 |
public void testGetSecondSetSize() { |
|
70 |
assertEquals(sizeable2.getSize() - sizeable1.getSize(), calculator.getSecondSetSize()); |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* Test method for |
|
75 |
* {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getFirstSetInitialIndex()} |
|
76 |
* . |
|
77 |
*/ |
|
78 |
public void testGetFirstSetInitialIndex() { |
|
79 |
calculator.setCurrentPage(0); |
|
80 |
assertEquals(0, calculator.getFirstSetInitialIndex()); |
|
81 |
|
|
82 |
calculator.setCurrentPage(1); |
|
83 |
assertEquals(0 + MAX_PAGE_SIZE, calculator.getFirstSetInitialIndex()); |
|
84 |
|
|
85 |
calculator.setCurrentPage(2); |
|
86 |
assertEquals(-1, calculator.getFirstSetInitialIndex()); |
|
87 |
|
|
88 |
calculator.setCurrentPage(3); |
|
89 |
assertEquals(-1, calculator.getFirstSetInitialIndex()); |
|
90 |
|
|
91 |
calculator.setCurrentPage(calculator.getNumPages() - 1); |
|
92 |
assertEquals(-1, calculator.getFirstSetInitialIndex()); |
|
93 |
|
|
94 |
// Change values so all data fits into a single page |
|
95 |
sizeable1.setSize(1l); |
|
96 |
sizeable2.setSize(15l); |
|
97 |
calculator.setMaxPageSize(20); |
|
98 |
|
|
99 |
calculator.setCurrentPage(0); |
|
100 |
assertEquals(0, calculator.getFirstSetInitialIndex()); |
|
101 |
} |
|
102 |
|
|
103 |
/** |
|
104 |
* Test method for |
|
105 |
* {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getSecondSetInitialIndex()} |
|
106 |
* . |
|
107 |
*/ |
|
108 |
public void testGetSecondSetInitialIndex() { |
|
109 |
calculator.setCurrentPage(0); |
|
110 |
assertEquals(-1, calculator.getSecondSetInitialIndex()); |
|
111 |
|
|
112 |
calculator.setCurrentPage(1); |
|
113 |
assertEquals(0, calculator.getSecondSetInitialIndex()); |
|
114 |
|
|
115 |
calculator.setCurrentPage(2); |
|
116 |
assertEquals(2, calculator.getSecondSetInitialIndex()); |
|
117 |
|
|
118 |
calculator.setCurrentPage(3); |
|
119 |
assertEquals(2 + MAX_PAGE_SIZE, calculator.getSecondSetInitialIndex()); |
|
120 |
|
|
121 |
calculator.setCurrentPage(calculator.getNumPages() - 1); |
|
122 |
assertEquals(2 + ((calculator.getNumPages() - 3) * MAX_PAGE_SIZE), |
|
123 |
calculator.getSecondSetInitialIndex()); |
|
124 |
|
|
125 |
// Change values so all data fits into a single page |
|
126 |
sizeable1.setSize(1l); |
|
127 |
sizeable2.setSize(15l); |
|
128 |
calculator.setMaxPageSize(20); |
|
129 |
|
|
130 |
calculator.setCurrentPage(0); |
|
131 |
assertEquals(0, calculator.getSecondSetInitialIndex()); |
|
132 |
|
|
133 |
// Set the two sets equal, so all elements in the first set are |
|
134 |
// contained in the second one |
|
135 |
sizeable1.setSize(15l); |
|
136 |
sizeable2.setSize(15l); |
|
137 |
calculator.setMaxPageSize(4); |
|
138 |
|
|
139 |
calculator.setCurrentPage(0); |
|
140 |
assertEquals(-1, calculator.getSecondSetInitialIndex()); |
|
141 |
|
|
142 |
calculator.setCurrentPage(1); |
|
143 |
assertEquals(-1, calculator.getSecondSetInitialIndex()); |
|
144 |
|
|
145 |
calculator.setCurrentPage(2); |
|
146 |
assertEquals(-1, calculator.getSecondSetInitialIndex()); |
|
147 |
|
|
148 |
calculator.setCurrentPage(3); |
|
149 |
assertEquals(-1, calculator.getSecondSetInitialIndex()); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Test method for |
|
154 |
* {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getFirstSetHowMany()} |
|
155 |
* . |
|
156 |
*/ |
|
157 |
public void testGetFirstSetHowMany() { |
|
158 |
calculator.setCurrentPage(0); |
|
159 |
assertEquals(MAX_PAGE_SIZE, calculator.getFirstSetHowMany()); |
|
160 |
|
|
161 |
calculator.setCurrentPage(1); |
|
162 |
assertEquals(2, calculator.getFirstSetHowMany()); |
|
163 |
|
|
164 |
calculator.setCurrentPage(2); |
|
165 |
assertEquals(0, calculator.getFirstSetHowMany()); |
|
166 |
|
|
167 |
calculator.setCurrentPage(3); |
|
168 |
assertEquals(0, calculator.getFirstSetHowMany()); |
|
169 |
|
|
170 |
calculator.setCurrentPage(calculator.getNumPages() - 1); |
|
171 |
assertEquals(0, calculator.getFirstSetHowMany()); |
|
172 |
|
|
173 |
// Change values so all data fits into a single page |
|
174 |
sizeable1.setSize(1l); |
|
175 |
sizeable2.setSize(15l); |
|
176 |
calculator.setMaxPageSize(20); |
|
177 |
|
|
178 |
calculator.setCurrentPage(0); |
|
179 |
assertEquals(1, calculator.getFirstSetHowMany()); |
|
180 |
|
|
181 |
// Change values so all data is available into the first set |
|
182 |
sizeable1.setSize(25l); |
|
183 |
sizeable2.setSize(25l); |
|
184 |
calculator.setMaxPageSize(20); |
|
185 |
|
|
186 |
calculator.setCurrentPage(0); |
|
187 |
assertEquals(20, calculator.getFirstSetHowMany()); |
|
188 |
|
|
189 |
calculator.setCurrentPage(1); |
|
190 |
assertEquals(5, calculator.getFirstSetHowMany()); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Test method for |
|
195 |
* {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getSecondSetHowMany()} |
|
196 |
* . |
|
197 |
*/ |
|
198 |
public void testGetSecondSetHowMany() { |
|
199 |
calculator.setCurrentPage(0); |
|
200 |
assertEquals(0l, calculator.getSecondSetHowMany()); |
|
201 |
|
|
202 |
calculator.setCurrentPage(1); |
|
203 |
assertEquals(2l, calculator.getSecondSetHowMany()); |
|
204 |
|
|
205 |
calculator.setCurrentPage(2); |
|
206 |
assertEquals(MAX_PAGE_SIZE, calculator.getSecondSetHowMany()); |
|
207 |
|
|
208 |
calculator.setCurrentPage(3); |
|
209 |
assertEquals(MAX_PAGE_SIZE, calculator.getSecondSetHowMany()); |
|
210 |
|
|
211 |
calculator.setCurrentPage(calculator.getNumPages() - 1); |
|
212 |
assertEquals(1l, calculator.getSecondSetHowMany()); |
|
213 |
|
|
214 |
// Change values so all data fits into a single page |
|
215 |
sizeable1.setSize(1l); |
|
216 |
sizeable2.setSize(15l); |
|
217 |
calculator.setMaxPageSize(20); |
|
218 |
|
|
219 |
calculator.setCurrentPage(0); |
|
220 |
assertEquals(14l, calculator.getSecondSetHowMany()); |
|
221 |
|
|
222 |
// Set the two sets equal, so all elements in the first set are |
|
223 |
// contained in the second one |
|
224 |
sizeable1.setSize(15l); |
|
225 |
sizeable2.setSize(15l); |
|
226 |
calculator.setMaxPageSize(4); |
|
227 |
|
|
228 |
calculator.setCurrentPage(0); |
|
229 |
assertEquals(0l, calculator.getSecondSetHowMany()); |
|
230 |
|
|
231 |
calculator.setCurrentPage(1); |
|
232 |
assertEquals(0l, calculator.getSecondSetHowMany()); |
|
233 |
|
|
234 |
calculator.setCurrentPage(2); |
|
235 |
assertEquals(0l, calculator.getSecondSetHowMany()); |
|
236 |
|
|
237 |
calculator.setCurrentPage(3); |
|
238 |
assertEquals(0l, calculator.getSecondSetHowMany()); |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* Test method for |
|
243 |
* {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#hasCurrentPageAllValuesInFirstSet()} |
|
244 |
* . |
|
245 |
*/ |
|
246 |
public void testHasCurrentPageAllValuesInFirstSet() { |
|
247 |
calculator.setCurrentPage(0); |
|
248 |
assertTrue(calculator.hasCurrentPageAllValuesInFirstSet()); |
|
249 |
|
|
250 |
calculator.setCurrentPage(1); |
|
251 |
assertFalse(calculator.hasCurrentPageAllValuesInFirstSet()); |
|
252 |
|
|
253 |
calculator.setCurrentPage(2); |
|
254 |
assertFalse(calculator.hasCurrentPageAllValuesInFirstSet()); |
|
255 |
|
|
256 |
calculator.setCurrentPage(3); |
|
257 |
assertFalse(calculator.hasCurrentPageAllValuesInFirstSet()); |
|
258 |
|
|
259 |
calculator.setCurrentPage(calculator.getNumPages() - 1); |
|
260 |
assertFalse(calculator.hasCurrentPageAllValuesInFirstSet()); |
|
261 |
|
|
262 |
// Change values so all data fits into a single page |
|
263 |
sizeable1.setSize(1l); |
|
264 |
sizeable2.setSize(15l); |
|
265 |
calculator.setMaxPageSize(20); |
|
266 |
|
|
267 |
calculator.setCurrentPage(0); |
|
268 |
assertFalse(calculator.hasCurrentPageAllValuesInFirstSet()); |
|
269 |
} |
|
270 |
|
|
271 |
/** |
|
272 |
* Test method for |
|
273 |
* {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#hasCurrentPageAnyValuesInFirstSet()} |
|
274 |
* . |
|
275 |
*/ |
|
276 |
public void testHasCurrentPageAnyValuesInFirstSet() { |
|
277 |
calculator.setCurrentPage(0); |
|
278 |
assertTrue(calculator.hasCurrentPageAnyValuesInFirstSet()); |
|
279 |
|
|
280 |
calculator.setCurrentPage(1); |
|
281 |
assertTrue(calculator.hasCurrentPageAnyValuesInFirstSet()); |
|
282 |
|
|
283 |
calculator.setCurrentPage(2); |
|
284 |
assertFalse(calculator.hasCurrentPageAnyValuesInFirstSet()); |
|
285 |
|
|
286 |
calculator.setCurrentPage(3); |
|
287 |
assertFalse(calculator.hasCurrentPageAnyValuesInFirstSet()); |
|
288 |
|
|
289 |
calculator.setCurrentPage(calculator.getNumPages() - 1); |
|
290 |
assertFalse(calculator.hasCurrentPageAnyValuesInFirstSet()); |
|
291 |
|
|
292 |
// Change values so all data fits into a single page |
|
293 |
sizeable1.setSize(1l); |
|
294 |
sizeable2.setSize(15l); |
|
295 |
calculator.setMaxPageSize(20); |
|
296 |
|
|
297 |
calculator.setCurrentPage(0); |
|
298 |
assertTrue(calculator.hasCurrentPageAnyValuesInFirstSet()); |
|
299 |
} |
|
300 |
|
|
301 |
/** |
|
302 |
* Test method for |
|
303 |
* {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#hasCurrentPageAnyValuesInSecondSet()} |
|
304 |
* . |
|
305 |
*/ |
|
306 |
public void testHasCurrentPageAnyValuesInSecondSet() { |
|
307 |
calculator.setCurrentPage(0); |
|
308 |
assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
309 |
|
|
310 |
calculator.setCurrentPage(1); |
|
311 |
assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
312 |
|
|
313 |
calculator.setCurrentPage(2); |
|
314 |
assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
315 |
|
|
316 |
calculator.setCurrentPage(3); |
|
317 |
assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
318 |
|
|
319 |
calculator.setCurrentPage(calculator.getNumPages() - 1); |
|
320 |
assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
321 |
|
|
322 |
// Change values so all data fits into a single page |
|
323 |
sizeable1.setSize(1l); |
|
324 |
sizeable2.setSize(15l); |
|
325 |
calculator.setMaxPageSize(20); |
|
326 |
|
|
327 |
calculator.setCurrentPage(0); |
|
328 |
assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
329 |
|
|
330 |
// Set the two sets equal, so all elements in the first set are |
|
331 |
// contained in the second one |
|
332 |
sizeable1.setSize(15l); |
|
333 |
sizeable2.setSize(15l); |
|
334 |
calculator.setMaxPageSize(4); |
|
335 |
|
|
336 |
calculator.setCurrentPage(0); |
|
337 |
assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
338 |
|
|
339 |
calculator.setCurrentPage(1); |
|
340 |
assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
341 |
|
|
342 |
calculator.setCurrentPage(2); |
|
343 |
assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
344 |
|
|
345 |
calculator.setCurrentPage(3); |
|
346 |
assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet()); |
|
347 |
} |
|
348 |
|
|
349 |
private class TestSizeable implements Sizeable { |
|
350 |
|
|
351 |
private long size; |
|
352 |
|
|
353 |
public TestSizeable(long size) { |
|
354 |
this.size = size; |
|
355 |
} |
|
356 |
|
|
357 |
public long getSize() { |
|
358 |
return size; |
|
359 |
} |
|
360 |
|
|
361 |
public void setSize(long size) { |
|
362 |
this.size = size; |
|
363 |
} |
|
364 |
} |
|
365 |
} |
tags/v2_0_0_Build_2032/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 |
} |
tags/v2_0_0_Build_2032/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/BaseTestEditableFeatureStore.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.Iterator; |
|
34 |
|
|
35 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
36 |
import org.gvsig.fmap.dal.DataStore; |
|
37 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
38 |
import org.gvsig.fmap.dal.DataTypes; |
|
39 |
import org.gvsig.fmap.dal.exception.DataException; |
|
40 |
import org.gvsig.fmap.dal.exception.RemoveException; |
|
41 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
42 |
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException; |
|
43 |
import org.gvsig.fmap.dal.feature.testmulithread.DeleteFirstAndLastFeature; |
|
44 |
import org.gvsig.fmap.dal.feature.testmulithread.DeleteLastFeature; |
|
45 |
import org.gvsig.fmap.dal.feature.testmulithread.InsertFeature; |
|
46 |
import org.gvsig.fmap.dal.feature.testmulithread.StoreTask; |
|
47 |
import org.gvsig.fmap.dal.feature.testmulithread.UpdateFeature; |
|
48 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
49 |
import org.gvsig.tools.evaluator.AbstractEvaluator; |
|
50 |
import org.gvsig.tools.evaluator.Evaluator; |
|
51 |
import org.gvsig.tools.evaluator.EvaluatorData; |
|
52 |
import org.gvsig.tools.evaluator.EvaluatorException; |
|
53 |
import org.gvsig.tools.evaluator.EvaluatorFieldValue; |
|
54 |
import org.gvsig.tools.observer.Observable; |
|
55 |
import org.gvsig.tools.observer.Observer; |
|
56 |
|
|
57 |
/** |
|
58 |
* @author jmvivo |
|
59 |
* |
|
60 |
*/ |
|
61 |
public abstract class BaseTestEditableFeatureStore extends BaseTestFeatureStore { |
|
62 |
|
|
63 |
public abstract NewFeatureStoreParameters getDefaultNewDataStoreParameters() |
|
64 |
throws Exception; |
|
65 |
|
|
66 |
public abstract boolean resourcesNotifyChanges(); |
|
67 |
|
|
68 |
//================================================= |
|
69 |
//================================================= |
|
70 |
|
|
71 |
|
|
72 |
public void fillPrimaryKeyInserFeature(EditableFeature feature) { |
|
73 |
return; |
|
74 |
} |
|
75 |
|
|
76 |
protected Evaluator getEvaluatorToLower(String attibuteName) { |
|
77 |
return new ToLower(attibuteName); |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
protected Evaluator getEvaluatorToUpper(String attibuteName) { |
|
82 |
return new ToUpper(attibuteName); |
|
83 |
} |
|
84 |
|
|
85 |
public class ToLower extends AbstractEvaluator { |
|
86 |
private String attributeName; |
|
87 |
|
|
88 |
public ToLower(String attrName) { |
|
89 |
this.attributeName = attrName; |
|
90 |
this.getFieldsInfo().addFieldValue(this.attributeName); |
|
91 |
} |
|
92 |
|
|
93 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
|
94 |
String value = (String) data.getDataValue(this.attributeName); |
|
95 |
if (value == null) { |
|
96 |
return null; |
|
97 |
} |
|
98 |
return value.toLowerCase(); |
|
99 |
} |
|
100 |
|
|
101 |
public String getSQL() { |
|
102 |
return null; |
|
103 |
} |
|
104 |
|
|
105 |
public String getDescription() { |
|
106 |
return null; |
|
107 |
} |
|
108 |
|
|
109 |
public String getName() { |
|
110 |
return null; |
|
111 |
} |
|
112 |
|
|
113 |
} |
|
114 |
|
|
115 |
public class ToUpper extends AbstractEvaluator { |
|
116 |
private String attributeName; |
|
117 |
|
|
118 |
public ToUpper(String attrName) { |
|
119 |
this.attributeName = attrName; |
|
120 |
this.getFieldsInfo().addFieldValue(this.attributeName); |
|
121 |
} |
|
122 |
|
|
123 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
|
124 |
String value = (String) data.getDataValue(this.attributeName); |
|
125 |
if (value == null) { |
|
126 |
return null; |
|
127 |
} |
|
128 |
return value.toUpperCase(); |
|
129 |
} |
|
130 |
|
|
131 |
public String getSQL() { |
|
132 |
return null; |
|
133 |
} |
|
134 |
|
|
135 |
public String getDescription() { |
|
136 |
return null; |
|
137 |
} |
|
138 |
|
|
139 |
public EvaluatorFieldValue[] getFieldValues(String name) { |
|
140 |
return null; |
|
141 |
} |
|
142 |
|
|
143 |
public String getName() { |
|
144 |
return null; |
|
145 |
} |
|
146 |
|
|
147 |
} |
|
148 |
|
|
149 |
protected FeatureStore getStoreCopy(FeatureStore source, |
|
150 |
NewFeatureStoreParameters targetParams) throws DataException, |
|
151 |
ValidateDataParametersException { |
|
152 |
DataServerExplorer explorer = source.getExplorer(); |
|
153 |
source.export(explorer, source.getProviderName(), targetParams); |
|
154 |
FeatureStore result = (FeatureStore) dataManager.openStore(source.getProviderName(), targetParams); |
|
155 |
|
|
156 |
return result; |
|
157 |
} |
|
158 |
|
|
159 |
protected void clearCopy(FeatureStore source, |
|
160 |
NewFeatureStoreParameters targetParams) throws Exception { |
|
161 |
DataServerExplorer explorer = source.getExplorer(); |
|
162 |
explorer.remove(targetParams); |
|
163 |
|
|
164 |
} |
|
165 |
|
|
166 |
protected boolean compareFeatures(Feature f1, Feature f2, |
|
167 |
String[] attrsNames, UpdateFeature updated, long index, |
|
168 |
long lastIndex) throws DataException, EvaluatorException { |
|
169 |
FeatureAttributeDescriptor attr1; |
|
170 |
FeatureAttributeDescriptor attr2; |
|
171 |
EditableFeature f2e = f2.getEditable(); |
|
172 |
updated.applyUpdateList(f2e, index, lastIndex); |
|
173 |
|
|
174 |
Object v1, v2; |
|
175 |
for (int i = 0; i < attrsNames.length; i++) { |
|
176 |
attr1 = f1.getType().getAttributeDescriptor(attrsNames[i]); |
|
177 |
attr2 = f2e.getType().getAttributeDescriptor(attrsNames[i]); |
|
178 |
if (attr1 != attr2) { |
|
179 |
if (!compareAttributes(attr1, attr1)) { |
|
180 |
return false; |
|
181 |
} |
|
182 |
} |
|
183 |
v1 = f1.get(attr1.getName()); |
|
184 |
v2 = f2.get(attr2.getName()); |
|
185 |
if (!compareFeatureValue(v1, v2, attr1)) { |
|
186 |
return false; |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
return true; |
|
191 |
} |
|
192 |
|
|
193 |
protected boolean compareFeatures(Feature f1, Feature f2, |
|
194 |
UpdateFeature updated, long index, long lastIndex) |
|
195 |
throws DataException, EvaluatorException { |
|
196 |
if (!compareTypes(f1.getType(), f2.getType())) { |
|
197 |
System.out.println("compareFeatures() type !="); |
|
198 |
return false; |
|
199 |
} |
|
200 |
Iterator iter = f1.getType().iterator(); |
|
201 |
FeatureAttributeDescriptor attr; |
|
202 |
EditableFeature f1e = f1.getEditable(); |
|
203 |
updated.applyUpdateList(f1e, index, lastIndex); |
|
204 |
Object v1, v2; |
|
205 |
while (iter.hasNext()) { |
|
206 |
attr = (FeatureAttributeDescriptor) iter.next(); |
|
207 |
v1 = f1e.get(attr.getName()); |
|
208 |
v2 = f2.get(attr.getName()); |
|
209 |
if (!compareFeatureValue(v1, v2, attr)) { |
|
210 |
return false; |
|
211 |
} |
|
212 |
} |
|
213 |
|
|
214 |
|
|
215 |
return true; |
|
216 |
|
|
217 |
} |
|
218 |
|
|
219 |
|
|
220 |
//--------------- |
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
//================================================= |
|
226 |
//================================================= |
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
public void testExport() throws Exception { |
|
232 |
DataStoreParameters parameters = null; |
|
233 |
|
|
234 |
parameters = getDefaultDataStoreParameters(); |
|
235 |
|
|
236 |
FeatureStore store = (FeatureStore) dataManager.createStore(parameters); |
|
237 |
|
|
238 |
NewFeatureStoreParameters newParams = this |
|
239 |
.getDefaultNewDataStoreParameters(); |
|
240 |
try { |
|
241 |
this.clearCopy(store, newParams); |
|
242 |
} catch (RemoveException e) { |
|
243 |
// Dp nothing |
|
244 |
} |
|
245 |
|
|
246 |
FeatureStore result = this.getStoreCopy(store, newParams); |
|
247 |
|
|
248 |
fullStoreIteratorTest(result); |
|
249 |
|
|
250 |
FeatureSet set; |
|
251 |
FeatureSet originalSet; |
|
252 |
if (result.getDefaultFeatureType().getPrimaryKey() != null |
|
253 |
&& result.getDefaultFeatureType().getPrimaryKey().length > 0) { |
|
254 |
FeatureQuery queryR = result.createFeatureQuery(); |
|
255 |
FeatureQuery queryO = store.createFeatureQuery(); |
|
256 |
FeatureAttributeDescriptor[] pk = result.getDefaultFeatureType() |
|
257 |
.getPrimaryKey(); |
|
258 |
for (int i = 0; i < pk.length; i++) { |
|
259 |
queryO.getOrder().add(pk[i].getName(), true); |
|
260 |
queryR.getOrder().add(pk[i].getName(), true); |
|
261 |
} |
|
262 |
|
|
263 |
|
|
264 |
set = result.getFeatureSet(queryR); |
|
265 |
originalSet = store.getFeatureSet(queryO); |
|
266 |
|
|
267 |
|
|
268 |
} else { |
|
269 |
set = result.getFeatureSet(); |
|
270 |
originalSet = store.getFeatureSet(); |
|
271 |
} |
|
272 |
assertEquals(set.getSize(), originalSet.getSize()); |
|
273 |
|
|
274 |
DisposableIterator originalIter = originalSet.iterator(); |
|
275 |
DisposableIterator iter = set.iterator(); |
|
276 |
assertTrue(compareFeatureIterators(originalIter, iter)); |
|
277 |
originalIter.dispose(); |
|
278 |
iter.dispose(); |
|
279 |
|
|
280 |
if (store.getEnvelope() != result.getEnvelope()) { |
|
281 |
if (store.getEnvelope() != null) { |
|
282 |
assertTrue(store.getEnvelope().equals(result.getEnvelope())); |
|
283 |
} else { |
|
284 |
fail("Envelope: src=" + store.getEnvelope() + " traget=" |
|
285 |
+ store.getEnvelope()); |
|
286 |
} |
|
287 |
} |
|
288 |
|
|
289 |
set.dispose(); |
|
290 |
originalSet.dispose(); |
|
291 |
|
|
292 |
result.dispose(); |
|
293 |
this.clearCopy(store, newParams); |
|
294 |
store.dispose(); |
|
295 |
|
|
296 |
} |
|
297 |
|
|
298 |
public void testRemove() throws Exception { |
|
299 |
DataStoreParameters parameters = null; |
|
300 |
|
|
301 |
parameters = getDefaultDataStoreParameters(); |
|
302 |
|
|
303 |
FeatureStore store = (FeatureStore) dataManager.createStore(parameters); |
|
304 |
|
|
305 |
NewFeatureStoreParameters newParams = this |
|
306 |
.getDefaultNewDataStoreParameters(); |
|
307 |
try { |
|
308 |
this.clearCopy(store, newParams); |
|
309 |
} catch (RemoveException e) { |
|
310 |
// Dp nothing |
|
311 |
} |
|
312 |
|
|
313 |
FeatureStore result = this.getStoreCopy(store, newParams); |
|
314 |
|
|
315 |
result.edit(FeatureStore.MODE_FULLEDIT); |
|
316 |
|
|
317 |
FeatureSet set = result.getFeatureSet(getDefaultQuery(result)); |
|
318 |
FeatureSet originalSet = store.getFeatureSet(getDefaultQuery(store)); |
|
319 |
assertEquals(set.getSize(), originalSet.getSize()); |
|
320 |
|
|
321 |
DisposableIterator originalIter = originalSet.iterator(); |
|
322 |
DisposableIterator iter = set.iterator(); |
|
323 |
int i = 0; |
|
324 |
while (iter.hasNext()) { |
|
325 |
assertTrue("" + i, compareFeatures((Feature) originalIter.next(), |
|
326 |
(Feature) iter.next())); |
|
327 |
i++; |
|
328 |
} |
|
329 |
|
|
330 |
iter.remove(); |
|
331 |
|
|
332 |
|
|
333 |
assertEquals(originalSet.getSize() - 1, set.getSize()); |
|
334 |
|
|
335 |
iter.dispose(); |
|
336 |
originalIter.dispose(); |
|
337 |
|
|
338 |
|
|
339 |
originalIter = originalSet.iterator(); |
|
340 |
iter = set.iterator(); |
|
341 |
i = 0; |
|
342 |
while (iter.hasNext()) { |
|
343 |
assertTrue("" + i, compareFeatures((Feature) originalIter.next(), |
|
344 |
(Feature) iter.next())); |
|
345 |
i++; |
|
346 |
} |
|
347 |
|
|
348 |
iter.remove(); |
|
349 |
|
|
350 |
assertEquals(originalSet.getSize() - 2, set.getSize()); |
|
351 |
|
|
352 |
iter.dispose(); |
|
353 |
originalIter.dispose(); |
|
354 |
|
|
355 |
set.dispose(); |
|
356 |
|
|
357 |
result.finishEditing(); |
|
358 |
|
|
359 |
set = result.getFeatureSet(); |
|
360 |
assertEquals(originalSet.getSize() - 2, set.getSize()); |
|
361 |
|
|
362 |
originalIter = originalSet.iterator(); |
|
363 |
iter = set.iterator(); |
|
364 |
i = 0; |
|
365 |
while (iter.hasNext()) { |
|
366 |
assertTrue("" + i, compareFeatures((Feature) originalIter.next(), |
|
367 |
(Feature) iter.next())); |
|
368 |
i++; |
|
369 |
} |
|
370 |
|
|
371 |
iter.dispose(); |
|
372 |
originalIter.dispose(); |
|
373 |
|
|
374 |
|
|
375 |
set.dispose(); |
|
376 |
originalSet.dispose(); |
|
377 |
|
|
378 |
result.dispose(); |
|
379 |
this.clearCopy(store, newParams); |
|
380 |
store.dispose(); |
|
381 |
|
|
382 |
|
|
383 |
} |
|
384 |
|
|
385 |
public void testInsert() throws Exception { |
|
386 |
DataStoreParameters parameters = null; |
|
387 |
|
|
388 |
parameters = getDefaultDataStoreParameters(); |
|
389 |
|
|
390 |
|
|
391 |
FeatureStore store = (FeatureStore) dataManager |
|
392 |
.createStore(parameters); |
|
393 |
|
|
394 |
NewFeatureStoreParameters newParams = this |
|
395 |
.getDefaultNewDataStoreParameters(); |
|
396 |
try { |
|
397 |
this.clearCopy(store, newParams); |
|
398 |
} catch (RemoveException e) { |
|
399 |
//Do nothing |
|
400 |
} |
|
401 |
|
|
402 |
FeatureStore result = this.getStoreCopy(store, newParams); |
|
403 |
|
|
404 |
result.edit(FeatureStore.MODE_FULLEDIT); |
|
405 |
|
|
406 |
FeatureSet set = result.getFeatureSet(getDefaultQuery(result)); |
|
407 |
FeatureSet originalSet = store.getFeatureSet(getDefaultQuery(store)); |
|
408 |
assertEquals(set.getSize(), originalSet.getSize()); |
|
409 |
|
|
410 |
EditableFeature newFeature = result.createNewFeature(true); |
|
411 |
fillPrimaryKeyInserFeature(newFeature); |
|
412 |
set.insert(newFeature); |
|
413 |
DisposableIterator originalIter = originalSet.iterator(); |
|
414 |
DisposableIterator iter = set.iterator(); |
|
415 |
int i = 0; |
|
416 |
while (originalIter.hasNext()) { |
|
417 |
assertTrue("" + i, compareFeatures((Feature) originalIter |
|
418 |
.next(), (Feature) iter.next())); |
|
419 |
i++; |
|
420 |
} |
|
421 |
assertTrue(iter.hasNext()); |
|
422 |
assertNotNull(iter.next()); |
|
423 |
assertFalse(iter.hasNext()); |
|
424 |
|
|
425 |
assertEquals(originalSet.getSize() + 1, set.getSize()); |
|
426 |
|
|
427 |
iter.dispose(); |
|
428 |
originalIter.dispose(); |
|
429 |
|
|
430 |
originalIter = originalSet.iterator(); |
|
431 |
iter = set.iterator(); |
|
432 |
i = 0; |
|
433 |
while (originalIter.hasNext()) { |
|
434 |
assertTrue("" + i, compareFeatures((Feature) originalIter |
|
435 |
.next(), (Feature) iter.next())); |
|
436 |
i++; |
|
437 |
} |
|
438 |
assertTrue(iter.hasNext()); |
|
439 |
assertNotNull(iter.next()); |
|
440 |
|
|
441 |
newFeature = result.createNewFeature(true); |
|
442 |
fillPrimaryKeyInserFeature(newFeature); |
|
443 |
set.insert(newFeature); |
|
444 |
|
|
445 |
assertEquals(originalSet.getSize() + 2, set.getSize()); |
|
446 |
|
|
447 |
iter.dispose(); |
|
448 |
originalIter.dispose(); |
|
449 |
|
|
450 |
set.dispose(); |
|
451 |
|
|
452 |
result.finishEditing(); |
|
453 |
|
|
454 |
set = result.getFeatureSet(); |
|
455 |
assertEquals(originalSet.getSize() + 2, set.getSize()); |
|
456 |
|
|
457 |
originalIter = originalSet.iterator(); |
|
458 |
iter = set.iterator(); |
|
459 |
i = 0; |
|
460 |
while (originalIter.hasNext()) { |
|
461 |
assertTrue("" + i, compareFeatures((Feature) originalIter |
|
462 |
.next(), (Feature) iter.next())); |
|
463 |
i++; |
|
464 |
} |
|
465 |
|
|
466 |
assertNotNull(iter.next()); |
|
467 |
assertNotNull(iter.next()); |
|
468 |
assertFalse(iter.hasNext()); |
|
469 |
|
|
470 |
iter.dispose(); |
|
471 |
originalIter.dispose(); |
|
472 |
|
|
473 |
set.dispose(); |
|
474 |
originalSet.dispose(); |
|
475 |
|
|
476 |
result.dispose(); |
|
477 |
this.clearCopy(store, newParams); |
|
478 |
store.dispose(); |
|
479 |
|
|
480 |
|
|
481 |
} |
|
482 |
|
|
483 |
|
|
484 |
|
|
485 |
public void testConcurrentRemove() throws Exception { |
|
486 |
DataStoreParameters parameters = null; |
|
487 |
|
|
488 |
parameters = getDefaultDataStoreParameters(); |
|
489 |
|
|
490 |
|
|
491 |
FeatureStore store = (FeatureStore) dataManager.createStore(parameters); |
|
492 |
|
|
493 |
NewFeatureStoreParameters newParams = this |
|
494 |
.getDefaultNewDataStoreParameters(); |
|
495 |
try { |
|
496 |
this.clearCopy(store, newParams); |
|
497 |
} catch (RemoveException e) { |
|
498 |
// Dp nothing |
|
499 |
} |
|
500 |
|
|
501 |
FeatureStore result = this.getStoreCopy(store, newParams); |
|
502 |
|
|
503 |
result.edit(FeatureStore.MODE_FULLEDIT); |
|
504 |
|
|
505 |
DeleteFirstAndLastFeature deleteFeature = new DeleteFirstAndLastFeature( |
|
506 |
"1", result, StoreTask.TIME_TO_WAIT_NO_WAIT); |
|
507 |
|
|
508 |
FeatureSet set = result.getFeatureSet(); |
|
509 |
|
|
510 |
DisposableIterator iter = set.iterator(); |
|
511 |
assertTrue(iter.hasNext()); |
|
512 |
assertNotNull(iter.next()); |
|
513 |
|
|
514 |
deleteFeature.start(); |
|
515 |
|
|
516 |
while (deleteFeature.getCurrentStatus() <= StoreTask.STATUS_RUNING) { |
|
517 |
Thread.yield(); |
|
518 |
Thread.sleep(100); |
|
519 |
if (deleteFeature.isOutOfDate()) { |
|
520 |
break; |
|
521 |
} |
|
522 |
} |
|
523 |
|
|
524 |
assertEquals(deleteFeature.getCurrentStatus(), |
|
525 |
StoreTask.STATUS_FINISHED_OK); |
|
526 |
|
|
527 |
Exception ex = null; |
|
528 |
try { |
|
529 |
iter.next(); |
|
530 |
} catch (Exception e) { |
|
531 |
ex = e; |
|
532 |
} |
|
533 |
assertNotNull(ex); |
|
534 |
assertEquals(ConcurrentDataModificationException.class, ex.getClass()); |
|
535 |
|
|
536 |
ex = null; |
|
537 |
try { |
|
538 |
set.getSize(); |
|
539 |
} catch (Exception e) { |
|
540 |
ex = e; |
|
541 |
} |
|
542 |
assertNotNull(ex); |
|
543 |
assertEquals(ConcurrentDataModificationException.class, ex.getClass()); |
|
544 |
|
|
545 |
iter.dispose(); |
|
546 |
result.dispose(); |
|
547 |
this.clearCopy(store, newParams); |
|
548 |
store.dispose(); |
|
549 |
|
|
550 |
} |
|
551 |
|
|
552 |
public void testConcurrentInsert() throws Exception{ |
|
553 |
DataStoreParameters parameters = null; |
|
554 |
|
|
555 |
parameters = getDefaultDataStoreParameters(); |
|
556 |
|
|
557 |
|
|
558 |
FeatureStore store = (FeatureStore) dataManager.createStore(parameters); |
|
559 |
|
|
560 |
NewFeatureStoreParameters newParams = this |
|
561 |
.getDefaultNewDataStoreParameters(); |
|
562 |
try { |
|
563 |
this.clearCopy(store, newParams); |
|
564 |
} catch (RemoveException e) { |
|
565 |
// Dp nothing |
|
566 |
} |
|
567 |
|
|
568 |
FeatureStore result = this.getStoreCopy(store, newParams); |
|
569 |
|
|
570 |
result.edit(FeatureStore.MODE_FULLEDIT); |
|
571 |
|
|
572 |
InsertFeature insertFeature = new InsertFeature("1", result, |
|
573 |
StoreTask.TIME_TO_WAIT_NO_WAIT, this); |
|
574 |
|
|
575 |
FeatureSet set = result.getFeatureSet(); |
|
576 |
|
|
577 |
DisposableIterator iter = set.iterator(); |
|
578 |
assertTrue(iter.hasNext()); |
|
579 |
assertNotNull(iter.next()); |
|
580 |
|
|
581 |
insertFeature.start(); |
|
582 |
|
|
583 |
while (insertFeature.getCurrentStatus() <= StoreTask.STATUS_RUNING) { |
|
584 |
Thread.yield(); |
|
585 |
Thread.sleep(100); |
|
586 |
if (insertFeature.isOutOfDate()) { |
|
587 |
break; |
|
588 |
} |
|
589 |
} |
|
590 |
|
|
591 |
assertEquals(StoreTask.STATUS_FINISHED_OK, insertFeature |
|
592 |
.getCurrentStatus()); |
|
593 |
|
|
594 |
Exception ex = null; |
|
595 |
try { |
|
596 |
iter.next(); |
|
597 |
} catch (Exception e) { |
|
598 |
ex = e; |
|
599 |
} |
|
600 |
assertNotNull(ex); |
|
601 |
assertEquals(ConcurrentDataModificationException.class, ex.getClass()); |
|
602 |
|
|
603 |
ex = null; |
|
604 |
try { |
|
605 |
set.getSize(); |
|
606 |
} catch (Exception e) { |
|
607 |
ex = e; |
|
608 |
} |
|
609 |
assertNotNull(ex); |
|
610 |
assertEquals(ConcurrentDataModificationException.class, ex.getClass()); |
|
611 |
|
|
612 |
iter.dispose(); |
|
613 |
result.dispose(); |
|
614 |
this.clearCopy(store, newParams); |
|
615 |
store.dispose(); |
|
616 |
} |
|
617 |
|
|
618 |
public void testConcurrentUpdate() throws Exception { |
|
619 |
DataStoreParameters parameters = null; |
|
620 |
|
|
621 |
parameters = getDefaultDataStoreParameters(); |
|
622 |
|
|
623 |
|
|
624 |
FeatureStore store = (FeatureStore) dataManager.createStore(parameters); |
|
625 |
|
|
626 |
NewFeatureStoreParameters newParams = this |
|
627 |
.getDefaultNewDataStoreParameters(); |
|
628 |
try { |
|
629 |
this.clearCopy(store, newParams); |
|
630 |
} catch (RemoveException e) { |
|
631 |
// Dp nothing |
|
632 |
} |
|
633 |
|
|
634 |
FeatureStore result = this.getStoreCopy(store, newParams); |
|
635 |
|
|
636 |
|
|
637 |
result.edit(FeatureStore.MODE_FULLEDIT); |
|
638 |
|
|
639 |
UpdateFeature updateFeature = new UpdateFeature("1", result, |
|
640 |
StoreTask.TIME_TO_WAIT_NO_WAIT); |
|
641 |
|
|
642 |
FeatureType fType = result.getDefaultFeatureType(); |
|
643 |
FeatureAttributeDescriptor attr; |
|
644 |
Iterator fTypeIter = fType.iterator(); |
|
645 |
String attrName = null; |
|
646 |
while (fTypeIter.hasNext()){ |
|
647 |
attr = (FeatureAttributeDescriptor) fTypeIter.next(); |
|
648 |
if (attr.getType() == DataTypes.STRING && !attr.isReadOnly() && !attr.isPrimaryKey() && !attr.isAutomatic()){ |
|
649 |
attrName= attr.getName(); |
|
650 |
} |
|
651 |
} |
|
652 |
if (attrName == null) { |
|
653 |
fail("This test needs an normal attribute String (no Pk, no ReadOnly & no Auto)"); |
|
654 |
return; |
|
655 |
} |
|
656 |
|
|
657 |
|
|
658 |
updateFeature.addUpdate(UpdateFeature.UPDATE_ALL_FEATURES, attrName, |
|
659 |
"XXX"); |
|
660 |
|
|
661 |
FeatureSet set = result.getFeatureSet(); |
|
662 |
|
|
663 |
DisposableIterator iter = set.iterator(); |
|
664 |
assertTrue(iter.hasNext()); |
|
665 |
assertNotNull(iter.next()); |
|
666 |
|
|
667 |
updateFeature.start(); |
|
668 |
|
|
669 |
while (updateFeature.getCurrentStatus() <= StoreTask.STATUS_RUNING) { |
|
670 |
Thread.yield(); |
|
671 |
Thread.sleep(100); |
|
672 |
if (updateFeature.isOutOfDate()) { |
|
673 |
break; |
|
674 |
} |
|
675 |
} |
|
676 |
|
|
677 |
assertEquals(StoreTask.STATUS_FINISHED_OK, updateFeature |
|
678 |
.getCurrentStatus()); |
|
679 |
|
|
680 |
Exception ex = null; |
|
681 |
try { |
|
682 |
iter.next(); |
|
683 |
} catch (Exception e) { |
|
684 |
ex = e; |
|
685 |
} |
|
686 |
assertNotNull(ex); |
|
687 |
assertEquals(ConcurrentDataModificationException.class, ex.getClass()); |
|
688 |
|
|
689 |
ex = null; |
|
690 |
try { |
|
691 |
set.getSize(); |
|
692 |
} catch (Exception e) { |
|
693 |
ex = e; |
|
694 |
} |
|
695 |
assertNotNull(ex); |
|
696 |
assertEquals(ConcurrentDataModificationException.class, ex.getClass()); |
|
697 |
|
|
698 |
iter.dispose(); |
|
699 |
result.dispose(); |
|
700 |
this.clearCopy(store, newParams); |
|
701 |
store.dispose(); |
|
702 |
|
|
703 |
|
|
704 |
|
Also available in: Unified diff