-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for pattern replace char filter analyzer
Signed-off-by: Grouh <[email protected]>
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...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,53 @@ | ||
/* | ||
* 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") | ||
.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 testDeserializePatternReplaceCharFilter() { | ||
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()); | ||
} | ||
} |