Skip to content

Commit 921ef2e

Browse files
authored
TRUNK-6464: Test Context should not create new application data directory for each test (#5466)
Apply to legacy BaseContextSensitiveTest
1 parent e93c245 commit 921ef2e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

api/src/test/java/org/openmrs/test/BaseContextSensitiveTest.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,18 +358,20 @@ public Properties getRuntimeProperties() {
358358
runtimeProperties.setProperty(Environment.HBM2DDL_AUTO, "update");
359359
}
360360

361-
try {
362-
File tempappdir = File.createTempFile("appdir-for-unit-tests-", "");
363-
tempappdir.delete(); // so we can make it into a directory
364-
tempappdir.mkdir(); // turn it into a directory
365-
tempappdir.deleteOnExit(); // clean up when we're done with tests
366-
367-
runtimeProperties.setProperty(OpenmrsConstants.APPLICATION_DATA_DIRECTORY_RUNTIME_PROPERTY, tempappdir
368-
.getAbsolutePath());
369-
OpenmrsUtil.setApplicationDataDirectory(tempappdir.getAbsolutePath());
370-
}
371-
catch (IOException e) {
372-
log.error("Unable to create temp dir", e);
361+
String appDataDir = OpenmrsUtil.getApplicationDataDirectory();
362+
if (appDataDir == null || !appDataDir.contains("appdir-for-unit-tests-")) {
363+
try {
364+
File tempappdir = File.createTempFile("appdir-for-unit-tests-", "");
365+
tempappdir.delete(); // so we can make it into a directory
366+
tempappdir.mkdir(); // turn it into a directory
367+
tempappdir.deleteOnExit(); // clean up when we're done with tests
368+
369+
runtimeProperties.setProperty(OpenmrsConstants.APPLICATION_DATA_DIRECTORY_RUNTIME_PROPERTY, tempappdir
370+
.getAbsolutePath());
371+
OpenmrsUtil.setApplicationDataDirectory(tempappdir.getAbsolutePath());
372+
} catch (IOException e) {
373+
log.error("Unable to create temp dir", e);
374+
}
373375
}
374376

375377
return runtimeProperties;

0 commit comments

Comments
 (0)