Skip to content

Commit

Permalink
Add unit test for pattern replace char filter analyzer
Browse files Browse the repository at this point in the history
Signed-off-by: Grouh <[email protected]>
  • Loading branch information
grouh committed Mar 14, 2024
1 parent e1d0e92 commit efe0d51
Showing 1 changed file with 53 additions and 0 deletions.
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());
}
}

0 comments on commit efe0d51

Please sign in to comment.