View Javadoc
1   /*
2    * Copyright 2023 Adrian Herscu
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  // NOTE duplicated from qa-jgiven-elasticsearch module
29  // -- maybe should do something else here?
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  }