Skip to content

Commit

Permalink
EIP-61 - Added base receiver sync test
Browse files Browse the repository at this point in the history
  • Loading branch information
wluyima committed Nov 23, 2021
1 parent 2b0c8a2 commit 234ef17
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource("application-common-web.properties")
@PropertySource("classpath:application-common-web.properties")
public class ActuatorConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AppPropertiesBeanPostProcessor implements BeanPostProcessor {
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (Constants.COMMON_PROP_SOURCE_BEAN_NAME.equals(beanName)) {
MapPropertySource propSource = (MapPropertySource) bean;
propSource.getSource().put("openmrs.db.port", BaseDbBackedCamelTest.MYSQL_PORT);
propSource.getSource().put("openmrs.db.port", BaseDbBackedCamelTest.mysqlPort);
propSource.getSource().put("openmrs.db.host", "localhost");
propSource.getSource().put("openmrs.db.name", mysqlContainer.getDatabaseName());
propSource.getSource().put("spring.openmrs-datasource.jdbcUrl", mysqlContainer.getJdbcUrl());
Expand Down
3 changes: 2 additions & 1 deletion commons/src/test/java/org/openmrs/eip/BaseCamelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@
DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
ResetMocksTestExecutionListener.class })
@TestPropertySource(properties = "logging.config=classpath:logback-test.xml")
@TestPropertySource(properties = "camel.component.direct.block=false")
@DirtiesContext
public abstract class BaseCamelTest {

private static final Logger log = LoggerFactory.getLogger(BaseCamelTest.class);
protected static final Logger log = LoggerFactory.getLogger(BaseCamelTest.class);

@Autowired
protected ApplicationContext applicationContext;
Expand Down
34 changes: 27 additions & 7 deletions commons/src/test/java/org/openmrs/eip/BaseDbBackedCamelTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.openmrs.eip;

import static org.testcontainers.utility.DockerImageName.parse;
import static org.testcontainers.utility.MountableFile.forClasspathResource;

import java.util.stream.Stream;

Expand All @@ -12,14 +12,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.transaction.annotation.Transactional;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.lifecycle.Startables;
import org.testcontainers.utility.MountableFile;

/**
* Base class for tests for routes that require access to the management and OpenMRS databases.
Expand All @@ -28,12 +29,21 @@
@TestExecutionListeners(value = { DeleteDataTestExecutionListener.class, SqlScriptsTestExecutionListener.class,
TransactionalTestExecutionListener.class })
@TestPropertySource(properties = "spring.jpa.properties.hibernate.hbm2ddl.auto=update")
@TestPropertySource(properties = "spring.mngt-datasource.driverClassName=org.h2.Driver")
@TestPropertySource(properties = "spring.mngt-datasource.jdbcUrl=jdbc:h2:mem:test;DB_CLOSE_DELAY=30;LOCK_TIMEOUT=10000")
@TestPropertySource(properties = "spring.mngt-datasource.username=sa")
@TestPropertySource(properties = "spring.mngt-datasource.password=test")
@TestPropertySource(properties = "spring.mngt-datasource.dialect=org.hibernate.dialect.H2Dialect")
@Transactional
public abstract class BaseDbBackedCamelTest extends BaseCamelTest {

protected static MySQLContainer mysqlContainer = new MySQLContainer<>(parse("mysql:5.7.31"));
protected static MySQLContainer mysqlContainer = new MySQLContainer("mysql:5.7.31");

protected static Integer MYSQL_PORT;
protected static Integer mysqlPort;

protected static final String SCRIPT_DIR = "/test_scripts/";

private static final PathMatchingResourcePatternResolver RESOURCE_RESOLVER = new PathMatchingResourcePatternResolver();

@Autowired
@Qualifier("mngtDataSource")
Expand All @@ -44,12 +54,22 @@ public abstract class BaseDbBackedCamelTest extends BaseCamelTest {
protected DataSource openmrsDataSource;

@BeforeClass
public static void startMysql() {
public static void startMysql() throws Exception {
mysqlContainer.withEnv("MYSQL_ROOT_PASSWORD", "test");
mysqlContainer.withDatabaseName("openmrs");
mysqlContainer.withCopyFileToContainer(MountableFile.forClasspathResource("my.cnf"), "/etc/mysql/my.cnf");
mysqlContainer.withCopyFileToContainer(forClasspathResource("my.cnf"), "/etc/mysql/my.cnf");

Resource[] scripts = RESOURCE_RESOLVER.getResources("classpath*:" + SCRIPT_DIR + "*.sql");

for (Resource script : scripts) {
String scriptFile = SCRIPT_DIR + script.getFilename();
log.info("Adding init SQL file from classpath to MySQL test container -> " + scriptFile);
mysqlContainer.withCopyFileToContainer(forClasspathResource(scriptFile),
"/docker-entrypoint-initdb.d/" + script.getFilename());
}

Startables.deepStart(Stream.of(mysqlContainer)).join();
MYSQL_PORT = mysqlContainer.getMappedPort(3306);
mysqlPort = mysqlContainer.getMappedPort(3306);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
spring.mngt-datasource.driverClassName=org.h2.Driver
spring.mngt-datasource.jdbcUrl=jdbc:h2:mem:test;DB_CLOSE_DELAY=30;LOCK_TIMEOUT=10000
spring.mngt-datasource.username=sa
spring.mngt-datasource.password=test
spring.mngt-datasource.dialect=org.hibernate.dialect.H2Dialect

openmrs.eip.log.level=DEBUG
logging.level.org.openmrs.eip=${openmrs.eip.log.level}
logging.level.db-event-listener=${openmrs.eip.log.level}
Expand All @@ -17,5 +11,3 @@ debezium.db.user=root
debezium.db.password=test
debezium.snapshotMode=schema_only
debezium.snapshotLockingMode=extended

camel.component.direct.block=false

0 comments on commit 234ef17

Please sign in to comment.