Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / openecomp / dcae / apod / analytics / cdap / tca / worker / TCADMaaPSubscriberWorkerTest.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.tca.worker;
22
23 import co.cask.cdap.api.worker.WorkerConfigurer;
24 import co.cask.cdap.api.worker.WorkerContext;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
28 import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
29 import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
30
31 import static org.mockito.ArgumentMatchers.anyString;
32 import static org.mockito.ArgumentMatchers.eq;
33 import static org.mockito.Mockito.doNothing;
34 import static org.mockito.Mockito.mock;
35 import static org.mockito.Mockito.times;
36 import static org.mockito.Mockito.verify;
37 import static org.mockito.Mockito.when;
38
39 /**
40  * @author Rajiv Singla . Creation Date: 12/20/2016.
41  */
42 public class TCADMaaPSubscriberWorkerTest extends BaseAnalyticsCDAPTCAUnitTest {
43
44     private static final String TEST_SUBSCRIBER_OUTPUT_STREAM_NAME = "testSubscriberOutputStream";
45
46     private WorkerConfigurer workerConfigurer;
47     private WorkerContext workerContext;
48     private TCADMaaPSubscriberWorker subscriberWorker;
49
50     @Before
51     public void before() throws Exception {
52         workerConfigurer = mock(WorkerConfigurer.class);
53         workerContext = mock(WorkerContext.class);
54         doNothing().when(workerConfigurer).setName(anyString());
55         doNothing().when(workerConfigurer).setDescription(anyString());
56         subscriberWorker =
57                 new TCADMaaPSubscriberWorker(TEST_SUBSCRIBER_OUTPUT_STREAM_NAME);
58
59     }
60
61     @Test
62     public void testConfigure() throws Exception {
63         subscriberWorker.configure(workerConfigurer);
64         verify(workerConfigurer, times(1))
65                 .setName(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_SUBSCRIBER_WORKER));
66         verify(workerConfigurer, times(1))
67                 .setDescription(eq(CDAPComponentsConstants.TCA_FIXED_DMAAP_SUBSCRIBER_DESCRIPTION_WORKER));
68     }
69
70     @Test(expected = CDAPSettingsException.class)
71     public void testInitializeWhenSettingsHaveErrors() throws Exception {
72         subscriberWorker.initialize(workerContext);
73     }
74
75     @Test
76     public void testInitializeWhenSettingsAreValid() throws Exception {
77         when(workerContext.getRuntimeArguments()).thenReturn(getPreferenceMap());
78         subscriberWorker.initialize(workerContext);
79     }
80
81 }