Skip to content

Commit

Permalink
fix: Fix unit test asserting on async log entry (#18567)
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante authored Sep 10, 2024
1 parent 675a8d3 commit d2e8338
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 48 deletions.
16 changes: 0 additions & 16 deletions dhis-2/dhis-support/dhis-support-hibernate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,6 @@
<version>3.3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core-test</artifactId>
<version>${log4j.version}</version>
<scope>test</scope>
</dependency>

<!-- Other -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
package org.hisp.dhis.datasource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
Expand All @@ -38,35 +37,17 @@
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import javax.sql.DataSource;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.appender.ListAppender;
import org.hisp.dhis.datasource.model.PoolConfig;
import org.hisp.dhis.external.conf.ConfigurationKey;
import org.hisp.dhis.external.conf.DhisConfigurationProvider;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

class DatabasePoolUtilsTest {

private static ListAppender appender;

@BeforeAll
public static void beforeAll() {
LoggerContext loggerContext = LoggerContext.getContext(false);
Logger logger = (Logger) loggerContext.getLogger(DatabasePoolUtils.class);
appender = new ListAppender("Test");
appender.start();
loggerContext.getConfiguration().addLoggerAppender(logger, appender);
}

@BeforeEach
public void beforeEach() throws SQLException {
appender.clear();
StubDriver jdbcDriver = new StubDriver();
DriverManager.registerDriver(jdbcDriver);
}
Expand All @@ -88,8 +69,6 @@ void testCreateDbPoolWhenDbPoolTypeIsUnPooled() throws PropertyVetoException, SQ

DataSource dataSource = DatabasePoolUtils.createDbPool(poolConfigBuilder.build());
assertInstanceOf(DriverManagerDataSource.class, dataSource);

assertEquals("Database pool type value is 'UNPOOLED'", getLogEntry());
}

@Test
Expand Down Expand Up @@ -127,8 +106,6 @@ void testCreateDbPoolWhenDbPoolTypeIsC3P0() throws PropertyVetoException, SQLExc

DataSource dataSource = DatabasePoolUtils.createDbPool(poolConfigBuilder.build());
assertInstanceOf(ComboPooledDataSource.class, dataSource);

assertEquals("Database pool type value is 'C3P0'", getLogEntry());
}

@Test
Expand Down Expand Up @@ -156,14 +133,5 @@ void testCreateDbPoolWhenDbPoolTypeIsHikari() throws PropertyVetoException, SQLE

DataSource dataSource = DatabasePoolUtils.createDbPool(poolConfigBuilder.build());
assertInstanceOf(HikariDataSource.class, dataSource);

assertEquals("Database pool type value is 'HIKARI'", getLogEntry());
}

private String getLogEntry() {
return appender.getEvents().stream()
.map(event -> event.getMessage().getFormattedMessage())
.collect(Collectors.toList())
.get(0);
}
}

0 comments on commit d2e8338

Please sign in to comment.