diff --git a/integrationtest/mapper/orm-spring-uberjar/application/src/main/resources/application.yaml b/integrationtest/mapper/orm-spring-uberjar/application/src/main/resources/application.yaml index 954a09748c7..04b67875966 100644 --- a/integrationtest/mapper/orm-spring-uberjar/application/src/main/resources/application.yaml +++ b/integrationtest/mapper/orm-spring-uberjar/application/src/main/resources/application.yaml @@ -7,7 +7,7 @@ spring.jpa: directory.root: ${LUCENE_ROOT_PATH:target/test-indexes}/${random.uuid} spring.datasource: - driver-class: org.h2.Driver + driver-class-name: org.h2.Driver url: jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 username: sa password: sa \ No newline at end of file diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/beanresolution/SpringBeanResolutionIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/beanresolution/SpringBeanResolutionIT.java index 93d40947e07..7d255584a4a 100644 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/beanresolution/SpringBeanResolutionIT.java +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/beanresolution/SpringBeanResolutionIT.java @@ -23,16 +23,15 @@ import org.hibernate.SessionFactory; import org.hibernate.search.engine.environment.bean.BeanHolder; import org.hibernate.search.engine.environment.bean.BeanReference; -import org.hibernate.search.integrationtest.spring.extension.HibernateSpringPropertiesSetterExtension; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; import org.hibernate.search.util.impl.integrationtest.common.extension.BackendMock; import org.hibernate.search.util.impl.integrationtest.common.stub.backend.BackendMappingHandle; +import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; import org.hibernate.search.util.impl.integrationtest.mapper.orm.HibernateOrmMappingHandle; import org.hibernate.search.util.impl.test.annotation.TestForIssue; import org.hibernate.search.util.impl.test.extension.StaticCounters; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.assertj.core.api.InstanceOfAssertFactories; @@ -51,6 +50,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.context.event.EventListener; +import org.springframework.mock.env.MockEnvironment; import org.springframework.stereotype.Component; /** @@ -60,7 +60,6 @@ * then checking the Spring-defined hooks (@PostConstruct and @PreDestroy) have been called * exactly as many times as expected. */ -@ExtendWith(HibernateSpringPropertiesSetterExtension.class) @TestForIssue(jiraKey = { "HSEARCH-1316", "HSEARCH-3171" }) class SpringBeanResolutionIT { @@ -180,8 +179,17 @@ private void doTest(ExpectedScope expectedScope, CounterKeys counterKeys, Be private ConfigurableApplicationContext startApplication() { Map properties = new LinkedHashMap<>(); properties.put( "test.backendMock", backendMock ); + + DatabaseContainer.Configuration configuration = DatabaseContainer.configuration(); + MockEnvironment environment = new MockEnvironment(); + environment.withProperty( "JDBC_DRIVER", configuration.driver() ); + environment.withProperty( "JDBC_URL", configuration.url() ); + environment.withProperty( "JDBC_USERNAME", configuration.user() ); + environment.withProperty( "JDBC_PASSWORD", configuration.pass() ); + return new SpringApplicationBuilder( SpringConfig.class ) .web( WebApplicationType.NONE ) + .environment( environment ) .properties( properties ) .run(); } diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/extension/HibernateSpringPropertiesSetterExtension.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/extension/HibernateSpringPropertiesSetterExtension.java deleted file mode 100644 index fbb91e5ee82..00000000000 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/extension/HibernateSpringPropertiesSetterExtension.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Hibernate Search, full-text search for your domain model - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.search.integrationtest.spring.extension; - -import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; - -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.ExtensionContext; - -public class HibernateSpringPropertiesSetterExtension implements BeforeAllCallback { - @Override - public void beforeAll(ExtensionContext context) { - DatabaseContainer.springConfiguration(); - } -} diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringIT.java index c575446f7b5..d26d799e535 100644 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringIT.java +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringIT.java @@ -12,9 +12,9 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; -import org.hibernate.search.integrationtest.spring.extension.HibernateSpringPropertiesSetterExtension; import org.hibernate.search.integrationtest.spring.jta.dao.SnertDAO; import org.hibernate.search.integrationtest.spring.jta.entity.Snert; +import org.hibernate.search.integrationtest.spring.testsupport.AbstractMapperOrmSpringIT; import org.hibernate.search.mapper.orm.session.impl.HibernateOrmSearchSessionHolder; import org.hibernate.search.util.impl.integrationtest.common.extension.BackendMock; import org.hibernate.search.util.impl.test.annotation.PortedFromSearch5; @@ -22,22 +22,18 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; -@ExtendWith(HibernateSpringPropertiesSetterExtension.class) -@ExtendWith(SpringExtension.class) @SpringBootTest(classes = JtaAndSpringApplicationConfiguration.class) @ActiveProfiles("jta") @PortedFromSearch5(original = "org.hibernate.search.test.integration.spring.jta.JtaAndSpringIT") @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -class JtaAndSpringIT { +class JtaAndSpringIT extends AbstractMapperOrmSpringIT { @Autowired @RegisterExtension diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringMoreComplexIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringMoreComplexIT.java index 648fe92e692..4587e8cdd0c 100644 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringMoreComplexIT.java +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringMoreComplexIT.java @@ -12,11 +12,11 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; -import org.hibernate.search.integrationtest.spring.extension.HibernateSpringPropertiesSetterExtension; import org.hibernate.search.integrationtest.spring.jta.dao.BoxDAO; import org.hibernate.search.integrationtest.spring.jta.entity.Box; import org.hibernate.search.integrationtest.spring.jta.entity.Doughnut; import org.hibernate.search.integrationtest.spring.jta.entity.Muffin; +import org.hibernate.search.integrationtest.spring.testsupport.AbstractMapperOrmSpringIT; import org.hibernate.search.mapper.orm.session.impl.HibernateOrmSearchSessionHolder; import org.hibernate.search.util.impl.integrationtest.common.extension.BackendMock; import org.hibernate.search.util.impl.test.annotation.PortedFromSearch5; @@ -24,22 +24,18 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; -@ExtendWith(HibernateSpringPropertiesSetterExtension.class) -@ExtendWith(SpringExtension.class) @SpringBootTest(classes = JtaAndSpringApplicationConfiguration.class) @ActiveProfiles("jta") @PortedFromSearch5(original = "org.hibernate.search.test.integration.spring.jta.JtaAndSpringMoreComplexIT") @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -class JtaAndSpringMoreComplexIT { +class JtaAndSpringMoreComplexIT extends AbstractMapperOrmSpringIT { @Autowired @RegisterExtension diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringOutboxIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringOutboxIT.java index 7cc797fa462..793cd52159b 100644 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringOutboxIT.java +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/JtaAndSpringOutboxIT.java @@ -12,30 +12,26 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; -import org.hibernate.search.integrationtest.spring.extension.HibernateSpringPropertiesSetterExtension; import org.hibernate.search.integrationtest.spring.jta.dao.SnertDAO; import org.hibernate.search.integrationtest.spring.jta.entity.Snert; +import org.hibernate.search.integrationtest.spring.testsupport.AbstractMapperOrmSpringIT; import org.hibernate.search.mapper.orm.session.impl.HibernateOrmSearchSessionHolder; import org.hibernate.search.util.impl.integrationtest.common.extension.BackendMock; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; -@ExtendWith(HibernateSpringPropertiesSetterExtension.class) -@ExtendWith(SpringExtension.class) @SpringBootTest(classes = JtaAndSpringOutboxApplicationConfiguration.class) @ActiveProfiles({ "jta", "outbox" }) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -class JtaAndSpringOutboxIT { +class JtaAndSpringOutboxIT extends AbstractMapperOrmSpringIT { @Autowired @RegisterExtension diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/timeout/RaisedTimeoutJtaAndSpringOutboxIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/timeout/RaisedTimeoutJtaAndSpringOutboxIT.java index 73e39d1547b..1844f31fc13 100644 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/timeout/RaisedTimeoutJtaAndSpringOutboxIT.java +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/timeout/RaisedTimeoutJtaAndSpringOutboxIT.java @@ -12,15 +12,14 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; -import org.hibernate.search.integrationtest.spring.extension.HibernateSpringPropertiesSetterExtension; import org.hibernate.search.integrationtest.spring.jta.JtaAndSpringOutboxApplicationConfiguration; import org.hibernate.search.integrationtest.spring.jta.dao.SnertDAO; import org.hibernate.search.integrationtest.spring.jta.entity.Snert; +import org.hibernate.search.integrationtest.spring.testsupport.AbstractMapperOrmSpringIT; import org.hibernate.search.util.impl.integrationtest.common.extension.BackendMock; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import com.atomikos.icatch.jta.TransactionManagerImp; @@ -29,14 +28,11 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; -@ExtendWith(HibernateSpringPropertiesSetterExtension.class) -@ExtendWith(SpringExtension.class) @SpringBootTest(classes = JtaAndSpringOutboxApplicationConfiguration.class) @ActiveProfiles({ "jta", "outbox", "transaction-timeout", "raised-timeout" }) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -class RaisedTimeoutJtaAndSpringOutboxIT { +class RaisedTimeoutJtaAndSpringOutboxIT extends AbstractMapperOrmSpringIT { @Autowired @RegisterExtension diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/timeout/TransactionTimeoutJtaAndSpringOutboxIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/timeout/TransactionTimeoutJtaAndSpringOutboxIT.java index c3a05d24788..98be0769737 100644 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/timeout/TransactionTimeoutJtaAndSpringOutboxIT.java +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/jta/timeout/TransactionTimeoutJtaAndSpringOutboxIT.java @@ -13,14 +13,13 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; -import org.hibernate.search.integrationtest.spring.extension.HibernateSpringPropertiesSetterExtension; import org.hibernate.search.integrationtest.spring.jta.JtaAndSpringOutboxApplicationConfiguration; import org.hibernate.search.integrationtest.spring.jta.dao.SnertDAO; import org.hibernate.search.integrationtest.spring.jta.entity.Snert; +import org.hibernate.search.integrationtest.spring.testsupport.AbstractMapperOrmSpringIT; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import com.atomikos.icatch.jta.TransactionManagerImp; @@ -28,14 +27,11 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; -@ExtendWith(HibernateSpringPropertiesSetterExtension.class) -@ExtendWith(SpringExtension.class) @SpringBootTest(classes = JtaAndSpringOutboxApplicationConfiguration.class) @ActiveProfiles({ "jta", "outbox", "transaction-timeout" }) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -class TransactionTimeoutJtaAndSpringOutboxIT { +class TransactionTimeoutJtaAndSpringOutboxIT extends AbstractMapperOrmSpringIT { @Autowired private SnertDAO snertDAO; @@ -58,7 +54,7 @@ void checkJta() { } @Test - void test() throws Exception { + void test() { Snert snert = new Snert(); snert.setId( 1L ); snert.setName( "dave" ); diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/outbox/TransactionOutboxIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/outbox/TransactionOutboxIT.java index c0f13003e4b..b18b3016d0e 100644 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/outbox/TransactionOutboxIT.java +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/outbox/TransactionOutboxIT.java @@ -10,32 +10,28 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.Id; +import org.hibernate.search.integrationtest.spring.testsupport.AbstractMapperOrmSpringIT; import org.hibernate.search.integrationtest.spring.testsupport.AbstractSpringITConfig; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; import org.hibernate.search.util.impl.integrationtest.common.extension.BackendMock; import org.hibernate.search.util.impl.integrationtest.mapper.orm.CoordinationStrategyExpectations; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Service; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -@ExtendWith(SpringExtension.class) -@SpringBootTest @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @ActiveProfiles(profiles = { "outbox" }) -class TransactionOutboxIT { +class TransactionOutboxIT extends AbstractMapperOrmSpringIT { @Configuration @EntityScan diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/sessionproxy/SessionProxyIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/sessionproxy/SessionProxyIT.java index e7b627d4b0f..03daa770531 100644 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/sessionproxy/SessionProxyIT.java +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/sessionproxy/SessionProxyIT.java @@ -18,6 +18,7 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.Id; +import org.hibernate.search.integrationtest.spring.testsupport.AbstractMapperOrmSpringIT; import org.hibernate.search.integrationtest.spring.testsupport.AbstractSpringITConfig; import org.hibernate.search.mapper.orm.Search; import org.hibernate.search.mapper.orm.session.SearchSession; @@ -29,17 +30,14 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Service; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.support.TransactionTemplate; @@ -48,10 +46,8 @@ * one can create a single SearchSession for all threads, and it will correctly use the correct EntityManager * depending on the current thread. */ -@ExtendWith(SpringExtension.class) -@SpringBootTest @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) -class SessionProxyIT { +class SessionProxyIT extends AbstractMapperOrmSpringIT { @Configuration @EntityScan diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/testsupport/AbstractMapperOrmSpringIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/testsupport/AbstractMapperOrmSpringIT.java new file mode 100644 index 00000000000..9a68b64846e --- /dev/null +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/testsupport/AbstractMapperOrmSpringIT.java @@ -0,0 +1,21 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.integrationtest.spring.testsupport; + +import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; + +@SpringBootTest +public abstract class AbstractMapperOrmSpringIT { + @DynamicPropertySource + static void configureProperties(DynamicPropertyRegistry registry) { + DatabaseContainer.configuration().addAsSpring( (key, value) -> registry.add( key, () -> value ) ); + } +} diff --git a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/transaction/TransactionIT.java b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/transaction/TransactionIT.java index eedf18fb581..1f9242eaff3 100644 --- a/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/transaction/TransactionIT.java +++ b/integrationtest/mapper/orm-spring/src/test/java/org/hibernate/search/integrationtest/spring/transaction/TransactionIT.java @@ -10,13 +10,13 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.Id; +import org.hibernate.search.integrationtest.spring.testsupport.AbstractMapperOrmSpringIT; import org.hibernate.search.integrationtest.spring.testsupport.AbstractSpringITConfig; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; import org.hibernate.search.util.impl.integrationtest.common.extension.BackendMock; import org.hibernate.search.util.impl.test.annotation.TestForIssue; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; @@ -27,16 +27,14 @@ import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -@ExtendWith(SpringExtension.class) // Adding a property here is just a "workaround" to make sure that a different context is used for this test // otherwise there can be build errors when running all the tests via maven. @SpringBootTest(properties = "spring.jta.atomikos.datasource.bean-name=hsearch-datasource1") @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -class TransactionIT { +class TransactionIT extends AbstractMapperOrmSpringIT { @Configuration @EntityScan diff --git a/integrationtest/mapper/orm-spring/src/test/resources/application.yaml b/integrationtest/mapper/orm-spring/src/test/resources/application.yaml index bd5c916a670..6a9ff30ff7d 100644 --- a/integrationtest/mapper/orm-spring/src/test/resources/application.yaml +++ b/integrationtest/mapper/orm-spring/src/test/resources/application.yaml @@ -2,14 +2,12 @@ spring.jpa: hibernate: ddl-auto: create-drop properties: - hibernate: - dialect: ${HIBERNATE_DIALECT} # From environment variable hibernate.search: # The backend is a mock anyway. schema_management.strategy: none spring.datasource: - driver-class: ${JDBC_DRIVER} # From environment variable + driver-class-name: ${JDBC_DRIVER} # From environment variable url: ${JDBC_URL} # From environment variable username: ${JDBC_USERNAME} # From environment variable password: ${JDBC_PASSWORD} # From environment variable @@ -22,10 +20,6 @@ logging.level: org.hibernate.search.elasticsearch.request: DEBUG org.hibernate.search.backend.lucene: DEBUG -# Default environment variable values for IDEs that are unable to extract them from the maven-failsafe configuration -# These values are overridden when running tests from Intellij IDEA or directly from Maven -JDBC_URL: jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 - # since atomikos connection pool has a max size set to 1 ... # we will not be able to execute more than one transaction at a time, leading to errors in tests spring: diff --git a/integrationtest/showcase/library/src/main/resources/application.yaml b/integrationtest/showcase/library/src/main/resources/application.yaml index 64ac5327dc5..1b64af49a8d 100644 --- a/integrationtest/showcase/library/src/main/resources/application.yaml +++ b/integrationtest/showcase/library/src/main/resources/application.yaml @@ -1,10 +1,5 @@ -spring.jpa: - properties: - hibernate: - dialect: ${HIBERNATE_DIALECT} # From environment variable - spring.datasource: - driver-class: ${JDBC_DRIVER} # From environment variable + driver-class-name: ${JDBC_DRIVER} # From environment variable url: ${JDBC_URL} # From environment variable username: ${JDBC_USERNAME} # From environment variable password: ${JDBC_PASSWORD} # From environment variable diff --git a/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/AbstractLibraryShowcaseSearchIT.java b/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/AbstractLibraryShowcaseSearchIT.java new file mode 100644 index 00000000000..65f68feddc1 --- /dev/null +++ b/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/AbstractLibraryShowcaseSearchIT.java @@ -0,0 +1,28 @@ +/* + * Hibernate Search, full-text search for your domain model + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.search.integrationtest.showcase.library; + +import static org.hibernate.search.integrationtest.showcase.library.TestActiveProfilesResolver.configuredBackend; + +import org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.SearchContainer; +import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; + +@SpringBootTest +abstract class AbstractLibraryShowcaseSearchIT { + @DynamicPropertySource + static void configureProperties(DynamicPropertyRegistry registry) { + DatabaseContainer.configuration().addAsSpring( (key, value) -> registry.add( key, () -> value ) ); + + if ( "elasticsearch".equals( configuredBackend() ) ) { + registry.add( "spring.jpa.properties.hibernate.search.backend.uris", SearchContainer::connectionUrl ); + } + } +} diff --git a/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/LibraryShowcaseMassIndexingIT.java b/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/LibraryShowcaseMassIndexingIT.java index a1801f14bd2..49ce4fdbb6e 100644 --- a/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/LibraryShowcaseMassIndexingIT.java +++ b/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/LibraryShowcaseMassIndexingIT.java @@ -19,16 +19,14 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; -@SpringBootTest @TestPropertySource(properties = { "spring.jpa.properties.hibernate.search.indexing.listeners.enabled=false" }) @ActiveProfiles(resolver = TestActiveProfilesResolver.class) -class LibraryShowcaseMassIndexingIT { +class LibraryShowcaseMassIndexingIT extends AbstractLibraryShowcaseSearchIT { private static final int NUMBER_OF_BOOKS = 200; diff --git a/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/LibraryShowcaseSearchIT.java b/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/LibraryShowcaseSearchIT.java index 65139a73ae5..3755120498a 100644 --- a/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/LibraryShowcaseSearchIT.java +++ b/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/LibraryShowcaseSearchIT.java @@ -58,14 +58,12 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -@SpringBootTest @ActiveProfiles(resolver = TestActiveProfilesResolver.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) -class LibraryShowcaseSearchIT { +class LibraryShowcaseSearchIT extends AbstractLibraryShowcaseSearchIT { private static boolean needsInit; diff --git a/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/TestActiveProfilesResolver.java b/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/TestActiveProfilesResolver.java index b4b595c65bf..af4d47e7dfc 100644 --- a/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/TestActiveProfilesResolver.java +++ b/integrationtest/showcase/library/src/test/java/org/hibernate/search/integrationtest/showcase/library/TestActiveProfilesResolver.java @@ -6,31 +6,27 @@ */ package org.hibernate.search.integrationtest.showcase.library; -import org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.SearchContainer; -import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; - import org.springframework.test.context.ActiveProfilesResolver; public class TestActiveProfilesResolver implements ActiveProfilesResolver { + /* + * Default when running tests from within an IDE. + * This is the main reason we're using an ActiveProfilesResolver: + * there is apparently no way to set default profiles for tests, + * as setting "spring.profiles.active" in a @TestPropertySource for example + * will *override* any command-line arguments, environment properties or system properties. + */ + private static final String DEFAULT_BACKEND = "lucene"; + @Override public String[] resolve(Class testClass) { - String testBackend = System.getProperty( "test.backend" ); - if ( testBackend == null ) { - /* - * Default when running tests from within an IDE. - * This is the main reason we're using an ActiveProfilesResolver: - * there is apparently no way to set default profiles for tests, - * as setting "spring.profiles.active" in a @TestPropertySource for example - * will *override* any command-line arguments, environment properties or system properties. - */ - testBackend = "lucene"; - } - if ( "elasticsearch".equals( testBackend ) ) { - System.setProperty( "ES_HOSTS", SearchContainer.connectionUrl() ); - } - DatabaseContainer.springConfiguration(); + String testBackend = configuredBackend(); // The test profiles must be mentioned last, to allow them to override properties return new String[] { testBackend, "test", "test-" + testBackend }; } + + public static String configuredBackend() { + return System.getProperty( "test.backend", DEFAULT_BACKEND ); + } } diff --git a/integrationtest/showcase/library/src/test/java17/org/hibernate/search/integrationtest/showcase/library/Java17IT.java b/integrationtest/showcase/library/src/test/java17/org/hibernate/search/integrationtest/showcase/library/Java17IT.java index d801f9d55f5..e2a8d6596c5 100644 --- a/integrationtest/showcase/library/src/test/java17/org/hibernate/search/integrationtest/showcase/library/Java17IT.java +++ b/integrationtest/showcase/library/src/test/java17/org/hibernate/search/integrationtest/showcase/library/Java17IT.java @@ -29,10 +29,9 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; -@SpringBootTest @ActiveProfiles(resolver = TestActiveProfilesResolver.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) -class Java17IT { +class Java17IT extends AbstractLibraryShowcaseSearchIT{ private static boolean needsInit; diff --git a/integrationtest/showcase/library/src/test/resources/application-test-elasticsearch.yaml b/integrationtest/showcase/library/src/test/resources/application-test-elasticsearch.yaml index 3d6f8ee2ca7..ea4b07f5d18 100644 --- a/integrationtest/showcase/library/src/test/resources/application-test-elasticsearch.yaml +++ b/integrationtest/showcase/library/src/test/resources/application-test-elasticsearch.yaml @@ -3,4 +3,4 @@ spring.jpa: hibernate.search: backend: log.json_pretty_printing: true - hosts: ${ES_HOSTS} + uris: ${ELASTICSEARCH_URIS:localhost:9200} diff --git a/integrationtest/showcase/library/src/test/resources/application-test.yaml b/integrationtest/showcase/library/src/test/resources/application-test.yaml index 9b389e11a6b..aac79e7aaf9 100644 --- a/integrationtest/showcase/library/src/test/resources/application-test.yaml +++ b/integrationtest/showcase/library/src/test/resources/application-test.yaml @@ -17,7 +17,3 @@ logging.level: org.hibernate.search.query: DEBUG org.hibernate.search.elasticsearch.request: DEBUG org.hibernate.search.backend.lucene: DEBUG - -# Default environment variable values for IDEs that are unable to extract them from the maven-failsafe configuration -# These values are overridden when running tests from Intellij IDEA or directly from Maven -JDBC_URL: jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 diff --git a/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/DatabaseContainer.java b/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/DatabaseContainer.java index 30bb0c62edb..7ab955dc4fe 100644 --- a/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/DatabaseContainer.java +++ b/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/DatabaseContainer.java @@ -11,7 +11,7 @@ import java.util.Collections; import java.util.Locale; import java.util.Map; -import java.util.function.Consumer; +import java.util.function.BiConsumer; import org.testcontainers.containers.JdbcDatabaseContainer; import org.testcontainers.images.builder.ImageFromDockerfile; @@ -29,10 +29,8 @@ public final class DatabaseContainer { private DatabaseContainer() { } - private static final Object LOCK = new Object(); private static final SupportedDatabase DATABASE; private static final HibernateSearchJdbcDatabaseContainer DATABASE_CONTAINER; - private static Boolean H2_INITIALIZED = Boolean.FALSE; static { @@ -47,14 +45,6 @@ private DatabaseContainer() { } public static Configuration configuration() { - return configure( Configuration::addAsSystemProperties ); - } - - public static Configuration springConfiguration() { - return configure( Configuration::addAsSpringSystemProperties ); - } - - private static Configuration configure(Consumer propertySetter) { if ( !SupportedDatabase.H2.equals( DATABASE ) ) { DATABASE_CONTAINER.start(); } @@ -64,15 +54,6 @@ private static Configuration configure(Consumer propertySetter) { synchronized (DATABASE_CONTAINER) { if ( !DATABASE_CONTAINER.isRunning() ) { DATABASE_CONTAINER.start(); - propertySetter.accept( configuration ); - } - } - } - else if ( !H2_INITIALIZED ) { - synchronized (LOCK) { - if ( !H2_INITIALIZED ) { - propertySetter.accept( configuration ); - H2_INITIALIZED = Boolean.TRUE; } } } @@ -360,6 +341,30 @@ public Configuration(String dialect, String driver, String url, String user, Str this.isolation = isolation; } + public String dialect() { + return dialect; + } + + public String driver() { + return driver; + } + + public String url() { + return url; + } + + public String user() { + return user; + } + + public String pass() { + return pass; + } + + public String isolation() { + return isolation; + } + public void add(Map map) { map.put( "hibernate.dialect", this.dialect ); map.put( "hibernate.connection.driver_class", this.driver ); @@ -369,22 +374,11 @@ public void add(Map map) { map.put( "hibernate.connection.isolation", this.isolation ); } - private void addAsSystemProperties() { - System.setProperty( "hibernate.dialect", this.dialect ); - System.setProperty( "hibernate.connection.driver_class", this.driver ); - System.setProperty( "hibernate.connection.url", this.url ); - System.setProperty( "hibernate.connection.username", this.user ); - System.setProperty( "hibernate.connection.password", this.pass ); - System.setProperty( "hibernate.connection.isolation", this.isolation ); - } - - private void addAsSpringSystemProperties() { - System.setProperty( "HIBERNATE_DIALECT", this.dialect ); - System.setProperty( "JDBC_DRIVER", this.driver ); - System.setProperty( "JDBC_URL", this.url ); - System.setProperty( "JDBC_USERNAME", this.user ); - System.setProperty( "JDBC_PASSWORD", this.pass ); - System.setProperty( "JDBC_ISOLATION", this.isolation ); + public void addAsSpring(BiConsumer consumer) { + consumer.accept( "spring.datasource.driver-class-name", this.driver ); + consumer.accept( "spring.datasource.url", this.url ); + consumer.accept( "spring.datasource.username", this.user ); + consumer.accept( "spring.datasource.password", this.pass ); } } } diff --git a/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/OrmSetupHelper.java b/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/OrmSetupHelper.java index 138ada8c7fc..323308d0967 100644 --- a/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/OrmSetupHelper.java +++ b/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/OrmSetupHelper.java @@ -47,11 +47,7 @@ public class OrmSetupHelper static { Map defaults = new LinkedHashMap<>(); - - String jdbcUrl = System.getProperty( "hibernate.connection.url" ); - if ( jdbcUrl == null || jdbcUrl.trim().isEmpty() ) { - DatabaseContainer.configuration(); - } + DatabaseContainer.configuration().add( defaults ); // we don't need a ServiceLoader using a general-purpose aggregated class loader, // since we expect the service impl in the direct dependent test module. @@ -61,12 +57,11 @@ public class OrmSetupHelper OrmSetupHelperConfig next = iterator.next(); DEFAULT_COORDINATION_STRATEGY_EXPECTATIONS = next.coordinationStrategyExpectations(); next.overrideHibernateSearchDefaults( defaults::put ); - DEFAULT_PROPERTIES = Collections.unmodifiableMap( defaults ); } else { DEFAULT_COORDINATION_STRATEGY_EXPECTATIONS = CoordinationStrategyExpectations.defaults(); - DEFAULT_PROPERTIES = Collections.emptyMap(); } + DEFAULT_PROPERTIES = Collections.unmodifiableMap( defaults ); } public static OrmSetupHelper withBackendMock(BackendMock backendMock) {