ebean-test - Fix AutoConfigureForTesting to skip configuration for non-default DatabaseConfig (#2644)

#2644 - ebean-test - Fix AutoConfigureForTesting to skip configuration for non-default DatabaseConfig
This commit is contained in:
Rob Bygrave authored and GitHub committed 2022-04-12 17:36:25 +12:00
1 parent 4b8eadad1c
commit 2aba1835f1
4 files changed
+20 -19

No files matched your search

@@ -1,4 +1,4 @@
package io.ebean.xtest.config; package io.ebean.config;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.ebean.annotation.MutationDetection; import io.ebean.annotation.MutationDetection;
@@ -17,11 +17,10 @@ import java.util.Properties;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
public class DatabaseConfigTest { class DatabaseConfigTest {
@Test @Test
public void testLoadFromEbeanProperties() { void testLoadFromEbeanProperties() {
DatabaseConfig config = new DatabaseConfig(); DatabaseConfig config = new DatabaseConfig();
config.loadFromProperties(); config.loadFromProperties();
@@ -30,8 +29,7 @@ public class DatabaseConfigTest {
} }
@Test @Test
public void evalPropertiesInput() { void evalPropertiesInput() {
String home = System.getProperty("user.home"); String home = System.getProperty("user.home");
String fileSeparator = System.getProperty("file.separator"); String fileSeparator = System.getProperty("file.separator");
@@ -46,8 +44,7 @@ public class DatabaseConfigTest {
} }
@Test @Test
public void testLoadWithProperties() { void testLoadWithProperties() {
DatabaseConfig config = new DatabaseConfig(); DatabaseConfig config = new DatabaseConfig();
config.setPersistBatch(PersistBatch.NONE); config.setPersistBatch(PersistBatch.NONE);
config.setPersistBatchOnCascade(PersistBatch.NONE); config.setPersistBatchOnCascade(PersistBatch.NONE);
@@ -154,8 +151,7 @@ public class DatabaseConfigTest {
} }
@Test @Test
public void test_defaults() { void test_defaults() {
DatabaseConfig config = new DatabaseConfig(); DatabaseConfig config = new DatabaseConfig();
assertTrue(config.isIdGeneratorAutomatic()); assertTrue(config.isIdGeneratorAutomatic());
assertTrue(config.isDefaultServer()); assertTrue(config.isDefaultServer());
@@ -186,8 +182,7 @@ public class DatabaseConfigTest {
} }
@Test @Test
public void test_putServiceObject() { void test_putServiceObject() {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
DatabaseConfig config = new DatabaseConfig(); DatabaseConfig config = new DatabaseConfig();
@@ -29,16 +29,17 @@ public class AutoConfigureForTesting implements AutoConfigure {
@Override @Override
public void preConfigure(DatabaseConfig config) { public void preConfigure(DatabaseConfig config) {
if (!config.isDefaultServer()) {
log.info("skip automatic testing config on non-default server name:{} register:{}", config.getName(), config.isRegister());
return;
}
Properties properties = config.getProperties(); Properties properties = config.getProperties();
if (isExtraServer(config, properties)) { if (isExtraServer(config, properties)) {
setupExtraDataSourceIfNecessary(config); setupExtraDataSourceIfNecessary(config);
return; return;
} }
String testPlatform = properties.getProperty("ebean.test.platform"); String testPlatform = properties.getProperty("ebean.test.platform");
log.debug("automatic testing config - with ebean.test.platform:{} environment db:{} name:{}", testPlatform, environmentDb, config.getName()); log.debug("automatic testing config - with ebean.test.platform:{} name:{} environmentDb:{}", testPlatform, config.getName(), environmentDb);
if (RunOnceMarker.isRun()) { if (RunOnceMarker.isRun()) {
setupPlatform(environmentDb, config); setupPlatform(environmentDb, config);
} }
@@ -46,8 +47,10 @@ public class AutoConfigureForTesting implements AutoConfigure {
@Override @Override
public void postConfigure(DatabaseConfig config) { public void postConfigure(DatabaseConfig config) {
if (!config.isDefaultServer()) {
return;
}
setupProviders(config); setupProviders(config);
if (org.h2.engine.Constants.VERSION_MAJOR == 1) { if (org.h2.engine.Constants.VERSION_MAJOR == 1) {
// This code may be removed later, when droppinv H2 1.xxx compatibility // This code may be removed later, when droppinv H2 1.xxx compatibility
System.err.println("Running tests in H2 1.xxx compatibility mode"); System.err.println("Running tests in H2 1.xxx compatibility mode");
@@ -68,6 +68,8 @@ public abstract class BaseTestCase {
DB_CLOCK_DELTA = 100; DB_CLOCK_DELTA = 100;
} }
try { try {
String propsFile = System.getProperty("props.file");
System.out.println("BaseTestCase: -Dprops.file=" + propsFile); // help debug CI
// First try, if we get the default server. If this fails, all tests will fail. // First try, if we get the default server. If this fails, all tests will fail.
DB.getDefault(); DB.getDefault();
} catch (Throwable e) { } catch (Throwable e) {
@@ -72,11 +72,12 @@
<appender-ref ref="STDOUT"/> <appender-ref ref="STDOUT"/>
</root> </root>
<logger name="org.tests" level="INFO"/> <logger name="org.tests" level="INFO"/>
<logger name="io.ebean" level="INFO"/> <logger name="io.ebean" level="INFO"/>
<logger name="io.avaje.config" level="TRACE"/>
<logger name="io.ebean.docker" level="TRACE"/> <logger name="io.ebean.docker" level="TRACE"/>
<logger name="io.ebean.test" level="TRACE"/>
<!-- <logger name="io.ebean.DDL" level="DEBUG"/>--> <!-- <logger name="io.ebean.DDL" level="DEBUG"/>-->
<!-- <logger name="io.ebean.SQL" level="TRACE"/>--> <!-- <logger name="io.ebean.SQL" level="TRACE"/>-->