-
Notifications
You must be signed in to change notification settings - Fork 54k
BAEL-9123: Added unit tests for elasticsearch wildcard service #18879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f0eb4bc
BAEL-9123: Added unit tests for elasticsearch wildcard service
diegotorrespy ad9aa8c
Merge branch 'eugenp:master' into master
diegotorrespy 7c08e8f
BAEL-9123: Fixed java files formatting
diegotorrespy 62f54e0
BAEL-9123: Fixed unit tests
diegotorrespy 4ee7c4f
Apply suggestion from @theangrydev
theangrydev cd55d9f
BAEL-9123: Fixed unit tests
diegotorrespy de9950e
Merge branch 'master' of github.com:diegotorrespy/tutorials
diegotorrespy be6a9fb
BAEL-9123: Improvements for unit tests
diegotorrespy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
199 changes: 199 additions & 0 deletions
199
persistence-modules/spring-data-elasticsearch-2/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <artifactId>spring-data-elasticsearch</artifactId> | ||
| <name>spring-data-elasticsearch</name> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <parent> | ||
| <groupId>com.baeldung</groupId> | ||
| <artifactId>parent-boot-3</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <relativePath>../../parent-boot-3</relativePath> | ||
| </parent> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.data</groupId> | ||
| <artifactId>spring-data-elasticsearch</artifactId> | ||
| <version>${spring-data-elasticsearch.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.elasticsearch.client</groupId> | ||
| <artifactId>elasticsearch-rest-high-level-client</artifactId> | ||
| <version>7.17.11</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <version>${lombok.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-autoconfigure</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.commons</groupId> | ||
| <artifactId>commons-csv</artifactId> | ||
| <version>${commons-csv.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-batch</artifactId> | ||
| <version>${spring-boot.version}</version> | ||
| </dependency> | ||
|
|
||
| <!-- https://mvnrepository.com/artifact/org.testcontainers/elasticsearch --> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>elasticsearch</artifactId> | ||
| <version>1.21.3</version> | ||
|
||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- MockWebServer for testing REST endpoints --> | ||
| <dependency> | ||
| <groupId>com.squareup.okhttp3</groupId> | ||
| <artifactId>mockwebserver</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- Elasticsearch Core --> | ||
| <dependency> | ||
| <groupId>org.elasticsearch</groupId> | ||
| <artifactId>elasticsearch</artifactId> | ||
| <version>${elasticsearch.version}</version> | ||
| </dependency> | ||
|
|
||
| <!-- Elasticsearch REST Client --> | ||
| <dependency> | ||
| <groupId>org.elasticsearch.client</groupId> | ||
| <artifactId>elasticsearch-rest-client</artifactId> | ||
| <version>${elasticsearch.version}</version> | ||
| </dependency> | ||
|
|
||
| <!-- Jackson for JSON processing --> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-core</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-databind</artifactId> | ||
| </dependency> | ||
|
|
||
| <!-- Logging --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-logging</artifactId> | ||
| </dependency> | ||
|
|
||
| <!-- Configuration Processor --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-configuration-processor</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
|
|
||
| <!-- ===== TEST DEPENDENCIES ===== --> | ||
|
|
||
| <!-- Spring Boot Test Starter --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- Spring Boot Testcontainers Support --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-testcontainers</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- Testcontainers JUnit 5 Integration --> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>junit-jupiter</artifactId> | ||
| <version>${testcontainers.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- Testcontainers Elasticsearch --> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>elasticsearch</artifactId> | ||
| <version>${testcontainers.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- Testcontainers Core --> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>testcontainers</artifactId> | ||
| <version>${testcontainers.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- MockWebServer for testing REST endpoints --> | ||
| <dependency> | ||
| <groupId>com.squareup.okhttp3</groupId> | ||
| <artifactId>mockwebserver</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <!-- AssertJ for better assertions (optional but recommended) --> | ||
| <dependency> | ||
| <groupId>org.assertj</groupId> | ||
| <artifactId>assertj-core</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
|
|
||
| </dependencies> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <!-- Testcontainers BOM to manage versions --> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>testcontainers-bom</artifactId> | ||
| <version>${testcontainers.version}</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <source>17</source> | ||
| <target>17</target> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| <properties> | ||
| <spring-data-elasticsearch.version>5.1.2</spring-data-elasticsearch.version> | ||
| <elasticsearch.version>8.9.0</elasticsearch.version> | ||
| <commons-csv.version>1.12.0</commons-csv.version> | ||
| <java.version>17</java.version> | ||
| <maven.compiler.source>17</maven.compiler.source> | ||
| <maven.compiler.target>17</maven.compiler.target> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <elasticsearch.version>8.11.1</elasticsearch.version> | ||
| <testcontainers.version>1.19.3</testcontainers.version> | ||
| </properties> | ||
|
|
||
| </project> | ||
14 changes: 14 additions & 0 deletions
14
persistence-modules/spring-data-elasticsearch-2/src/main/java/com/baeldung/Application.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.baeldung; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
|
|
||
| // Exclude DataSource auto-configuration since we're only using Elasticsearch | ||
| @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) | ||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(Application.class, args); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...g-data-elasticsearch-2/src/main/java/com/baeldung/wildcardsearch/ElasticsearchConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.baeldung.wildcardsearch; | ||
|
|
||
| import co.elastic.clients.elasticsearch.ElasticsearchClient; | ||
| import co.elastic.clients.json.jackson.JacksonJsonpMapper; | ||
| import co.elastic.clients.transport.rest_client.RestClientTransport; | ||
|
|
||
| import org.apache.http.HttpHost; | ||
| import org.elasticsearch.client.RestClient; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class ElasticsearchConfig { | ||
|
|
||
| @Value("${elasticsearch.host:localhost}") | ||
| private String host; | ||
|
|
||
| @Value("${elasticsearch.port:9200}") | ||
| private int port; | ||
|
|
||
| @Bean | ||
| public RestClient restClient() { | ||
| return RestClient.builder(new HttpHost(host, port, "http")) | ||
| .setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000) | ||
| .setSocketTimeout(60000)) | ||
| .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setMaxConnTotal(100) | ||
| .setMaxConnPerRoute(100)) | ||
| .build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public ElasticsearchClient elasticsearchClient(RestClient restClient) { | ||
| RestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper()); | ||
| return new ElasticsearchClient(transport); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.