80 lines
2.9 KiB
Java
80 lines
2.9 KiB
Java
/*
|
|
* Copyright [2021] [your_name]
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
*/
|
|
|
|
|
|
package usi.vaa.elasticsearch.plugin.ingest.lookup;
|
|
|
|
import org.elasticsearch.ingest.IngestDocument;
|
|
import org.elasticsearch.ingest.RandomDocumentPicks;
|
|
import org.elasticsearch.test.ESTestCase;
|
|
import org.junit.BeforeClass;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import static usi.vaa.elasticsearch.plugin.ingest.lookup.LookupProcessor.FIELD_PROPERTY;
|
|
import static usi.vaa.elasticsearch.plugin.ingest.lookup.LookupProcessor.LOOKUP_MAP_PROPERTY;
|
|
|
|
public class LookupProcessorTests extends ESTestCase {
|
|
private static final String DOC_FIELD = "field_to_replace";
|
|
private static LookupProcessor processor;
|
|
|
|
@BeforeClass
|
|
public static void defaultSettings() {
|
|
processor = new LookupProcessor.Factory().create(
|
|
null,
|
|
"test-lookup",
|
|
"Test lookup processor pipeline",
|
|
new HashMap<>(Map.of(
|
|
FIELD_PROPERTY, DOC_FIELD,
|
|
LOOKUP_MAP_PROPERTY, Map.of(
|
|
"C001", "tyre",
|
|
"C010", "front wing",
|
|
"C100", "damper"
|
|
)
|
|
))
|
|
);
|
|
}
|
|
|
|
private IngestDocument getDocWithContent(final String content) {
|
|
final Map<String, Object> doc = Map.of(DOC_FIELD, content);
|
|
return RandomDocumentPicks.randomIngestDocument(random(), doc);
|
|
}
|
|
|
|
private void testWithContent(final String originalContent, final String expectedContent) {
|
|
final IngestDocument doc = getDocWithContent(originalContent);
|
|
processor.execute(doc);
|
|
assertEquals(expectedContent, doc.getSourceAndMetadata().get(DOC_FIELD));
|
|
}
|
|
|
|
public void testSimple() {
|
|
final String originalContent = "Need to optimize the C001 temperature.\n" +
|
|
"C010 needs to be changed as it is damaged.\tC100 seems ok.";
|
|
final String expectedContent = "Need to optimize the tyre temperature.\n" +
|
|
"front wing needs to be changed as it is damaged.\tdamper seems ok.";
|
|
|
|
testWithContent(originalContent, expectedContent);
|
|
}
|
|
|
|
public void testEmptyField() {
|
|
final String originalContent = "";
|
|
final String expectedContent = "";
|
|
|
|
testWithContent(originalContent, expectedContent);
|
|
}
|
|
}
|