Skip to content

Commit

Permalink
ebean-test - Fix AutoConfigureForTesting to skip configuration for no…
Browse files Browse the repository at this point in the history
…n-default DatabaseConfig (#2644)

#2644 - ebean-test - Fix AutoConfigureForTesting to skip configuration for non-default DatabaseConfig
  • Loading branch information
rbygrave authored Apr 12, 2022
1 parent 4b8eada commit 2aba183
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.ebean.xtest.config;
package io.ebean.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.ebean.annotation.MutationDetection;
Expand All @@ -17,11 +17,10 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

public class DatabaseConfigTest {
class DatabaseConfigTest {

@Test
public void testLoadFromEbeanProperties() {

void testLoadFromEbeanProperties() {
DatabaseConfig config = new DatabaseConfig();
config.loadFromProperties();

Expand All @@ -30,8 +29,7 @@ public void testLoadFromEbeanProperties() {
}

@Test
public void evalPropertiesInput() {

void evalPropertiesInput() {
String home = System.getProperty("user.home");
String fileSeparator = System.getProperty("file.separator");

Expand All @@ -46,8 +44,7 @@ public void evalPropertiesInput() {
}

@Test
public void testLoadWithProperties() {

void testLoadWithProperties() {
DatabaseConfig config = new DatabaseConfig();
config.setPersistBatch(PersistBatch.NONE);
config.setPersistBatchOnCascade(PersistBatch.NONE);
Expand Down Expand Up @@ -154,8 +151,7 @@ public void testLoadWithProperties() {
}

@Test
public void test_defaults() {

void test_defaults() {
DatabaseConfig config = new DatabaseConfig();
assertTrue(config.isIdGeneratorAutomatic());
assertTrue(config.isDefaultServer());
Expand Down Expand Up @@ -186,8 +182,7 @@ public void test_defaults() {
}

@Test
public void test_putServiceObject() {

void test_putServiceObject() {
ObjectMapper objectMapper = new ObjectMapper();

DatabaseConfig config = new DatabaseConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,28 @@ public class AutoConfigureForTesting implements AutoConfigure {

@Override
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();
if (isExtraServer(config, properties)) {
setupExtraDataSourceIfNecessary(config);
return;
}

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()) {
setupPlatform(environmentDb, config);
}
}

@Override
public void postConfigure(DatabaseConfig config) {
if (!config.isDefaultServer()) {
return;
}
setupProviders(config);

if (org.h2.engine.Constants.VERSION_MAJOR == 1) {
// This code may be removed later, when droppinv H2 1.xxx compatibility
System.err.println("Running tests in H2 1.xxx compatibility mode");
Expand Down
2 changes: 2 additions & 0 deletions ebean-test/src/test/java/io/ebean/xtest/BaseTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public void checkForLeak(TestInfo testInfo) {
DB_CLOCK_DELTA = 100;
}
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.
DB.getDefault();
} catch (Throwable e) {
Expand Down
5 changes: 3 additions & 2 deletions ebean-test/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@
<appender-ref ref="STDOUT"/>
</root>


<logger name="org.tests" 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.test" level="TRACE"/>

<!-- <logger name="io.ebean.DDL" level="DEBUG"/>-->

<!-- <logger name="io.ebean.SQL" level="TRACE"/>-->
Expand Down

0 comments on commit 2aba183

Please sign in to comment.