diff --git a/commons-web/src/main/java/org/openmrs/eip/web/ActuatorConfig.java b/commons-web/src/main/java/org/openmrs/eip/web/ActuatorConfig.java index 3f5082ecb..16064407b 100644 --- a/commons-web/src/main/java/org/openmrs/eip/web/ActuatorConfig.java +++ b/commons-web/src/main/java/org/openmrs/eip/web/ActuatorConfig.java @@ -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 {} diff --git a/commons/src/test/java/org/openmrs/eip/AppPropertiesBeanPostProcessor.java b/commons/src/test/java/org/openmrs/eip/AppPropertiesBeanPostProcessor.java index 17320ba17..01f040608 100644 --- a/commons/src/test/java/org/openmrs/eip/AppPropertiesBeanPostProcessor.java +++ b/commons/src/test/java/org/openmrs/eip/AppPropertiesBeanPostProcessor.java @@ -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()); diff --git a/commons/src/test/java/org/openmrs/eip/BaseCamelTest.java b/commons/src/test/java/org/openmrs/eip/BaseCamelTest.java index 3b3c4e352..338571d99 100644 --- a/commons/src/test/java/org/openmrs/eip/BaseCamelTest.java +++ b/commons/src/test/java/org/openmrs/eip/BaseCamelTest.java @@ -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; diff --git a/commons/src/test/java/org/openmrs/eip/BaseDbBackedCamelTest.java b/commons/src/test/java/org/openmrs/eip/BaseDbBackedCamelTest.java index 4ba4870e8..78ccae52f 100644 --- a/commons/src/test/java/org/openmrs/eip/BaseDbBackedCamelTest.java +++ b/commons/src/test/java/org/openmrs/eip/BaseDbBackedCamelTest.java @@ -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; @@ -12,6 +12,8 @@ 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; @@ -19,7 +21,6 @@ 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. @@ -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") @@ -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); } } diff --git a/openmrs-watcher/src/test/resources/watcher-application-test.properties b/openmrs-watcher/src/test/resources/watcher-application-test.properties index b4b58da54..d1b8fd364 100644 --- a/openmrs-watcher/src/test/resources/watcher-application-test.properties +++ b/openmrs-watcher/src/test/resources/watcher-application-test.properties @@ -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} @@ -17,5 +11,3 @@ debezium.db.user=root debezium.db.password=test debezium.snapshotMode=schema_only debezium.snapshotLockingMode=extended - -camel.component.direct.block=false