Skip to content

Commit 134a674

Browse files
BAEL-9123: Added unit tests for elasticsearch wildcard service (#18879)
* BAEL-9123: Added unit tests for elasticsearch wildcard service Signed-off-by: Diego Torres <[email protected]> * BAEL-9123: Fixed java files formatting Signed-off-by: Diego Torres <[email protected]> * BAEL-9123: Fixed unit tests Signed-off-by: Diego Torres <[email protected]> * Apply suggestion from @theangrydev * BAEL-9123: Fixed unit tests Signed-off-by: Diego Torres <[email protected]> * BAEL-9123: Improvements for unit tests Signed-off-by: Diego Torres <[email protected]> --------- Signed-off-by: Diego Torres <[email protected]> Co-authored-by: Liam Williams <[email protected]>
1 parent 487a5e8 commit 134a674

File tree

7 files changed

+1229
-0
lines changed

7 files changed

+1229
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>spring-data-elasticsearch</artifactId>
6+
<name>spring-data-elasticsearch</name>
7+
<packaging>jar</packaging>
8+
9+
<parent>
10+
<groupId>com.baeldung</groupId>
11+
<artifactId>parent-boot-3</artifactId>
12+
<version>0.0.1-SNAPSHOT</version>
13+
<relativePath>../../parent-boot-3</relativePath>
14+
</parent>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.springframework.data</groupId>
19+
<artifactId>spring-data-elasticsearch</artifactId>
20+
<version>${spring-data-elasticsearch.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.elasticsearch.client</groupId>
24+
<artifactId>elasticsearch-rest-high-level-client</artifactId>
25+
<version>7.17.11</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.projectlombok</groupId>
29+
<artifactId>lombok</artifactId>
30+
<version>${lombok.version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-autoconfigure</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.apache.commons</groupId>
38+
<artifactId>commons-csv</artifactId>
39+
<version>${commons-csv.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-batch</artifactId>
44+
<version>${spring-boot.version}</version>
45+
</dependency>
46+
47+
<!-- Elasticsearch Core -->
48+
<dependency>
49+
<groupId>org.elasticsearch</groupId>
50+
<artifactId>elasticsearch</artifactId>
51+
<version>${elasticsearch.version}</version>
52+
</dependency>
53+
54+
<!-- Elasticsearch REST Client -->
55+
<dependency>
56+
<groupId>org.elasticsearch.client</groupId>
57+
<artifactId>elasticsearch-rest-client</artifactId>
58+
<version>${elasticsearch.version}</version>
59+
</dependency>
60+
61+
<!-- Jackson for JSON processing -->
62+
<dependency>
63+
<groupId>com.fasterxml.jackson.core</groupId>
64+
<artifactId>jackson-core</artifactId>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>com.fasterxml.jackson.core</groupId>
69+
<artifactId>jackson-databind</artifactId>
70+
</dependency>
71+
72+
<!-- Logging -->
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-starter-logging</artifactId>
76+
</dependency>
77+
78+
<!-- Configuration Processor -->
79+
<dependency>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-configuration-processor</artifactId>
82+
<optional>true</optional>
83+
</dependency>
84+
85+
<!-- ===== TEST DEPENDENCIES ===== -->
86+
87+
<!-- Spring Boot Test Starter -->
88+
<dependency>
89+
<groupId>org.springframework.boot</groupId>
90+
<artifactId>spring-boot-starter-test</artifactId>
91+
<scope>test</scope>
92+
</dependency>
93+
94+
<!-- Spring Boot Testcontainers Support -->
95+
<dependency>
96+
<groupId>org.springframework.boot</groupId>
97+
<artifactId>spring-boot-testcontainers</artifactId>
98+
<scope>test</scope>
99+
</dependency>
100+
101+
<!-- Testcontainers JUnit 5 Integration -->
102+
<dependency>
103+
<groupId>org.testcontainers</groupId>
104+
<artifactId>junit-jupiter</artifactId>
105+
<version>${testcontainers.version}</version>
106+
<scope>test</scope>
107+
</dependency>
108+
109+
<!-- Testcontainers Elasticsearch -->
110+
<dependency>
111+
<groupId>org.testcontainers</groupId>
112+
<artifactId>elasticsearch</artifactId>
113+
<version>${testcontainers.version}</version>
114+
<scope>test</scope>
115+
</dependency>
116+
117+
<!-- Testcontainers Core -->
118+
<dependency>
119+
<groupId>org.testcontainers</groupId>
120+
<artifactId>testcontainers</artifactId>
121+
<version>${testcontainers.version}</version>
122+
<scope>test</scope>
123+
</dependency>
124+
125+
<!-- MockWebServer for testing REST endpoints -->
126+
<dependency>
127+
<groupId>com.squareup.okhttp3</groupId>
128+
<artifactId>mockwebserver</artifactId>
129+
<scope>test</scope>
130+
</dependency>
131+
132+
<!-- AssertJ for better assertions (optional but recommended) -->
133+
<dependency>
134+
<groupId>org.assertj</groupId>
135+
<artifactId>assertj-core</artifactId>
136+
<scope>test</scope>
137+
</dependency>
138+
139+
<dependency>
140+
<groupId>org.awaitility</groupId>
141+
<artifactId>awaitility</artifactId>
142+
<version>4.3.0</version>
143+
<scope>test</scope>
144+
</dependency>
145+
</dependencies>
146+
147+
<dependencyManagement>
148+
<dependencies>
149+
<!-- Testcontainers BOM to manage versions -->
150+
<dependency>
151+
<groupId>org.testcontainers</groupId>
152+
<artifactId>testcontainers-bom</artifactId>
153+
<version>${testcontainers.version}</version>
154+
<type>pom</type>
155+
<scope>import</scope>
156+
</dependency>
157+
</dependencies>
158+
</dependencyManagement>
159+
160+
<build>
161+
<plugins>
162+
<plugin>
163+
<groupId>org.springframework.boot</groupId>
164+
<artifactId>spring-boot-maven-plugin</artifactId>
165+
</plugin>
166+
<plugin>
167+
<groupId>org.apache.maven.plugins</groupId>
168+
<artifactId>maven-compiler-plugin</artifactId>
169+
<configuration>
170+
<source>17</source>
171+
<target>17</target>
172+
</configuration>
173+
</plugin>
174+
</plugins>
175+
</build>
176+
177+
<properties>
178+
<spring-data-elasticsearch.version>5.1.2</spring-data-elasticsearch.version>
179+
<elasticsearch.version>8.9.0</elasticsearch.version>
180+
<commons-csv.version>1.12.0</commons-csv.version>
181+
<java.version>17</java.version>
182+
<maven.compiler.source>17</maven.compiler.source>
183+
<maven.compiler.target>17</maven.compiler.target>
184+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
185+
<elasticsearch.version>8.11.1</elasticsearch.version>
186+
<testcontainers.version>1.19.3</testcontainers.version>
187+
</properties>
188+
189+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
6+
7+
// Exclude DataSource auto-configuration since we're only using Elasticsearch
8+
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
9+
public class Application {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(Application.class, args);
13+
}
14+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.wildcardsearch;
2+
3+
import co.elastic.clients.elasticsearch.ElasticsearchClient;
4+
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
5+
import co.elastic.clients.transport.rest_client.RestClientTransport;
6+
7+
import org.apache.http.HttpHost;
8+
import org.elasticsearch.client.RestClient;
9+
import org.springframework.beans.factory.annotation.Value;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.context.annotation.Configuration;
12+
13+
@Configuration
14+
public class ElasticsearchConfig {
15+
16+
@Value("${elasticsearch.host:localhost}")
17+
private String host;
18+
19+
@Value("${elasticsearch.port:9200}")
20+
private int port;
21+
22+
@Bean
23+
public RestClient restClient() {
24+
return RestClient.builder(new HttpHost(host, port, "http"))
25+
.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000)
26+
.setSocketTimeout(60000))
27+
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setMaxConnTotal(100)
28+
.setMaxConnPerRoute(100))
29+
.build();
30+
}
31+
32+
@Bean
33+
public ElasticsearchClient elasticsearchClient(RestClient restClient) {
34+
RestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
35+
return new ElasticsearchClient(transport);
36+
}
37+
}

0 commit comments

Comments
 (0)