Initial TCA commit into DCAEGEN2
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / openecomp / dcae / apod / analytics / cdap / tca / flowlet / TCAVESAlertsSinkFlowletTest.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.flowlet;
22
23 import co.cask.cdap.api.dataset.lib.ObjectMappedTable;
24 import co.cask.cdap.api.flow.flowlet.FlowletContext;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
28 import org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca.TCAVESAlertEntity;
29 import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
30
31 import static org.junit.Assert.assertTrue;
32 import static org.mockito.ArgumentMatchers.any;
33 import static org.mockito.ArgumentMatchers.eq;
34 import static org.mockito.Mockito.doNothing;
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/16/2016.
41  */
42 public class TCAVESAlertsSinkFlowletTest extends BaseAnalyticsCDAPTCAUnitTest {
43
44
45     @Test
46     public void testConfigure() throws Exception {
47         final TCAVESAlertsSinkFlowlet tcavesAlertsSinkFlowlet =
48                 new TCAVESAlertsSinkFlowlet("testTCAVESAlertTableName");
49         assertFlowletNameAndDescription(CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_SINK_NAME_FLOWLET,
50                 CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_SINK_DESCRIPTION_FLOWLET, tcavesAlertsSinkFlowlet);
51     }
52
53     @SuppressWarnings("unchecked")
54     @Test
55     public void saveAlerts() throws Exception {
56
57         final String testAlertTableName = "testTCAVESAlertTableName";
58
59         final TCAVESAlertsSinkFlowlet tcavesAlertsSinkFlowlet = new TCAVESAlertsSinkFlowlet(testAlertTableName);
60
61         final FlowletContext mockFlowletContext = Mockito.mock(FlowletContext.class);
62         final ObjectMappedTable mockObjectMappedTable = Mockito.mock(ObjectMappedTable.class);
63         when(mockFlowletContext.getDataset(eq(testAlertTableName))).thenReturn(mockObjectMappedTable);
64         tcavesAlertsSinkFlowlet.initialize(mockFlowletContext);
65         final ObjectMappedTable tcaVESAlertsTableName =
66                 getPrivateFiledValue(tcavesAlertsSinkFlowlet, "tcaVESAlertsTable", ObjectMappedTable.class);
67         assertTrue(tcaVESAlertsTableName == mockObjectMappedTable);
68
69         doNothing().when(mockObjectMappedTable).write(any(String.class), any(TCAVESAlertEntity.class));
70         final String testAlertMessage = "testMessage";
71         tcavesAlertsSinkFlowlet.saveAlerts(testAlertMessage);
72
73         verify(mockObjectMappedTable,
74                 times(1)).write(any(String.class), any(TCAVESAlertEntity.class));
75
76     }
77
78 }