forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pattern replace by making flag optional as on api (opensearch-pro…
…ject#895) * Fix pattern replace by making flag optional as on api Signed-off-by: Grouh <[email protected]> * Update changelog Signed-off-by: Grouh <[email protected]> * Add unit test for pattern replace char filter analyzer Signed-off-by: Grouh <[email protected]> * fix changelog Signed-off-by: Grouh <[email protected]> * fix char pattern replace by making replcement optional Signed-off-by: Grouh <[email protected]> * Add deserialze test with only pattern set Signed-off-by: Grouh <[email protected]> --------- Signed-off-by: Grouh <[email protected]>
- Loading branch information
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()); | ||
} | ||
} |