aboutsummaryrefslogtreecommitdiffstats
path: root/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca
diff options
context:
space:
mode:
Diffstat (limited to 'dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca')
-rw-r--r--dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java123
-rw-r--r--dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java38
-rw-r--r--dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java128
-rw-r--r--dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAVESAlertsPersisterTest.java63
4 files changed, 352 insertions, 0 deletions
diff --git a/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java
new file mode 100644
index 0000000..9415373
--- /dev/null
+++ b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java
@@ -0,0 +1,123 @@
+/*
+ * ===============================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);
+
+ }
+
+}
diff --git a/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java
new file mode 100644
index 0000000..2ce1b7f
--- /dev/null
+++ b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java
@@ -0,0 +1,38 @@
+/*
+ * ===============================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 org.junit.Test;
+import org.onap.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Rajiv Singla . Creation Date: 2/16/2017.
+ */
+public class TCACalculatorMessageTypeTest extends BaseAnalyticsCDAPCommonUnitTest {
+
+ @Test
+ public void testCalculatorMessageType() throws Exception {
+ assertThat("There must be 3 calculator message type", TCACalculatorMessageType.values().length, is(3));
+ }
+}
diff --git a/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java
new file mode 100644
index 0000000..2e12a1e
--- /dev/null
+++ b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java
@@ -0,0 +1,128 @@
+/*
+ * ===============================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);
+
+ }
+
+}
diff --git a/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAVESAlertsPersisterTest.java b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAVESAlertsPersisterTest.java
new file mode 100644
index 0000000..558e5a8
--- /dev/null
+++ b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAVESAlertsPersisterTest.java
@@ -0,0 +1,63 @@
+/*
+ * ===============================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 org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;
+
+import java.util.Date;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+/**
+ * @author Rajiv Singla . Creation Date: 2/16/2017.
+ */
+public class TCAVESAlertsPersisterTest extends BaseAnalyticsCDAPCommonUnitTest {
+
+ @Test
+ public void testPersist() throws Exception {
+ final ObjectMappedTable<TCAVESAlertEntity> tcaVESAlertTable = Mockito.mock(ObjectMappedTable.class);
+ TCAVESAlertsPersister.persist("test alert message", tcaVESAlertTable);
+ verify(tcaVESAlertTable, times(1)).write(anyString(),
+ any(TCAVESAlertEntity.class));
+ }
+
+ @Test
+ public void testGetDatasetProperties() throws Exception {
+ final DatasetProperties datasetProperties = TCAVESAlertsPersister.getDatasetProperties(20000);
+ Assert.assertNotNull(datasetProperties);
+ }
+
+ @Test
+ public void testCreateRowKey() throws Exception {
+ final String rowKey = TCAVESAlertsPersister.createRowKey(new Date());
+ Assert.assertThat(rowKey.toCharArray().length, is(25));
+ }
+
+}