From c489a2eb22484e798c39a978bc8b61821b92322f Mon Sep 17 00:00:00 2001 From: an4828 Date: Mon, 22 Jan 2018 17:17:34 -0500 Subject: TCA: Replace any openecomp reference by onap Change-Id: I7c6d812ab5c1d7b30c63653d1974b0b1abc099be Signed-off-by: an4828 Issue-ID: DCAEGEN2-224 Signed-off-by: an4828 --- .../common/BaseAnalyticsCDAPCommonUnitTest.java | 89 ++++++++++++++ .../tca/TCAAlertsAbatementPersisterTest.java | 123 ++++++++++++++++++++ .../tca/TCACalculatorMessageTypeTest.java | 38 ++++++ .../tca/TCAMessageStatusPersisterTest.java | 128 +++++++++++++++++++++ .../persistance/tca/TCAVESAlertsPersisterTest.java | 63 ++++++++++ .../common/settings/CDAPBaseAppConfigTest.java | 58 ++++++++++ .../cdap/common/utils/DMaaPMRUtilsTest.java | 112 ++++++++++++++++++ .../cdap/common/utils/ValidationUtilsTest.java | 80 +++++++++++++ .../common/BaseAnalyticsCDAPCommonUnitTest.java | 89 -------------- .../tca/TCAAlertsAbatementPersisterTest.java | 123 -------------------- .../tca/TCACalculatorMessageTypeTest.java | 38 ------ .../tca/TCAMessageStatusPersisterTest.java | 128 --------------------- .../persistance/tca/TCAVESAlertsPersisterTest.java | 63 ---------- .../common/settings/CDAPBaseAppConfigTest.java | 58 ---------- .../cdap/common/utils/DMaaPMRUtilsTest.java | 112 ------------------ .../cdap/common/utils/ValidationUtilsTest.java | 80 ------------- 16 files changed, 691 insertions(+), 691 deletions(-) create mode 100644 dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java create mode 100644 dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java create mode 100644 dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java create mode 100644 dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java create mode 100644 dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/persistance/tca/TCAVESAlertsPersisterTest.java create mode 100644 dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/settings/CDAPBaseAppConfigTest.java create mode 100644 dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/utils/DMaaPMRUtilsTest.java create mode 100644 dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/utils/ValidationUtilsTest.java delete mode 100644 dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java delete mode 100644 dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java delete mode 100644 dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java delete mode 100644 dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java delete mode 100644 dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAVESAlertsPersisterTest.java delete mode 100644 dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/settings/CDAPBaseAppConfigTest.java delete mode 100644 dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/utils/DMaaPMRUtilsTest.java delete mode 100644 dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/utils/ValidationUtilsTest.java (limited to 'dcae-analytics-cdap-common/src/test/java') diff --git a/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java new file mode 100644 index 0000000..6798f8b --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java @@ -0,0 +1,89 @@ +/* + * ===============================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; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Suppliers; +import org.onap.dcae.apod.analytics.cdap.common.settings.CDAPAppSettings; +import org.onap.dcae.apod.analytics.cdap.common.settings.CDAPBaseAppConfig; +import org.onap.dcae.apod.analytics.cdap.common.utils.ValidationUtils; +import org.onap.dcae.apod.analytics.cdap.common.validation.CDAPAppSettingsValidator; +import org.onap.dcae.apod.analytics.common.validation.GenericValidationResponse; +import org.onap.dcae.apod.analytics.model.util.json.AnalyticsModelObjectMapperSupplier; +import org.onap.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest; + +/** + * @author Rajiv Singla . Creation Date: 1/12/2017. + */ +public abstract class BaseAnalyticsCDAPCommonUnitTest extends BaseDCAEAnalyticsUnitTest { + + protected static final String CEF_MESSAGE_FILE_LOCATION = "data/json/cef/cef_message.json"; + protected static final String TCA_POLICY_FILE_LOCATION = "data/json/policy/tca_policy.json"; + protected static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER = + Suppliers.memoize(new AnalyticsModelObjectMapperSupplier()).get(); + + /** + * Test Implementation for {@link CDAPBaseAppConfig} + */ + public class CDAPBaseAppConfigImp extends CDAPBaseAppConfig { + } + + + /** + * Test implementation for {@link CDAPAppSettings} + */ + public class CDAPTestAppSettings implements CDAPAppSettings { + + private String settingsField; + + public String getSettingsField() { + return settingsField; + } + + public void setSettingsField(String settingsField) { + this.settingsField = settingsField; + } + } + + + /** + * Test implementation for {@link CDAPAppSettingsValidator} + */ + public class CDAPTestAppSettingsValidator implements CDAPAppSettingsValidator> { + + private static final long serialVersionUID = 1L; + + @Override + public GenericValidationResponse + validateAppSettings(CDAPTestAppSettings cdapTestAppSettings) { + GenericValidationResponse validationResponse = new + GenericValidationResponse<>(); + if (ValidationUtils.isEmpty(cdapTestAppSettings.getSettingsField())) { + validationResponse + .addErrorMessage("settingsField", "Settings Field must not be empty"); + } + return validationResponse; + } + } + + +} 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 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 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 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)); + } + +} diff --git a/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/settings/CDAPBaseAppConfigTest.java b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/settings/CDAPBaseAppConfigTest.java new file mode 100644 index 0000000..ca2c2ca --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/settings/CDAPBaseAppConfigTest.java @@ -0,0 +1,58 @@ +/* + * ===============================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.settings; + +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Test; +import org.onap.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest; +import org.onap.dcae.apod.analytics.cdap.common.CDAPComponentsConstants; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author Rajiv Singla . Creation Date: 12/12/2016. + */ +public class CDAPBaseAppConfigTest extends BaseAnalyticsCDAPCommonUnitTest { + + private CDAPBaseAppConfigImp cdapBaseAppConfigImp = null; + + @Before + public void before() { + cdapBaseAppConfigImp = new CDAPBaseAppConfigImp(); + } + + @Test + public void testGetAppName() throws Exception { + assertThat("Common Default Name must match", + cdapBaseAppConfigImp.getAppName(), + CoreMatchers.is(CDAPComponentsConstants.COMMON_DEFAULT_DCAE_CDAP_NAME_APP)); + } + + @Test + public void testGetAppDescription() throws Exception { + assertThat("Default App Description must match", + cdapBaseAppConfigImp.getAppDescription(), + is(CDAPComponentsConstants.COMMON_DEFAULT_DCAE_CDAP_DESCRIPTION_APP)); + } + +} diff --git a/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/utils/DMaaPMRUtilsTest.java b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/utils/DMaaPMRUtilsTest.java new file mode 100644 index 0000000..31ff13b --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/utils/DMaaPMRUtilsTest.java @@ -0,0 +1,112 @@ +/* + * ===============================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.utils; + +import co.cask.cdap.api.metrics.Metrics; +import com.google.common.collect.ImmutableList; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; +import org.onap.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest; +import org.onap.dcae.apod.analytics.cdap.common.CDAPMetricsConstants; +import org.onap.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; +import org.onap.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; +import org.onap.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; + +import java.util.Collections; + +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * @author Rajiv Singla . Creation Date: 2/6/2017. + */ +public class DMaaPMRUtilsTest extends BaseAnalyticsCDAPCommonUnitTest { + + private DMaaPMRSubscriber subscriber; + private Metrics metrics; + + + @Before + public void before() throws Exception { + metrics = mock(Metrics.class); + doNothing().when(metrics).count(anyString(), anyInt()); + subscriber = mock(DMaaPMRSubscriber.class); + } + + @Test + public void testGetSubscriberMessagesWhenMessagesAreFound() throws Exception { + final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); + when(subscriberResponse.getResponseCode()).thenReturn(200); + when(subscriberResponse.getResponseMessage()).thenReturn("testMessage"); + when(subscriberResponse.getFetchedMessages()).thenReturn(ImmutableList.of("testMessage1", "testMessage1")); + when(subscriber.fetchMessages()).thenReturn(subscriberResponse); + DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); + verify(metrics, Mockito.times(1)).count(ArgumentMatchers.eq(CDAPMetricsConstants + .DMAAP_MR_SUBSCRIBER_TOTAL_MESSAGES_PROCESSED_METRIC), eq(2)); + } + + @Test + public void testSubscriberMessagesWhenSubscriberResponseCodeIsNull() throws Exception { + final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); + when(subscriberResponse.getResponseCode()).thenReturn(null); + when(subscriber.fetchMessages()).thenReturn(subscriberResponse); + DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); + } + + @Test + public void testSubscriberMessagesWhenNoMessagesFound() throws Exception { + final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); + when(subscriberResponse.getResponseCode()).thenReturn(200); + when(subscriberResponse.getResponseMessage()).thenReturn("no messages"); + when(subscriberResponse.getFetchedMessages()).thenReturn(Collections.emptyList()); + when(subscriber.fetchMessages()).thenReturn(subscriberResponse); + DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); + verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants + .DMAAP_MR_SUBSCRIBER_RESPONSES_WITH_NO_MESSAGES_METRIC), eq(1)); + } + + + @Test + public void testWhenSubscriberReturnNonSuccessfulReturnCode() throws Exception { + final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); + when(subscriberResponse.getResponseCode()).thenReturn(500); + when(subscriber.fetchMessages()).thenReturn(subscriberResponse); + DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); + verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants + .DMAAP_MR_SUBSCRIBER_UNSUCCESSFUL_RESPONSES_METRIC), eq(1)); + } + + @Test + public void testWhenSubscriberThrowsException() throws Exception { + final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); + when(subscriberResponse.getResponseCode()).thenReturn(500); + when(subscriber.fetchMessages()).thenThrow(DCAEAnalyticsRuntimeException.class); + DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); + } + +} diff --git a/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/utils/ValidationUtilsTest.java b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/utils/ValidationUtilsTest.java new file mode 100644 index 0000000..d6240fd --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/onap/dcae/apod/analytics/cdap/common/utils/ValidationUtilsTest.java @@ -0,0 +1,80 @@ +/* + * ===============================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.utils; + +import org.junit.Test; +import org.onap.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest; +import org.onap.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * @author Rajiv Singla . Creation Date: 12/12/2016. + */ +public class ValidationUtilsTest extends BaseAnalyticsCDAPCommonUnitTest { + + @Test + public void testIsEmptyWhenStringIsNull() throws Exception { + assertTrue(ValidationUtils.isEmpty(null)); + } + + @Test + public void testIsEmptyWhenStringIsEmpty() throws Exception { + String emptyString = ""; + assertTrue(ValidationUtils.isEmpty(emptyString)); + } + + @Test + public void testIsEmptyWhenStringIsEmptyWithBlanks() throws Exception { + String blankString = " "; + assertTrue(ValidationUtils.isEmpty(blankString)); + } + + + @Test + public void testIsNotPresent() throws Exception { + assertFalse(ValidationUtils.isPresent(null)); + String emptyString = ""; + assertFalse(ValidationUtils.isPresent(emptyString)); + String blankString = " "; + assertFalse(ValidationUtils.isPresent(blankString)); + String validString = "SomeValue"; + assertTrue(ValidationUtils.isPresent(validString)); + } + + @Test + public void testValidateSettingsWhenValidationPasses() throws Exception { + CDAPTestAppSettings cdapTestAppSettings = new CDAPTestAppSettings(); + cdapTestAppSettings.setSettingsField("testValue"); + ValidationUtils.validateSettings(cdapTestAppSettings, new CDAPTestAppSettingsValidator()); + } + + @Test(expected = CDAPSettingsException.class) + public void testValidateSettingsWhenValidationFails() throws Exception { + + CDAPTestAppSettings cdapTestAppSettings = new CDAPTestAppSettings(); + cdapTestAppSettings.setSettingsField(""); + ValidationUtils.validateSettings(cdapTestAppSettings, new CDAPTestAppSettingsValidator()); + } + +} + diff --git a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java deleted file mode 100644 index 793512b..0000000 --- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * ===============================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.openecomp.dcae.apod.analytics.cdap.common; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Suppliers; -import org.openecomp.dcae.apod.analytics.cdap.common.settings.CDAPAppSettings; -import org.openecomp.dcae.apod.analytics.cdap.common.settings.CDAPBaseAppConfig; -import org.openecomp.dcae.apod.analytics.cdap.common.utils.ValidationUtils; -import org.openecomp.dcae.apod.analytics.cdap.common.validation.CDAPAppSettingsValidator; -import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse; -import org.openecomp.dcae.apod.analytics.model.util.json.AnalyticsModelObjectMapperSupplier; -import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest; - -/** - * @author Rajiv Singla . Creation Date: 1/12/2017. - */ -public abstract class BaseAnalyticsCDAPCommonUnitTest extends BaseDCAEAnalyticsUnitTest { - - protected static final String CEF_MESSAGE_FILE_LOCATION = "data/json/cef/cef_message.json"; - protected static final String TCA_POLICY_FILE_LOCATION = "data/json/policy/tca_policy.json"; - protected static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER = - Suppliers.memoize(new AnalyticsModelObjectMapperSupplier()).get(); - - /** - * Test Implementation for {@link CDAPBaseAppConfig} - */ - public class CDAPBaseAppConfigImp extends CDAPBaseAppConfig { - } - - - /** - * Test implementation for {@link CDAPAppSettings} - */ - public class CDAPTestAppSettings implements CDAPAppSettings { - - private String settingsField; - - public String getSettingsField() { - return settingsField; - } - - public void setSettingsField(String settingsField) { - this.settingsField = settingsField; - } - } - - - /** - * Test implementation for {@link CDAPAppSettingsValidator} - */ - public class CDAPTestAppSettingsValidator implements CDAPAppSettingsValidator> { - - private static final long serialVersionUID = 1L; - - @Override - public GenericValidationResponse - validateAppSettings(CDAPTestAppSettings cdapTestAppSettings) { - GenericValidationResponse validationResponse = new - GenericValidationResponse<>(); - if (ValidationUtils.isEmpty(cdapTestAppSettings.getSettingsField())) { - validationResponse - .addErrorMessage("settingsField", "Settings Field must not be empty"); - } - return validationResponse; - } - } - - -} diff --git a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java deleted file mode 100644 index ed46e60..0000000 --- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * ===============================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.openecomp.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.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest; -import org.openecomp.dcae.apod.analytics.common.utils.PersistenceUtils; -import org.openecomp.dcae.apod.analytics.model.domain.cef.CommonEventHeader; -import org.openecomp.dcae.apod.analytics.model.domain.cef.Event; -import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener; -import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName; -import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold; -import org.openecomp.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 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/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java deleted file mode 100644 index 89cf241..0000000 --- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * ===============================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.openecomp.dcae.apod.analytics.cdap.common.persistance.tca; - -import org.junit.Test; -import org.openecomp.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/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java deleted file mode 100644 index 372e9e6..0000000 --- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * ===============================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.openecomp.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.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest; -import org.openecomp.dcae.apod.analytics.model.domain.cef.CommonEventHeader; -import org.openecomp.dcae.apod.analytics.model.domain.cef.Domain; -import org.openecomp.dcae.apod.analytics.model.domain.cef.Event; -import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener; -import org.openecomp.dcae.apod.analytics.model.domain.cef.EventSeverity; -import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Direction; -import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName; -import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy; -import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold; -import org.openecomp.dcae.apod.analytics.tca.processor.TCACEFProcessorContext; -import org.openecomp.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 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/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAVESAlertsPersisterTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAVESAlertsPersisterTest.java deleted file mode 100644 index 151cbd9..0000000 --- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAVESAlertsPersisterTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * ===============================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.openecomp.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.openecomp.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 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)); - } - -} diff --git a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/settings/CDAPBaseAppConfigTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/settings/CDAPBaseAppConfigTest.java deleted file mode 100644 index b4bb9e7..0000000 --- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/settings/CDAPBaseAppConfigTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ===============================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.openecomp.dcae.apod.analytics.cdap.common.settings; - -import org.hamcrest.CoreMatchers; -import org.junit.Before; -import org.junit.Test; -import org.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest; -import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -/** - * @author Rajiv Singla . Creation Date: 12/12/2016. - */ -public class CDAPBaseAppConfigTest extends BaseAnalyticsCDAPCommonUnitTest { - - private CDAPBaseAppConfigImp cdapBaseAppConfigImp = null; - - @Before - public void before() { - cdapBaseAppConfigImp = new CDAPBaseAppConfigImp(); - } - - @Test - public void testGetAppName() throws Exception { - assertThat("Common Default Name must match", - cdapBaseAppConfigImp.getAppName(), - CoreMatchers.is(CDAPComponentsConstants.COMMON_DEFAULT_DCAE_CDAP_NAME_APP)); - } - - @Test - public void testGetAppDescription() throws Exception { - assertThat("Default App Description must match", - cdapBaseAppConfigImp.getAppDescription(), - is(CDAPComponentsConstants.COMMON_DEFAULT_DCAE_CDAP_DESCRIPTION_APP)); - } - -} diff --git a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/utils/DMaaPMRUtilsTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/utils/DMaaPMRUtilsTest.java deleted file mode 100644 index 9a52e41..0000000 --- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/utils/DMaaPMRUtilsTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * ===============================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.openecomp.dcae.apod.analytics.cdap.common.utils; - -import co.cask.cdap.api.metrics.Metrics; -import com.google.common.collect.ImmutableList; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentMatchers; -import org.mockito.Mockito; -import org.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest; -import org.openecomp.dcae.apod.analytics.cdap.common.CDAPMetricsConstants; -import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException; -import org.openecomp.dcae.apod.analytics.dmaap.domain.response.DMaaPMRSubscriberResponse; -import org.openecomp.dcae.apod.analytics.dmaap.service.subscriber.DMaaPMRSubscriber; - -import java.util.Collections; - -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * @author Rajiv Singla . Creation Date: 2/6/2017. - */ -public class DMaaPMRUtilsTest extends BaseAnalyticsCDAPCommonUnitTest { - - private DMaaPMRSubscriber subscriber; - private Metrics metrics; - - - @Before - public void before() throws Exception { - metrics = mock(Metrics.class); - doNothing().when(metrics).count(anyString(), anyInt()); - subscriber = mock(DMaaPMRSubscriber.class); - } - - @Test - public void testGetSubscriberMessagesWhenMessagesAreFound() throws Exception { - final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); - when(subscriberResponse.getResponseCode()).thenReturn(200); - when(subscriberResponse.getResponseMessage()).thenReturn("testMessage"); - when(subscriberResponse.getFetchedMessages()).thenReturn(ImmutableList.of("testMessage1", "testMessage1")); - when(subscriber.fetchMessages()).thenReturn(subscriberResponse); - DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); - verify(metrics, Mockito.times(1)).count(ArgumentMatchers.eq(CDAPMetricsConstants - .DMAAP_MR_SUBSCRIBER_TOTAL_MESSAGES_PROCESSED_METRIC), eq(2)); - } - - @Test - public void testSubscriberMessagesWhenSubscriberResponseCodeIsNull() throws Exception { - final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); - when(subscriberResponse.getResponseCode()).thenReturn(null); - when(subscriber.fetchMessages()).thenReturn(subscriberResponse); - DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); - } - - @Test - public void testSubscriberMessagesWhenNoMessagesFound() throws Exception { - final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); - when(subscriberResponse.getResponseCode()).thenReturn(200); - when(subscriberResponse.getResponseMessage()).thenReturn("no messages"); - when(subscriberResponse.getFetchedMessages()).thenReturn(Collections.emptyList()); - when(subscriber.fetchMessages()).thenReturn(subscriberResponse); - DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); - verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants - .DMAAP_MR_SUBSCRIBER_RESPONSES_WITH_NO_MESSAGES_METRIC), eq(1)); - } - - - @Test - public void testWhenSubscriberReturnNonSuccessfulReturnCode() throws Exception { - final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); - when(subscriberResponse.getResponseCode()).thenReturn(500); - when(subscriber.fetchMessages()).thenReturn(subscriberResponse); - DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); - verify(metrics, Mockito.times(1)).count(eq(CDAPMetricsConstants - .DMAAP_MR_SUBSCRIBER_UNSUCCESSFUL_RESPONSES_METRIC), eq(1)); - } - - @Test - public void testWhenSubscriberThrowsException() throws Exception { - final DMaaPMRSubscriberResponse subscriberResponse = mock(DMaaPMRSubscriberResponse.class); - when(subscriberResponse.getResponseCode()).thenReturn(500); - when(subscriber.fetchMessages()).thenThrow(DCAEAnalyticsRuntimeException.class); - DMaaPMRUtils.getSubscriberMessages(subscriber, metrics); - } - -} diff --git a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/utils/ValidationUtilsTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/utils/ValidationUtilsTest.java deleted file mode 100644 index 5344ca5..0000000 --- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/utils/ValidationUtilsTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * ===============================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.openecomp.dcae.apod.analytics.cdap.common.utils; - -import org.junit.Test; -import org.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest; -import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * @author Rajiv Singla . Creation Date: 12/12/2016. - */ -public class ValidationUtilsTest extends BaseAnalyticsCDAPCommonUnitTest { - - @Test - public void testIsEmptyWhenStringIsNull() throws Exception { - assertTrue(ValidationUtils.isEmpty(null)); - } - - @Test - public void testIsEmptyWhenStringIsEmpty() throws Exception { - String emptyString = ""; - assertTrue(ValidationUtils.isEmpty(emptyString)); - } - - @Test - public void testIsEmptyWhenStringIsEmptyWithBlanks() throws Exception { - String blankString = " "; - assertTrue(ValidationUtils.isEmpty(blankString)); - } - - - @Test - public void testIsNotPresent() throws Exception { - assertFalse(ValidationUtils.isPresent(null)); - String emptyString = ""; - assertFalse(ValidationUtils.isPresent(emptyString)); - String blankString = " "; - assertFalse(ValidationUtils.isPresent(blankString)); - String validString = "SomeValue"; - assertTrue(ValidationUtils.isPresent(validString)); - } - - @Test - public void testValidateSettingsWhenValidationPasses() throws Exception { - CDAPTestAppSettings cdapTestAppSettings = new CDAPTestAppSettings(); - cdapTestAppSettings.setSettingsField("testValue"); - ValidationUtils.validateSettings(cdapTestAppSettings, new CDAPTestAppSettingsValidator()); - } - - @Test(expected = CDAPSettingsException.class) - public void testValidateSettingsWhenValidationFails() throws Exception { - - CDAPTestAppSettings cdapTestAppSettings = new CDAPTestAppSettings(); - cdapTestAppSettings.setSettingsField(""); - ValidationUtils.validateSettings(cdapTestAppSettings, new CDAPTestAppSettingsValidator()); - } - -} - -- cgit 1.2.3-korg