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.streaming.dmaap;
23 import co.cask.cdap.api.data.format.StructuredRecord;
24 import co.cask.cdap.etl.api.streaming.StreamingContext;
25 import org.apache.spark.streaming.api.java.JavaDStream;
26 import org.apache.spark.streaming.api.java.JavaReceiverInputDStream;
27 import org.apache.spark.streaming.api.java.JavaStreamingContext;
28 import org.apache.spark.streaming.receiver.Receiver;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
32 import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
33 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.TestDMaaPMRSourcePluginConfig;
35 import static org.junit.Assert.assertNotNull;
36 import static org.mockito.ArgumentMatchers.any;
37 import static org.mockito.Mockito.when;
40 * @author Rajiv Singla . Creation Date: 2/20/2017.
42 public class MockDMaaPMRSourceTest extends BaseAnalyticsCDAPPluginsUnitTest {
45 public void testGetStream() throws Exception {
46 final StreamingContext streamingContext = Mockito.mock(StreamingContext.class);
47 final JavaStreamingContext javaStreamingContext = Mockito.mock(JavaStreamingContext.class);
48 final JavaReceiverInputDStream dMaaPMRReceiver = Mockito.mock(JavaReceiverInputDStream.class);
49 when(streamingContext.getSparkStreamingContext()).thenReturn(javaStreamingContext);
50 when(javaStreamingContext.receiverStream(any(Receiver.class))).thenReturn(dMaaPMRReceiver);
52 MockDMaaPMRSource mockDMaaPMRSource = new MockDMaaPMRSource(getTestDMaaPMRSourcePluginConfig());
53 final JavaDStream<StructuredRecord> stream = mockDMaaPMRSource.getStream(streamingContext);
54 assertNotNull(stream);
57 @Test(expected = CDAPSettingsException.class)
58 public void testConfigurePipelineWhenPollingIntervalNotPresent() throws Exception {
59 final TestDMaaPMRSourcePluginConfig testDMaaPMRSourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
60 testDMaaPMRSourcePluginConfig.setPollingInterval(null);
61 final MockDMaaPMRSource mockDMaaPMRSource = new MockDMaaPMRSource(testDMaaPMRSourcePluginConfig);
62 mockDMaaPMRSource.configurePipeline(null);
66 public void testConfigurePipelineWhenPollingIntervalIsPresent() throws Exception {
67 final TestDMaaPMRSourcePluginConfig testDMaaPMRSourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
68 final MockDMaaPMRSource mockDMaaPMRSource = new MockDMaaPMRSource(testDMaaPMRSourcePluginConfig);
69 mockDMaaPMRSource.configurePipeline(null);
70 assertNotNull(mockDMaaPMRSource);