2 * ===============================LICENSE_START======================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============================LICENSE_END===========================================
21 package org.onap.dcae.apod.analytics.cdap.plugins.transform.filter;
23 import co.cask.cdap.api.data.format.StructuredRecord;
24 import co.cask.cdap.api.data.schema.Schema;
25 import co.cask.cdap.etl.api.Emitter;
26 import co.cask.cdap.etl.api.PipelineConfigurer;
27 import co.cask.cdap.etl.api.StageConfigurer;
28 import org.junit.Test;
29 import org.mockito.ArgumentMatchers;
30 import org.mockito.Mockito;
31 import org.onap.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
33 import java.util.Date;
35 import static org.mockito.ArgumentMatchers.any;
36 import static org.mockito.Mockito.doNothing;
37 import static org.mockito.Mockito.mock;
38 import static org.mockito.Mockito.times;
39 import static org.mockito.Mockito.verify;
40 import static org.mockito.Mockito.when;
43 * @author Rajiv Singla . Creation Date: 3/3/2017.
45 public class JsonPathFilterTest extends BaseAnalyticsCDAPPluginsUnitTest {
49 public void testInitializeWhenFilterMappingIsValid() throws Exception {
50 final JsonPathFilter jsonPathFilter = new JsonPathFilter(getJsonPathFilterPluginConfig());
51 jsonPathFilter.initialize(null);
56 public void configurePipeline() throws Exception {
57 final JsonPathFilter jsonPathFilter = new JsonPathFilter(getJsonPathFilterPluginConfig());
58 final PipelineConfigurer pipelineConfigurer = mock(PipelineConfigurer.class);
59 final StageConfigurer stageConfigurer = mock(StageConfigurer.class);
60 when(pipelineConfigurer.getStageConfigurer()).thenReturn(stageConfigurer);
61 when(stageConfigurer.getInputSchema()).thenReturn(getSimpleTCAPluginInputSchema());
62 doNothing().when(stageConfigurer).setOutputSchema(any(Schema.class));
63 jsonPathFilter.configurePipeline(pipelineConfigurer);
64 verify(stageConfigurer, times(1)).setOutputSchema(any(Schema.class));
68 public void testTransform() throws Exception {
69 final JsonPathFilter jsonPathFilter = new JsonPathFilter(getJsonPathFilterPluginConfig());
70 jsonPathFilter.initialize(null);
71 final StructuredRecord inputSR = StructuredRecord.builder(getJsonFilterPluginInputSchema())
72 .set("ts", new Date().getTime())
73 .set("responseCode", 200)
74 .set("responseMessage", "OK")
75 .set("message", fromStream(CEF_MESSAGE_JSON_FILE_LOCATION))
78 final Emitter emitter = Mockito.mock(Emitter.class);
79 doNothing().when(emitter).emit(ArgumentMatchers.any(StructuredRecord.class));
80 jsonPathFilter.transform(inputSR, emitter);
81 verify(emitter, times(1)).emit(any(StructuredRecord.class));