Skip to content

Commit 5b7c00b

Browse files
committed
hsearch-elasticsearch-wikipedia: Add indexing/searching test
1 parent 5ae8ad0 commit 5b7c00b

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

hibernate-search/hsearch-elasticsearch-wikipedia/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@
8181
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
8282
<version>${hibernate.search.version}</version>
8383
</dependency>
84+
<dependency>
85+
<groupId>io.rest-assured</groupId>
86+
<artifactId>rest-assured</artifactId>
87+
<scope>test</scope>
88+
</dependency>
89+
<dependency>
90+
<groupId>org.skyscreamer</groupId>
91+
<artifactId>jsonassert</artifactId>
92+
<scope>test</scope>
93+
</dependency>
8494
</dependencies>
8595

8696
<build>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
spring.jpa:
2+
generate-ddl: true
3+
show-sql: true
4+
hibernate:
5+
ddl-auto: create-drop
6+
properties:
7+
hibernate.search:
8+
schema_management.strategy: drop-and-create-and-drop
9+
backend:
10+
automatic_indexing:
11+
synchronization.strategy: sync
12+
13+
logging.level:
14+
org.hibernate.SQL: DEBUG
15+
org.hibernate.search.massindexing: INFO
16+
org.hibernate.search.query: TRACE
17+
org.hibernate.search.elasticsearch.request: TRACE
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
11
package org.hibernate.search.demos.wikipedia;
22

3+
import static io.restassured.RestAssured.given;
4+
import static org.skyscreamer.jsonassert.JSONCompare.compareJSON;
5+
36
import org.junit.Test;
47
import org.junit.runner.RunWith;
8+
9+
import io.restassured.RestAssured;
10+
import io.restassured.http.ContentType;
11+
import org.json.JSONException;
12+
import org.skyscreamer.jsonassert.JSONCompareMode;
513
import org.springframework.boot.test.context.SpringBootTest;
14+
import org.springframework.test.context.ActiveProfiles;
615
import org.springframework.test.context.junit4.SpringRunner;
716

817
@RunWith(SpringRunner.class)
9-
@SpringBootTest
18+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
19+
@ActiveProfiles("test")
1020
public class HsearchElasticsearchWikipediaApplicationIT {
1121

22+
static {
23+
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
24+
}
25+
1226
@Test
13-
public void contextLoads() {
27+
public void indexAndSearch() throws JSONException {
28+
String body = given().param( "q", "brave" )
29+
.when().get( "/page/search" )
30+
.then()
31+
.statusCode( 200 )
32+
.extract().body().asString();
33+
compareJSON( "{\"totalCount\": 0}", body, JSONCompareMode.LENIENT );
34+
35+
given().body( "{\"title\": \"Brave new World\", \"content\": \"A classic.\"}" )
36+
.contentType( ContentType.JSON )
37+
.when().post( "/page" ).then()
38+
.statusCode( 201 );
39+
40+
body = given().param( "q", "brave" )
41+
.when().get( "/page/search" )
42+
.then()
43+
.statusCode( 200 )
44+
.extract().body().asString();
45+
compareJSON( "{\"totalCount\": 1}", body, JSONCompareMode.LENIENT );
1446
}
1547

1648
}

0 commit comments

Comments
 (0)