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