6a842d056579ac05fad24724d363ad4f12e4dbbb
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-plugins / src / test / java / org / onap / dcae / apod / analytics / cdap / plugins / streaming / dmaap / MockDMaaPMRSourceTest.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
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
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
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===========================================
19  */
20
21 package org.onap.dcae.apod.analytics.cdap.plugins.streaming.dmaap;
22
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.onap.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
32 import org.onap.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
33 import org.onap.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.TestDMaaPMRSourcePluginConfig;
34
35 import static org.junit.Assert.assertNotNull;
36 import static org.mockito.ArgumentMatchers.any;
37 import static org.mockito.Mockito.when;
38
39 /**
40  * @author Rajiv Singla . Creation Date: 2/20/2017.
41  */
42 @SuppressWarnings("unchecked")
43 public class MockDMaaPMRSourceTest extends BaseAnalyticsCDAPPluginsUnitTest {
44
45     @Test
46     public void testGetStream() throws Exception {
47         final StreamingContext streamingContext = Mockito.mock(StreamingContext.class);
48         final JavaStreamingContext javaStreamingContext = Mockito.mock(JavaStreamingContext.class);
49         final JavaReceiverInputDStream dMaaPMRReceiver = Mockito.mock(JavaReceiverInputDStream.class);
50         when(streamingContext.getSparkStreamingContext()).thenReturn(javaStreamingContext);
51         when(javaStreamingContext.receiverStream(any(Receiver.class))).thenReturn(dMaaPMRReceiver);
52
53         MockDMaaPMRSource mockDMaaPMRSource = new MockDMaaPMRSource(getTestDMaaPMRSourcePluginConfig());
54         final JavaDStream<StructuredRecord> stream = mockDMaaPMRSource.getStream(streamingContext);
55         assertNotNull(stream);
56     }
57
58     @Test(expected = CDAPSettingsException.class)
59     public void testConfigurePipelineWhenPollingIntervalNotPresent() throws Exception {
60         final TestDMaaPMRSourcePluginConfig testDMaaPMRSourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
61         testDMaaPMRSourcePluginConfig.setPollingInterval(null);
62         final MockDMaaPMRSource mockDMaaPMRSource = new MockDMaaPMRSource(testDMaaPMRSourcePluginConfig);
63         mockDMaaPMRSource.configurePipeline(null);
64     }
65
66     @Test
67     public void testConfigurePipelineWhenPollingIntervalIsPresent() throws Exception {
68         final TestDMaaPMRSourcePluginConfig testDMaaPMRSourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
69         final MockDMaaPMRSource mockDMaaPMRSource = new MockDMaaPMRSource(testDMaaPMRSourcePluginConfig);
70         mockDMaaPMRSource.configurePipeline(null);
71         assertNotNull(mockDMaaPMRSource);
72     }
73
74 }