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