svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.dbf / src / test / java / org / gvsig / fmap / dal / store / dbf / TestExtraColumn.java @ 44777
History | View | Annotate | Download (4.26 KB)
1 | 44669 | jjdelcerro | package org.gvsig.fmap.dal.store.dbf; |
---|---|---|---|
2 | 43512 | jjdelcerro | |
3 | 44669 | jjdelcerro | import java.io.File; |
4 | 43512 | jjdelcerro | import junit.framework.TestCase; |
5 | 44669 | jjdelcerro | import org.gvsig.fmap.dal.DALLocator; |
6 | import org.gvsig.fmap.dal.DataManager; |
||
7 | import org.gvsig.fmap.dal.DataServerExplorer; |
||
8 | import org.gvsig.fmap.dal.DataStore; |
||
9 | import org.gvsig.fmap.dal.feature.EditableFeature; |
||
10 | 44771 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
11 | 44669 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
12 | import org.gvsig.fmap.dal.feature.Feature; |
||
13 | 44771 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureExtraColumn; |
14 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
15 | 44669 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
16 | import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
||
17 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
||
18 | 44098 | jjdelcerro | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
19 | 43512 | jjdelcerro | |
20 | 44771 | jjdelcerro | public class TestExtraColumn extends TestCase { |
21 | 43512 | jjdelcerro | |
22 | 44771 | jjdelcerro | public TestExtraColumn(String testName) { |
23 | 43512 | jjdelcerro | super(testName);
|
24 | } |
||
25 | |||
26 | @Override
|
||
27 | protected void setUp() throws Exception { |
||
28 | super.setUp();
|
||
29 | 44098 | jjdelcerro | new DefaultLibrariesInitializer().fullInitialize();
|
30 | 43512 | jjdelcerro | } |
31 | |||
32 | @Override
|
||
33 | protected void tearDown() throws Exception { |
||
34 | super.tearDown();
|
||
35 | } |
||
36 | |||
37 | // TODO add test methods here. The name must begin with 'test'. For example:
|
||
38 | // public void testHello() {}
|
||
39 | |||
40 | 44669 | jjdelcerro | protected String getProviderName() { |
41 | return DataStore.DBASE_PROVIDER_NAME;
|
||
42 | 43512 | jjdelcerro | } |
43 | |||
44 | 44669 | jjdelcerro | protected String getTargetFilename() { |
45 | return "testCreateTarget1.dbf"; |
||
46 | 43512 | jjdelcerro | } |
47 | 44139 | jjdelcerro | |
48 | 44669 | jjdelcerro | protected FeatureStore openTargetStore1() throws Exception { |
49 | DataManager dataManager = DALLocator.getDataManager(); |
||
50 | File f = TestUtils.getResource(getTargetFilename());
|
||
51 | FeatureStore store = (FeatureStore) dataManager.openStore( |
||
52 | getProviderName(), |
||
53 | "DbfFile",f
|
||
54 | ); |
||
55 | return store;
|
||
56 | 43512 | jjdelcerro | } |
57 | 44139 | jjdelcerro | |
58 | 44669 | jjdelcerro | protected void createFrom(FeatureStore sourceStore) throws Exception { |
59 | DataManager dataManager = DALLocator.getDataManager(); |
||
60 | DataServerExplorer explorer = dataManager.openServerExplorer( |
||
61 | DataServerExplorer.FILESYSTEM_SERVER_EXPLORER_NAME, |
||
62 | "root", TestUtils.getTargetFolder()
|
||
63 | ); |
||
64 | 44421 | jjdelcerro | |
65 | 44669 | jjdelcerro | NewFeatureStoreParameters params = (NewFeatureStoreParameters) explorer.getAddParameters( |
66 | getProviderName() |
||
67 | ); |
||
68 | ((FilesystemStoreParameters)params).setFile(TestUtils.getResource(getTargetFilename())); |
||
69 | EditableFeatureType ft = params.getDefaultFeatureType(); |
||
70 | ft.addAll(sourceStore.getDefaultFeatureType()); |
||
71 | explorer.add(getProviderName(), params, true);
|
||
72 | 44421 | jjdelcerro | } |
73 | |||
74 | 43512 | jjdelcerro | |
75 | 44669 | jjdelcerro | protected void copyFrom(FeatureStore sourceStore, int mode) throws Exception { |
76 | FeatureStore targetStore = openTargetStore1(); |
||
77 | targetStore.edit(mode); |
||
78 | try {
|
||
79 | for (Feature sourceFeature : sourceStore.getFeatureSet()) {
|
||
80 | EditableFeature targetFeature = targetStore.createNewFeature(sourceFeature); |
||
81 | targetStore.insert(targetFeature); |
||
82 | } |
||
83 | } finally {
|
||
84 | targetStore.finishEditing(); |
||
85 | } |
||
86 | 43512 | jjdelcerro | } |
87 | |||
88 | 44771 | jjdelcerro | public void testColumnExtra1() throws Exception { |
89 | 44669 | jjdelcerro | FeatureStore sourceStore = TestUtils.openSourceStore1(); |
90 | 44384 | jjdelcerro | |
91 | 44669 | jjdelcerro | createFrom(sourceStore); |
92 | copyFrom(sourceStore, FeatureStore.MODE_APPEND); |
||
93 | 44771 | jjdelcerro | FeatureStore store = openTargetStore1(); |
94 | FeatureQuery query = store.createFeatureQuery(); |
||
95 | FeatureExtraColumn extra = query.getExtraColumn(); |
||
96 | 44777 | jjdelcerro | query.addFilter("ID = 3");
|
97 | EditableFeatureAttributeDescriptor descriptor = extra.add("test1");
|
||
98 | query.retrievesAllAttributes(); |
||
99 | descriptor.setFeatureAttributeEmulator("Long/10.0");
|
||
100 | 44771 | jjdelcerro | Feature f = store.findFirst(query); |
101 | 44777 | jjdelcerro | |
102 | // El feature type de la feature debe tener la columna extra
|
||
103 | EditableFeatureAttributeDescriptor descriptor2 = f.getType().getExtraColumn().get("test1");
|
||
104 | assertTrue(descriptor2!=null);
|
||
105 | 44775 | jjdelcerro | |
106 | 44777 | jjdelcerro | // El feature type de los descriptores de los columnas extra debe ser null siempre.
|
107 | assertTrue(descriptor2.getFeatureType()==null);
|
||
108 | |||
109 | // El valor de la columna extra debe ser el que toca.
|
||
110 | Number value = (Number) f.getExtraValue("test1"); |
||
111 | assertEquals(Long.valueOf(300), value); |
||
112 | 44098 | jjdelcerro | } |
113 | 43939 | jjdelcerro | } |