gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.lib / org.gvsig.vcsgis.lib.impl / src / test / java / org / gvsig / vcsgis / lib / impl / Test02Initws.java @ 2725
History | View | Annotate | Download (6.66 KB)
1 |
package org.gvsig.vcsgis.lib.impl; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.Arrays; |
5 |
import java.util.Collections; |
6 |
import java.util.Comparator; |
7 |
import java.util.List; |
8 |
import junit.framework.TestCase; |
9 |
import static junit.framework.TestCase.assertEquals; |
10 |
import org.apache.commons.io.FileUtils; |
11 |
import org.apache.commons.lang3.StringUtils; |
12 |
import org.apache.commons.lang3.tuple.ImmutablePair; |
13 |
import org.apache.commons.lang3.tuple.Pair; |
14 |
import org.gvsig.fmap.dal.DALLocator; |
15 |
import org.gvsig.fmap.dal.DataManager; |
16 |
import org.gvsig.fmap.dal.DataStoreParameters; |
17 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
18 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
19 |
import org.gvsig.fmap.dal.feature.FeatureType; |
20 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
21 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
22 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
23 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
24 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
25 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
26 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
27 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
28 |
import org.gvsig.vcsgis.lib.workspace.tables.EntitiesTable; |
29 |
import org.gvsig.vcsgis.lib.workspace.tables.WorkspaceChangesTable; |
30 |
import org.gvsig.vcsgis.lib.workspace.tables.RemoteChangesTable; |
31 |
import org.gvsig.vcsgis.lib.workspace.tables.VarsTable; |
32 |
import org.slf4j.Logger; |
33 |
import org.slf4j.LoggerFactory; |
34 |
|
35 |
public class Test02Initws extends TestCase { |
36 |
|
37 |
private static final Logger LOGGER = LoggerFactory.getLogger(Test02Initws.class); |
38 |
|
39 |
public Test02Initws(String testName) { |
40 |
super(testName);
|
41 |
} |
42 |
|
43 |
@Override
|
44 |
protected void setUp() throws Exception { |
45 |
super.setUp();
|
46 |
new DefaultLibrariesInitializer().fullInitialize();
|
47 |
} |
48 |
|
49 |
@Override
|
50 |
protected void tearDown() throws Exception { |
51 |
super.tearDown();
|
52 |
} |
53 |
|
54 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
55 |
// public void testHello() {}
|
56 |
|
57 |
public void testCreateWS() throws Exception { |
58 |
String testid = "initws"; |
59 |
VCSGisManager vcsgismanager = VCSGisLocator.getVCSGisManager(); |
60 |
|
61 |
JDBCServerExplorerParameters server = TestUtils.getServerExplorerParameters("srv-"+testid);
|
62 |
File wsfile = TestUtils.getFile(FileUtils.getFile("test-dbs","ws-"+testid)); |
63 |
|
64 |
int r = vcsgismanager.initRepository(server, null); |
65 |
assertEquals("initRepository status", 0, r); |
66 |
|
67 |
TestUtils.h2sql_repository(server); |
68 |
VCSGisRepository repo = vcsgismanager.openRepository(server); |
69 |
|
70 |
r = vcsgismanager.initWorkspace(wsfile, repo, "Test initws", null); |
71 |
assertEquals("initWorkspace ws status", 0, r); |
72 |
TestUtils.h2sql_workspace(wsfile); |
73 |
|
74 |
VCSGisWorkspace workspace = vcsgismanager.openWorkspace(wsfile); |
75 |
assertNotNull("Can't open workspace", workspace);
|
76 |
|
77 |
|
78 |
JDBCServerExplorer wsexplorer = TestUtils.openServerExplorer(wsfile); |
79 |
List<DataStoreParameters> tables = wsexplorer.list();
|
80 |
Collections.sort(tables, new Comparator<DataStoreParameters>() { |
81 |
@Override
|
82 |
public int compare(DataStoreParameters o1, DataStoreParameters o2) { |
83 |
return StringUtils.compare(
|
84 |
((JDBCStoreParameters) o1).getTable(), |
85 |
((JDBCStoreParameters) o2).getTable() |
86 |
); |
87 |
} |
88 |
}); |
89 |
Pair<String, FeatureType>[] expectedTables = new Pair[]{ |
90 |
new ImmutablePair(WorkspaceChangesTable.TABLE_NAME,WorkspaceChangesTable.featureType()),
|
91 |
new ImmutablePair(VarsTable.TABLE_NAME,VarsTable.featureType()),
|
92 |
new ImmutablePair(EntitiesTable.TABLE_NAME,EntitiesTable.featureType()),
|
93 |
new ImmutablePair(RemoteChangesTable.TABLE_NAME,RemoteChangesTable.featureType()),
|
94 |
new ImmutablePair("gvsigd_config",null), |
95 |
// new ImmutablePair("gvsigd_repository",null),
|
96 |
new ImmutablePair("gvsigd_resources",null), |
97 |
}; |
98 |
Arrays.sort(expectedTables, new Comparator<Pair<String, FeatureType>>() { |
99 |
@Override
|
100 |
public int compare(Pair<String, FeatureType> o1, Pair<String, FeatureType> o2) { |
101 |
return StringUtils.compare(o1.getKey(),o2.getKey());
|
102 |
} |
103 |
}); |
104 |
int n = 0; |
105 |
for (DataStoreParameters table : tables) {
|
106 |
JDBCStoreParameters params = (JDBCStoreParameters) table; |
107 |
String tableName = params.getTable();
|
108 |
if (!tableName.startsWith("VCSGIS_") && !tableName.startsWith("gvsigd_")) { |
109 |
continue;
|
110 |
} |
111 |
assertEquals("table " + n, expectedTables[n++].getKey(), tableName);
|
112 |
} |
113 |
DataManager dataManager = DALLocator.getDataManager(); |
114 |
n = 0;
|
115 |
for (DataStoreParameters tableParams : tables) {
|
116 |
JDBCStoreParameters params = (JDBCStoreParameters) tableParams; |
117 |
String tableName = params.getTable();
|
118 |
if (!tableName.startsWith("VCSGIS_") && !tableName.startsWith("gvsigd_")) { |
119 |
continue;
|
120 |
} |
121 |
FeatureStore store = (FeatureStore) dataManager.openStore(params.getProviderName(), params); |
122 |
assertEquals("table " + n, expectedTables[n].getKey(), store.getName());
|
123 |
FeatureType expectedFeatureType = expectedTables[n].getValue(); |
124 |
if( expectedFeatureType!=null ) { |
125 |
FeatureType ft = store.getDefaultFeatureTypeQuietly(); |
126 |
for (FeatureAttributeDescriptor expectedAttr : expectedFeatureType) {
|
127 |
FeatureAttributeDescriptor attr = ft.getAttributeDescriptor(expectedAttr.getName()); |
128 |
assertNotNull("Attr "+expectedAttr.getName(), attr);
|
129 |
assertEquals("Attr "+expectedAttr.getName()+" type", expectedAttr.getType(), attr.getType()); |
130 |
assertEquals("Attr "+expectedAttr.getName()+" size", expectedAttr.getSize(), attr.getSize()); |
131 |
assertEquals("Attr "+expectedAttr.getName()+" isPrimaryKey", expectedAttr.isPrimaryKey(), attr.isPrimaryKey()); |
132 |
assertEquals("Attr "+expectedAttr.getName()+" isIndexed", expectedAttr.isIndexed(), attr.isIndexed()); |
133 |
assertEquals("Attr "+expectedAttr.getName()+" allowIndexDuplicateds", expectedAttr.allowIndexDuplicateds(), attr.allowIndexDuplicateds()); |
134 |
assertEquals("Attr "+expectedAttr.getName()+" isReadOnly", expectedAttr.isReadOnly(), attr.isReadOnly()); |
135 |
assertEquals("Attr "+expectedAttr.getName()+" DefaultValue", expectedAttr.getDefaultValue(), attr.getDefaultValue()); |
136 |
} |
137 |
} |
138 |
store.dispose(); |
139 |
n++; |
140 |
} |
141 |
} |
142 |
} |