TCA: Replace any openecomp reference by onap
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / test / java / org / onap / dcae / apod / analytics / cdap / tca / flowlet / TCAVESThresholdViolationCalculatorFlowletTest.java
-/*\r
- * ===============================LICENSE_START======================================\r
- *  dcae-analytics\r
- * ================================================================================\r
- *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * ================================================================================\r
- *  Licensed under the Apache License, Version 2.0 (the "License");\r
- *  you may not use this file except in compliance with the License.\r
- *   You may obtain a copy of the License at\r
- *\r
- *          http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- *  ============================LICENSE_END===========================================\r
- */\r
-\r
-package org.openecomp.dcae.apod.analytics.cdap.tca.flowlet;\r
-\r
-import co.cask.cdap.api.app.ApplicationSpecification;\r
-import co.cask.cdap.api.dataset.lib.ObjectMappedTable;\r
-import co.cask.cdap.api.flow.flowlet.FlowletContext;\r
-import co.cask.cdap.api.flow.flowlet.OutputEmitter;\r
-import co.cask.cdap.api.metrics.Metrics;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.mockito.Mockito;\r
-import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;\r
-import org.openecomp.dcae.apod.analytics.cdap.common.domain.tca.ThresholdCalculatorOutput;\r
-import org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca.TCAMessageStatusEntity;\r
-import org.openecomp.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;\r
-import org.openecomp.dcae.apod.analytics.cdap.tca.utils.CDAPTCAUtils;\r
-import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;\r
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;\r
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;\r
-\r
-import static org.mockito.ArgumentMatchers.any;\r
-import static org.mockito.ArgumentMatchers.anyInt;\r
-import static org.mockito.ArgumentMatchers.anyString;\r
-import static org.mockito.Mockito.doNothing;\r
-import static org.mockito.Mockito.times;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-\r
-/**\r
- * @author Rajiv Singla . Creation Date: 12/19/2016.\r
- */\r
-@SuppressWarnings("unchecked")\r
-public class TCAVESThresholdViolationCalculatorFlowletTest extends BaseAnalyticsCDAPTCAUnitTest {\r
-\r
-    private static final String messageStatusTableName = "TEST_MESSAGE_STATUS_TABLE";\r
-\r
-    private TCAVESThresholdViolationCalculatorFlowlet violationCalculatorFlowlet;\r
-    private Metrics metrics;\r
-    private OutputEmitter outputEmitter;\r
-    private ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable;\r
-\r
-    private static class TCATestVESThresholdViolationCalculatorFlowlet extends\r
-            TCAVESThresholdViolationCalculatorFlowlet {\r
-        public TCATestVESThresholdViolationCalculatorFlowlet(\r
-                final String messageStatusTableName,\r
-                final OutputEmitter tcaAlertOutputEmitter,\r
-                ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable,\r
-                Metrics metrics) {\r
-            super(messageStatusTableName);\r
-            this.tcaAlertOutputEmitter = tcaAlertOutputEmitter;\r
-            this.metrics = metrics;\r
-        }\r
-    }\r
-\r
-    @Before\r
-    public void before() {\r
-        violationCalculatorFlowlet = new TCAVESThresholdViolationCalculatorFlowlet(messageStatusTableName);\r
-        vesMessageStatusTable = Mockito.mock(ObjectMappedTable.class);\r
-        outputEmitter = Mockito.mock(OutputEmitter.class);\r
-        metrics = Mockito.mock(Metrics.class);\r
-    }\r
-\r
-    @Test\r
-    public void testConfigure() throws Exception {\r
-        assertFlowletNameAndDescription(\r
-                CDAPComponentsConstants.TCA_FIXED_VES_THRESHOLD_VIOLATION_CALCULATOR_NAME_FLOWLET,\r
-                CDAPComponentsConstants.TCA_FIXED_VES_THRESHOLD_VIOLATION_CALCULATOR_DESCRIPTION_FLOWLET,\r
-                violationCalculatorFlowlet);\r
-    }\r
-\r
-    @Test\r
-    public void testInitialize() throws Exception {\r
-        final FlowletContext mockFlowletContext = initializeFlowlet(violationCalculatorFlowlet, vesMessageStatusTable);\r
-        verify(mockFlowletContext, times(1)).getDataset(anyString());\r
-    }\r
-\r
-    @Test\r
-    public void testFilterVESMessagesWhenVESMessageIsInApplicable() throws Exception {\r
-        final TCATestVESThresholdViolationCalculatorFlowlet thresholdViolationCalculatorFlowlet =\r
-                createTestViolationCalculator(vesMessageStatusTable, outputEmitter, metrics);\r
-        initializeFlowlet(thresholdViolationCalculatorFlowlet, vesMessageStatusTable);\r
-        thresholdViolationCalculatorFlowlet.filterVESMessages("inapplicable");\r
-        verify(vesMessageStatusTable, times(1)).write(anyString(),\r
-                any(TCAMessageStatusEntity.class));\r
-    }\r
-\r
-    @Test\r
-    public void testFilterVESMessagesWhenVESMessageIsCompliant() throws Exception {\r
-        final TCATestVESThresholdViolationCalculatorFlowlet thresholdViolationCalculatorFlowlet =\r
-                createTestViolationCalculator(vesMessageStatusTable, outputEmitter, metrics);\r
-        initializeFlowlet(thresholdViolationCalculatorFlowlet, vesMessageStatusTable);\r
-        thresholdViolationCalculatorFlowlet.filterVESMessages(getValidCEFMessage());\r
-        verify(vesMessageStatusTable, times(1)).write(anyString(),\r
-                any(TCAMessageStatusEntity.class));\r
-    }\r
-\r
-    @Test\r
-    public void testFilterVESMessagesWhenVESMessageNonCompliant() throws Exception {\r
-        final TCATestVESThresholdViolationCalculatorFlowlet thresholdViolationCalculatorFlowlet =\r
-                createTestViolationCalculator(vesMessageStatusTable, outputEmitter, metrics);\r
-        final FlowletContext flowletContext =\r
-                initializeFlowlet(thresholdViolationCalculatorFlowlet, vesMessageStatusTable);\r
-        final TCAPolicy policy = CDAPTCAUtils.getValidatedTCAPolicyPreferences(flowletContext);\r
-        final Threshold threshold = policy.getMetricsPerEventName().get(0).getThresholds().get(0);\r
-        final Long thresholdValue = threshold.getThresholdValue();\r
-        final EventListener thresholdViolatingMessage = getCEFEventListener();\r
-        thresholdViolatingMessage.getEvent().getMeasurementsForVfScalingFields().getVNicPerformanceArray().\r
-                get(0).setReceivedBroadcastPacketsAccumulated(thresholdValue - 1);\r
-        thresholdViolationCalculatorFlowlet.filterVESMessages(\r
-                ANALYTICS_MODEL_OBJECT_MAPPER.writeValueAsString(thresholdViolatingMessage));\r
-        verify(vesMessageStatusTable, times(1)).write(anyString(),\r
-                any(TCAMessageStatusEntity.class));\r
-        verify(outputEmitter, times(1)).emit(any(ThresholdCalculatorOutput.class));\r
-    }\r
-\r
-    private static TCATestVESThresholdViolationCalculatorFlowlet createTestViolationCalculator(\r
-            final ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable,\r
-            final OutputEmitter outputEmitter, final Metrics metrics) {\r
-        doNothing().when(outputEmitter).emit(anyString());\r
-        doNothing().when(metrics).count(anyString(), anyInt());\r
-        doNothing().when(vesMessageStatusTable).write(anyString(), any(TCAMessageStatusEntity.class));\r
-        return new TCATestVESThresholdViolationCalculatorFlowlet(messageStatusTableName, outputEmitter,\r
-                vesMessageStatusTable, metrics);\r
-    }\r
-\r
-    private static <T extends TCAVESThresholdViolationCalculatorFlowlet> FlowletContext initializeFlowlet(\r
-            T calculatorFlowlet, ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable) throws Exception {\r
-        final FlowletContext mockFlowletContext = getTestFlowletContextWithValidPolicy();\r
-        when(mockFlowletContext.getDataset(anyString())).thenReturn(vesMessageStatusTable);\r
-        when(mockFlowletContext.getInstanceId()).thenReturn(1);\r
-        ApplicationSpecification mockApplicationSpecification = Mockito.mock(ApplicationSpecification.class);\r
-        when(mockApplicationSpecification.getConfiguration()).thenReturn(fromStream(TCA_APP_CONFIG_FILE_LOCATION));\r
-        when(mockFlowletContext.getApplicationSpecification()).thenReturn(mockApplicationSpecification);\r
-        when(mockApplicationSpecification.getName()).thenReturn("TestTCAAppName");\r
-        try {\r
-            calculatorFlowlet.initialize(mockFlowletContext);\r
-            return mockFlowletContext;\r
-        } catch (Exception e) {\r
-            LOG.error("error while flowlet initialization");\r
-            throw new RuntimeException(e);\r
-        }\r
-    }\r
-\r
-}\r
+/*
+ * ===============================LICENSE_START======================================
+ *  dcae-analytics
+ * ================================================================================
+ *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *          http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  ============================LICENSE_END===========================================
+ */
+
+package org.onap.dcae.apod.analytics.cdap.tca.flowlet;
+
+import co.cask.cdap.api.app.ApplicationSpecification;
+import co.cask.cdap.api.dataset.lib.ObjectMappedTable;
+import co.cask.cdap.api.flow.flowlet.FlowletContext;
+import co.cask.cdap.api.flow.flowlet.OutputEmitter;
+import co.cask.cdap.api.metrics.Metrics;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
+import org.onap.dcae.apod.analytics.cdap.common.domain.tca.ThresholdCalculatorOutput;
+import org.onap.dcae.apod.analytics.cdap.common.persistance.tca.TCAMessageStatusEntity;
+import org.onap.dcae.apod.analytics.cdap.tca.BaseAnalyticsCDAPTCAUnitTest;
+import org.onap.dcae.apod.analytics.cdap.tca.utils.CDAPTCAUtils;
+import org.onap.dcae.apod.analytics.model.domain.cef.EventListener;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.Threshold;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Rajiv Singla . Creation Date: 12/19/2016.
+ */
+@SuppressWarnings("unchecked")
+public class TCAVESThresholdViolationCalculatorFlowletTest extends BaseAnalyticsCDAPTCAUnitTest {
+
+    private static final String messageStatusTableName = "TEST_MESSAGE_STATUS_TABLE";
+
+    private TCAVESThresholdViolationCalculatorFlowlet violationCalculatorFlowlet;
+    private Metrics metrics;
+    private OutputEmitter outputEmitter;
+    private ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable;
+
+    private static class TCATestVESThresholdViolationCalculatorFlowlet extends
+            TCAVESThresholdViolationCalculatorFlowlet {
+        public TCATestVESThresholdViolationCalculatorFlowlet(
+                final String messageStatusTableName,
+                final OutputEmitter tcaAlertOutputEmitter,
+                ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable,
+                Metrics metrics) {
+            super(messageStatusTableName);
+            this.tcaAlertOutputEmitter = tcaAlertOutputEmitter;
+            this.metrics = metrics;
+        }
+    }
+
+    @Before
+    public void before() {
+        violationCalculatorFlowlet = new TCAVESThresholdViolationCalculatorFlowlet(messageStatusTableName);
+        vesMessageStatusTable = Mockito.mock(ObjectMappedTable.class);
+        outputEmitter = Mockito.mock(OutputEmitter.class);
+        metrics = Mockito.mock(Metrics.class);
+    }
+
+    @Test
+    public void testConfigure() throws Exception {
+        assertFlowletNameAndDescription(
+                CDAPComponentsConstants.TCA_FIXED_VES_THRESHOLD_VIOLATION_CALCULATOR_NAME_FLOWLET,
+                CDAPComponentsConstants.TCA_FIXED_VES_THRESHOLD_VIOLATION_CALCULATOR_DESCRIPTION_FLOWLET,
+                violationCalculatorFlowlet);
+    }
+
+    @Test
+    public void testInitialize() throws Exception {
+        final FlowletContext mockFlowletContext = initializeFlowlet(violationCalculatorFlowlet, vesMessageStatusTable);
+        verify(mockFlowletContext, times(1)).getDataset(anyString());
+    }
+
+    @Test
+    public void testFilterVESMessagesWhenVESMessageIsInApplicable() throws Exception {
+        final TCATestVESThresholdViolationCalculatorFlowlet thresholdViolationCalculatorFlowlet =
+                createTestViolationCalculator(vesMessageStatusTable, outputEmitter, metrics);
+        initializeFlowlet(thresholdViolationCalculatorFlowlet, vesMessageStatusTable);
+        thresholdViolationCalculatorFlowlet.filterVESMessages("inapplicable");
+        verify(vesMessageStatusTable, times(1)).write(anyString(),
+                any(TCAMessageStatusEntity.class));
+    }
+
+    @Test
+    public void testFilterVESMessagesWhenVESMessageIsCompliant() throws Exception {
+        final TCATestVESThresholdViolationCalculatorFlowlet thresholdViolationCalculatorFlowlet =
+                createTestViolationCalculator(vesMessageStatusTable, outputEmitter, metrics);
+        initializeFlowlet(thresholdViolationCalculatorFlowlet, vesMessageStatusTable);
+        thresholdViolationCalculatorFlowlet.filterVESMessages(getValidCEFMessage());
+        verify(vesMessageStatusTable, times(1)).write(anyString(),
+                any(TCAMessageStatusEntity.class));
+    }
+
+    @Test
+    public void testFilterVESMessagesWhenVESMessageNonCompliant() throws Exception {
+        final TCATestVESThresholdViolationCalculatorFlowlet thresholdViolationCalculatorFlowlet =
+                createTestViolationCalculator(vesMessageStatusTable, outputEmitter, metrics);
+        final FlowletContext flowletContext =
+                initializeFlowlet(thresholdViolationCalculatorFlowlet, vesMessageStatusTable);
+        final TCAPolicy policy = CDAPTCAUtils.getValidatedTCAPolicyPreferences(flowletContext);
+        final Threshold threshold = policy.getMetricsPerEventName().get(0).getThresholds().get(0);
+        final Long thresholdValue = threshold.getThresholdValue();
+        final EventListener thresholdViolatingMessage = getCEFEventListener();
+        thresholdViolatingMessage.getEvent().getMeasurementsForVfScalingFields().getVNicPerformanceArray().
+                get(0).setReceivedBroadcastPacketsAccumulated(thresholdValue - 1);
+        thresholdViolationCalculatorFlowlet.filterVESMessages(
+                ANALYTICS_MODEL_OBJECT_MAPPER.writeValueAsString(thresholdViolatingMessage));
+        verify(vesMessageStatusTable, times(1)).write(anyString(),
+                any(TCAMessageStatusEntity.class));
+        verify(outputEmitter, times(1)).emit(any(ThresholdCalculatorOutput.class));
+    }
+
+    private static TCATestVESThresholdViolationCalculatorFlowlet createTestViolationCalculator(
+            final ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable,
+            final OutputEmitter outputEmitter, final Metrics metrics) {
+        doNothing().when(outputEmitter).emit(anyString());
+        doNothing().when(metrics).count(anyString(), anyInt());
+        doNothing().when(vesMessageStatusTable).write(anyString(), any(TCAMessageStatusEntity.class));
+        return new TCATestVESThresholdViolationCalculatorFlowlet(messageStatusTableName, outputEmitter,
+                vesMessageStatusTable, metrics);
+    }
+
+    private static <T extends TCAVESThresholdViolationCalculatorFlowlet> FlowletContext initializeFlowlet(
+            T calculatorFlowlet, ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable) throws Exception {
+        final FlowletContext mockFlowletContext = getTestFlowletContextWithValidPolicy();
+        when(mockFlowletContext.getDataset(anyString())).thenReturn(vesMessageStatusTable);
+        when(mockFlowletContext.getInstanceId()).thenReturn(1);
+        ApplicationSpecification mockApplicationSpecification = Mockito.mock(ApplicationSpecification.class);
+        when(mockApplicationSpecification.getConfiguration()).thenReturn(fromStream(TCA_APP_CONFIG_FILE_LOCATION));
+        when(mockFlowletContext.getApplicationSpecification()).thenReturn(mockApplicationSpecification);
+        when(mockApplicationSpecification.getName()).thenReturn("TestTCAAppName");
+        try {
+            calculatorFlowlet.initialize(mockFlowletContext);
+            return mockFlowletContext;
+        } catch (Exception e) {
+            LOG.error("error while flowlet initialization");
+            throw new RuntimeException(e);
+        }
+    }
+
+}