2424@ RunWith (DbAndIOTestRunner .class )
2525public class DbMaintenanceToolIntegrationTest {
2626
27- private final String fs ;
2827 private File configDir ;
2928 private GeometryFactory geometryFactory ;
3029
31- public DbMaintenanceToolIntegrationTest () {
32- fs = File .separator ;
33- }
34-
3530 @ Before
3631 public void setUp () {
3732 final File testDirectory = TestUtil .createTestDirectory ();
@@ -86,8 +81,7 @@ public void testInvalidCommandLine() throws ParseException {
8681
8782 @ Test
8883 public void testCorrectPaths_MongoDb_empty_Db () throws IOException , ParseException {
89- TestUtil .writeDatabaseProperties_MongoDb (configDir );
90- TestUtil .writeSystemConfig (configDir );
84+ setUpMongoDb ();
9185
9286 final String [] args = new String []{"-c" , configDir .getAbsolutePath (),
9387 "-p" , "/data/archive/wrong" , "-r" , "/archive/correct" };
@@ -98,153 +92,119 @@ public void testCorrectPaths_MongoDb_empty_Db() throws IOException, ParseExcepti
9892
9993 @ Test
10094 public void testCorrectPaths_MongoDb_alterNoPath () throws IOException , ParseException , SQLException {
101- TestUtil .writeDatabaseProperties_MongoDb (configDir );
102- TestUtil .writeSystemConfig (configDir );
103- final BasicDataSource dataSource = TestUtil .getDataSource_MongoDb ();
95+ final BasicDataSource dataSource = setUpMongoDb ();
10496
10597 runTest_alterNoPath (dataSource );
10698 }
10799
108100 @ Test
109101 public void testCorrectPaths_Postgres_alterNoPath () throws IOException , ParseException , SQLException {
110- TestUtil .writeDatabaseProperties_Postgres (configDir );
111- TestUtil .writeSystemConfig (configDir );
112- final BasicDataSource dataSource = TestUtil .getDataSource_Postgres ();
102+ final BasicDataSource dataSource = setUpPostgresDb ();
113103
114104 runTest_alterNoPath (dataSource );
115105 }
116106
117107 @ Test
118108 public void testCorrectPaths_H2_alterNoPath () throws IOException , ParseException , SQLException {
119- TestUtil .writeDatabaseProperties_H2 (configDir );
120- TestUtil .writeSystemConfig (configDir );
121- final BasicDataSource dataSource = TestUtil .getDatasource_H2 ();
109+ final BasicDataSource dataSource = setUpH2Db ();
122110
123111 runTest_alterNoPath (dataSource );
124112 }
125113
126114 @ Test
127115 public void testCorrectPaths_MongoDb_alterSomePaths () throws IOException , ParseException , SQLException {
128- TestUtil .writeDatabaseProperties_MongoDb (configDir );
129- TestUtil .writeSystemConfig (configDir );
130- final BasicDataSource dataSource = TestUtil .getDataSource_MongoDb ();
116+ final BasicDataSource dataSource = setUpMongoDb ();
131117
132118 runTest_alterSomePaths (dataSource );
133119 }
134120
135121 @ Test
136122 public void testCorrectPaths_Postgres_alterSomePaths () throws IOException , ParseException , SQLException {
137- TestUtil .writeDatabaseProperties_Postgres (configDir );
138- TestUtil .writeSystemConfig (configDir );
139- final BasicDataSource dataSource = TestUtil .getDataSource_Postgres ();
123+ final BasicDataSource dataSource = setUpPostgresDb ();
140124
141125 runTest_alterSomePaths (dataSource );
142126 }
143127
144128 @ Test
145129 public void testTruncatePaths_MongoDb_alterSomePaths () throws IOException , ParseException , SQLException {
146- TestUtil .writeDatabaseProperties_MongoDb (configDir );
147- TestUtil .writeSystemConfig (configDir );
148- final BasicDataSource dataSource = TestUtil .getDataSource_MongoDb ();
130+ final BasicDataSource dataSource = setUpMongoDb ();
149131
150132 runTest_truncatePath (dataSource );
151133 }
152134
153135 @ Test
154136 public void testTruncatePaths_Postgres_alterSomePaths () throws IOException , ParseException , SQLException {
155- TestUtil .writeDatabaseProperties_Postgres (configDir );
156- TestUtil .writeSystemConfig (configDir );
157- final BasicDataSource dataSource = TestUtil .getDataSource_Postgres ();
137+ final BasicDataSource dataSource = setUpPostgresDb ();
158138
159139 runTest_truncatePath (dataSource );
160140 }
161141
162142 @ Test
163143 public void testTruncatePaths_H2_alterSomePaths () throws IOException , ParseException , SQLException {
164- TestUtil .writeDatabaseProperties_H2 (configDir );
165- TestUtil .writeSystemConfig (configDir );
166- final BasicDataSource dataSource = TestUtil .getDatasource_H2 ();
144+ final BasicDataSource dataSource = setUpH2Db ();
167145
168146 runTest_truncatePath (dataSource );
169147 }
170148
171149 @ Test
172150 public void testTruncatePaths_MongoDb_innerSegment () throws IOException , ParseException , SQLException {
173- TestUtil .writeDatabaseProperties_MongoDb (configDir );
174- TestUtil .writeSystemConfig (configDir );
175- final BasicDataSource dataSource = TestUtil .getDataSource_MongoDb ();
151+ final BasicDataSource dataSource = setUpMongoDb ();
176152
177153 runTest_truncatePath_innerSegment (dataSource );
178154 }
179155
180156 @ Test
181157 public void testTruncatePaths_Postgres_innerSegment () throws IOException , ParseException , SQLException {
182- TestUtil .writeDatabaseProperties_Postgres (configDir );
183- TestUtil .writeSystemConfig (configDir );
184- final BasicDataSource dataSource = TestUtil .getDataSource_Postgres ();
158+ final BasicDataSource dataSource = setUpPostgresDb ();
185159
186160 runTest_truncatePath_innerSegment (dataSource );
187161 }
188162
189163 @ Test
190164 public void testTruncatePaths_H2_innerSegment () throws IOException , ParseException , SQLException {
191- TestUtil .writeDatabaseProperties_H2 (configDir );
192- TestUtil .writeSystemConfig (configDir );
193- final BasicDataSource dataSource = TestUtil .getDatasource_H2 ();
165+ final BasicDataSource dataSource = setUpH2Db ();
194166
195167 runTest_truncatePath_innerSegment (dataSource );
196168 }
197169
198170 @ Test
199171 public void testDryRun_MongoDb_correctPaths () throws IOException , ParseException , SQLException {
200- TestUtil .writeDatabaseProperties_MongoDb (configDir );
201- TestUtil .writeSystemConfig (configDir );
202- final BasicDataSource dataSource = TestUtil .getDataSource_MongoDb ();
172+ final BasicDataSource dataSource = setUpMongoDb ();
203173
204174 runTest_dryRun_allOk (dataSource );
205175 }
206176
207177 @ Test
208178 public void testDryRun_Postgres_correctPaths () throws IOException , ParseException , SQLException {
209- TestUtil .writeDatabaseProperties_Postgres (configDir );
210- TestUtil .writeSystemConfig (configDir );
211- final BasicDataSource dataSource = TestUtil .getDataSource_Postgres ();
179+ final BasicDataSource dataSource = setUpPostgresDb ();
212180
213181 runTest_dryRun_allOk (dataSource );
214182 }
215183
216184 @ Test
217185 public void testDryRun_H2_correctPaths () throws IOException , ParseException , SQLException {
218- TestUtil .writeDatabaseProperties_H2 (configDir );
219- TestUtil .writeSystemConfig (configDir );
220- final BasicDataSource dataSource = TestUtil .getDatasource_H2 ();
186+ final BasicDataSource dataSource = setUpH2Db ();
221187
222188 runTest_dryRun_allOk (dataSource );
223189 }
224190
225191 @ Test
226192 public void testDryRun_MongoDb_someIncorrectPaths () throws IOException , ParseException , SQLException {
227- TestUtil .writeDatabaseProperties_MongoDb (configDir );
228- TestUtil .writeSystemConfig (configDir );
229- final BasicDataSource dataSource = TestUtil .getDataSource_MongoDb ();
193+ final BasicDataSource dataSource = setUpMongoDb ();
230194
231195 runTest_dryRun_someNotOk (dataSource );
232196 }
233197
234198 @ Test
235199 public void testDryRun_Postgres_someIncorrectPaths () throws IOException , ParseException , SQLException {
236- TestUtil .writeDatabaseProperties_Postgres (configDir );
237- TestUtil .writeSystemConfig (configDir );
238- final BasicDataSource dataSource = TestUtil .getDataSource_Postgres ();
200+ final BasicDataSource dataSource = setUpPostgresDb ();
239201
240202 runTest_dryRun_someNotOk (dataSource );
241203 }
242204
243205 @ Test
244206 public void testDryRun_H2_someIncorrectPaths () throws IOException , ParseException , SQLException {
245- TestUtil .writeDatabaseProperties_H2 (configDir );
246- TestUtil .writeSystemConfig (configDir );
247- final BasicDataSource dataSource = TestUtil .getDatasource_H2 ();
207+ final BasicDataSource dataSource = setUpH2Db ();
248208
249209 runTest_dryRun_someNotOk (dataSource );
250210 }
@@ -272,7 +232,7 @@ private void runTest_alterNoPath(BasicDataSource dataSource) throws SQLException
272232 final List <SatelliteObservation > observations = storage .get ();
273233 assertEquals (12 , observations .size ());
274234 for (SatelliteObservation satelliteObservation : observations ) {
275- assertTrue (satelliteObservation .getDataFilePath ().toString ().contains (fs + "archive" + fs + "correct" ));
235+ assertTrue (satelliteObservation .getDataFilePath ().toString ().contains (replacePath ));
276236 }
277237 } finally {
278238 storage .clear ();
@@ -306,7 +266,7 @@ private void runTest_alterSomePaths(BasicDataSource dataSource) throws SQLExcept
306266 final List <SatelliteObservation > observations = storage .get ();
307267 assertEquals (16 , observations .size ());
308268 for (SatelliteObservation satelliteObservation : observations ) {
309- assertTrue (satelliteObservation .getDataFilePath ().toString ().contains (fs + "archive" + fs + "correct" ));
269+ assertTrue (satelliteObservation .getDataFilePath ().toString ().contains (replacePath ));
310270 }
311271 } finally {
312272 storage .clear ();
@@ -474,4 +434,23 @@ private Storage initializeStorage(BasicDataSource dataSource) throws SQLExceptio
474434
475435 return storage ;
476436 }
437+
438+ private BasicDataSource setUpMongoDb () throws IOException {
439+ TestUtil .writeDatabaseProperties_MongoDb (configDir );
440+ TestUtil .writeSystemConfig (configDir );
441+
442+ return TestUtil .getDataSource_MongoDb ();
443+ }
444+
445+ private BasicDataSource setUpPostgresDb () throws IOException {
446+ TestUtil .writeDatabaseProperties_Postgres (configDir );
447+ TestUtil .writeSystemConfig (configDir );
448+ return TestUtil .getDataSource_Postgres ();
449+ }
450+
451+ private BasicDataSource setUpH2Db () throws IOException {
452+ TestUtil .writeDatabaseProperties_H2 (configDir );
453+ TestUtil .writeSystemConfig (configDir );
454+ return TestUtil .getDatasource_H2 ();
455+ }
477456}
0 commit comments