1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package dev.aherscu.qa.jgiven.elasticsearch.steps;
18
19 import java.util.function.*;
20
21 import com.tngtech.jgiven.annotation.*;
22
23 import co.elastic.clients.elasticsearch.*;
24 import dev.aherscu.qa.jgiven.commons.steps.*;
25 import dev.aherscu.qa.jgiven.elasticsearch.model.*;
26 import lombok.extern.slf4j.*;
27
28 @Slf4j
29 public class ElasticSearchFixtures<T, TDocument, SELF extends ElasticSearchFixtures<T, TDocument, SELF>>
30 extends GenericFixtures<ElasticSearchScenarioType<TDocument>, SELF> {
31
32 @ProvidedScenarioState
33 protected final ThreadLocal<String> index =
34 new ThreadLocal<>();
35 @ProvidedScenarioState
36 protected final ThreadLocal<Class<TDocument>> documentType =
37 new ThreadLocal<>();
38 @ProvidedScenarioState
39 protected final ThreadLocal<Function<TDocument, T>> convertBy =
40 ThreadLocal.withInitial(() -> tDocument -> (T) tDocument);
41
42
43
44 @ProvidedScenarioState
45 protected ElasticsearchClient elasticsearchClient;
46
47 @Hidden
48 public SELF convertingBy(final Function<TDocument, T> convertBy) {
49 log.debug("setting custom conversion function");
50 this.convertBy.set(convertBy);
51 return self();
52 }
53
54 public SELF elastic_search(
55 @Hidden final ElasticsearchClient elasticsearchClient) {
56 log.debug("setting client {}", elasticsearchClient);
57 this.elasticsearchClient = elasticsearchClient;
58 return self();
59 }
60
61 public SELF indexed_by(final String index) {
62 log.debug("setting index {}", index);
63 this.index.set(index);
64 return self();
65 }
66
67 public SELF storing(final Class<TDocument> documentType) {
68 log.debug("setting document type {}", documentType);
69 this.documentType.set(documentType);
70 return self();
71 }
72 }