-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix pattern replace by making flag optional as on api * Update changelog * Add unit test for pattern replace char filter analyzer * fix changelog * fix char pattern replace by making replcement optional * Add deserialze test with only pattern set --------- (cherry picked from commit e240b27) Signed-off-by: Grouh <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1b2ff84
commit 0be1935
Showing
3 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
71 changes: 71 additions & 0 deletions
71
...t/java/org/opensearch/client/opensearch/_types/analysis/PatternReplaceCharFilterTest.java
This file contains 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,71 @@ | ||
/* | ||
* 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.client.opensearch._types.analysis; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import jakarta.json.stream.JsonParser; | ||
import java.io.StringReader; | ||
import org.junit.Test; | ||
import org.opensearch.client.json.jackson.JacksonJsonpMapper; | ||
|
||
public class PatternReplaceCharFilterTest { | ||
@Test | ||
public void testCreatePatternReplaceCharFilter() { | ||
PatternReplaceCharFilter patternReplaceCharFilter = new PatternReplaceCharFilter.Builder().pattern("pattern").build(); | ||
assertEquals("pattern", patternReplaceCharFilter.pattern()); | ||
} | ||
|
||
@Test | ||
public void testCreatePatternReplaceCharFilterWithReplacement() { | ||
PatternReplaceCharFilter patternReplaceCharFilter = new PatternReplaceCharFilter.Builder().pattern("pattern") | ||
.replacement("replacement") | ||
.build(); | ||
assertEquals("pattern", patternReplaceCharFilter.pattern()); | ||
assertEquals("replacement", patternReplaceCharFilter.replacement()); | ||
} | ||
|
||
@Test | ||
public void testCreatePatternReplaceCharFilterWithFlags() { | ||
PatternReplaceCharFilter patternReplaceCharFilter = new PatternReplaceCharFilter.Builder().pattern("pattern") | ||
.replacement("replacement") | ||
.flags("flags") | ||
.build(); | ||
assertEquals("pattern", patternReplaceCharFilter.pattern()); | ||
assertEquals("replacement", patternReplaceCharFilter.replacement()); | ||
assertEquals("flags", patternReplaceCharFilter.flags()); | ||
} | ||
|
||
@Test | ||
public void testDeserializePatternReplaceCharFilterWithAllFields() { | ||
String jsonString = | ||
"{\"type\": \"pattern_replace\", \"pattern\": \"pattern\", \"replacement\": \"replacement\", \"flags\": \"flags\"}"; | ||
|
||
StringReader reader = new StringReader(jsonString); | ||
JacksonJsonpMapper mapper = new JacksonJsonpMapper(); | ||
JsonParser parser = mapper.jsonProvider().createParser(reader); | ||
|
||
PatternReplaceCharFilter patternReplaceCharFilter = PatternReplaceCharFilter._DESERIALIZER.deserialize(parser, mapper); | ||
assertEquals("pattern", patternReplaceCharFilter.pattern()); | ||
assertEquals("replacement", patternReplaceCharFilter.replacement()); | ||
assertEquals("flags", patternReplaceCharFilter.flags()); | ||
} | ||
|
||
@Test | ||
public void testDeserializePatternReplaceCharFilterWithPatternOnly() { | ||
String jsonString = "{\"type\": \"pattern_replace\", \"pattern\": \"pattern\"}"; | ||
|
||
StringReader reader = new StringReader(jsonString); | ||
JacksonJsonpMapper mapper = new JacksonJsonpMapper(); | ||
JsonParser parser = mapper.jsonProvider().createParser(reader); | ||
|
||
PatternReplaceCharFilter patternReplaceCharFilter = PatternReplaceCharFilter._DESERIALIZER.deserialize(parser, mapper); | ||
assertEquals("pattern", patternReplaceCharFilter.pattern()); | ||
} | ||
} |