svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.mdb / src / test / java / org / gvsig / fmap / dal / store / mdb / operations / sql / TestCount.java @ 44916
History | View | Annotate | Download (3.33 KB)
1 |
package org.gvsig.fmap.dal.store.mdb.operations.sql; |
---|---|
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.FeatureQuery; |
7 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
8 |
import org.gvsig.fmap.dal.feature.FeatureType; |
9 |
import org.gvsig.fmap.dal.store.mdb.TestUtils; |
10 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
11 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
12 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
13 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
14 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CountOperation; |
15 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation; |
16 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
17 |
import org.slf4j.Logger; |
18 |
import org.slf4j.LoggerFactory; |
19 |
|
20 |
public class TestCount extends TestCase { |
21 |
|
22 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestCount.class); |
23 |
|
24 |
public TestCount(String testName) { |
25 |
super(testName);
|
26 |
} |
27 |
|
28 |
@Override
|
29 |
protected void setUp() throws Exception { |
30 |
super.setUp();
|
31 |
new DefaultLibrariesInitializer().fullInitialize();
|
32 |
} |
33 |
|
34 |
@Override
|
35 |
protected void tearDown() throws Exception { |
36 |
super.tearDown();
|
37 |
} |
38 |
|
39 |
public void testCount() throws Exception { |
40 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
41 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
42 |
OperationsFactory operations = helper.getOperations(); |
43 |
|
44 |
List<String> expectedSQLs = TestUtils.getSQLs("count.sql"); |
45 |
|
46 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
47 |
|
48 |
TableReference table = operations.createTableReference( |
49 |
"dbtest",
|
50 |
sqlbuilder.default_schema(), |
51 |
"test",
|
52 |
null
|
53 |
); |
54 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
55 |
CountOperation count = operations.createCount( |
56 |
featureType, |
57 |
table, |
58 |
null,
|
59 |
null
|
60 |
); |
61 |
|
62 |
String sql = count.getSQL();
|
63 |
assertEquals("Count SQL", expectedSQLs.get(0), sql); |
64 |
} |
65 |
|
66 |
public void testSimpleGroup() throws Exception { |
67 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
68 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
69 |
OperationsFactory operations = helper.getOperations(); |
70 |
|
71 |
List<String> expectedSQLs = TestUtils.getSQLs("count.sql"); |
72 |
|
73 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
74 |
|
75 |
TableReference table = operations.createTableReference( |
76 |
"dbtest",
|
77 |
sqlbuilder.default_schema(), |
78 |
"test",
|
79 |
null
|
80 |
); |
81 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
82 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
83 |
query.getGroupByColumns().add("Long");
|
84 |
query.getAggregateFunctions().put("ID", "MIN"); |
85 |
query.getAggregateFunctions().put("Byte", "MAX"); |
86 |
query.getAggregateFunctions().put("Double", "SUM"); |
87 |
query.getOrder().add("Long");
|
88 |
CountOperation count = operations.createCount( |
89 |
featureType, |
90 |
table, |
91 |
null,
|
92 |
query |
93 |
); |
94 |
String sql = count.getSQL();
|
95 |
System.out.println("###### SQL:"+sql); |
96 |
System.out.println("###### EXP:"+expectedSQLs.get(1)); |
97 |
|
98 |
assertEquals("Count with group SQL", expectedSQLs.get(1), sql); |
99 |
} |
100 |
|
101 |
// TODO: a?adir un test con where, group y order.
|
102 |
} |