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.h2 / src / test / java / org / gvsig / fmap / dal / store / h2 / operations / sql / TestPerformChanges.java @ 44871
History | View | Annotate | Download (3.59 KB)
1 | 44678 | jjdelcerro | package org.gvsig.fmap.dal.store.h2.operations.sql; |
---|---|---|---|
2 | 43512 | jjdelcerro | |
3 | 44678 | jjdelcerro | import java.util.Collections; |
4 | 44669 | jjdelcerro | import java.util.List; |
5 | 43512 | jjdelcerro | import junit.framework.TestCase; |
6 | 44669 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
7 | import org.gvsig.fmap.dal.DataTypes; |
||
8 | 44678 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
9 | 44669 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
10 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
11 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
12 | 44871 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureType.FeatureTypeChanged; |
13 | 44678 | jjdelcerro | import org.gvsig.fmap.dal.store.h2.TestUtils; |
14 | import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
||
15 | import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
||
16 | import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
||
17 | import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
||
18 | import org.gvsig.fmap.dal.store.jdbc2.spi.operations.PerformChangesOperation; |
||
19 | 44098 | jjdelcerro | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
20 | 44669 | jjdelcerro | import org.slf4j.Logger; |
21 | import org.slf4j.LoggerFactory; |
||
22 | 43512 | jjdelcerro | |
23 | 44678 | jjdelcerro | public class TestPerformChanges extends TestCase { |
24 | 43512 | jjdelcerro | |
25 | 44678 | jjdelcerro | private static final Logger LOGGER = LoggerFactory.getLogger(TestPerformChanges.class); |
26 | 44139 | jjdelcerro | |
27 | 44678 | jjdelcerro | public TestPerformChanges(String testName) { |
28 | super(testName);
|
||
29 | } |
||
30 | |||
31 | @Override
|
||
32 | protected void setUp() throws Exception { |
||
33 | super.setUp();
|
||
34 | new DefaultLibrariesInitializer().fullInitialize();
|
||
35 | } |
||
36 | |||
37 | @Override
|
||
38 | protected void tearDown() throws Exception { |
||
39 | super.tearDown();
|
||
40 | } |
||
41 | |||
42 | // TODO add test methods here. The name must begin with 'test'. For example:
|
||
43 | // public void testHello() {}
|
||
44 | |||
45 | public void testPerformChanges() throws Exception { |
||
46 | 44685 | jjdelcerro | JDBCHelper helper = TestUtils.getJDBCHelper(); |
47 | 44678 | jjdelcerro | JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
48 | OperationsFactory operations = helper.getOperations(); |
||
49 | |||
50 | List<String> expectedSQLs = TestUtils.getSQLs("performChanges.sql"); |
||
51 | 43512 | jjdelcerro | |
52 | 44678 | jjdelcerro | FeatureStore sourceStore = TestUtils.openSourceStore1(); |
53 | 44421 | jjdelcerro | |
54 | 44678 | jjdelcerro | TableReference table = operations.createTableReference( |
55 | "dbtest",
|
||
56 | sqlbuilder.default_schema(), |
||
57 | "test",
|
||
58 | null
|
||
59 | ); |
||
60 | FeatureType featureType = sourceStore.getDefaultFeatureType(); |
||
61 | 44421 | jjdelcerro | |
62 | 43512 | jjdelcerro | |
63 | 44678 | jjdelcerro | FeatureTypeChanged featureTypeChanged = new FeatureTypeChanged() {
|
64 | @Override
|
||
65 | public FeatureType getSource() {
|
||
66 | EditableFeatureType ft = DALLocator.getDataManager().createFeatureType(); |
||
67 | EditableFeatureAttributeDescriptor id = ft.add("ID", DataTypes.INT);
|
||
68 | id.copyFrom(featureType.getAttributeDescriptor("ID"));
|
||
69 | return ft;
|
||
70 | } |
||
71 | 44139 | jjdelcerro | |
72 | 44678 | jjdelcerro | @Override
|
73 | public FeatureType getTarget() {
|
||
74 | return featureType;
|
||
75 | } |
||
76 | }; |
||
77 | List<FeatureTypeChanged> featureTypesChangeds = Collections.singletonList(featureTypeChanged); |
||
78 | 43512 | jjdelcerro | |
79 | 44678 | jjdelcerro | PerformChangesOperation performChanges = operations.createPerformChanges( |
80 | table, |
||
81 | sourceStore.getDefaultFeatureType(), |
||
82 | null,
|
||
83 | null,
|
||
84 | null,
|
||
85 | featureTypesChangeds.iterator() |
||
86 | ); |
||
87 | String insertSQL = performChanges.getInsertSQL();
|
||
88 | String deleteSQL = performChanges.getDeleteSQL();
|
||
89 | String updateSQL = performChanges.getUpdateSQL();
|
||
90 | List<String> updateTableSQLs = performChanges.getUpdateTableSQLs(); |
||
91 | 44139 | jjdelcerro | |
92 | 44678 | jjdelcerro | assertEquals("Insert SQL", expectedSQLs.get(0), insertSQL); |
93 | assertEquals("Delete SQL", expectedSQLs.get(1), deleteSQL); |
||
94 | assertEquals("Update SQL", expectedSQLs.get(2), updateSQL); |
||
95 | assertEquals("UpdateTable num. SQLs", expectedSQLs.size()-3, updateTableSQLs.size()); |
||
96 | for (int i = 0; i < updateTableSQLs.size(); i++) { |
||
97 | assertEquals("UpdateTable SQL "+i, expectedSQLs.get(i+3), updateTableSQLs.get(i)); |
||
98 | 43512 | jjdelcerro | } |
99 | |||
100 | 44678 | jjdelcerro | |
101 | } |
||
102 | |||
103 | 43939 | jjdelcerro | } |