Revision 39309

View differences:

tags/v2_0_0_Build_2059/libraries/libFMap_dal/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
6

  
7
	<modelVersion>4.0.0</modelVersion>
8
	<artifactId>org.gvsig.fmap.dal</artifactId>
9
	<name>libFMap_dal</name>
10
	<version>2.0-SNAPSHOT</version>
11
    <parent>
12
        <artifactId>gvsig-base-library-pom</artifactId>
13
        <groupId>org.gvsig</groupId>
14
        <version>2.0-SNAPSHOT</version>
15
    </parent>   
16
	<dependencies>
17
		<dependency>
18
			<groupId>org.gvsig</groupId>
19
			<artifactId>org.gvsig.tools.lib</artifactId>
20
            <scope>compile</scope>
21
		</dependency>
22
        <dependency>
23
            <groupId>org.gvsig</groupId>
24
            <artifactId>org.gvsig.compat</artifactId>
25
            <scope>compile</scope>
26
        </dependency>
27
		<dependency>
28
			<groupId>org.gvsig</groupId>
29
			<artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
30
            <scope>compile</scope>
31
		</dependency>
32
        <dependency>
33
            <groupId>org.gvsig</groupId>
34
            <artifactId>org.gvsig.i18n</artifactId>
35
            <scope>compile</scope>
36
        </dependency>
37
		<dependency>
38
			<groupId>org.gvsig</groupId>
39
			<artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
40
			<scope>runtime</scope>
41
		</dependency>
42
		<dependency>
43
			<groupId>org.gvsig</groupId>
44
			<artifactId>org.gvsig.projection</artifactId>
45
            <scope>compile</scope>
46
		</dependency>
47
		<dependency>
48
			<groupId>org.gvsig</groupId>
49
			<artifactId>org.gvsig.fmap.geometry</artifactId>
50
            <scope>compile</scope>
51
		</dependency>
52
		<dependency>
53
            <groupId>org.gvsig</groupId>
54
            <artifactId>org.gvsig.timesupport.lib.api</artifactId>
55
            <scope>compile</scope>
56
        </dependency>
57
        <dependency>
58
            <groupId>org.slf4j</groupId>
59
            <artifactId>slf4j-api</artifactId>
60
            <scope>compile</scope>
61
        </dependency>
62
		<dependency>
63
			<groupId>easymock</groupId>
64
			<artifactId>easymock</artifactId>
65
			<version>1.2_Java1.3</version>
66
			<scope>test</scope>
67
		</dependency>
68
        <dependency>
69
            <groupId>easymock</groupId>
70
            <artifactId>easymockclassextension</artifactId>
71
            <version>1.2</version>
72
            <scope>test</scope>
73
        </dependency>
74
        <dependency>
75
            <groupId>xmlpull</groupId>
76
            <artifactId>xmlpull</artifactId>
77
            <scope>compile</scope>
78
        </dependency>
79
		<!-- Implementation dependencies for TESTS -->
80
		<dependency>
81
			<groupId>org.gvsig</groupId>
82
			<artifactId>org.gvsig.tools.lib</artifactId>
83
			<type>test-jar</type>
84
		</dependency>
85
        <dependency>
86
            <groupId>org.gvsig</groupId>
87
            <artifactId>org.gvsig.compat</artifactId>
88
            <classifier>se</classifier>
89
            <scope>test</scope>
90
        </dependency>
91
		<dependency>
92
			<groupId>org.gvsig</groupId>
93
			<artifactId>org.gvsig.fmap.geometry</artifactId>
94
			<classifier>impl</classifier>
95
			<scope>test</scope>
96
		</dependency>
97
	</dependencies>
98
	<properties>
99
		<build-dir>${basedir}/../build</build-dir>
100
        <eclipse.project.name>libFMap_dal</eclipse.project.name>
101
	</properties>
102
	
103
	<profiles>
104
		<profile>
105
			<id>se</id>
106
			<activation>
107
				<activeByDefault>true</activeByDefault>
108
			</activation>
109
			<dependencies>
110
				<!-- TESTS -->
111
				<dependency>
112
					<groupId>org.gvsig</groupId>
113
					<artifactId>org.gvsig.fmap.geometry</artifactId>
114
					<classifier>operation</classifier>
115
					<scope>test</scope>
116
				</dependency>
117
				<dependency>
118
					<groupId>org.gvsig</groupId>
119
					<artifactId>org.gvsig.projection</artifactId>
120
					<classifier>cresques-impl</classifier>
121
					<scope>test</scope>
122
				</dependency>
123
				<dependency>
124
					<groupId>org.geotools</groupId>
125
					<artifactId>gt2-legacy</artifactId>
126
					<scope>test</scope>
127
				</dependency>
128
				<dependency>
129
					<groupId>org.geotools</groupId>
130
					<artifactId>gt2-main</artifactId>
131
					<scope>test</scope>
132
				</dependency>
133
				<dependency>
134
					<groupId>org.opengis</groupId>
135
				    <artifactId>geoapi</artifactId>
136
					<scope>test</scope>
137
				</dependency>
138
				<dependency>
139
					<groupId>javax.media</groupId>
140
					<artifactId>jai_core</artifactId>
141
					<scope>test</scope>
142
				</dependency>
143
				<dependency>
144
					<groupId>javax.media</groupId>
145
					<artifactId>jai_codec</artifactId>
146
					<scope>test</scope>
147
				</dependency>
148
			</dependencies>
149
		</profile>
150
		<profile>
151
			<id>cdc</id>
152
			<activation>
153
				<activeByDefault>false</activeByDefault>
154
			</activation>
155
			
156
			<dependencies>
157
				<!-- TESTS -->
158
				<dependency>
159
					<groupId>org.gvsig.mobile</groupId>
160
					<artifactId>org.gvsig.mobile.libProjection</artifactId>
161
					<version>0.0.1-SNAPSHOT</version>
162
				</dependency>
163
			</dependencies>			
164
		</profile>
165
		<profile>
166
			<id>eclipse-project</id>
167
			<build>
168
				<defaultGoal>antrun:run</defaultGoal>
169
				<plugins>
170
					<plugin>
171
						<artifactId>maven-antrun-plugin</artifactId>
172
						<configuration>
173
							<tasks>
174
								<ant antfile="${build-dir}/ant-tasks/eclipse-tasks.xml"
175
									target="eclipse.all"/>
176
							</tasks>
177
						</configuration>
178
					</plugin>
179
				</plugins>
180
			</build>				
181
		</profile>		
182
	</profiles>
183
			
184
	<build>
185
		<sourceDirectory>src</sourceDirectory>
186
		<testSourceDirectory>src-test</testSourceDirectory>
187
		<plugins>
188
			<plugin>
189
				<groupId>org.apache.maven.plugins</groupId>
190
				<artifactId>maven-compiler-plugin</artifactId>
191
				<configuration>
192
					<source>1.4</source>
193
					<target>1.4</target>
194
				</configuration>
195
			</plugin>
196
			<plugin>
197
				<groupId>org.apache.maven.plugins</groupId>
198
				<artifactId>maven-jar-plugin</artifactId>
199
				<configuration>
200
					<excludes>
201
						<exclude>**/impl/**</exclude>
202
						<exclude>**/spi/**</exclude>
203
					</excludes>
204
				</configuration>
205
				<executions>
206
					<!--
207
						Generates a jar file only with the DAL default implementation
208
					-->
209
					<execution>
210
						<id>impl</id>
211
						<phase>package</phase>
212
						<goals>
213
							<goal>jar</goal>
214
						</goals>
215
						<configuration>
216
							<classifier>impl</classifier>
217
							<includes>
218
								<include>**/impl/**</include>
219
							</includes>
220
							<excludes>
221
								<exclude>**/spi/**</exclude>
222
							</excludes>
223
						</configuration>
224
					</execution>
225
					<!--
226
						Generates a jar file only with the DAL SPI
227
					-->
228
					<execution>
229
						<id>spi</id>
230
						<phase>package</phase>
231
						<goals>
232
							<goal>jar</goal>
233
						</goals>
234
						<configuration>
235
							<classifier>spi</classifier>
236
							<includes>
237
								<include>**/spi/**</include>
238
							</includes>
239
							<excludes>
240
								<exclude>**/impl/**</exclude>
241
							</excludes>
242
						</configuration>
243
					</execution>
244
					<!--
245
						Generates a jar file only with the test classes
246
					-->
247
					<execution>
248
						<goals>
249
							<goal>test-jar</goal>
250
						</goals>
251
						<configuration>
252
							<includes>
253
								<include>**/**</include>
254
							</includes>
255
							<excludes>
256
								<exclude>NONE</exclude>
257
							</excludes>
258
						</configuration>
259
					</execution>
260
				</executions>
261
			</plugin>
262
			<plugin>
263
				<artifactId>maven-antrun-plugin</artifactId>
264
				<executions>
265
					<execution>
266
						<id>services</id>
267
						<phase>package</phase>
268
						<goals>
269
							<goal>run</goal>
270
						</goals>
271
						<configuration>
272
							<tasks>
273
								<jar destfile="${project.build.directory}/${project.build.finalName}.jar"
274
									update="true">
275
									<fileset dir="${basedir}/resources/api" />
276
								</jar>
277
								<jar destfile="${project.build.directory}/${project.build.finalName}-impl.jar"
278
									update="true">
279
									<fileset dir="${basedir}/resources/impl" />
280
								</jar>
281
							</tasks>
282
						</configuration>
283
					</execution>
284
				</executions>
285
			</plugin>
286
			<plugin>
287
				<groupId>org.apache.maven.plugins</groupId>
288
				<artifactId>maven-surefire-plugin</artifactId>
289
				<configuration>
290
					<excludes>
291
						<exclude>**/BlockTest.java</exclude>
292
					</excludes>
293
					<additionalClasspathElements>
294
						<additionalClasspathElement>${basedir}/resources/api</additionalClasspathElement>
295
						<additionalClasspathElement>${basedir}/resources/impl</additionalClasspathElement>
296
					</additionalClasspathElements>
297
                    <skipTests>true</skipTests>
298
				</configuration>
299
			</plugin>
300
		</plugins>
301
	</build>
302
	<reporting>
303
		<plugins>
304
			<plugin>
305
				<groupId>org.apache.maven.plugins</groupId>
306
				<artifactId>maven-javadoc-plugin</artifactId>
307
				<reportSets>
308
					<reportSet>
309
						<id>api</id>
310
						<configuration>
311
							<excludePackageNames>*.spi:*.impl</excludePackageNames>
312
							<name>Javadoc: API</name>
313
							<destDir>apidoc</destDir>
314
							<windowtitle>API Documentation</windowtitle>
315
						</configuration>
316
						<reports>
317
							<report>javadoc</report>
318
						</reports>
319
					</reportSet>
320
					<reportSet>
321
						<id>spi</id>
322
						<configuration>
323
							<doctitle>${project.name} ${project.version} SPI</doctitle>
324
							<subpackages>org.gvsig.fmap.dal.spi:org.gvsig.fmap.dal.feature.spi:org.gvsig.fmap.dal.raster.spi:org.gvsig.fmap.dal.resource.spi</subpackages>
325
							<name>Javadoc: SPI</name>
326
							<destDir>spidoc</destDir>
327
							<windowtitle>SPI Documentation</windowtitle>
328
							<links>
329
								<link>../apidoc/</link>
330
							</links>
331
						</configuration>
332
						<reports>
333
							<report>javadoc</report>
334
						</reports>
335
					</reportSet>
336
					<reportSet>
337
						<id>impl</id>
338
						<configuration>
339
							<doctitle>${project.name} ${project.version} Default implementation</doctitle>
340
							<subpackages>org.gvsig.fmap.dal.impl:org.gvsig.fmap.dal.feature.impl:org.gvsig.fmap.dal.raster.impl:org.gvsig.fmap.dal.resource.impl</subpackages>
341
							<name>Javadoc: Impl</name>
342
							<destDir>impldoc</destDir>
343
							<windowtitle>Default implementation Documentation</windowtitle>
344
							<links>
345
								<link>../apidoc/</link>
346
								<link>../spidoc/</link>
347
							</links>
348
						</configuration>
349
						<reports>
350
							<report>javadoc</report>
351
						</reports>
352
					</reportSet>
353
				</reportSets>
354
			</plugin>
355
		</plugins>
356
	</reporting>
357
</project>
tags/v2_0_0_Build_2059/libraries/libFMap_dal/resources/impl/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.impl.DALDefaultImplLibrary
tags/v2_0_0_Build_2059/libraries/libFMap_dal/resources/impl/org/gvsig/fmap/dal/i18n/text.properties
1
filling_index=Llenando ?ndice
2
updating_index=Actualizando ?ndice
tags/v2_0_0_Build_2059/libraries/libFMap_dal/resources/impl/org/gvsig/fmap/dal/i18n/text_en.properties
1
filling_index=Filling index
2
updating_index=Updating index
tags/v2_0_0_Build_2059/libraries/libFMap_dal/resources/api/org/gvsig/fmap/dal/MetadataDefinitions.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5
    <class name="DataProvider" namespace="metadata">
6
      <description>Metadata of a feature store</description>
7
      <fields>
8
        <field name="ProviderName" type="string" mandatory="true">
9
          <description>The name of the provider of data</description>
10
        </field>
11
        <field name="ContainerName" type="string" mandatory="false">
12
          <description>Name of the container of the data, by example, in a dbf, the file name of the dbf</description>
13
        </field>
14
      </fields>
15
    </class>
16

  
17
    <class name="FeatureProvider" namespace="metadata">
18
      <extends>
19
      	<class namespace="metadata" name="DataProvider"/>
20
      </extends>
21
      <description>Metadata of a feature store</description>
22
      <fields>
23
        <field name="FeatureType" type="dynobject" subType="org.gvsig.fmap.dal.feature.FeatureType" mandatory="false">
24
          <description>The definition of the structure of the store</description>
25
        </field>    
26
      </fields>
27
    </class>
28

  
29
    <class name="SpatialProvider" namespace="metadata">
30
      <extends>
31
      	<class namespace="metadata" name="FeatureProvider"/>
32
      </extends>
33
      <description>Metadata of a feature store with spatial support</description>
34
      <fields>
35
        <field name="CRS" type="crs" mandatory="false">
36
          <description></description>
37
        </field>    
38
        <field name="Envelope" type="envelope" mandatory="false">
39
          <description></description>
40
        </field>    
41
      </fields>
42
    </class>
43

  
44
  </classes>
45
</definitions>  
0 46

  
tags/v2_0_0_Build_2059/libraries/libFMap_dal/resources/api/org/gvsig/fmap/dal/spi/ProviderParametersDefinition.xml
1
<?xml version="1.0"?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5
    <class namespace="dal" name="ProviderParameters">
6
      <description>Parameters used for open a store</description>
7
      <fields>
8
        <field name="ProviderName" type="string" mandatory="true" group="Advanced">
9
          <description>Name of the provider</description>
10
        </field>
11
      </fields>
12
    </class>
13

  
14
    <class namespace="dal" name="NewProviderParameters">
15
      <extends>
16
      	<class namespace="dal" name="ProviderParameters"/>
17
      </extends>
18
      <description>Parameters used for create a new store in the server</description>
19
      <fields>
20
        <field name="FeatureType" type="object" mandatory="true" hidden="true" classOfValue="org.gvsig.fmap.dal.feature.FeatureType">
21
          <description>Define the structure of the new store</description>
22
        </field>
23
      </fields>
24
    </class>
25

  
26
  </classes>
27
</definitions>  
0 28

  
tags/v2_0_0_Build_2059/libraries/libFMap_dal/resources/api/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.DALLibrary
2
org.gvsig.fmap.dal.store.memory.MemoryStoreLibrary
3

  
tags/v2_0_0_Build_2059/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_2059/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_2059/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_2059/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_2059/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_2059/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_2059/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/FeatureSetTestParent.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian 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
 * 2008 {DiSiD Technologies}   {{Test indexed iterator retrieval}}
26
 */
27
package org.gvsig.fmap.dal.feature;
28

  
29
import junit.framework.TestCase;
30

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

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

  
44

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

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

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

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

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

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

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

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

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

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

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

  
123
    protected abstract void register();
124

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

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

  
tags/v2_0_0_Build_2059/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/impl/JoinTransform.java
1
package org.gvsig.fmap.dal.feature.impl;
2

  
3
import java.util.Arrays;
4
import java.util.HashMap;
5
import java.util.Iterator;
6
import java.util.Map;
7

  
8
import org.gvsig.fmap.dal.DALLocator;
9
import org.gvsig.fmap.dal.exception.DataException;
10
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform;
11
import org.gvsig.fmap.dal.feature.EditableFeature;
12
import org.gvsig.fmap.dal.feature.EditableFeatureType;
13
import org.gvsig.fmap.dal.feature.Feature;
14
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
15
import org.gvsig.fmap.dal.feature.FeatureQuery;
16
import org.gvsig.fmap.dal.feature.FeatureSet;
17
import org.gvsig.fmap.dal.feature.FeatureStore;
18
import org.gvsig.fmap.dal.feature.FeatureType;
19
import org.gvsig.tools.dispose.DisposableIterator;
20
import org.gvsig.tools.dispose.DisposeUtils;
21
import org.gvsig.tools.evaluator.Evaluator;
22
import org.gvsig.tools.persistence.PersistentState;
23
import org.gvsig.tools.persistence.exception.PersistenceException;
24

  
25
public class JoinTransform extends AbstractFeatureStoreTransform {
26

  
27
	/**
28
	 * Store from which the join transform will get the additional attributes
29
	 */
30
	private FeatureStore store2;
31

  
32
	/**
33
	 * name of the key attr in store1 that will be used to match features in
34
	 * store2
35
	 */
36
	private String keyAttr1;
37

  
38
	/**
39
	 * name of the key attr in store2 that will be used to match features in
40
	 * store1
41
	 */
42
	private String keyAttr2;
43

  
44
	/**
45
	 * names of the attributes to join from store2 to store1
46
	 */
47
	private String[] attrs;
48

  
49
	/**
50
	 * Attribute names may change after transformation if they are repeated in
51
	 * both stores. This map keeps correspondence between store2 original names
52
	 * and their transformed counterparts.
53
	 */
54
	private Map targetNamesMap;
55

  
56
	private FeatureType originalFeatureType;
57

  
58
	/**
59
	 * A default constructor
60
	 */
61
	public JoinTransform() {
62
		targetNamesMap = new HashMap();
63
	}
64

  
65
	/**
66
	 * Initializes all the necessary data for this transform
67
	 *
68
	 * @param store1
69
	 *            store whose default feature type is the target of this
70
	 *            transform
71
	 *
72
	 * @param store2
73
	 *            store whose default feature type will provide the new
74
	 *            attributes to join
75
	 *
76
	 * @param keyAttr1
77
	 *            key attribute in store1 that matches keyAttr2 in store2
78
	 *            (foreign key), used for joining both stores.
79
	 *
80
	 * @param keyAttr2
81
	 *            key attribute in store2 that matches keyAttr1 in store2
82
	 *            (foreign key), used for joining both stores.
83
	 *
84
	 * @param attrs
85
	 *            names of the attributes in store2 that will be joined to
86
	 *            store1.
87
	 */
88
	public void initialize(FeatureStore store1, FeatureStore store2,
89
			String keyAttr1, String keyAttr2, String[] attrs)
90
			throws DataException {
91

  
92
		// Initialize needed data
93
		this.setFeatureStore(store1);
94

  
95
		this.store2 = store2;
96
		this.keyAttr1 = keyAttr1;
97
		this.keyAttr2 = keyAttr2;
98
		this.attrs = attrs;
99
		this.originalFeatureType = this.getFeatureStore()
100
				.getDefaultFeatureType();
101

  
102
		// calculate this transform resulting feature type
103
		// by adding all specified attrs from store2 to store1's default
104
		// feature type
105
		EditableFeatureType type = this.getFeatureStore().getDefaultFeatureType().getEditable();
106

  
107
		for (int i = 0; i < attrs.length; i++) {
108
			String name = attrs[i];
109

  
110
			// If an attribute already exists with the same name in store1's
111
			// default feature type,
112
			// calculate an alternate name and add it to our type
113
			int j = 0;
114
			while (type.getIndex(name) >= 0) {
115
				name = attrs[i] + "_" + ++j;
116
			}
117
			type.add(name, store2.getDefaultFeatureType()
118
					.getAttributeDescriptor(attrs[i]).getType());
119

  
120
			// keep correspondence between original name and transformed name
121
			this.targetNamesMap.put(attrs[i], name);
122
		}
123

  
124
		// assign calculated feature type as this transform's feature type
125
		FeatureType[] types = new FeatureType[] { type.getNotEditableCopy() };
126
		setFeatureTypes(Arrays.asList(types), types[0]);
127
	}
128

  
129
	/**
130
	 *
131
	 *
132
	 * @param source
133
	 *
134
	 * @param target
135
	 *
136
	 * @throws DataException
137
	 */
138
	public void applyTransform(Feature source, EditableFeature target)
139
			throws DataException {
140

  
141
		// copy the data from store1 into the resulting feature
142
		target.copyFrom(source);
143

  
144
		// ask store2 for the specified attributes, filtering by the key
145
		// attribute value
146
		// from the source feature
147
		Evaluator eval = DALLocator.getDataManager().createExpresion(
148
				keyAttr2 + "=" + source.get(keyAttr1));
149
		FeatureQuery query = this.getFeatureStore().createFeatureQuery();
150
		query.setAttributeNames(attrs);
151
		query.setFilter(eval);
152

  
153
		FeatureSet set = null;
154
		DisposableIterator it = null;
155

  
156
		try {
157
			set = store2.getFeatureSet(query);
158

  
159
			// In this join implementation, we will take only the first matching
160
			// feature found in store2
161
			it = set.iterator();
162
			if (it.hasNext()) {
163
				Feature feat = (Feature) it.next();
164

  
165
				// copy all attributes from joined feature to target
166
				Iterator it2 = feat.getType().iterator();
167
				while (it2.hasNext()) {
168
					FeatureAttributeDescriptor attr =
169
							(FeatureAttributeDescriptor) it2.next();
170
					// find original attribute name
171
					String targetName =
172
							(String) this.targetNamesMap.get(attr.getName());
173
					// copy its value to target feature attribute
174
					target.set(targetName, feat.get(attr.getName()));
175
				}
176
			}
177
		} finally {
178
			DisposeUtils.dispose(set);
179
			DisposeUtils.dispose(it);
180
		}
181
	}
182

  
183
	public void saveToState(PersistentState state) throws PersistenceException {
184
		// TODO Auto-generated method stub
185

  
186
	}
187

  
188
	public void loadFromState(PersistentState state) throws PersistenceException {
189
		// TODO Auto-generated method stub
190

  
191
	}
192

  
193
	/*
194
	 * (non-Javadoc)
195
	 *
196
	 * @see
197
	 * org.gvsig.fmap.dal.feature.FeatureStoreTransform#getSourceFeatureTypeFrom
198
	 * (org.gvsig.fmap.dal.feature.FeatureType)
199
	 */
200
	public FeatureType getSourceFeatureTypeFrom(FeatureType targetFeatureType) {
201
		return this.originalFeatureType;
202
	}
203

  
204
	public boolean isTransformsOriginalValues() {
205
		return false;
206
	}
207

  
208
}
0 209

  
tags/v2_0_0_Build_2059/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/impl/MyTransform.java
1
package org.gvsig.fmap.dal.feature.impl;
2

  
3
import java.util.Arrays;
4

  
5
import org.gvsig.fmap.dal.DataTypes;
6
import org.gvsig.fmap.dal.exception.DataException;
7
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform;
8
import org.gvsig.fmap.dal.feature.EditableFeature;
9
import org.gvsig.fmap.dal.feature.EditableFeatureType;
10
import org.gvsig.fmap.dal.feature.Feature;
11
import org.gvsig.fmap.dal.feature.FeatureStore;
12
import org.gvsig.fmap.dal.feature.FeatureType;
13
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException;
14
import org.gvsig.fmap.geom.GeometryLocator;
15
import org.gvsig.fmap.geom.GeometryManager;
16
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
17
import org.gvsig.fmap.geom.Geometry.TYPES;
18
import org.gvsig.fmap.geom.primitive.Point;
19
import org.gvsig.tools.persistence.PersistentState;
20
import org.gvsig.tools.persistence.exception.PersistenceException;
21

  
22
/**
23
 *
24
 * This transform adds a new attribute of type Geometry to the original store's
25
 * default FeatureType. When applying the transform to a single feature this new
26
 * attribute is assigned the value of a point whose coordinates proceed from two
27
 * numeric attributes from the store, called xname, yname.
28
 *
29
 */
30
class MyTransform extends AbstractFeatureStoreTransform {
31

  
32
	private FeatureType originalType;
33
	private String geomName;
34
	private String xname;
35
	private String yname;
36

  
37
	/**
38
	 * Empty default constructor
39
	 */
40
	public MyTransform() {
41
	}
42

  
43
	/**
44
	 * Initializes the transform by assigning the source store and the names of
45
	 * the necessary attributes.
46
	 *
47
	 * @param store
48
	 *            source store.
49
	 *
50
	 * @param geomName
51
	 *            name of the geometry attribute in the default feature type
52
	 *            from the source store.
53
	 *
54
	 * @param xname
55
	 *            name of the attribute containing the X coordinates
56
	 *
57
	 * @param yname
58
	 *            name of the attribute containing the Y coordinates
59
	 *
60
	 * @throws DataException
61
	 */
62
	public void initialize(FeatureStore store, String geomName, String xname, String yname) throws DataException {
63

  
64
		// Initialize some data
65
		this.setFeatureStore(store);
66
		this.geomName = geomName;
67
		this.xname = xname;
68
		this.yname = yname;
69

  
70
		this.originalType = store.getDefaultFeatureType();
71
		// obtain the feature type, add the new attribute and keep a reference to the resulting feature type
72
		EditableFeatureType type = store.getDefaultFeatureType().getEditable();
73
		type.add(geomName, DataTypes.GEOMETRY);
74
		FeatureType[] types = new FeatureType[] { type.getNotEditableCopy() };
75
		setFeatureTypes(Arrays.asList(types), types[0]);
76
	}
77

  
78
	/**
79
	 * Applies this transform to a target editable feature, using data from the
80
	 * source feature.
81
	 */
82
	public void applyTransform(Feature source, EditableFeature target)
83
			throws DataException {
84

  
85
		// copy source feature data over target feature
86
		target.copyFrom(source);
87

  
88
		// calculate and assign new attribute's value
89
		GeometryManager geomManager = GeometryLocator.getGeometryManager();
90
		Point point;
91
		try {
92
			point = (Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D);
93
			point.setX(source.getDouble(xname));
94
			point.setY(source.getDouble(yname));
95
			target.setGeometry(this.geomName, point);
96
		} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
97
        	throw new CreateGeometryException(TYPES.POINT, SUBTYPES.GEOM2D, e);
98
		}
99
	}
100

  
101
	public void saveToState(PersistentState state) throws PersistenceException {
102
		state.set("geomName", this.geomName);
103
		state.set("xname", this.xname);
104
		state.set("yname", this.yname);
105
	}
106

  
107
	public void loadFromState(PersistentState state) throws PersistenceException {
108
	}
109

  
110
	/*
111
	 * (non-Javadoc)
112
	 *
113
	 * @see
114
	 * org.gvsig.fmap.dal.feature.FeatureStoreTransform#getSourceFeatureTypeFrom
115
	 * (org.gvsig.fmap.dal.feature.FeatureType)
116
	 */
117
	public FeatureType getSourceFeatureTypeFrom(FeatureType targetFeatureType) {
118
		return originalType;
119
	}
120

  
121
	public boolean isTransformsOriginalValues() {
122
		return false;
123
	}
124

  
125
}
0 126

  
tags/v2_0_0_Build_2059/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/impl/DefaultFeatureReferenceSelectionTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian 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
 * 2008 {DiSiD Technologies}  {{Task}}
26
 */
27
package org.gvsig.fmap.dal.feature.impl;
28

  
29
import java.util.Iterator;
30

  
31
import junit.framework.TestCase;
32

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

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

  
48
    private FeatureReferenceSelection selection;
49
    private MockControl refControl1;
50
    private FeatureReference ref1;
51
    private MockControl refControl2;
52
    private FeatureReference ref2;
53
    private MockControl storeControl;
54
    private FeatureStore store;
55
    private MockControl fsetControl;
56
    private FeatureSet featureSet;
57
    private MockControl helperControl;
58
    private FeatureSelectionHelper helper;
59

  
60
    private int total = 10;
61

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

  
68
        storeControl = MockControl.createNiceControl(FeatureStore.class);
69
        store = (FeatureStore) storeControl.getMock();
70
        storeControl.expectAndReturn(store.getFeatureCount(), total);
71

  
72
        helperControl = MockControl
73
                .createNiceControl(FeatureSelectionHelper.class);
74
        helper = (FeatureSelectionHelper) helperControl.getMock();
75
        helperControl.expectAndDefaultReturn(helper.getFeatureStoreDeltaSize(),
76
                0);
77

  
78
        fsetControl = MockControl.createNiceControl(FeatureSet.class);
79
        featureSet = (FeatureSet) fsetControl.getMock();
80

  
81
        storeControl.expectAndReturn(store.getFeatureSet(), featureSet);
82
        fsetControl.expectAndReturn(featureSet.getSize(), total);
83

  
84

  
85

  
86
        storeControl.replay();
87
        fsetControl.replay();
88
        helperControl.replay();
89

  
90
        selection = new DefaultFeatureReferenceSelection(store, helper);
91
    }
92

  
93
    protected void tearDown() throws Exception {
94
        super.tearDown();
95
    }
96

  
97
    public void testSelect() throws Exception {
98
        // Add a feature
99
        selection.select(ref1);
100
        assertTrue(selection.isSelected(ref1));
101
        assertFalse(selection.isSelected(ref2));
102

  
103
        selection.select(ref2);
104
        assertTrue(selection.isSelected(ref2));
105
    }
106

  
107
    public void testSelectAll() throws Exception {
108
        selection.selectAll();
109
        assertTrue(selection.isSelected(ref1));
110
        assertTrue(selection.isSelected(ref2));
111
    }
112

  
113
    public void testDeselect() throws Exception {
114
        // Remove a feature
115
        selection.select(ref1);
116
        selection.select(ref2);
117
        assertTrue(selection.isSelected(ref2));
118
        selection.deselect(ref2);
119
        assertFalse(selection.isSelected(ref2));
120
        selection.deselect(ref1);
121
        assertFalse(selection.isSelected(ref1));
122
    }
123

  
124
    public void testDeselectAll() throws Exception {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff