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.openecomp.dcae.apod.analytics.cdap.plugins.batch.sink.dmaap;
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 co.cask.cdap.etl.api.batch.BatchSinkContext;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
33 import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
35 import static org.mockito.ArgumentMatchers.any;
36 import static org.mockito.ArgumentMatchers.eq;
37 import static org.mockito.Mockito.doNothing;
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: 1/30/2017.
45 public class DMaaPMRSinkTest extends BaseAnalyticsCDAPPluginsUnitTest {
47 private DMaaPMRSink dMaaPMRSink;
50 public void before() {
51 dMaaPMRSink = new DMaaPMRSink(getTestDMaaPMRSinkPluginConfig());
55 public void testConfigurePipeline() throws Exception {
56 final PipelineConfigurer pipelineConfigurer = Mockito.mock(PipelineConfigurer.class);
57 final StageConfigurer stageConfigurer = Mockito.mock(StageConfigurer.class);
58 when(pipelineConfigurer.getStageConfigurer()).thenReturn(stageConfigurer);
59 when(stageConfigurer.getInputSchema()).thenReturn(getDMaaPMRSinkTestSchema());
60 dMaaPMRSink.configurePipeline(pipelineConfigurer);
61 verify(stageConfigurer, times(1)).getInputSchema();
64 @Test(expected = CDAPSettingsException.class)
65 public void testConfigurePipelineWithInvalidSchema() throws Exception {
66 final PipelineConfigurer pipelineConfigurer = Mockito.mock(PipelineConfigurer.class);
67 final StageConfigurer stageConfigurer = Mockito.mock(StageConfigurer.class);
68 when(pipelineConfigurer.getStageConfigurer()).thenReturn(stageConfigurer);
69 when(stageConfigurer.getInputSchema()).thenReturn(Schema.recordOf(
70 "DMaaPMRSinkInvalidSchema",
71 Schema.Field.of("message1", Schema.of(Schema.Type.STRING)),
72 Schema.Field.of("field1", Schema.of(Schema.Type.STRING))
74 dMaaPMRSink.configurePipeline(pipelineConfigurer);
78 public void testPrepareRun() throws Exception {
79 final BatchSinkContext batchSinkContext = Mockito.mock(BatchSinkContext.class);
80 dMaaPMRSink.prepareRun(batchSinkContext);
84 public void testTransform() throws Exception {
85 final StructuredRecord structuredRecord = Mockito.mock(StructuredRecord.class);
86 final Emitter emitter = Mockito.mock(Emitter.class);
87 final String incomingTestMessage = "test message";
88 when(structuredRecord.get(
89 eq(getTestDMaaPMRSinkPluginConfig().getMessageColumnName()))).thenReturn(incomingTestMessage);
90 doNothing().when(emitter).emit(any());
91 dMaaPMRSink.transform(structuredRecord, emitter);