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 @ 46193

History | View | Annotate | Download (3.73 KB)

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

    
3
import java.util.ArrayList;
4
import java.util.List;
5
import junit.framework.TestCase;
6
import static junit.framework.TestCase.assertEquals;
7
import org.apache.commons.math.stat.inference.TestUtils;
8
import org.gvsig.expressionevaluator.ExpressionUtils;
9
import org.gvsig.fmap.dal.DataTypes;
10
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
11
import org.gvsig.fmap.dal.feature.EditableFeatureType;
12
import org.gvsig.fmap.dal.feature.Feature;
13
import org.gvsig.fmap.dal.feature.FeatureQuery;
14
import org.gvsig.fmap.dal.feature.FeatureStore;
15
import org.gvsig.fmap.dal.feature.FeatureType;
16
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression;
17
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
18
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation;
19
import org.gvsig.tools.dispose.DisposeUtils;
20
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
21
import org.slf4j.Logger;
22
import org.slf4j.LoggerFactory;
23

    
24
public abstract class AbstractTestJsonValue extends TestCase {
25

    
26
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractTestJsonValue.class);
27

    
28
    protected AbstractTestUtils utils;
29

    
30
    public AbstractTestJsonValue(String testName) {
31
        super(testName);
32
    }
33

    
34
    @Override
35
    protected void setUp() throws Exception {
36
        super.setUp();
37
        new DefaultLibrariesInitializer().fullInitialize();
38
    }
39

    
40
    @Override
41
    protected void tearDown() throws Exception {
42
        super.tearDown();
43
    }
44

    
45
    public AbstractTestUtils utils() {
46
        if (this.utils == null) {
47
            this.utils = this.createUtils();
48
        }
49
        return this.utils;
50
    }
51

    
52
    protected abstract AbstractTestUtils createUtils();
53

    
54
    public void testJsonValue1() throws Exception {
55
        try {
56
            if (!utils().isTheDatabaseAvailable()) {
57
                return;
58
            }
59
            JDBCHelper helper = utils().createJDBCHelper();
60
            JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
61
            OperationsFactory operations = helper.getOperations();
62

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

    
65
            FeatureStore sourceStore = utils().openSourceStore1();
66

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

    
78
            extraColumn1.setFeatureAttributeEmulator(
79
                    new DefaultFeatureAttributeEmulatorExpression(
80
                            featureType,
81
                            ExpressionUtils.createExpression("JSON_VALUE(String,'$.acc_cit')")));
82

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

    
103

    
104
}