Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-plugins / src / test / java / org / openecomp / 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.openecomp.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.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;
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 public class MockDMaaPMRSourceTest extends BaseAnalyticsCDAPPluginsUnitTest {
43
44     @Test
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);
51
52         MockDMaaPMRSource mockDMaaPMRSource = new MockDMaaPMRSource(getTestDMaaPMRSourcePluginConfig());
53         final JavaDStream<StructuredRecord> stream = mockDMaaPMRSource.getStream(streamingContext);
54         assertNotNull(stream);
55     }
56
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);
63     }
64
65     @Test
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);
71     }
72
73 }