Revision c0248cde
Added by Andreas Müller over 7 years ago
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/database/update/CdmUpdaterTest.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2009 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
// ******************** TESTS ****************************************************/ |
55 |
|
|
55 |
|
|
56 | 56 |
@Ignore |
57 | 57 |
@Test |
58 | 58 |
public void testUpdateToCurrentVersion() { |
... | ... | |
66 | 66 |
} catch (SQLException e) { |
67 | 67 |
Assert.fail(); |
68 | 68 |
} |
69 |
cdmUpdater.updateToCurrentVersion(datasource, null);
|
|
69 |
cdmUpdater.updateToCurrentVersion(datasource, null); |
|
70 | 70 |
} |
71 |
|
|
71 |
|
|
72 | 72 |
private static ICdmDataSource cdm_test_andreasM(){ |
73 | 73 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
74 | 74 |
String cdmServer = "192.168.2.10"; |
75 |
String cdmDB = "cdm_test_andreasM";
|
|
75 |
String cdmDB = "cdm_test_andreasM"; |
|
76 | 76 |
String cdmUserName = "edit"; |
77 | 77 |
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
78 | 78 |
} |
79 |
|
|
79 |
|
|
80 | 80 |
private static ICdmDataSource cdm_test_algaterra(){ |
81 | 81 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
82 | 82 |
String cdmServer = "160.45.63.201"; |
83 |
String cdmDB = "cdm_edit_algaterra";
|
|
83 |
String cdmDB = "cdm_edit_algaterra"; |
|
84 | 84 |
String cdmUserName = "edit"; |
85 | 85 |
return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
86 | 86 |
} |
87 |
|
|
87 |
|
|
88 | 88 |
// private static ICdmDataSource cdm_import(){ |
89 | 89 |
// DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
90 | 90 |
// String cdmServer = "160.45.63.151"; |
91 |
// String cdmDB = "cdm_production_campanulaceae";
|
|
91 |
// String cdmDB = "cdm_production_campanulaceae"; |
|
92 | 92 |
// String cdmUserName = "edit"; |
93 | 93 |
// return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null); |
94 | 94 |
// } |
95 |
|
|
95 |
|
|
96 | 96 |
private static ICdmDataSource makeDestination(DatabaseTypeEnum dbType, String cdmServer, String cdmDB, int port, String cdmUserName, String pwd ){ |
97 | 97 |
//establish connection |
98 | 98 |
pwd = AccountStore.readOrStorePassword(cdmServer, cdmDB, cdmUserName, pwd); |
99 | 99 |
ICdmDataSource destination; |
100 | 100 |
if(dbType.equals(DatabaseTypeEnum.MySQL)){ |
101 |
destination = CdmDataSource.NewMySqlInstance(cdmServer, cdmDB, port, cdmUserName, pwd, null);
|
|
101 |
destination = CdmDataSource.NewMySqlInstance(cdmServer, cdmDB, port, cdmUserName, pwd);
|
|
102 | 102 |
} else if(dbType.equals(DatabaseTypeEnum.PostgreSQL)){ |
103 |
destination = CdmDataSource.NewPostgreSQLInstance(cdmServer, cdmDB, port, cdmUserName, pwd, null);
|
|
103 |
destination = CdmDataSource.NewPostgreSQLInstance(cdmServer, cdmDB, port, cdmUserName, pwd);
|
|
104 | 104 |
} else { |
105 | 105 |
//TODO others |
106 | 106 |
throw new RuntimeException("Unsupported DatabaseType"); |
107 | 107 |
} |
108 | 108 |
return destination; |
109 | 109 |
} |
110 |
|
|
110 |
|
|
111 | 111 |
@Test |
112 | 112 |
public void testRecursiveCallSchemaUpdater(){ |
113 | 113 |
CdmUpdater updater = new CdmUpdater(); |
... | ... | |
115 | 115 |
try { |
116 | 116 |
Method method = CdmUpdater.class.getDeclaredMethod("getCurrentSchemaUpdater"); |
117 | 117 |
method.setAccessible(true); |
118 |
|
|
118 |
|
|
119 | 119 |
currentUpdater = (ISchemaUpdater)method.invoke(updater); |
120 | 120 |
} catch (Exception e) { |
121 | 121 |
Assert.fail("CdmUpdater.getCurrentSchemaUpdater not found:" + e.getMessage());; |
122 | 122 |
} |
123 | 123 |
ISchemaUpdater lastUpdater = null; |
124 | 124 |
ISchemaUpdater tmpUpdater = currentUpdater; |
125 |
|
|
125 |
|
|
126 | 126 |
int i = 0; |
127 | 127 |
//get very first schema updater available (= SchemaUpdater_24_25) by recursive call to getPreviousUpdater |
128 | 128 |
while (tmpUpdater.getPreviousUpdater() != null && i++<1000){ |
... | ... | |
131 | 131 |
} |
132 | 132 |
Assert.assertNotNull("Current Updater must not be null", currentUpdater); |
133 | 133 |
Assert.assertEquals("Very first schema updater must be schemaUpdater_24_25. Something seems to be wrong in recursive call of getPreviousSchemaUpdater", SchemaUpdater_24_25.class, lastUpdater.getClass()); |
134 |
|
|
134 |
|
|
135 | 135 |
i = 0; |
136 | 136 |
while (tmpUpdater.getNextUpdater() != null && i++<1000){ |
137 | 137 |
tmpUpdater = tmpUpdater.getNextUpdater(); |
138 | 138 |
lastUpdater = tmpUpdater; |
139 | 139 |
} |
140 | 140 |
Assert.assertEquals("Current schema updater not found by recursive call firstUpdater.getNextUpdater()", currentUpdater.getClass(), lastUpdater.getClass()); |
141 |
|
|
141 |
|
|
142 | 142 |
//test correct schema version string |
143 | 143 |
Assert.assertEquals(CdmMetaData.getDbSchemaVersion(), currentUpdater.getTargetVersion()); |
144 | 144 |
} |
145 |
|
|
145 |
|
|
146 | 146 |
@Test |
147 | 147 |
public void testRecursiveCallTermUpdater(){ |
148 | 148 |
CdmUpdater updater = new CdmUpdater(); |
... | ... | |
163 | 163 |
tmpUpdater = tmpUpdater.getPreviousUpdater(); |
164 | 164 |
lastUpdater = tmpUpdater; |
165 | 165 |
} |
166 |
|
|
166 |
|
|
167 | 167 |
Assert.assertEquals(TermUpdater_24_25.class, lastUpdater.getClass()); |
168 |
|
|
168 |
|
|
169 | 169 |
i = 0; |
170 | 170 |
while (tmpUpdater.getNextUpdater() != null && i++<1000){ |
171 | 171 |
tmpUpdater = tmpUpdater.getNextUpdater(); |
... | ... | |
176 | 176 |
//test correct schema version string |
177 | 177 |
Assert.assertEquals(CdmMetaData.getTermsVersion(), currentUpdater.getTargetVersion()); |
178 | 178 |
} |
179 |
|
|
179 |
|
|
180 | 180 |
} |
Also available in: Unified diff
ref #3658 remove nomenclaturalCode from all datasource related classes