Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-133: Upgrade dependencies and frameworks under new 4.0.0 major. #43

Merged
merged 11 commits into from
Nov 20, 2023
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
platform: [ ubuntu-latest ]
java-version: [ 1.8 ]
java-version: [ 17 ]

runs-on: ${{ matrix.platform }}
env:
Expand Down
6 changes: 3 additions & 3 deletions commons-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openmrs.eip</groupId>
<artifactId>openmrs-eip</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
</parent>
<artifactId>commons-web</artifactId>
<packaging>jar</packaging>
Expand All @@ -21,11 +21,11 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

Expand Down
19 changes: 3 additions & 16 deletions commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openmrs.eip</groupId>
<artifactId>openmrs-eip</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
</parent>
<artifactId>commons</artifactId>
<packaging>jar</packaging>
Expand All @@ -14,15 +14,9 @@
<description>Provides shared classes and resources</description>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${sprintBootVersion}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-artemis</artifactId>
<version>${sprintBootVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
Expand All @@ -35,6 +29,7 @@
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-sql</artifactId>
<version>${camelVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
Expand Down Expand Up @@ -70,14 +65,6 @@
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
</dependency>
</dependencies>

</project>
14 changes: 10 additions & 4 deletions commons/src/main/java/org/openmrs/eip/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand All @@ -20,11 +21,16 @@ public class Utils {
/**
* Gets a list of all watched table names
*
* @return
* @return a list of table names
*/
public static List<String> getWatchedTables() {
String watchedTables = AppContext.getBean(Environment.class).getProperty(Constants.PROP_WATCHED_TABLES);
return Arrays.asList(watchedTables.split(","));
Optional<String> watchedTables = Optional
.ofNullable(AppContext.getBean(Environment.class).getProperty(Constants.PROP_WATCHED_TABLES));
if (watchedTables.isEmpty()) {
throw new EIPException("The property " + Constants.PROP_WATCHED_TABLES
+ " must be set to a comma-separated list of table names to watch");
}
return Arrays.asList(watchedTables.get().split(","));
Ruhanga marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -36,7 +42,7 @@ public static List<String> getWatchedTables() {
*/
public static List<String> getListOfTablesInHierarchy(String tableName) {
//TODO This logic should be extensible
List<String> tables = new ArrayList();
List<String> tables = new ArrayList<>();
tables.add(tableName);
if ("person".equalsIgnoreCase(tableName) || "patient".equalsIgnoreCase(tableName)) {
tables.add("person".equalsIgnoreCase(tableName) ? "patient" : "person");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import jakarta.persistence.EntityManagerFactory;
corneliouzbett marked this conversation as resolved.
Show resolved Hide resolved

import org.apache.camel.component.jpa.DefaultTransactionStrategy;
import org.apache.camel.component.jpa.JpaComponent;
import org.hibernate.cfg.AvailableSettings;
import org.openmrs.eip.Constants;
Expand Down Expand Up @@ -55,7 +57,7 @@ public DataSource dataSource() throws ClassNotFoundException {
public LocalContainerEntityManagerFactoryBean entityManager(final EntityManagerFactoryBuilder builder,
@Qualifier("mngtDataSource") final DataSource dataSource, ConfigurableEnvironment env) {

Map<String, String> props = new HashMap();
Map<String, String> props = new HashMap<>();
props.put(AvailableSettings.DIALECT, hibernateDialect);
props.put(AvailableSettings.HBM2DDL_AUTO, "none");

Expand All @@ -72,12 +74,10 @@ public PlatformTransactionManager transactionManager(
@Bean(value = "jpa")
public JpaComponent jpa(@Qualifier(value = "mngtEntityManager") EntityManagerFactory entityManagerFactory,
@Qualifier(value = "mngtTransactionManager") PlatformTransactionManager txMgr) {

JpaComponent comp = new JpaComponent();
comp.setEntityManagerFactory(entityManagerFactory);
comp.setTransactionManager(txMgr);

return comp;
JpaComponent component = new JpaComponent();
component.setEntityManagerFactory(entityManagerFactory);
component.setTransactionStrategy(new DefaultTransactionStrategy(component.getCamelContext(), entityManagerFactory));
return component;
}

@Bean(name = Constants.LIQUIBASE_BEAN_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.validation.constraints.NotNull;

@MappedSuperclass
public abstract class AbstractEntity implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class BaseRetryQueueItem extends AbstractEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class CommonConfig {
@Bean
public DeadLetterChannelBuilder deadLetterChannelBuilder() {
DeadLetterChannelBuilder builder = new DeadLetterChannelBuilder("direct:dlc");
builder.setUseOriginalMessage(true);
builder.useOriginalMessage();
return builder;
}

Expand Down
4 changes: 2 additions & 2 deletions commons/src/main/resources/application-common.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spring.jpa.properties.hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.hbm2ddl.auto=none
logging.level.org.openmrs.eip=${openmrs.eip.log.level}
logging.level.oauth=${openmrs.eip.log.level}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.env.MapPropertySource;

import com.mysql.jdbc.Driver;
import com.mysql.cj.jdbc.Driver;

/**
* Test BeanPostProcessor that injects the OpenMRS datasource properties values after the
Expand All @@ -22,7 +22,8 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
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() + "?useSSL=false");
propSource.getSource().put("spring.openmrs-datasource.jdbcUrl",
mysqlContainer.getJdbcUrl() + "?useSSL=false&mode=MySQL");
propSource.getSource().put("spring.openmrs-datasource.driverClassName", Driver.class.getName());
propSource.getSource().put("spring.openmrs-datasource.username", "root");
propSource.getSource().put("spring.openmrs-datasource.password", mysqlContainer.getPassword());
Expand Down
50 changes: 28 additions & 22 deletions commons/src/test/java/org/openmrs/eip/BaseCamelTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.openmrs.eip;

import static org.apache.camel.builder.AdviceWith.adviceWith;
import static org.junit.jupiter.api.Assertions.fail;
import static org.slf4j.Logger.ROOT_LOGGER_NAME;

import java.io.InputStream;
Expand All @@ -13,10 +15,9 @@
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.RoutesDefinition;
import org.apache.camel.test.spring.CamelSpringRunner;
import org.junit.Assert;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.apache.camel.xml.jaxb.JaxbHelper;
import org.junit.jupiter.api.BeforeEach;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -25,7 +26,6 @@
import org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
Expand All @@ -34,22 +34,24 @@

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Appender;
import ch.qos.logback.core.read.ListAppender;

/**
* Base class for camel route tests and processors
*/
@RunWith(CamelSpringRunner.class)
@SpringBootTest(classes = TestConfig.class)

@CamelSpringBootTest
@SpringBootTest(classes = { TestConfig.class })
@TestExecutionListeners(value = { DirtiesContextBeforeModesTestExecutionListener.class, MockitoTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
ResetMocksTestExecutionListener.class })
@TestPropertySource(properties = "logging.config=classpath:logback-test.xml")
@TestPropertySource(properties = "camel.component.direct.block=false")
@TestPropertySource(properties = "openmrs.eip.log.level=DEBUG")
@TestPropertySource(properties = "logging.level.org.openmrs.eip=DEBUG")
@DirtiesContext
@TestPropertySource(properties = "camel.springboot.routes-collector-enabled=true")
corneliouzbett marked this conversation as resolved.
Show resolved Hide resolved
public abstract class BaseCamelTest {

protected static final Logger log = LoggerFactory.getLogger(BaseCamelTest.class);
Expand All @@ -69,10 +71,10 @@ public abstract class BaseCamelTest {
protected ConfigurableEnvironment env;

protected void advise(String routeId, AdviceWithRouteBuilder builder) throws Exception {
camelContext.adviceWith(camelContext.getRouteDefinition(routeId), builder);
adviceWith(routeId, camelContext, builder);
}

@Before
@BeforeEach
public void beforeBaseCamelTest() throws Exception {
loadXmlRoutesInDirectory("camel-common", "test-error-handler.xml");
if (loggerContext == null) {
Expand All @@ -83,16 +85,22 @@ public void beforeBaseCamelTest() throws Exception {
}

protected void assertMessageLogged(Level level, String message) {
ListAppender<LoggingEvent> app = (ListAppender) loggerContext.getLogger(ROOT_LOGGER_NAME).getAppender("test");
List<LoggingEvent> list = app.list;
for (LoggingEvent e : list) {
if (e.getLevel().equals(level) && e.getMessage().equalsIgnoreCase(message)) {
log.info("Log event satisfied -> [" + level + "] " + message);
return;
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Appender<ILoggingEvent> appender = loggerContext.getLogger(ROOT_LOGGER_NAME).getAppender("test");

if (appender instanceof ListAppender<ILoggingEvent> listAppender) {
List<ILoggingEvent> list = listAppender.list;

for (ILoggingEvent e : list) {
if (e.getLevel().equals(level) && e.getMessage().equalsIgnoreCase(message)) {
log.info("Log event satisfied -> [" + level + "] " + message);
return;
}
}
} else {
// Handle the case where the appender is not of the expected type
fail("Log event not satisfied -> [" + level + "] " + message);
}

Assert.fail("Log event not satisfied -> [" + level + "] " + message);
}

/**
Expand All @@ -104,8 +112,7 @@ protected void assertMessageLogged(Level level, String message) {
private void loadXmlRoutes(String... filenames) throws Exception {
for (String file : filenames) {
InputStream in = getClass().getClassLoader().getResourceAsStream(file);
RoutesDefinition rd = (RoutesDefinition) camelContext.getXMLRoutesDefinitionLoader()
.loadRoutesDefinition(camelContext, in);
RoutesDefinition rd = JaxbHelper.loadRoutesDefinition(camelContext, in);
camelContext.addRouteDefinitions(rd.getRoutes());
}
}
Expand Down Expand Up @@ -140,5 +147,4 @@ protected String getErrorMessage(Exchange e) {
protected Exception getException(Exchange e) {
return e.getProperty("error", Exception.class);
}

}
22 changes: 16 additions & 6 deletions commons/src/test/java/org/openmrs/eip/BaseDbBackedCamelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

import javax.sql.DataSource;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
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.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener;
Expand All @@ -30,9 +32,11 @@
@TestPropertySource(properties = "spring.mngt-datasource.username=sa")
@TestPropertySource(properties = "spring.mngt-datasource.password=test")
@TestPropertySource(properties = "spring.mngt-datasource.dialect=org.hibernate.dialect.H2Dialect")
@TestPropertySource(properties = "spring.openmrs-datasource.driverClassName=com.mysql.cj.jdbc.Driver")
@TestPropertySource(properties = "spring.openmrs-datasource.dialect=org.hibernate.dialect.MySQLDialect")
public abstract class BaseDbBackedCamelTest extends BaseCamelTest {

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

protected static Integer mysqlPort;

Expand All @@ -48,7 +52,14 @@ public abstract class BaseDbBackedCamelTest extends BaseCamelTest {
@Qualifier(Constants.OPENMRS_DATASOURCE_NAME)
protected DataSource openmrsDataSource;

@BeforeClass
@DynamicPropertySource
static void setProperties(DynamicPropertyRegistry registry) {
registry.add("spring.openmrs-datasource.jdbcUrl", () -> "jdbc:mysql://localhost:" + mysqlPort + "/openmrs");
registry.add("spring.openmrs-datasource.username", () -> "root");
registry.add("spring.openmrs-datasource.password", () -> "test");
}

@BeforeAll
public static void startMysql() throws Exception {
mysqlContainer.withEnv("MYSQL_ROOT_PASSWORD", "test");
mysqlContainer.withDatabaseName("openmrs");
Expand All @@ -67,9 +78,8 @@ public static void startMysql() throws Exception {
mysqlPort = mysqlContainer.getMappedPort(3306);
}

@AfterClass
@AfterAll
public static void stopMysql() {
mysqlContainer.stop();
}

}
Loading
Loading