Skip to content

Commit

Permalink
Merge pull request #2722 from dropwizard/issue-2721
Browse files Browse the repository at this point in the history
Allow to disable logging bootstrap in DAOTest
  • Loading branch information
jplock committed Apr 6, 2019
2 parents ad96950 + cc0a7cf commit ce53e69
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Expand Up @@ -17,10 +17,6 @@
import java.util.function.Consumer;

public class DAOTest {
static {
BootstrapLogging.bootstrap();
}

@SuppressWarnings("unchecked")
public static abstract class Builder<B extends Builder<B>> {
private String url = "jdbc:h2:mem:" + UUID.randomUUID();
Expand All @@ -30,6 +26,7 @@ public static abstract class Builder<B extends Builder<B>> {
private String hbm2ddlAuto = "create";
private boolean showSql = false;
private boolean useSqlComments = false;
private boolean bootstrapLogging = true;
private Set<Class<?>> entityClasses = new LinkedHashSet<>();
private Map<String, String> properties = new HashMap<>();
private Consumer<Configuration> configurationCustomizer = c -> {
Expand Down Expand Up @@ -65,6 +62,11 @@ public B useSqlComments(boolean useSqlComments) {
return (B) this;
}

public B bootstrapLogging(boolean value){
bootstrapLogging = value;
return (B) this;
}

public B addEntityClass(Class<?> entityClass) {
this.entityClasses.add(entityClass);
return (B) this;
Expand All @@ -81,6 +83,10 @@ public B customizeConfiguration(Consumer<Configuration> configurationCustomizer)
}

protected DAOTest buildDAOTest() {
if (bootstrapLogging) {
BootstrapLogging.bootstrap();
}

final Configuration config = new Configuration();
config.setProperty(AvailableSettings.URL, url);
config.setProperty(AvailableSettings.USER, username);
Expand Down
Expand Up @@ -6,7 +6,7 @@

import static org.assertj.core.api.Assertions.assertThat;

public class ResourceTestRuleWithoutLoggingBootstrap {
public class ResourceTestRuleWithoutLoggingBootstrapTest {
@SuppressWarnings("deprecation")
@Rule
public final ResourceTestRule resourceTestRule = ResourceTestRule.builder()
Expand Down
@@ -0,0 +1,24 @@
package io.dropwizard.testing.junit;

import io.dropwizard.testing.app.TestEntity;
import org.hibernate.SessionFactory;
import org.junit.Rule;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class DAOTestRuleWithoutLoggingBootstrapTest {
@SuppressWarnings("deprecation")
@Rule
public final DAOTestRule daoTestRule = DAOTestRule.newBuilder()
.addEntityClass(TestEntity.class)
.bootstrapLogging(false)
.build();

@Test
public void ruleCreatedSessionFactory() {
final SessionFactory sessionFactory = daoTestRule.getSessionFactory();

assertThat(sessionFactory).isNotNull();
}
}

0 comments on commit ce53e69

Please sign in to comment.