-
Notifications
You must be signed in to change notification settings - Fork 53
Add test cases for dynamic_templates mappings #446
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
Closed
rursprung
wants to merge
1
commit into
opensearch-project:main
from
rursprung:add-dynamic_templates-test-case
Closed
Changes from all commits
Commits
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
116 changes: 116 additions & 0 deletions
116
...src/test/java/org/opensearch/data/client/core/index/DynamicTemplatesContextBaseTests.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,116 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.data.client.core.index; | ||
|
||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.DisabledIf; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.elasticsearch.annotations.Document; | ||
import org.springframework.data.elasticsearch.annotations.DynamicTemplates; | ||
import org.springframework.data.elasticsearch.annotations.Field; | ||
import org.springframework.data.elasticsearch.annotations.FieldType; | ||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations; | ||
import org.springframework.data.elasticsearch.core.IndexOperations; | ||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; | ||
import org.springframework.data.elasticsearch.core.query.Query; | ||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest; | ||
import org.springframework.data.elasticsearch.utils.IndexNameProvider; | ||
import org.springframework.lang.Nullable; | ||
|
||
@SpringIntegrationTest | ||
public abstract class DynamicTemplatesContextBaseTests { | ||
@Autowired protected ElasticsearchOperations operations; | ||
@Autowired protected IndexNameProvider indexNameProvider; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
indexNameProvider.increment(); | ||
} | ||
|
||
@AfterEach | ||
void cleanup() { | ||
operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + "*")).delete(); | ||
} | ||
|
||
@Test | ||
void shouldCreateDynamicTemplateOne() { | ||
IndexOperations indexOperations = operations.indexOps(SampleDynamicTemplatesEntity.class); | ||
assertThat(indexOperations.createWithMapping()).isTrue(); | ||
|
||
operations.save(new SampleDynamicTemplatesEntity(Map.of("John", "Smith"))); | ||
assertThat(operations.search(Query.findAll(), SampleDynamicTemplatesEntity.class).get().count()).isEqualTo(1L); | ||
} | ||
|
||
private boolean isOSCTest() { | ||
return this instanceof DynamicTemplatesOSCIntegrationTests; | ||
} | ||
|
||
@Test | ||
@DisabledIf(value = "isOSCTest", disabledReason = "https://github.com/opensearch-project/opensearch-java/issues/1513") | ||
void shouldCreateDynamicTemplateTwo() { | ||
IndexOperations indexOperations = operations.indexOps(SampleDynamicTemplatesEntityTwo.class); | ||
assertThat(indexOperations.createWithMapping()).isTrue(); | ||
|
||
operations.save(new SampleDynamicTemplatesEntityTwo(Map.of("A.B", "1"))); | ||
assertThat(operations.search(Query.findAll(), SampleDynamicTemplatesEntityTwo.class).get().count()).isEqualTo(1L); | ||
} | ||
|
||
/** | ||
* @author Petr Kukral | ||
*/ | ||
@Document(indexName = "#{@indexNameProvider.indexName()}") | ||
@DynamicTemplates(mappingPath = "/mappings/test-dynamic_templates_mappings.json") | ||
static class SampleDynamicTemplatesEntity { | ||
|
||
@Nullable | ||
@Id private String id; | ||
|
||
@Nullable | ||
@Field(type = FieldType.Object) private final Map<String, String> names; | ||
|
||
public SampleDynamicTemplatesEntity() { | ||
this(new HashMap<>()); | ||
} | ||
|
||
public SampleDynamicTemplatesEntity(final Map<String, String> names) { | ||
this.names = names; | ||
} | ||
} | ||
|
||
/** | ||
* @author Petr Kukral | ||
*/ | ||
@Document(indexName = "#{@indexNameProvider.indexName()}") | ||
@DynamicTemplates(mappingPath = "/mappings/test-dynamic_templates_mappings_two.json") | ||
static class SampleDynamicTemplatesEntityTwo { | ||
|
||
@Nullable | ||
@Id private String id; | ||
|
||
@Nullable | ||
@Field(type = FieldType.Object) private final Map<String, String> test; | ||
|
||
public SampleDynamicTemplatesEntityTwo() { | ||
this(new HashMap<>()); | ||
} | ||
|
||
public SampleDynamicTemplatesEntityTwo(final Map<String, String> test) { | ||
this.test = test; | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...est/java/org/opensearch/data/client/core/index/DynamicTemplatesORHLCIntegrationTests.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,29 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.data.client.core.index; | ||
|
||
import org.opensearch.data.client.junit.jupiter.OpenSearchRestTemplateConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.elasticsearch.utils.IndexNameProvider; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
@ContextConfiguration(classes = {DynamicTemplatesORHLCIntegrationTests.Config.class}) | ||
public class DynamicTemplatesORHLCIntegrationTests extends DynamicTemplatesContextBaseTests { | ||
@Configuration | ||
@Import({ OpenSearchRestTemplateConfiguration.class }) | ||
static class Config { | ||
@Bean | ||
IndexNameProvider indexNameProvider() { | ||
return new IndexNameProvider("dynamic-templates-os"); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
.../test/java/org/opensearch/data/client/core/index/DynamicTemplatesOSCIntegrationTests.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,29 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.data.client.core.index; | ||
|
||
import org.opensearch.data.client.junit.jupiter.OpenSearchTemplateConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.data.elasticsearch.utils.IndexNameProvider; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
@ContextConfiguration(classes = {DynamicTemplatesOSCIntegrationTests.Config.class}) | ||
public class DynamicTemplatesOSCIntegrationTests extends DynamicTemplatesContextBaseTests { | ||
@Configuration | ||
@Import({OpenSearchTemplateConfiguration.class}) | ||
static class Config { | ||
@Bean | ||
IndexNameProvider indexNameProvider() { | ||
return new IndexNameProvider("dynamic-templates-os"); | ||
} | ||
} | ||
} |
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
22 changes: 9 additions & 13 deletions
22
spring-data-opensearch/src/test/resources/mappings/test-dynamic_templates_mappings_two.json
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
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.
remove this to see the test failing