Statistics
| Revision:

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.jdbc / src / test / java / org / gvsig / fmap / dal / store / jdbc2 / AbstractTestJsonValue.java @ 47606

History | View | Annotate | Download (3.67 KB)

1
package org.gvsig.fmap.dal.store.jdbc2;
2

    
3
import java.util.List;
4
import junit.framework.TestCase;
5
import static junit.framework.TestCase.assertEquals;
6
import org.gvsig.expressionevaluator.ExpressionUtils;
7
import org.gvsig.fmap.dal.DataTypes;
8
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
9
import org.gvsig.fmap.dal.feature.FeatureQuery;
10
import org.gvsig.fmap.dal.feature.FeatureStore;
11
import org.gvsig.fmap.dal.feature.FeatureType;
12
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression;
13
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
14
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation;
15
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18

    
19
public abstract class AbstractTestJsonValue extends TestCase {
20

    
21
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractTestJsonValue.class);
22

    
23
    protected AbstractTestUtils utils;
24

    
25
    public AbstractTestJsonValue(String testName) {
26
        super(testName);
27
    }
28

    
29
    @Override
30
    protected void setUp() throws Exception {
31
        super.setUp();
32
        new DefaultLibrariesInitializer().fullInitialize();
33
    }
34

    
35
    @Override
36
    protected void tearDown() throws Exception {
37
        super.tearDown();
38
    }
39

    
40
    public AbstractTestUtils utils() {
41
        if (this.utils == null) {
42
            this.utils = this.createUtils();
43
        }
44
        return this.utils;
45
    }
46

    
47
    protected abstract AbstractTestUtils createUtils();
48

    
49
    public void testJsonValue() throws Exception {
50
        try {
51
            if (!utils().isTheDatabaseAvailable()) {
52
                return;
53
            }
54
            JDBCHelper helper = utils().createJDBCHelper();
55
            JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
56
            OperationsFactory operations = helper.getOperations();
57

    
58
            List<String> expectedSQLs = utils().getExpectedSQLs("testJsonValue.sql"); //getSQLs("resultSetForSetProvider.sql");
59

    
60
            FeatureStore sourceStore = utils().openSourceStore1();
61

    
62
            OperationsFactory.TableReference table = operations.createTableReference(
63
                    "dbtest",
64
                    sqlbuilder.default_schema(),
65
                    "test",
66
                    null
67
            );
68
            FeatureType featureType = sourceStore.getDefaultFeatureType();
69
            FeatureQuery query = sourceStore.createFeatureQuery("JSON_VALUE(String,'$.acc_cit')=1");
70
            EditableFeatureAttributeDescriptor extraColumn1
71
                    = query.getExtraColumn().add("JsonValue1", DataTypes.INTEGER);
72

    
73
            extraColumn1.setFeatureAttributeEmulator(
74
                    new DefaultFeatureAttributeEmulatorExpression(
75
                            featureType,
76
                            ExpressionUtils.createExpression("JSON_VALUE(String,'$.acc_cit')")));
77

    
78
            ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider(
79
                    table,
80
                    null,
81
                    null,
82
                    query,
83
                    featureType,
84
                    featureType,
85
                    0,
86
                    0,
87
                    0
88
            );
89
            String sql = resultSetForSetProvider.getSQL();
90
            System.out.println("###### testJsonValue(0)");
91
            System.out.println("###### SQL:" + sql + ";");
92
            System.out.println("###### EXP:" + expectedSQLs.get(0) + ";");
93
            
94
            assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(0), sql);
95
        } catch (Throwable th) {
96
            LOGGER.warn("", th);
97
            throw th;
98
        }
99
    }
100

    
101

    
102
}