Unit tests are starting to work again ...
This commit is contained in:
92
src/main/java/ca/uhn/fhir/jpa/starter/EnvironmentHelper.java
Normal file
92
src/main/java/ca/uhn/fhir/jpa/starter/EnvironmentHelper.java
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
package ca.uhn.fhir.jpa.starter;
|
||||||
|
|
||||||
|
import org.springframework.core.env.CompositePropertySource;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.EnumerablePropertySource;
|
||||||
|
import org.springframework.core.env.PropertySource;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class EnvironmentHelper {
|
||||||
|
|
||||||
|
public static Properties getHibernateProperties(ConfigurableEnvironment environment) {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
if (environment.getProperty("spring.jpa.properties", String.class) == null) {
|
||||||
|
properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
|
||||||
|
properties.put("hibernate.search.model_mapping", "ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory");
|
||||||
|
properties.put("hibernate.format_sql", "false");
|
||||||
|
properties.put("hibernate.show_sql", "false");
|
||||||
|
properties.put("hibernate.hbm2ddl.auto", "update");
|
||||||
|
properties.put("hibernate.jdbc.batch_size", "20");
|
||||||
|
properties.put("hibernate.cache.use_query_cache", "false");
|
||||||
|
properties.put("hibernate.cache.use_second_level_cache", "false");
|
||||||
|
properties.put("hibernate.cache.use_structured_entries", "false");
|
||||||
|
properties.put("hibernate.cache.use_minimal_puts", "false");
|
||||||
|
properties.put("hibernate.search.default.directory_provider", "filesystem");
|
||||||
|
properties.put("hibernate.search.default.indexBase", "target/lucenefiles");
|
||||||
|
properties.put("hibernate.search.lucene_version", "LUCENE_CURRENT");
|
||||||
|
} else {
|
||||||
|
Arrays.asList(environment.getProperty("spring.jpa.properties", String.class).split(" ")).stream().forEach(s ->
|
||||||
|
{
|
||||||
|
String[] values = s.split("=");
|
||||||
|
properties.put(values[0], values[1]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Object> getPropertiesStartingWith(ConfigurableEnvironment aEnv,
|
||||||
|
String aKeyPrefix) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
Map<String, Object> map = getAllProperties(aEnv);
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
|
||||||
|
if (key.startsWith(aKeyPrefix)) {
|
||||||
|
result.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Object> getAllProperties(ConfigurableEnvironment aEnv) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
aEnv.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps)));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Object> getAllProperties(PropertySource<?> aPropSource) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
if (aPropSource instanceof CompositePropertySource) {
|
||||||
|
CompositePropertySource cps = (CompositePropertySource) aPropSource;
|
||||||
|
cps.getPropertySources().forEach(ps -> addAll(result, getAllProperties(ps)));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aPropSource instanceof EnumerablePropertySource<?>) {
|
||||||
|
EnumerablePropertySource<?> ps = (EnumerablePropertySource<?>) aPropSource;
|
||||||
|
Arrays.asList(ps.getPropertyNames()).forEach(key -> result.put(key, ps.getProperty(key)));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addAll(Map<String, Object> aBase, Map<String, Object> aToBeAdded) {
|
||||||
|
for (Map.Entry<String, Object> entry : aToBeAdded.entrySet()) {
|
||||||
|
if (aBase.containsKey(entry.getKey())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
aBase.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,11 +8,16 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Profile("dstu2")
|
@Profile("dstu2")
|
||||||
@@ -37,6 +42,9 @@ public class FhirServerConfigDstu2 extends BaseJavaConfigDstu2 {
|
|||||||
return pagingProvider;
|
return pagingProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigurableEnvironment configurableEnvironment;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Bean()
|
@Bean()
|
||||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||||
@@ -48,8 +56,7 @@ public class FhirServerConfigDstu2 extends BaseJavaConfigDstu2 {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
|
throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
|
||||||
}
|
}
|
||||||
|
retVal.setJpaProperties(EnvironmentHelper.getHibernateProperties(configurableEnvironment));
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,4 +68,5 @@ public class FhirServerConfigDstu2 extends BaseJavaConfigDstu2 {
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
|
||||||
@@ -37,6 +38,9 @@ public class FhirServerConfigDstu3 extends BaseJavaConfigDstu3 {
|
|||||||
return pagingProvider;
|
return pagingProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigurableEnvironment configurableEnvironment;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Bean
|
@Bean
|
||||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||||
@@ -49,7 +53,7 @@ public class FhirServerConfigDstu3 extends BaseJavaConfigDstu3 {
|
|||||||
throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
|
throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retVal.setJpaProperties(EnvironmentHelper.getHibernateProperties(configurableEnvironment));
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,15 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Profile("r4")
|
@Profile("r4")
|
||||||
@@ -37,6 +41,9 @@ public class FhirServerConfigR4 extends BaseJavaConfigR4 {
|
|||||||
return pagingProvider;
|
return pagingProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigurableEnvironment configurableEnvironment;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Bean()
|
@Bean()
|
||||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||||
@@ -49,7 +56,7 @@ public class FhirServerConfigR4 extends BaseJavaConfigR4 {
|
|||||||
throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
|
throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retVal.setJpaProperties(EnvironmentHelper.getHibernateProperties(configurableEnvironment));
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||||
|
|
||||||
@@ -36,6 +37,10 @@ public class FhirServerConfigR5 extends BaseJavaConfigR5 {
|
|||||||
pagingProvider.setMaximumPageSize(appProperties.getMax_page_size());
|
pagingProvider.setMaximumPageSize(appProperties.getMax_page_size());
|
||||||
return pagingProvider;
|
return pagingProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigurableEnvironment configurableEnvironment;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Bean()
|
@Bean()
|
||||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||||
@@ -48,7 +53,7 @@ public class FhirServerConfigR5 extends BaseJavaConfigR5 {
|
|||||||
throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
|
throw new ConfigurationException("Could not set the data source due to a configuration issue", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
retVal.setJpaProperties(HapiProperties.getJpaProperties());
|
retVal.setJpaProperties(EnvironmentHelper.getHibernateProperties(configurableEnvironment));
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,23 @@ spring:
|
|||||||
max-active: 15
|
max-active: 15
|
||||||
profiles:
|
profiles:
|
||||||
### This is the FHIR version. Choose between, dstu2, dstu3, r4 or r5
|
### This is the FHIR version. Choose between, dstu2, dstu3, r4 or r5
|
||||||
active: r4
|
active: dstu2
|
||||||
|
jpa:
|
||||||
|
properties:
|
||||||
|
hibernate.dialect: org.hibernate.dialect.H2Dialect
|
||||||
|
hibernate.search.model_mapping: ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory
|
||||||
|
hibernate.format_sql: false
|
||||||
|
hibernate.show_sql: false
|
||||||
|
hibernate.hbm2ddl.auto: update
|
||||||
|
hibernate.jdbc.batch_size: 20
|
||||||
|
hibernate.cache.use_query_cache: false
|
||||||
|
hibernate.cache.use_second_level_cache: false
|
||||||
|
hibernate.cache.use_structured_entries: false
|
||||||
|
hibernate.cache.use_minimal_puts: false
|
||||||
|
hibernate.search.default.directory_provider: filesystem
|
||||||
|
hibernate.search.default.indexBase: target/lucenefiles
|
||||||
|
hibernate.search.lucene_version: LUCENE_CURRENT
|
||||||
|
|
||||||
hapi:
|
hapi:
|
||||||
fhir:
|
fhir:
|
||||||
#supported_resource_types:
|
#supported_resource_types:
|
||||||
|
|||||||
@@ -12,11 +12,13 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.web.server.LocalServerPort;
|
import org.springframework.boot.web.server.LocalServerPort;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@TestPropertySource(locations = "/application-integrationtest.yaml")
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties =
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties =
|
||||||
{
|
{
|
||||||
"spring.batch.job.enabled=false",
|
"spring.batch.job.enabled=false",
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ spring:
|
|||||||
max-active: 15
|
max-active: 15
|
||||||
profiles:
|
profiles:
|
||||||
### This is the FHIR version. Choose between, dstu2, dstu3, r4 or r5
|
### This is the FHIR version. Choose between, dstu2, dstu3, r4 or r5
|
||||||
active: r4
|
active: dstu2
|
||||||
|
|
||||||
hapi:
|
hapi:
|
||||||
fhir:
|
fhir:
|
||||||
#supported_resource_types:
|
#supported_resource_types:
|
||||||
|
|||||||
Reference in New Issue
Block a user