2 * ===============================LICENSE_START======================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===========================================
21 package org.openecomp.dcae.apod.analytics.cdap.tca.flowlet;
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;
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;
40 * @author Rajiv Singla . Creation Date: 12/16/2016.
42 public class TCAVESAlertsSinkFlowletTest extends BaseAnalyticsCDAPTCAUnitTest {
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);
53 @SuppressWarnings("unchecked")
55 public void saveAlerts() throws Exception {
57 final String testAlertTableName = "testTCAVESAlertTableName";
59 final TCAVESAlertsSinkFlowlet tcavesAlertsSinkFlowlet = new TCAVESAlertsSinkFlowlet(testAlertTableName);
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);
69 doNothing().when(mockObjectMappedTable).write(any(String.class), any(TCAVESAlertEntity.class));
70 final String testAlertMessage = "testMessage";
71 tcavesAlertsSinkFlowlet.saveAlerts(testAlertMessage);
73 verify(mockObjectMappedTable,
74 times(1)).write(any(String.class), any(TCAVESAlertEntity.class));