svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.csv / src / test / java / org / gvsig / fmap / dal / store / csv / TestFilter1.java @ 44738
History | View | Annotate | Download (3.04 KB)
1 |
package org.gvsig.fmap.dal.store.csv; |
---|---|
2 |
|
3 |
import java.util.List; |
4 |
import junit.framework.TestCase; |
5 |
import static junit.framework.TestCase.assertEquals; |
6 |
import org.gvsig.fmap.dal.feature.Feature; |
7 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
8 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
9 |
import org.slf4j.Logger; |
10 |
import org.slf4j.LoggerFactory; |
11 |
|
12 |
public class TestFilter1 extends TestCase { |
13 |
|
14 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestFilter1.class); |
15 |
|
16 |
public TestFilter1(String testName) { |
17 |
super(testName);
|
18 |
} |
19 |
|
20 |
@Override
|
21 |
protected void setUp() throws Exception { |
22 |
super.setUp();
|
23 |
new DefaultLibrariesInitializer().fullInitialize();
|
24 |
} |
25 |
|
26 |
@Override
|
27 |
protected void tearDown() throws Exception { |
28 |
super.tearDown();
|
29 |
} |
30 |
|
31 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
32 |
// public void testHello() {}
|
33 |
|
34 |
public void testSimpleFilter1() throws Exception { |
35 |
TestUtils.initialiceRepository(); |
36 |
FeatureStore countries = TestUtils.openSourceCountries(); |
37 |
List<Feature> features = countries.getFeatures("LASTCENSUS > 0"); |
38 |
assertEquals("Filter: LASTCENSUS > 0", features.size(), 209); |
39 |
} |
40 |
|
41 |
public void testSimpleFilter2() throws Exception { |
42 |
TestUtils.initialiceRepository(); |
43 |
FeatureStore countries = TestUtils.openSourceCountries(); |
44 |
List<Feature> features = countries.getFeatures("countries.LASTCENSUS > 0"); |
45 |
assertEquals("Filter: countries.LASTCENSUS > 0", features.size(), 209); |
46 |
} |
47 |
|
48 |
public void testSubselectFilter1() throws Exception { |
49 |
TestUtils.initialiceRepository(); |
50 |
|
51 |
// Sobre la tabla de continentes, para obtener la lista de continentes
|
52 |
// que tienen paises asociados a Gran Breta?a.
|
53 |
// Filtramos continentes por un campo del pais.
|
54 |
StringBuilder filter = new StringBuilder(); |
55 |
filter.append("EXISTS(");
|
56 |
filter.append(" SELECT * FROM countries");
|
57 |
filter.append(" WHERE ");
|
58 |
filter.append(" continents.NAME = countries.CONTINENT AND ");
|
59 |
filter.append(" countries.SOV_A3 = 'GB1' "); //FR1=4, GB1=6 |
60 |
filter.append(" LIMIT 1; ");
|
61 |
filter.append(")");
|
62 |
|
63 |
FeatureStore continents = TestUtils.openSourceContinents(); |
64 |
List<Feature> features = continents.getFeatures(filter.toString());
|
65 |
assertEquals("Filter: subselect GB1", features.size(), 6); |
66 |
} |
67 |
|
68 |
public void testSubselectFilter2() throws Exception { |
69 |
TestUtils.initialiceRepository(); |
70 |
|
71 |
// Sobre la tabla de continentes, para obtener la lista de continentes
|
72 |
// que tienen paises asociados a Francia.
|
73 |
StringBuilder filter = new StringBuilder(); |
74 |
filter.append("EXISTS(");
|
75 |
filter.append(" SELECT 1 FROM countries");
|
76 |
filter.append(" WHERE ");
|
77 |
filter.append(" continents.NAME = countries.CONTINENT AND ");
|
78 |
filter.append(" countries.SOV_A3 = 'FR1' "); //FR1=4, GB1=6 |
79 |
filter.append(" LIMIT 1; ");
|
80 |
filter.append(")");
|
81 |
|
82 |
FeatureStore continents = TestUtils.openSourceContinents(); |
83 |
List<Feature> features = continents.getFeatures(filter.toString());
|
84 |
assertEquals("Filter: subselect FR1", features.size(), 4); |
85 |
} |
86 |
} |