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 / TCAAlertsAbatementPersisterTest.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.base.Joiner;\r
-import com.google.common.collect.ImmutableList;\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.common.utils.PersistenceUtils;\r
-import org.openecomp.dcae.apod.analytics.model.domain.cef.CommonEventHeader;\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.policy.tca.MetricsPerEventName;\r
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;\r
-import org.openecomp.dcae.apod.analytics.model.facade.tca.TCAVESResponse;\r
-\r
-import static org.junit.Assert.assertEquals;\r
-import static org.junit.Assert.assertNotNull;\r
-import static org.mockito.ArgumentMatchers.any;\r
-import static org.mockito.ArgumentMatchers.anyString;\r
-import static org.mockito.ArgumentMatchers.eq;\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: 9/13/2017.\r
- */\r
-public class TCAAlertsAbatementPersisterTest extends BaseAnalyticsCDAPCommonUnitTest {\r
-\r
-    private static final String EVENT_NAME = "testEventName";\r
-    private static final String SOURCE_NAME = "testSourceName";\r
-    private static final String REPORTING_ENTITY_NAME = "testReportingEntityName";\r
-    private static final String THRESHOLD_CLOSED_LOOP_CONTROL_NAME = "testControlLoopName";\r
-    private static final String THRESHOLD_FIELD_PATH = "testFieldPath";\r
-    private static final String EXPECTED_LOOKUP_KEY = Joiner.on(PersistenceUtils.ROW_KEY_DELIMITER).join(\r
-            ImmutableList.of(EVENT_NAME, SOURCE_NAME, REPORTING_ENTITY_NAME,\r
-                    THRESHOLD_CLOSED_LOOP_CONTROL_NAME, THRESHOLD_FIELD_PATH));\r
-\r
-    private ObjectMappedTable<TCAAlertsAbatementEntity> alertsAbatementTable;\r
-    private EventListener eventListener;\r
-    private MetricsPerEventName violatedMetricsPerEventName;\r
-    private TCAVESResponse tcavesResponse;\r
-    private String abatementTS;\r
-    private Event event;\r
-    private CommonEventHeader commonEventHeader;\r
-    private Threshold violatedThreshold;\r
-\r
-    @Before\r
-    public void before() throws Exception {\r
-        alertsAbatementTable = mock(ObjectMappedTable.class);\r
-        eventListener = mock(EventListener.class);\r
-        event = mock(Event.class);\r
-        commonEventHeader = mock(CommonEventHeader.class);\r
-\r
-        when(eventListener.getEvent()).thenReturn(event);\r
-        when(event.getCommonEventHeader()).thenReturn(commonEventHeader);\r
-        when(commonEventHeader.getEventName()).thenReturn(EVENT_NAME);\r
-        when(commonEventHeader.getSourceName()).thenReturn(SOURCE_NAME);\r
-        when(commonEventHeader.getReportingEntityName()).thenReturn(REPORTING_ENTITY_NAME);\r
-\r
-        violatedMetricsPerEventName = mock(MetricsPerEventName.class);\r
-        when(violatedMetricsPerEventName.getEventName()).thenReturn(EVENT_NAME);\r
-        violatedThreshold = mock(Threshold.class);\r
-        when(violatedMetricsPerEventName.getThresholds()).thenReturn(ImmutableList.of(violatedThreshold));\r
-        when(violatedThreshold.getClosedLoopControlName()).thenReturn(THRESHOLD_CLOSED_LOOP_CONTROL_NAME);\r
-        when(violatedThreshold.getFieldPath()).thenReturn(THRESHOLD_FIELD_PATH);\r
-        tcavesResponse = mock(TCAVESResponse.class);\r
-        abatementTS = "1234";\r
-    }\r
-\r
-    @Test\r
-    public void testGetDatasetProperties() throws Exception {\r
-        final DatasetProperties datasetProperties = TCAAlertsAbatementPersister.getDatasetProperties(20000);\r
-        assertNotNull(datasetProperties);\r
-    }\r
-\r
-    @Test\r
-    public void testPersist() throws Exception {\r
-\r
-        TCAAlertsAbatementPersister.persist(eventListener, violatedMetricsPerEventName, tcavesResponse,\r
-                abatementTS, alertsAbatementTable);\r
-        verify(alertsAbatementTable, times(1)).write(anyString(),\r
-                any(TCAAlertsAbatementEntity.class));\r
-\r
-    }\r
-\r
-    @Test\r
-    public void testLookUpByKey() throws Exception {\r
-        TCAAlertsAbatementPersister.lookUpByKey(eventListener, violatedMetricsPerEventName, alertsAbatementTable);\r
-        verify(alertsAbatementTable, times(1)).read(eq(EXPECTED_LOOKUP_KEY));\r
-    }\r
-\r
-    @Test\r
-    public void testCreateKey() throws Exception {\r
-        final String createdKey = TCAAlertsAbatementPersister.createKey(eventListener, violatedMetricsPerEventName);\r
-        assertEquals(createdKey, EXPECTED_LOOKUP_KEY);\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.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;
+import org.onap.dcae.apod.analytics.common.utils.PersistenceUtils;
+import org.onap.dcae.apod.analytics.model.domain.cef.CommonEventHeader;
+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.policy.tca.MetricsPerEventName;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.Threshold;
+import org.onap.dcae.apod.analytics.model.facade.tca.TCAVESResponse;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+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: 9/13/2017.
+ */
+public class TCAAlertsAbatementPersisterTest extends BaseAnalyticsCDAPCommonUnitTest {
+
+    private static final String EVENT_NAME = "testEventName";
+    private static final String SOURCE_NAME = "testSourceName";
+    private static final String REPORTING_ENTITY_NAME = "testReportingEntityName";
+    private static final String THRESHOLD_CLOSED_LOOP_CONTROL_NAME = "testControlLoopName";
+    private static final String THRESHOLD_FIELD_PATH = "testFieldPath";
+    private static final String EXPECTED_LOOKUP_KEY = Joiner.on(PersistenceUtils.ROW_KEY_DELIMITER).join(
+            ImmutableList.of(EVENT_NAME, SOURCE_NAME, REPORTING_ENTITY_NAME,
+                    THRESHOLD_CLOSED_LOOP_CONTROL_NAME, THRESHOLD_FIELD_PATH));
+
+    private ObjectMappedTable<TCAAlertsAbatementEntity> alertsAbatementTable;
+    private EventListener eventListener;
+    private MetricsPerEventName violatedMetricsPerEventName;
+    private TCAVESResponse tcavesResponse;
+    private String abatementTS;
+    private Event event;
+    private CommonEventHeader commonEventHeader;
+    private Threshold violatedThreshold;
+
+    @Before
+    public void before() throws Exception {
+        alertsAbatementTable = mock(ObjectMappedTable.class);
+        eventListener = mock(EventListener.class);
+        event = mock(Event.class);
+        commonEventHeader = mock(CommonEventHeader.class);
+
+        when(eventListener.getEvent()).thenReturn(event);
+        when(event.getCommonEventHeader()).thenReturn(commonEventHeader);
+        when(commonEventHeader.getEventName()).thenReturn(EVENT_NAME);
+        when(commonEventHeader.getSourceName()).thenReturn(SOURCE_NAME);
+        when(commonEventHeader.getReportingEntityName()).thenReturn(REPORTING_ENTITY_NAME);
+
+        violatedMetricsPerEventName = mock(MetricsPerEventName.class);
+        when(violatedMetricsPerEventName.getEventName()).thenReturn(EVENT_NAME);
+        violatedThreshold = mock(Threshold.class);
+        when(violatedMetricsPerEventName.getThresholds()).thenReturn(ImmutableList.of(violatedThreshold));
+        when(violatedThreshold.getClosedLoopControlName()).thenReturn(THRESHOLD_CLOSED_LOOP_CONTROL_NAME);
+        when(violatedThreshold.getFieldPath()).thenReturn(THRESHOLD_FIELD_PATH);
+        tcavesResponse = mock(TCAVESResponse.class);
+        abatementTS = "1234";
+    }
+
+    @Test
+    public void testGetDatasetProperties() throws Exception {
+        final DatasetProperties datasetProperties = TCAAlertsAbatementPersister.getDatasetProperties(20000);
+        assertNotNull(datasetProperties);
+    }
+
+    @Test
+    public void testPersist() throws Exception {
+
+        TCAAlertsAbatementPersister.persist(eventListener, violatedMetricsPerEventName, tcavesResponse,
+                abatementTS, alertsAbatementTable);
+        verify(alertsAbatementTable, times(1)).write(anyString(),
+                any(TCAAlertsAbatementEntity.class));
+
+    }
+
+    @Test
+    public void testLookUpByKey() throws Exception {
+        TCAAlertsAbatementPersister.lookUpByKey(eventListener, violatedMetricsPerEventName, alertsAbatementTable);
+        verify(alertsAbatementTable, times(1)).read(eq(EXPECTED_LOOKUP_KEY));
+    }
+
+    @Test
+    public void testCreateKey() throws Exception {
+        final String createdKey = TCAAlertsAbatementPersister.createKey(eventListener, violatedMetricsPerEventName);
+        assertEquals(createdKey, EXPECTED_LOOKUP_KEY);
+
+    }
+
+}