TCA: Replace any openecomp reference by onap
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-common / src / test / java / org / onap / dcae / apod / analytics / cdap / common / persistance / tca / TCAMessageStatusPersisterTest.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.common.persistance.tca;\r
-\r
-import co.cask.cdap.api.dataset.DatasetProperties;\r
-import co.cask.cdap.api.dataset.lib.ObjectMappedTable;\r
-import com.google.common.collect.ImmutableList;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;\r
-import org.openecomp.dcae.apod.analytics.model.domain.cef.CommonEventHeader;\r
-import org.openecomp.dcae.apod.analytics.model.domain.cef.Domain;\r
-import org.openecomp.dcae.apod.analytics.model.domain.cef.Event;\r
-import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;\r
-import org.openecomp.dcae.apod.analytics.model.domain.cef.EventSeverity;\r
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Direction;\r
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;\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
-import org.openecomp.dcae.apod.analytics.tca.processor.TCACEFProcessorContext;\r
-import org.openecomp.dcae.apod.analytics.tca.utils.TCAUtils;\r
-\r
-import static org.mockito.ArgumentMatchers.any;\r
-import static org.mockito.ArgumentMatchers.anyString;\r
-import static org.mockito.Mockito.mock;\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: 2/16/2017.\r
- */\r
-public class TCAMessageStatusPersisterTest extends BaseAnalyticsCDAPCommonUnitTest {\r
-\r
-    private static final int TEST_INSTANCE_ID = 0;\r
-    private static final Domain TEST_DOMAIN = Domain.other;\r
-    private static final String TEST_EVENT_NAME = "TEST_EVENT_NAME";\r
-\r
-    private ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable;\r
-    private TCACEFProcessorContext processorContext;\r
-    private EventListener eventListener;\r
-    private Event event;\r
-    private CommonEventHeader commonEventHeader;\r
-\r
-\r
-    @Before\r
-    @SuppressWarnings("unchecked")\r
-    public void before() {\r
-        vesMessageStatusTable = mock(ObjectMappedTable.class);\r
-        processorContext = mock(TCACEFProcessorContext.class);\r
-        eventListener = mock(EventListener.class);\r
-        event = mock(Event.class);\r
-        commonEventHeader = mock(CommonEventHeader.class);\r
-        when(processorContext.getMessage()).thenReturn("testMessage");\r
-        when(processorContext.getCEFEventListener()).thenReturn(eventListener);\r
-        when(eventListener.getEvent()).thenReturn(event);\r
-        when(event.getCommonEventHeader()).thenReturn(commonEventHeader);\r
-        when(commonEventHeader.getEventName()).thenReturn(TEST_EVENT_NAME);\r
-        when(commonEventHeader.getDomain()).thenReturn(TEST_DOMAIN);\r
-    }\r
-\r
-\r
-    @Test\r
-    public void testPersistWithInApplicableMessage() throws Exception {\r
-        TCAMessageStatusPersister.persist\r
-                (processorContext, TEST_INSTANCE_ID, TCACalculatorMessageType.INAPPLICABLE, vesMessageStatusTable);\r
-        verify(vesMessageStatusTable, times(1)).write(anyString(),\r
-                any(TCAMessageStatusEntity.class));\r
-    }\r
-\r
-    @Test\r
-    public void testPersistWithNonCompliantMessage() throws Exception {\r
-        final MetricsPerEventName metricsPerEventName = mock(MetricsPerEventName.class);\r
-        final Threshold threshold = mock(Threshold.class);\r
-        when(processorContext.getMetricsPerEventName()).thenReturn(metricsPerEventName);\r
-        when((metricsPerEventName.getThresholds())).thenReturn(ImmutableList.of(threshold));\r
-        when(threshold.getDirection()).thenReturn(Direction.GREATER);\r
-        when(threshold.getSeverity()).thenReturn(EventSeverity.CRITICAL);\r
-        TCAMessageStatusPersister.persist(\r
-                processorContext, TEST_INSTANCE_ID, TCACalculatorMessageType.NON_COMPLIANT,\r
-                vesMessageStatusTable, "testAlert");\r
-        verify(vesMessageStatusTable, times(1)).write(anyString(),\r
-                any(TCAMessageStatusEntity.class));\r
-    }\r
-\r
-    @Test\r
-    public void testPersistWithCompliantMessage() throws Exception {\r
-        final String cefMessage = fromStream(CEF_MESSAGE_FILE_LOCATION);\r
-        final String tcaPolicyString = fromStream(TCA_POLICY_FILE_LOCATION);\r
-\r
-        final TCAPolicy tcaPolicy = ANALYTICS_MODEL_OBJECT_MAPPER.readValue(tcaPolicyString, TCAPolicy.class);\r
-        final TCACEFProcessorContext tcacefProcessorContext = TCAUtils.filterCEFMessage(cefMessage, tcaPolicy);\r
-        final TCACEFProcessorContext finalProcessorContext =\r
-                TCAUtils.computeThresholdViolations(tcacefProcessorContext);\r
-\r
-        TCAMessageStatusPersister.persist(finalProcessorContext, TEST_INSTANCE_ID,\r
-                TCACalculatorMessageType.COMPLIANT, vesMessageStatusTable, "testAlert");\r
-        verify(vesMessageStatusTable, times(1)).write(anyString(),\r
-                any(TCAMessageStatusEntity.class));\r
-    }\r
-\r
-    @Test\r
-    public void testGetDatasetProperties() throws Exception {\r
-        final DatasetProperties datasetProperties = TCAMessageStatusPersister.getDatasetProperties(20000);\r
-        Assert.assertNotNull(datasetProperties);\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.common.persistance.tca;
+
+import co.cask.cdap.api.dataset.DatasetProperties;
+import co.cask.cdap.api.dataset.lib.ObjectMappedTable;
+import com.google.common.collect.ImmutableList;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;
+import org.onap.dcae.apod.analytics.model.domain.cef.CommonEventHeader;
+import org.onap.dcae.apod.analytics.model.domain.cef.Domain;
+import org.onap.dcae.apod.analytics.model.domain.cef.Event;
+import org.onap.dcae.apod.analytics.model.domain.cef.EventListener;
+import org.onap.dcae.apod.analytics.model.domain.cef.EventSeverity;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.Direction;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.Threshold;
+import org.onap.dcae.apod.analytics.tca.processor.TCACEFProcessorContext;
+import org.onap.dcae.apod.analytics.tca.utils.TCAUtils;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Rajiv Singla . Creation Date: 2/16/2017.
+ */
+public class TCAMessageStatusPersisterTest extends BaseAnalyticsCDAPCommonUnitTest {
+
+    private static final int TEST_INSTANCE_ID = 0;
+    private static final Domain TEST_DOMAIN = Domain.other;
+    private static final String TEST_EVENT_NAME = "TEST_EVENT_NAME";
+
+    private ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable;
+    private TCACEFProcessorContext processorContext;
+    private EventListener eventListener;
+    private Event event;
+    private CommonEventHeader commonEventHeader;
+
+
+    @Before
+    @SuppressWarnings("unchecked")
+    public void before() {
+        vesMessageStatusTable = mock(ObjectMappedTable.class);
+        processorContext = mock(TCACEFProcessorContext.class);
+        eventListener = mock(EventListener.class);
+        event = mock(Event.class);
+        commonEventHeader = mock(CommonEventHeader.class);
+        when(processorContext.getMessage()).thenReturn("testMessage");
+        when(processorContext.getCEFEventListener()).thenReturn(eventListener);
+        when(eventListener.getEvent()).thenReturn(event);
+        when(event.getCommonEventHeader()).thenReturn(commonEventHeader);
+        when(commonEventHeader.getEventName()).thenReturn(TEST_EVENT_NAME);
+        when(commonEventHeader.getDomain()).thenReturn(TEST_DOMAIN);
+    }
+
+
+    @Test
+    public void testPersistWithInApplicableMessage() throws Exception {
+        TCAMessageStatusPersister.persist
+                (processorContext, TEST_INSTANCE_ID, TCACalculatorMessageType.INAPPLICABLE, vesMessageStatusTable);
+        verify(vesMessageStatusTable, times(1)).write(anyString(),
+                any(TCAMessageStatusEntity.class));
+    }
+
+    @Test
+    public void testPersistWithNonCompliantMessage() throws Exception {
+        final MetricsPerEventName metricsPerEventName = mock(MetricsPerEventName.class);
+        final Threshold threshold = mock(Threshold.class);
+        when(processorContext.getMetricsPerEventName()).thenReturn(metricsPerEventName);
+        when((metricsPerEventName.getThresholds())).thenReturn(ImmutableList.of(threshold));
+        when(threshold.getDirection()).thenReturn(Direction.GREATER);
+        when(threshold.getSeverity()).thenReturn(EventSeverity.CRITICAL);
+        TCAMessageStatusPersister.persist(
+                processorContext, TEST_INSTANCE_ID, TCACalculatorMessageType.NON_COMPLIANT,
+                vesMessageStatusTable, "testAlert");
+        verify(vesMessageStatusTable, times(1)).write(anyString(),
+                any(TCAMessageStatusEntity.class));
+    }
+
+    @Test
+    public void testPersistWithCompliantMessage() throws Exception {
+        final String cefMessage = fromStream(CEF_MESSAGE_FILE_LOCATION);
+        final String tcaPolicyString = fromStream(TCA_POLICY_FILE_LOCATION);
+
+        final TCAPolicy tcaPolicy = ANALYTICS_MODEL_OBJECT_MAPPER.readValue(tcaPolicyString, TCAPolicy.class);
+        final TCACEFProcessorContext tcacefProcessorContext = TCAUtils.filterCEFMessage(cefMessage, tcaPolicy);
+        final TCACEFProcessorContext finalProcessorContext =
+                TCAUtils.computeThresholdViolations(tcacefProcessorContext);
+
+        TCAMessageStatusPersister.persist(finalProcessorContext, TEST_INSTANCE_ID,
+                TCACalculatorMessageType.COMPLIANT, vesMessageStatusTable, "testAlert");
+        verify(vesMessageStatusTable, times(1)).write(anyString(),
+                any(TCAMessageStatusEntity.class));
+    }
+
+    @Test
+    public void testGetDatasetProperties() throws Exception {
+        final DatasetProperties datasetProperties = TCAMessageStatusPersister.getDatasetProperties(20000);
+        Assert.assertNotNull(datasetProperties);
+
+    }
+
+}