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 / Test01InitRepo.java @ 3075
History | View | Annotate | Download (6.72 KB)
1 |
package org.gvsig.vcsgis.lib.impl; |
---|---|
2 |
|
3 |
import java.util.Collections; |
4 |
import java.util.List; |
5 |
import junit.framework.TestCase; |
6 |
import static junit.framework.TestCase.assertEquals; |
7 |
import org.apache.commons.lang3.StringUtils; |
8 |
import org.gvsig.fmap.dal.DALLocator; |
9 |
import org.gvsig.fmap.dal.DataManager; |
10 |
import org.gvsig.fmap.dal.DataStoreParameters; |
11 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_CONFIGURATION_NAME; |
12 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.TABLE_RESOURCES_NAME; |
13 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
15 |
import org.gvsig.fmap.dal.feature.FeatureType; |
16 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
17 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
18 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
19 |
import org.gvsig.tools.util.ListBuilder; |
20 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
21 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
22 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.DataRepoTable; |
23 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.EntitiesRepoTable; |
24 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.HooksRepoTable; |
25 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.RevisionsRepoTable; |
26 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.ServerConfigRepoTable; |
27 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.TopologyplanRepoTable; |
28 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable; |
29 |
import org.slf4j.Logger; |
30 |
import org.slf4j.LoggerFactory; |
31 |
|
32 |
public class Test01InitRepo extends TestCase { |
33 |
|
34 |
private static final Logger LOGGER = LoggerFactory.getLogger(Test01InitRepo.class); |
35 |
|
36 |
public Test01InitRepo(String testName) { |
37 |
super(testName);
|
38 |
} |
39 |
|
40 |
@Override
|
41 |
protected void setUp() throws Exception { |
42 |
super.setUp();
|
43 |
new DefaultLibrariesInitializer().fullInitialize();
|
44 |
} |
45 |
|
46 |
@Override
|
47 |
protected void tearDown() throws Exception { |
48 |
super.tearDown();
|
49 |
} |
50 |
|
51 |
private static class ExpectedValue implements Comparable<ExpectedValue>{ |
52 |
|
53 |
private final String tableName; |
54 |
private final FeatureType featureType; |
55 |
public ExpectedValue(String tableName, FeatureType featureType) { |
56 |
this.tableName = tableName;
|
57 |
this.featureType = featureType;
|
58 |
} |
59 |
|
60 |
@Override
|
61 |
public int compareTo(ExpectedValue o) { |
62 |
return this.tableName.compareTo(o.tableName); |
63 |
} |
64 |
} |
65 |
|
66 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
67 |
// public void testHello() {}
|
68 |
public void testInit1() throws Exception { |
69 |
final String testid = "initrepo"; |
70 |
JDBCServerExplorer server = TestUtils.openServerExplorer("srv-"+testid);
|
71 |
|
72 |
VCSGisManager vcsgismanager = VCSGisLocator.getVCSGisManager(); |
73 |
|
74 |
int r = vcsgismanager.initRepository(server.getParameters(), null); |
75 |
assertEquals("initRepository status", 0, r); |
76 |
TestUtils.h2sql_repository(server); |
77 |
|
78 |
List<DataStoreParameters> tables = server.list();
|
79 |
Collections.sort(tables, (DataStoreParameters o1, DataStoreParameters o2) -> StringUtils.compare(
|
80 |
((JDBCStoreParameters) o1).getTable(), |
81 |
((JDBCStoreParameters) o2).getTable() |
82 |
)); |
83 |
List<ExpectedValue> expectedValues = new ListBuilder() |
84 |
.add(new ExpectedValue(DataRepoTable.TABLE_NAME,DataRepoTable.featureType()))
|
85 |
.add(new ExpectedValue(EntitiesRepoTable.TABLE_NAME,EntitiesRepoTable.featureType()))
|
86 |
.add(new ExpectedValue(HooksRepoTable.TABLE_NAME,HooksRepoTable.featureType()))
|
87 |
.add(new ExpectedValue(RevisionsRepoTable.TABLE_NAME,RevisionsRepoTable.featureType()))
|
88 |
.add(new ExpectedValue(ServerConfigRepoTable.TABLE_NAME,ServerConfigRepoTable.featureType()))
|
89 |
.add(new ExpectedValue(TopologyplanRepoTable.TABLE_NAME,TopologyplanRepoTable.featureType()))
|
90 |
.add(new ExpectedValue(UsersRepoTable.TABLE_NAME,UsersRepoTable.featureType()))
|
91 |
|
92 |
.add(new ExpectedValue(TABLE_CONFIGURATION_NAME,null)) |
93 |
// .add(new ExpectedValue(TABLE_REPOSITORY_NAME,null))
|
94 |
.add(new ExpectedValue(TABLE_RESOURCES_NAME,null)) |
95 |
.asList(); |
96 |
Collections.sort(expectedValues);
|
97 |
|
98 |
|
99 |
int n = 0; |
100 |
for (DataStoreParameters table : tables) {
|
101 |
JDBCStoreParameters params = (JDBCStoreParameters) table; |
102 |
String tableName = params.getTable();
|
103 |
if (!tableName.startsWith("VCSGIS_") && !tableName.startsWith("GVSIGD_")) { |
104 |
continue;
|
105 |
} |
106 |
assertEquals("table " + n, expectedValues.get(n++).tableName, tableName);
|
107 |
} |
108 |
DataManager dataManager = DALLocator.getDataManager(); |
109 |
n = 0;
|
110 |
for (DataStoreParameters tableParams : tables) {
|
111 |
JDBCStoreParameters params = (JDBCStoreParameters) tableParams; |
112 |
String tableName = params.getTable();
|
113 |
if (!tableName.startsWith("VCSGIS_") && !tableName.startsWith("GVSIGD_")) { |
114 |
continue;
|
115 |
} |
116 |
FeatureStore store = (FeatureStore) dataManager.openStore(params.getProviderName(), params); |
117 |
assertEquals("table " + n, expectedValues.get(n).tableName, store.getName());
|
118 |
FeatureType expectedFeatureType = expectedValues.get(n).featureType; |
119 |
if (expectedFeatureType != null) { |
120 |
FeatureType ft = store.getDefaultFeatureTypeQuietly(); |
121 |
for (FeatureAttributeDescriptor expectedAttr : expectedFeatureType) {
|
122 |
FeatureAttributeDescriptor attr = ft.getAttributeDescriptor(expectedAttr.getName()); |
123 |
assertNotNull("Attr " + expectedAttr.getName(), attr);
|
124 |
assertEquals("Attr " + expectedAttr.getName() + " type", expectedAttr.getType(), attr.getType()); |
125 |
assertEquals("Attr " + expectedAttr.getName() + " size", expectedAttr.getSize(), attr.getSize()); |
126 |
assertEquals("Attr " + expectedAttr.getName() + " isPrimaryKey", expectedAttr.isPrimaryKey(), attr.isPrimaryKey()); |
127 |
assertEquals("Attr " + expectedAttr.getName() + " isIndexed", expectedAttr.isIndexed(), attr.isIndexed()); |
128 |
assertEquals("Attr " + expectedAttr.getName() + " allowIndexDuplicateds", expectedAttr.allowIndexDuplicateds(), attr.allowIndexDuplicateds()); |
129 |
assertEquals("Attr " + expectedAttr.getName() + " isReadOnly", expectedAttr.isReadOnly(), attr.isReadOnly()); |
130 |
assertEquals("Attr " + expectedAttr.getName() + " DefaultValue", expectedAttr.getDefaultValue(), attr.getDefaultValue()); |
131 |
} |
132 |
} |
133 |
store.dispose(); |
134 |
n++; |
135 |
} |
136 |
} |
137 |
} |