Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / openecomp / dcae / apod / analytics / cdap / tca / flowlet / TCAVESAlertsSinkFlowletTest.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\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
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\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
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.cdap.tca.flowlet;\r
22 \r
23 import co.cask.cdap.api.dataset.lib.ObjectMappedTable;\r
24 import co.cask.cdap.api.flow.flowlet.FlowletContext;\r
25 import org.junit.Test;\r
26 import org.mockito.Mockito;\r
27 import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;\r
28 import org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca.TCAVESAlertEntity;\r
29 import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;\r
30 \r
31 import static org.junit.Assert.assertTrue;\r
32 import static org.mockito.ArgumentMatchers.any;\r
33 import static org.mockito.ArgumentMatchers.eq;\r
34 import static org.mockito.Mockito.doNothing;\r
35 import static org.mockito.Mockito.times;\r
36 import static org.mockito.Mockito.verify;\r
37 import static org.mockito.Mockito.when;\r
38 \r
39 /**\r
40  * @author Rajiv Singla . Creation Date: 12/16/2016.\r
41  */\r
42 public class TCAVESAlertsSinkFlowletTest extends BaseAnalyticsCDAPTCAUnitTest {\r
43 \r
44 \r
45     @Test\r
46     public void testConfigure() throws Exception {\r
47         final TCAVESAlertsSinkFlowlet tcavesAlertsSinkFlowlet =\r
48                 new TCAVESAlertsSinkFlowlet("testTCAVESAlertTableName");\r
49         assertFlowletNameAndDescription(CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_SINK_NAME_FLOWLET,\r
50                 CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_SINK_DESCRIPTION_FLOWLET, tcavesAlertsSinkFlowlet);\r
51     }\r
52 \r
53     @SuppressWarnings("unchecked")\r
54     @Test\r
55     public void saveAlerts() throws Exception {\r
56 \r
57         final String testAlertTableName = "testTCAVESAlertTableName";\r
58 \r
59         final TCAVESAlertsSinkFlowlet tcavesAlertsSinkFlowlet = new TCAVESAlertsSinkFlowlet(testAlertTableName);\r
60 \r
61         final FlowletContext mockFlowletContext = Mockito.mock(FlowletContext.class);\r
62         final ObjectMappedTable mockObjectMappedTable = Mockito.mock(ObjectMappedTable.class);\r
63         when(mockFlowletContext.getDataset(eq(testAlertTableName))).thenReturn(mockObjectMappedTable);\r
64         tcavesAlertsSinkFlowlet.initialize(mockFlowletContext);\r
65         final ObjectMappedTable tcaVESAlertsTableName =\r
66                 getPrivateFiledValue(tcavesAlertsSinkFlowlet, "tcaVESAlertsTable", ObjectMappedTable.class);\r
67         assertTrue(tcaVESAlertsTableName == mockObjectMappedTable);\r
68 \r
69         doNothing().when(mockObjectMappedTable).write(any(String.class), any(TCAVESAlertEntity.class));\r
70         final String testAlertMessage = "testMessage";\r
71         tcavesAlertsSinkFlowlet.saveAlerts(testAlertMessage);\r
72 \r
73         verify(mockObjectMappedTable,\r
74                 times(1)).write(any(String.class), any(TCAVESAlertEntity.class));\r
75 \r
76     }\r
77 \r
78 }\r