Skip to content

Commit

Permalink
HSEARCH-4674 Make showcase and v5 tests aware of testcontainers
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Nov 8, 2023
1 parent 9901222 commit c5d89ac
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 6 deletions.
12 changes: 6 additions & 6 deletions integrationtest/showcase/library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<artifactId>hibernate-search-backend-elasticsearch-aws</artifactId>
<scope>test</scope>
</dependency>
<!-- Only needed to start ES container in tests -->
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-util-internal-integrationtest-backend-elasticsearch</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -114,12 +120,6 @@
Here we chose to use environment variables.
-->
<environmentVariables>
<HIBERNATE_DIALECT>${db.dialect}</HIBERNATE_DIALECT>
<JDBC_DRIVER>${jdbc.driver}</JDBC_DRIVER>
<JDBC_URL>${jdbc.url}</JDBC_URL>
<JDBC_USERNAME>${jdbc.user}</JDBC_USERNAME>
<JDBC_PASSWORD>${jdbc.pass}</JDBC_PASSWORD>
<JDBC_ISOLATION>${jdbc.isolation}</JDBC_ISOLATION>
<ELASTICSEARCH_URIS>${test.elasticsearch.connection.uris}</ELASTICSEARCH_URIS>
<ELASTICSEARCH_USERNAME>${test.elasticsearch.connection.username}</ELASTICSEARCH_USERNAME>
<ELASTICSEARCH_PASSWORD>${test.elasticsearch.connection.password}</ELASTICSEARCH_PASSWORD>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
*/
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 {

@Override
public String[] resolve(Class<?> testClass) {
String testBackend = System.getProperty( "test.backend" );
Expand All @@ -22,6 +26,10 @@ public String[] resolve(Class<?> testClass) {
*/
testBackend = "lucene";
}
if ( "elasticsearch".equals( testBackend ) ) {
System.setProperty( "ES_HOSTS", SearchContainer.host() + ":" + SearchContainer.mappedPort( 9200 ) );
}
DatabaseContainer.springConfiguration();
// The test profiles must be mentioned last, to allow them to override properties
return new String[] { testBackend, "test", "test-" + testBackend };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ spring.jpa:
hibernate.search:
backend:
log.json_pretty_printing: true
hosts: ${ES_HOSTS}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.cfg.Configuration;
import org.hibernate.search.util.common.SearchException;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer;

import org.junit.jupiter.api.Test;

Expand All @@ -23,6 +27,13 @@ class UnresolvedBridgeTest {
void testSerializableType() {
Configuration cfg = new Configuration();

// DB properties:
Map<String, Object> db = new HashMap<>();
DatabaseContainer.configuration().add( db );
for ( Map.Entry<String, Object> entry : db.entrySet() ) {
cfg.setProperty( entry.getKey(), entry.getValue().toString() );
}

for ( int i = 0; i < getAnnotatedClasses().length; i++ ) {
cfg.addAnnotatedClass( getAnnotatedClasses()[i] );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.hibernate.search.util.impl.integrationtest.common.extension.BackendSetupStrategy;
import org.hibernate.search.util.impl.integrationtest.common.extension.MappingSetupHelper;
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.integrationtest.mapper.orm.OrmAssertionHelper;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper;
Expand Down Expand Up @@ -104,6 +105,8 @@ public final class SetupContext
// Ensure we don't build Jandex indexes needlessly:
// discovery based on Jandex ought to be tested in real projects that don't use this setup helper.
withProperty( HibernateOrmMapperSettings.MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES, false );
// DB properties:
DatabaseContainer.configuration().add( overriddenProperties );
// Ensure overridden properties will be applied
withConfiguration( builder -> overriddenProperties.forEach( builder::setProperty ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.hibernate.search.util.impl.integrationtest.common.extension.BackendSetupStrategy;
import org.hibernate.search.util.impl.integrationtest.common.extension.MappingSetupHelper;
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.integrationtest.mapper.orm.OrmAssertionHelper;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper;
Expand Down Expand Up @@ -105,6 +106,10 @@ public final class SetupContext
// Ensure we don't build Jandex indexes needlessly:
// discovery based on Jandex ought to be tested in real projects that don't use this setup helper.
withProperty( HibernateOrmMapperSettings.MAPPING_BUILD_MISSING_DISCOVERED_JANDEX_INDEXES, false );

// DB properties:
DatabaseContainer.configuration().add( overriddenProperties );

// Ensure overridden properties will be applied
withConfiguration( builder -> overriddenProperties.forEach( builder::setProperty ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.function.Consumer;

Expand Down Expand Up @@ -384,6 +385,15 @@ public Configuration(String dialect, String driver, String url, String user, Str
this.isolation = isolation;
}

public void add(Map<String, Object> 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 );
}

private void addAsSystemProperties() {
System.setProperty( "hibernate.dialect", this.dialect );
System.setProperty( "hibernate.connection.driver_class", this.driver );
Expand Down

0 comments on commit c5d89ac

Please sign in to comment.