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 / AbstractTestWhereWithComputedField.java @ 46170

History | View | Annotate | Download (4.31 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.gvsig.expressionevaluator.ExpressionUtils;
8
import org.gvsig.fmap.dal.DataTypes;
9
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
10
import org.gvsig.fmap.dal.feature.EditableFeatureType;
11
import org.gvsig.fmap.dal.feature.Feature;
12
import org.gvsig.fmap.dal.feature.FeatureQuery;
13
import org.gvsig.fmap.dal.feature.FeatureStore;
14
import org.gvsig.fmap.dal.feature.FeatureType;
15
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression;
16
import org.gvsig.tools.dispose.DisposeUtils;
17
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

    
21
public abstract class AbstractTestWhereWithComputedField extends TestCase {
22

    
23
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractTestWhereWithComputedField.class);
24

    
25
    protected AbstractTestUtils utils;
26

    
27
    public AbstractTestWhereWithComputedField(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
    public AbstractTestUtils utils() {
43
        if (this.utils == null) {
44
            this.utils = this.createUtils();
45
        }
46
        return this.utils;
47
    }
48

    
49
    protected abstract AbstractTestUtils createUtils();
50

    
51
    // TODO add test methods here. The name must begin with 'test'. For example:
52
    // public void testHello() {}
53
    protected void testWhereWithComputedField() throws Exception {
54
        try {
55
            if (!utils().isTheDatabaseAvailable()) {
56
                return;
57
            }
58
            FeatureStore sourceStore = utils().openSourceStore2();
59
            JDBCServerExplorer explorer = utils().openServerExplorer("testCreate");
60
            utils().initWorkspace("testCreate");
61
            
62
            utils().info_jdbc(explorer);
63

    
64
            utils().drop_tables(explorer, "testCreateTarget2");
65
            utils().create_table_from(explorer, "testCreateTarget2", sourceStore);
66
            utils().insert_into_from(explorer, "testCreateTarget2", sourceStore, FeatureStore.MODE_APPEND);
67

    
68
            FeatureStore dbstore = utils().openStore(explorer, "testCreateTarget2");
69
            dbstore.edit();
70
            FeatureType featureType = dbstore.getDefaultFeatureType();
71
            EditableFeatureType eFeatureType = featureType.getEditable();
72
            eFeatureType.add("Compu1",
73
                    DataTypes.INTEGER,
74
                    new DefaultFeatureAttributeEmulatorExpression(
75
                            eFeatureType,
76
                            ExpressionUtils.createExpression("ID*2")
77
                    ));
78
            eFeatureType.add("Compu2",
79
                    DataTypes.INTEGER,
80
                    new DefaultFeatureAttributeEmulatorExpression(
81
                            eFeatureType,
82
                            ExpressionUtils.createExpression("Poblacion+10000+Compu1")
83
                    ));
84
            dbstore.update(eFeatureType);
85
            dbstore.finishEditing();
86
            List<Feature> features1 = dbstore.getFeatures("Compu1>8");
87
            System.out.println("## in output");
88
            assertEquals("Features 1 size:", 5, features1.size());
89
            for (int i = 0; i < features1.size(); i++) {
90
                Feature feature = features1.get(i);
91
                System.out.println("field Compu1: "+feature.format("Compu1") + " feature "+i+": "+feature.toString());
92
            }
93
            List<Feature> features2 = dbstore.getFeatures("Compu1<=8");
94
            System.out.println("## in output");
95
            assertEquals("Features 2 size:", 5, features2.size());
96
            for (int i = 0; i < features2.size(); i++) {
97
                Feature feature = features2.get(i);
98
                System.out.println("field Compu1: "+feature.format("Compu1") + " feature "+i+": "+feature.toString());
99
            }
100
            
101
            System.out.println("## end output");
102
            DisposeUtils.dispose(dbstore);
103
        } catch (Throwable th) {
104
            LOGGER.warn("", th);
105
            throw th;
106
        }
107
    }
108

    
109
}