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