2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.cdap.plugins.streaming.dmaap;
\r
23 import co.cask.cdap.api.data.format.StructuredRecord;
\r
24 import co.cask.cdap.api.data.schema.Schema;
\r
25 import co.cask.cdap.etl.api.PipelineConfigurer;
\r
26 import co.cask.cdap.etl.api.StageConfigurer;
\r
27 import co.cask.cdap.etl.api.streaming.StreamingContext;
\r
28 import org.apache.spark.streaming.api.java.JavaDStream;
\r
29 import org.apache.spark.streaming.api.java.JavaReceiverInputDStream;
\r
30 import org.apache.spark.streaming.api.java.JavaStreamingContext;
\r
31 import org.apache.spark.streaming.receiver.Receiver;
\r
32 import org.junit.Before;
\r
33 import org.junit.Test;
\r
34 import org.mockito.Mockito;
\r
35 import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
\r
36 import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
\r
37 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.TestDMaaPMRSourcePluginConfig;
\r
39 import static org.junit.Assert.assertNotNull;
\r
40 import static org.mockito.ArgumentMatchers.any;
\r
41 import static org.mockito.Mockito.doNothing;
\r
42 import static org.mockito.Mockito.when;
\r
45 * @author Rajiv Singla . Creation Date: 1/24/2017.
\r
47 public class DMaaPMRSourceTest extends BaseAnalyticsCDAPPluginsUnitTest {
\r
49 private PipelineConfigurer pipelineConfigurer;
\r
52 public void before() {
\r
53 pipelineConfigurer = Mockito.mock(PipelineConfigurer.class);
\r
54 final StageConfigurer stageConfigurer = Mockito.mock(StageConfigurer.class);
\r
55 when(pipelineConfigurer.getStageConfigurer()).thenReturn(stageConfigurer);
\r
56 doNothing().when(stageConfigurer).setOutputSchema(any(Schema.class));
\r
60 public void testDMaaPMRSourceConfigurePipelineWithValidPluginSettings() throws Exception {
\r
61 final TestDMaaPMRSourcePluginConfig testDMaaPMRSourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
\r
62 final DMaaPMRSource dMaaPMRSource = new DMaaPMRSource(testDMaaPMRSourcePluginConfig);
\r
63 dMaaPMRSource.configurePipeline(pipelineConfigurer);
\r
64 assertNotNull(dMaaPMRSource);
\r
67 @Test(expected = CDAPSettingsException.class)
\r
68 public void testDMaaPMRSourceConfigurePipelineWithInvalidPluginSettings() throws Exception {
\r
69 final TestDMaaPMRSourcePluginConfig testDMaaPMRSourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
\r
70 // blank out DMaaP MR Source Host
\r
71 testDMaaPMRSourcePluginConfig.setHostName(null);
\r
72 final DMaaPMRSource dMaaPMRSource = new DMaaPMRSource(testDMaaPMRSourcePluginConfig);
\r
73 dMaaPMRSource.configurePipeline(pipelineConfigurer);
\r
78 @SuppressWarnings("unchecked")
\r
79 public void testGetStream() throws Exception {
\r
80 final StreamingContext streamingContext = Mockito.mock(StreamingContext.class);
\r
81 final JavaStreamingContext javaStreamingContext = Mockito.mock(JavaStreamingContext.class);
\r
82 final JavaReceiverInputDStream dMaaPMRReceiver = Mockito.mock(JavaReceiverInputDStream.class);
\r
83 when(streamingContext.getSparkStreamingContext()).thenReturn(javaStreamingContext);
\r
84 when(javaStreamingContext.receiverStream(any(Receiver.class))).thenReturn(dMaaPMRReceiver);
\r
86 final TestDMaaPMRSourcePluginConfig testDMaaPMRSourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
\r
87 final DMaaPMRSource dMaaPMRSource = new DMaaPMRSource(testDMaaPMRSourcePluginConfig);
\r
88 final JavaDStream<StructuredRecord> stream = dMaaPMRSource.getStream(streamingContext);
\r
89 assertNotNull(stream);
\r