diff --git a/documentation/src/test/java/org/hibernate/search/documentation/mapper/orm/gettingstarted/withouthsearch/GettingStartedWithoutHibernateSearchIT.java b/documentation/src/test/java/org/hibernate/search/documentation/mapper/orm/gettingstarted/withouthsearch/GettingStartedWithoutHibernateSearchIT.java index c1a7b5ffac8..ede38ab6b1c 100644 --- a/documentation/src/test/java/org/hibernate/search/documentation/mapper/orm/gettingstarted/withouthsearch/GettingStartedWithoutHibernateSearchIT.java +++ b/documentation/src/test/java/org/hibernate/search/documentation/mapper/orm/gettingstarted/withouthsearch/GettingStartedWithoutHibernateSearchIT.java @@ -7,6 +7,7 @@ package org.hibernate.search.documentation.mapper.orm.gettingstarted.withouthsearch; import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.search.documentation.testsupport.TestConfiguration.databaseConnectionProperties; import static org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with; import java.util.List; @@ -26,7 +27,8 @@ class GettingStartedWithoutHibernateSearchIT { @BeforeEach void setup() { - entityManagerFactory = Persistence.createEntityManagerFactory( "GettingStartedWithoutHibernateSearchIT" ); + entityManagerFactory = Persistence.createEntityManagerFactory( "GettingStartedWithoutHibernateSearchIT", + databaseConnectionProperties() ); } @AfterEach diff --git a/documentation/src/test/java/org/hibernate/search/documentation/testsupport/TestConfiguration.java b/documentation/src/test/java/org/hibernate/search/documentation/testsupport/TestConfiguration.java index ab75404ad64..1f6a3b2fdd8 100644 --- a/documentation/src/test/java/org/hibernate/search/documentation/testsupport/TestConfiguration.java +++ b/documentation/src/test/java/org/hibernate/search/documentation/testsupport/TestConfiguration.java @@ -11,6 +11,7 @@ import org.hibernate.search.util.impl.integrationtest.common.TestConfigurationProvider; import org.hibernate.search.util.impl.integrationtest.common.extension.BackendConfiguration; +import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; public final class TestConfiguration { @@ -22,8 +23,8 @@ private TestConfiguration() { * * @return Configuration properties to use when bootstrapping Hibernate ORM with JPA. */ - public static Map ormMapperProperties(TestConfigurationProvider configurationProvider) { - Map properties = new HashMap<>(); + public static Map ormMapperProperties(TestConfigurationProvider configurationProvider) { + Map properties = databaseConnectionProperties(); // Hack: override example properties set in persistence.xml properties.put( "hibernate.search.backend.hosts", "" ); @@ -40,6 +41,12 @@ public static Map ormMapperProperties(TestConfigurationProvider return properties; } + public static Map databaseConnectionProperties() { + Map properties = new HashMap<>(); + DatabaseContainer.configuration().add( properties ); + return properties; + } + /** * @param configurationProvider A test configuration provider. * @param backendConfiguration The backend configuration. diff --git a/integrationtest/mapper/orm-jakarta-batch/src/test/java/org/hibernate/search/integrationtest/jakarta/batch/util/HibernateSearchBatchTestConnectionProperties.java b/integrationtest/mapper/orm-jakarta-batch/src/test/java/org/hibernate/search/integrationtest/jakarta/batch/util/HibernateSearchBatchTestConnectionProperties.java index a00c11664b6..2489423bc90 100644 --- a/integrationtest/mapper/orm-jakarta-batch/src/test/java/org/hibernate/search/integrationtest/jakarta/batch/util/HibernateSearchBatchTestConnectionProperties.java +++ b/integrationtest/mapper/orm-jakarta-batch/src/test/java/org/hibernate/search/integrationtest/jakarta/batch/util/HibernateSearchBatchTestConnectionProperties.java @@ -27,7 +27,7 @@ public static Map connectionProperties() { SearchBackendContainer.connectionUrl() ); } - DatabaseContainer.configuration(); + DatabaseContainer.configuration().add( properties ); return properties; } 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/mapper/orm/src/test/java/org/hibernate/search/integrationtest/mapper/orm/bootstrap/HibernateOrmIntegrationBooterIT.java b/integrationtest/mapper/orm/src/test/java/org/hibernate/search/integrationtest/mapper/orm/bootstrap/HibernateOrmIntegrationBooterIT.java index 7b8398722c3..5c96b8608b7 100644 --- a/integrationtest/mapper/orm/src/test/java/org/hibernate/search/integrationtest/mapper/orm/bootstrap/HibernateOrmIntegrationBooterIT.java +++ b/integrationtest/mapper/orm/src/test/java/org/hibernate/search/integrationtest/mapper/orm/bootstrap/HibernateOrmIntegrationBooterIT.java @@ -13,6 +13,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -44,6 +45,7 @@ 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.common.stub.backend.index.StubSchemaManagementWork; +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.integrationtest.mapper.orm.SimpleSessionFactoryBuilder; @@ -116,6 +118,7 @@ public void configure(HibernateOrmMappingConfigurationContext context) { } } ); + DatabaseContainer.configuration().add( booterGeneratedProperties ); for ( Map.Entry booterGeneratedProperty : booterGeneratedProperties.entrySet() ) { builder.setProperty( booterGeneratedProperty.getKey(), booterGeneratedProperty.getValue() ); } @@ -160,6 +163,9 @@ private HibernateOrmIntegrationBooter createBooter(CompletableFuture connectionProperties = new HashMap<>(); + DatabaseContainer.configuration().add( connectionProperties ); + registryBuilder.applySettings( connectionProperties ); StandardServiceRegistry serviceRegistry = registryBuilder.build(); toClose.add( serviceRegistry ); 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..b4637d0d24f --- /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.SearchBackendContainer; +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", SearchBackendContainer::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/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/batchindexing/DatabaseMultitenancyTest.java b/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/batchindexing/DatabaseMultitenancyTest.java index 5abbc08a6c3..51f677d8121 100644 --- a/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/batchindexing/DatabaseMultitenancyTest.java +++ b/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/batchindexing/DatabaseMultitenancyTest.java @@ -8,6 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.listAll; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.IOException; import java.util.List; @@ -20,8 +21,7 @@ import org.hibernate.search.query.dsl.QueryBuilder; import org.hibernate.search.test.SearchTestBase; import org.hibernate.search.util.common.impl.CollectionHelper; - -import org.hibernate.testing.orm.junit.RequiresDialect; +import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -43,10 +43,6 @@ * @author Sanne Grinovero * @since 5.2 */ -@RequiresDialect( - comment = "The connection provider for this test ignores configuration and requires H2", - value = org.hibernate.dialect.H2Dialect.class -) class DatabaseMultitenancyTest extends SearchTestBase { /** @@ -74,6 +70,7 @@ class DatabaseMultitenancyTest extends SearchTestBase { @Override @BeforeEach public void setUp() throws Exception { + requiresDialectCheck(); super.setUp(); Session sessionMetamec = openSessionWithTenantId( METAMEC_TID ); @@ -224,6 +221,7 @@ private void persist(Session session, Object... clocks) { @AfterEach void deleteEntities() { + requiresDialectCheck(); Session session = openSessionWithTenantId( METAMEC_TID ); deleteClocks( session ); session.close(); @@ -233,6 +231,13 @@ void deleteEntities() { session.close(); } + private static void requiresDialectCheck() { + assumeTrue( + org.hibernate.dialect.H2Dialect.class.getName().equals( DatabaseContainer.configuration().driver() ), + "The connection provider for this test ignores configuration and requires H2" + ); + } + private void deleteClocks(Session session) { session.beginTransaction(); List clocks = listAll( session, Clock.class ); diff --git a/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/configuration/LobTest.java b/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/configuration/LobTest.java index f195aa6b854..9ed5c7e7c54 100644 --- a/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/configuration/LobTest.java +++ b/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/configuration/LobTest.java @@ -7,6 +7,7 @@ package org.hibernate.search.test.configuration; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.util.List; @@ -17,7 +18,6 @@ import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.dialect.SybaseDialect; import org.hibernate.search.FullTextQuery; import org.hibernate.search.FullTextSession; import org.hibernate.search.Search; @@ -26,8 +26,7 @@ import org.hibernate.search.query.dsl.QueryBuilder; import org.hibernate.search.test.SearchTestBase; import org.hibernate.search.testsupport.TestForIssue; - -import org.hibernate.testing.orm.junit.SkipForDialect; +import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; import org.junit.jupiter.api.Test; @@ -42,8 +41,11 @@ class LobTest extends SearchTestBase { @Test - @SkipForDialect(dialectClass = SybaseDialect.class, reason = "Sybase does not support @Lob") void testCreateIndexSearchEntityWithLobField() { + assumeFalse( + org.hibernate.dialect.SybaseDialect.class.getName().equals( DatabaseContainer.configuration().driver() ), + "Sybase does not support @Lob" + ); // create and index Session session = openSession(); Transaction tx = session.beginTransaction(); diff --git a/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/envers/SearchAndEnversIntegrationTest.java b/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/envers/SearchAndEnversIntegrationTest.java index b795cf5e439..0f8fae8a65e 100644 --- a/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/envers/SearchAndEnversIntegrationTest.java +++ b/integrationtest/v5migrationhelper/orm/src/test/java/org/hibernate/search/test/envers/SearchAndEnversIntegrationTest.java @@ -7,11 +7,11 @@ package org.hibernate.search.test.envers; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assumptions.assumeFalse; import java.util.List; import org.hibernate.Transaction; -import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.envers.AuditReader; import org.hibernate.envers.AuditReaderFactory; import org.hibernate.envers.query.AuditEntity; @@ -21,8 +21,7 @@ import org.hibernate.search.test.SearchTestBase; import org.hibernate.search.testsupport.TestForIssue; import org.hibernate.search.testsupport.junit.Tags; - -import org.hibernate.testing.orm.junit.SkipForDialect; +import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -37,7 +36,6 @@ * * @author Davide Di Somma */ -@SkipForDialect(reason = "HSEARCH-1943", dialectClass = PostgreSQLDialect.class) @Tag(Tags.PORTED_TO_SEARCH_6) class SearchAndEnversIntegrationTest extends SearchTestBase { @@ -53,6 +51,10 @@ class SearchAndEnversIntegrationTest extends SearchTestBase { @TestForIssue(jiraKey = "HSEARCH-1293") @Test void testHibernateSearchAndEnversIntegration() { + assumeFalse( + org.hibernate.dialect.PostgreSQLDialect.class.getName().equals( DatabaseContainer.configuration().driver() ), + "HSEARCH-1943" + ); atRevision1(); atRevision2(); atRevision3(); 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 133f9430387..b8d1e8e1b0b 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 @@ -12,7 +12,9 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.function.Consumer; +import java.util.function.BiConsumer; + +import org.hibernate.cfg.JdbcSettings; import com.github.dockerjava.api.model.HostConfig; import com.github.dockerjava.api.model.Ulimit; @@ -33,10 +35,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 { @@ -51,14 +51,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(); } @@ -68,15 +60,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; } } } @@ -374,31 +357,45 @@ public Configuration(String dialect, String driver, String url, String user, Str this.isolation = isolation; } - public void add(Map map) { - map.put( "hibernate.dialect", this.dialect ); - map.put( "hibernate.connection.driver_class", this.driver ); - map.put( "hibernate.connection.url", this.url ); - map.put( "hibernate.connection.username", this.user ); - map.put( "hibernate.connection.password", this.pass ); - map.put( "hibernate.connection.isolation", this.isolation ); + public String dialect() { + return dialect; + } + + public String driver() { + return driver; + } + + public String url() { + return url; + } + + public String user() { + return user; } - 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 ); + public String pass() { + return pass; + } + + public String isolation() { + return isolation; + } + + @SuppressWarnings("deprecation") // since DialectContext is using the deprecated properties we cannot switch to JAKARTA_* for now... + public void add(Map map) { + map.put( JdbcSettings.DIALECT, this.dialect ); + map.put( JdbcSettings.DRIVER, this.driver ); + map.put( JdbcSettings.URL, this.url ); + map.put( JdbcSettings.USER, this.user ); + map.put( JdbcSettings.PASS, this.pass ); + map.put( JdbcSettings.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) { diff --git a/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/multitenancy/impl/MultitenancyTestHelper.java b/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/multitenancy/impl/MultitenancyTestHelper.java index b17d017a9e6..1627b20bab2 100644 --- a/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/multitenancy/impl/MultitenancyTestHelper.java +++ b/util/internal/integrationtest/mapper/orm/src/main/java/org/hibernate/search/util/impl/integrationtest/mapper/orm/multitenancy/impl/MultitenancyTestHelper.java @@ -9,11 +9,9 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.H2Dialect; +import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer; import org.hibernate.search.util.impl.integrationtest.mapper.orm.SimpleSessionFactoryBuilder; -import org.hibernate.testing.orm.junit.DialectContext; - /** * Utility to help setting up a test SessionFactory which uses multi-tenancy based * on multiple databases. @@ -36,7 +34,9 @@ private MultitenancyTestHelper(String[] tenantIds) { private void attachTo(SimpleSessionFactoryBuilder builder) { assumeTrue( - DialectContext.getDialect() instanceof H2Dialect, + // Until we adapt the dialect context ... (that is if we need to adapt it) + // DialectContext.getDialect() instanceof H2Dialect, + org.hibernate.dialect.H2Dialect.class.getName().equals( DatabaseContainer.configuration().driver() ), "This test relies on multi-tenancy, which can currently only be set up with H2" );