diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/DatabaseBackedPagingProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/DatabaseBackedPagingProvider.java index 12ae5e73bab..95f862f081d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/DatabaseBackedPagingProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/DatabaseBackedPagingProvider.java @@ -28,7 +28,9 @@ import ca.uhn.fhir.rest.server.IPagingProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -@Service +// Note: this class is not annotated with @Service because we want to +// explicitly define it in BaseConfig.java. This is done so that +// implementors can override if they want to. public class DatabaseBackedPagingProvider extends BasePagingProvider implements IPagingProvider { @Autowired diff --git a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/main/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfiguration.java b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/main/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfiguration.java index af2c39999d3..8844fa69321 100644 --- a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/main/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfiguration.java +++ b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/main/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfiguration.java @@ -31,6 +31,7 @@ import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.provider.BaseJpaProvider; import ca.uhn.fhir.jpa.provider.BaseJpaSystemProvider; +import ca.uhn.fhir.model.dstu2.resource.AuditEvent; import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory; import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory; import ca.uhn.fhir.rest.client.api.IClientInterceptor; @@ -46,6 +47,7 @@ import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor; import okhttp3.OkHttpClient; import org.apache.http.client.HttpClient; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.*; @@ -69,6 +71,7 @@ import org.springframework.util.CollectionUtils; import javax.servlet.ServletException; import javax.sql.DataSource; import java.util.List; +import java.util.concurrent.ScheduledExecutorService; /** * {@link EnableAutoConfiguration Auto-configuration} for HAPI FHIR. @@ -164,26 +167,11 @@ public class FhirAutoConfiguration { @ConditionalOnBean(DataSource.class) @EnableConfigurationProperties(FhirProperties.class) static class FhirJpaServerConfiguration { - - @Bean - @ConditionalOnMissingBean - public ScheduledExecutorFactoryBean scheduledExecutorService() { - ScheduledExecutorFactoryBean b = new ScheduledExecutorFactoryBean(); - b.setPoolSize(5); - return b; - } - - @Bean(name=BaseConfig.TASK_EXECUTOR_NAME) - public AsyncTaskExecutor taskScheduler() { - ConcurrentTaskScheduler retVal = new ConcurrentTaskScheduler(); - retVal.setConcurrentExecutor(scheduledExecutorService().getObject()); - retVal.setScheduledExecutor(scheduledExecutorService().getObject()); - return retVal; - } + @Autowired + private ScheduledExecutorService myScheduledExecutorService; @Configuration @EntityScan(basePackages = {"ca.uhn.fhir.jpa.entity", "ca.uhn.fhir.jpa.model.entity"}) - @EnableJpaRepositories(basePackages = "ca.uhn.fhir.jpa.dao.data") static class FhirJpaDaoConfiguration { @Bean diff --git a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java index 72c7df521d0..1627726556c 100644 --- a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java +++ b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java @@ -1,8 +1,5 @@ package ca.uhn.fhir.spring.boot.autoconfigure; -import java.net.URL; -import java.net.URLClassLoader; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.dao.DaoConfig; @@ -14,18 +11,19 @@ import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.spring.boot.autoconfigure.FhirAutoConfiguration.FhirJpaServerConfiguration.Dstu3; import org.assertj.core.util.Arrays; import org.junit.After; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; -import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.mock.env.MockEnvironment; + +import java.net.URL; +import java.net.URLClassLoader; import static org.assertj.core.api.Assertions.assertThat; @@ -36,149 +34,157 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class FhirAutoConfigurationTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); + @Rule + public final ExpectedException thrown = ExpectedException.none(); - private AnnotationConfigApplicationContext context; + private AnnotationConfigApplicationContext context; - @After - public void close() { - if (this.context != null) { - this.context.close(); - } - } + @After + public void close() { + if (this.context != null) { + this.context.close(); + } + } - @Test - public void withFhirContext() throws Exception { - load(); - assertThat(this.context.getBeansOfType(FhirContext.class)).hasSize(1); - } + @Test + public void withFhirContext() throws Exception { + load(); + assertThat(this.context.getBeansOfType(FhirContext.class)).hasSize(1); + } - @Test - public void withFhirVersion() throws Exception { - load(Arrays.array(EmbeddedDataSourceConfiguration.class, - HibernateJpaAutoConfiguration.class, - FhirAutoConfiguration.class), - "hapi.fhir.version:DSTU3", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", - "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); - assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.DSTU3.getVersionImplementation()); + @Test + public void withFhirVersion() throws Exception { + load(Arrays.array(EmbeddedDataSourceConfiguration.class, + HibernateJpaAutoConfiguration.class, + FhirAutoConfiguration.class), + "hapi.fhir.version:DSTU3", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", + "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); + assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.DSTU3.getVersionImplementation()); - load(Arrays.array(EmbeddedDataSourceConfiguration.class, - HibernateJpaAutoConfiguration.class, - FhirAutoConfiguration.class), - "hapi.fhir.version:R4", - "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", - "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); - assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.R4.getVersionImplementation()); - } + load(Arrays.array(EmbeddedDataSourceConfiguration.class, + HibernateJpaAutoConfiguration.class, + FhirAutoConfiguration.class), + "hapi.fhir.version:R4", + "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", + "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); + assertThat(this.context.getBean(FhirContext.class).getVersion()).isEqualTo(FhirVersionEnum.R4.getVersionImplementation()); + } - @Test - public void withRestfulServer() { - load("hapi.fhir.server.path:/hapi-fhir/*"); - assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1); - assertThat(this.context.getBeansOfType(RestfulServer.class)).hasSize(1); - assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings()).contains("/hapi-fhir/*"); - } + @Test + public void withRestfulServer() { + load("hapi.fhir.server.path:/hapi-fhir/*"); + assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1); + assertThat(this.context.getBeansOfType(RestfulServer.class)).hasSize(1); + assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings()).contains("/hapi-fhir/*"); + } - @Test - public void withJpaServer() { - load( - Arrays.array( - EmbeddedDataSourceConfiguration.class, - HibernateJpaAutoConfiguration.class, - PropertyPlaceholderAutoConfiguration.class, - FhirAutoConfiguration.class), - "hapi.fhir.version:DSTU3", - "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", - "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); - assertThat(this.context.getBeansOfType(DaoConfig.class)).hasSize(1); - assertThat(this.context.getBeansOfType(Dstu3.class)).hasSize(1); - } + @Test + public void withJpaServer() { + load( + Arrays.array( + EmbeddedDataSourceConfiguration.class, + HibernateJpaAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class, + FhirAutoConfiguration.class), + "hapi.fhir.version:DSTU3", + "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", + "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); + assertThat(this.context.getBeansOfType(DaoConfig.class)).hasSize(1); + assertThat(this.context.getBeansOfType(Dstu3.class)).hasSize(1); + } - @Test - public void withNoValidation() { - load("hapi.fhir.validation.enabled:false"); - this.thrown.expect(NoSuchBeanDefinitionException.class); - this.context.getBean(RequestValidatingInterceptor.class); - } + @Test + public void withNoValidation() { + load("hapi.fhir.validation.enabled:false"); + this.thrown.expect(NoSuchBeanDefinitionException.class); + this.context.getBean(RequestValidatingInterceptor.class); + } - @Test - public void withValidation() { - load(); - assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1); - } + @Test + public void withValidation() { + load(); + assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1); + } - @Test - public void withValidations() { - load("hapi.fhir.validation.request-only=false"); - assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(2); - } + @Test + public void withValidations() { + load("hapi.fhir.validation.request-only:false"); + assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(2); + } - @Test - public void withCustomValidationSchemaLocation() { - load("hapi.fhir.validation.schema-location:custom-schema-location"); - assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1); - } + @Test + public void withCustomValidationSchemaLocation() { + load("hapi.fhir.validation.schema-location:custom-schema-location"); + assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1); + } - @Test - public void withApacheHttpClient() { - load(new HidePackagesClassLoader("okhttp3"), "hapi.fhir.server.url:http://localhost:8080"); - assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(1); - assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(0); - } + @Test + public void withApacheHttpClient() { + load(new HidePackagesClassLoader("okhttp3"), "hapi.fhir.server.url:http://localhost:8080"); + assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(1); + assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(0); + } - @Test - public void withOkHttpClient() { - load("hapi.fhir.server.url:http://localhost:8080"); - assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(1); - assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(0); - } + @Test + public void withOkHttpClient() { + load("hapi.fhir.server.url:http://localhost:8080"); + assertThat(this.context.getBeansOfType(OkHttpRestfulClientFactory.class)).hasSize(1); + assertThat(this.context.getBeansOfType(ApacheRestfulClientFactory.class)).hasSize(0); + } - private void load(String... environment) { - load(new Class[] { FhirAutoConfiguration.class }, null, environment); - } + private void load(String... environment) { + load(new Class[]{FhirAutoConfiguration.class}, null, environment); + } - private void load(ClassLoader classLoader, String... environment) { - load(new Class[] { FhirAutoConfiguration.class }, classLoader, environment); - } + private void load(ClassLoader classLoader, String... environment) { + load(new Class[]{FhirAutoConfiguration.class}, classLoader, environment); + } - private void load(Class[] configs, String... environment) { - load(configs, null, environment); - } + private void load(Class[] configs, String... environment) { + load(configs, null, environment); + } - private void load(Class[] configs, ClassLoader classLoader, String... environment) { - AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); - EnvironmentTestUtils.addEnvironment(applicationContext, environment); - if (classLoader != null) { - applicationContext.setClassLoader(classLoader); - } - if (configs != null) { - applicationContext.register(configs); - } - applicationContext.refresh(); - this.context = applicationContext; - } + private void load(Class[] configs, ClassLoader classLoader, String... environment) { - private static final class HidePackagesClassLoader extends URLClassLoader { + MockEnvironment env = new MockEnvironment(); + for (String next : environment) { + String nextKey = next.substring(0, next.indexOf(':')); + String nextValue = next.substring(next.indexOf(':') + 1); + env.setProperty(nextKey, nextValue); + } - private final String[] hiddenPackages; + AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); + applicationContext.setEnvironment(env); + if (classLoader != null) { + applicationContext.setClassLoader(classLoader); + } + if (configs != null) { + applicationContext.register(configs); + } + applicationContext.refresh(); + this.context = applicationContext; + } - private HidePackagesClassLoader(String... hiddenPackages) { - super(new URL[0], FhirAutoConfigurationTest.class.getClassLoader()); - this.hiddenPackages = hiddenPackages; - } + private static final class HidePackagesClassLoader extends URLClassLoader { - @Override - protected Class loadClass(String name, boolean resolve) - throws ClassNotFoundException { - for (String hiddenPackage : this.hiddenPackages) { - if (name.startsWith(hiddenPackage)) { - throw new ClassNotFoundException(); - } - } - return super.loadClass(name, resolve); - } + private final String[] hiddenPackages; - } + private HidePackagesClassLoader(String... hiddenPackages) { + super(new URL[0], FhirAutoConfigurationTest.class.getClassLoader()); + this.hiddenPackages = hiddenPackages; + } + + @Override + protected Class loadClass(String name, boolean resolve) + throws ClassNotFoundException { + for (String hiddenPackage : this.hiddenPackages) { + if (name.startsWith(hiddenPackage)) { + throw new ClassNotFoundException(); + } + } + return super.loadClass(name, resolve); + } + + } } diff --git a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/test/java/sample/fhir/server/jpa/SampleJpaRestfulServerApplicationTest.java b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/test/java/sample/fhir/server/jpa/SampleJpaRestfulServerApplicationTest.java index a94bb83fea0..76060a6dc17 100644 --- a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/test/java/sample/fhir/server/jpa/SampleJpaRestfulServerApplicationTest.java +++ b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/test/java/sample/fhir/server/jpa/SampleJpaRestfulServerApplicationTest.java @@ -4,14 +4,12 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.client.api.IGenericClient; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) diff --git a/hapi-fhir-structures-dstu2/pom.xml b/hapi-fhir-structures-dstu2/pom.xml index b0d20486c60..99d2ba65c71 100644 --- a/hapi-fhir-structures-dstu2/pom.xml +++ b/hapi-fhir-structures-dstu2/pom.xml @@ -211,18 +211,18 @@ org.jacoco jacoco-maven-plugin - - ${basedir}/target/classes - ${basedir}/../hapi-fhir-base/target/classes - ${basedir}/../hapi-fhir-client/target/classes - ${basedir}/../hapi-fhir-server/target/classes - - - ${basedir}/src/main/java - ${basedir}/../hapi-fhir-base/src/main/java - ${basedir}/../hapi-fhir-client/src/main/java - ${basedir}/../hapi-fhir-server/src/main/java - + + + + + + + + + + + + true @@ -360,7 +360,8 @@ ca.uhn.fhir.model.dstu2 dstu2 true - + ca.uhn.fhir.model.dstu2 + diff --git a/pom.xml b/pom.xml index e09431cbca6..7d33f434610 100644 --- a/pom.xml +++ b/pom.xml @@ -544,7 +544,8 @@ 1.7.25 5.1.3.RELEASE 2.1.3.RELEASE - 1.5.6.RELEASE + + 2.1.1.RELEASE 3.1.4 3.0.11.RELEASE @@ -791,7 +792,7 @@ javax.validation validation-api - 1.1.0.Final + 2.0.1.Final javax.ws.rs diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 98e511ef6bb..da45a93af41 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -20,6 +20,7 @@
  • thymeleaf-spring4 (Testpage Overlay) has been replaced with thymeleaf-spring5
  • Commons-Lang3: 3.8 -> 3.8.1
  • Commons-Text: 1.4 -> 1.4
  • +
  • Spring Boot: 1.5.6.RELEASE -> 2.1.1.RELEASE
  • ]]>