1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package dev.aherscu.qa.testing.example.scenarios.tutorial8;
18
19 import static dev.aherscu.qa.testing.utils.StreamMatchersExtensions.*;
20 import static org.hamcrest.Matchers.*;
21
22 import org.testng.annotations.*;
23
24 import dev.aherscu.qa.jgiven.elasticsearch.*;
25 import lombok.*;
26 import lombok.extern.jackson.*;
27
28
29
30 public class ElasticSearchTest
31 extends AbstractElasticSearchTest<ElasticSearchTest.AnObject, ElasticSearchTest.AnObject> {
32
33 protected ElasticSearchTest() {
34 super(TestConfiguration.class);
35 }
36
37 @Test
38 public void shouldIndexDocument() {
39 given().indexed_by("some-objects")
40 .and().storing(AnObject.class)
41 .and().elastic_search(configuration()
42 .elasticSearchClient());
43
44 when()
45 .adding_single_document(AnObject.DUMMY, AnObject::getId);
46
47 then()
48 .the_document("dummy", is(AnObject.DUMMY));
49 }
50
51 @Test
52 void shouldFindDocument() {
53 given().indexed_by("some-objects").and().storing(AnObject.class).and().elastic_search(configuration()
54 .elasticSearchClient());
55
56 when()
57 .adding_single_document(AnObject.DUMMY, AnObject::getId);
58
59 then()
60 .the_index(q -> q.match(m -> m
61 .field("value")
62 .query("kuku")),
63 hasSpecificItemsInAnyOrder(AnObject.DUMMY));
64 }
65
66 @Builder
67 @Jacksonized
68 @Getter
69 @EqualsAndHashCode
70 @ToString
71 public static class AnObject {
72 public static final AnObject DUMMY = AnObject.builder()
73 .id("dummy")
74 .value("kuku")
75 .build();
76
77 public final String id;
78 public final String value;
79 }
80 }