Skip to content

Commit b68ac93

Browse files
committed
hsearch-quarkus: Add test
1 parent 8a0b6a4 commit b68ac93

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

hibernate-search/hsearch-quarkus/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@
6666
<groupId>io.quarkus</groupId>
6767
<artifactId>quarkus-hibernate-search-orm-elasticsearch</artifactId>
6868
</dependency>
69+
<dependency>
70+
<groupId>io.rest-assured</groupId>
71+
<artifactId>rest-assured</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>net.javacrumbs.json-unit</groupId>
76+
<artifactId>json-unit</artifactId>
77+
<version>2.28.0</version>
78+
<scope>test</scope>
79+
</dependency>
6980
</dependencies>
7081
<build>
7182
<plugins>

hibernate-search/hsearch-quarkus/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ quarkus.hibernate-search-orm.elasticsearch.version=7
66

77
%dev.quarkus.hibernate-orm.sql-load-script=test-dataset.sql
88

9+
%test.quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=sync
10+
911
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://${POSTGRES_HOST}/${POSTGRES_DB}
1012
%prod.quarkus.datasource.username=${POSTGRES_USER}
1113
%prod.quarkus.datasource.password=${POSTGRES_PASSWORD}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.hibernate.demos.quarkus;
2+
3+
import static io.restassured.RestAssured.given;
4+
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import com.google.gson.JsonObject;
9+
import io.quarkus.test.junit.QuarkusTest;
10+
import io.restassured.RestAssured;
11+
import io.restassured.config.LogConfig;
12+
import io.restassured.config.ObjectMapperConfig;
13+
import io.restassured.config.RestAssuredConfig;
14+
import io.restassured.http.ContentType;
15+
import io.restassured.mapper.ObjectMapperType;
16+
import io.restassured.response.Response;
17+
import net.javacrumbs.jsonunit.core.Option;
18+
19+
@QuarkusTest
20+
public class ClientTest {
21+
22+
static {
23+
RestAssured.config = RestAssuredConfig.config()
24+
.objectMapperConfig( ObjectMapperConfig.objectMapperConfig()
25+
.defaultObjectMapperType( ObjectMapperType.GSON ) )
26+
.logConfig( LogConfig.logConfig()
27+
.enableLoggingOfRequestAndResponseIfValidationFails() );
28+
}
29+
30+
@Test
31+
public void indexAndSearch() {
32+
given()
33+
.when()
34+
.queryParam( "terms", "acme" )
35+
.get( "/client/search" )
36+
.then()
37+
.statusCode( 200 )
38+
.body( jsonEquals( "[]" )
39+
.when( Option.IGNORING_EXTRA_FIELDS, Option.IGNORING_ARRAY_ORDER ) );
40+
given()
41+
.contentType( ContentType.JSON )
42+
.body( "{"
43+
+ " \"name\":\"ACME Corporation\""
44+
+ "}" )
45+
.when().post( "/client/" )
46+
.then()
47+
.statusCode( 200 )
48+
.extract().response();
49+
given()
50+
.when()
51+
.queryParam( "terms", "acme" )
52+
.get( "/client/search" )
53+
.then()
54+
.statusCode( 200 )
55+
.body( jsonEquals( "[{\n" +
56+
" \"name\": \"ACME Corporation\"\n" +
57+
"}]" )
58+
.when( Option.IGNORING_EXTRA_FIELDS, Option.IGNORING_ARRAY_ORDER ) );
59+
}
60+
61+
}

0 commit comments

Comments
 (0)