diff options
author | an4828 <nekrassov@att.com> | 2017-08-21 11:05:08 -0400 |
---|---|---|
committer | Lusheng Ji <lji@research.att.com> | 2017-08-24 00:56:45 +0000 |
commit | e86be39dc5ff812b73398e0720aa3fbf0c48213c (patch) | |
tree | fe3198f180128163490c14c66a1d6074760b220b /dcae-analytics-cdap-common/src/test | |
parent | ff6a13c7ce03ec95fba9d0b4f04b74d0bfeb6a47 (diff) |
Initial TCA commit into DCAEGEN2
Change-Id: I5f7f8af2a00419854cafc34b79277df60d1af095
Issue-ID: DCAEGEN2-53
Signed-off-by: an4828 <nekrassov@att.com>
Diffstat (limited to 'dcae-analytics-cdap-common/src/test')
10 files changed, 712 insertions, 0 deletions
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 new file mode 100644 index 0000000..825cdf0 --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/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.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_message.json"; + protected static final String TCA_POLICY_FILE_LOCATION = "data/json/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<CDAPTestAppSettings, + GenericValidationResponse<CDAPTestAppSettings>> { + + private static final long serialVersionUID = 1L; + + @Override + public GenericValidationResponse<CDAPTestAppSettings> + validateAppSettings(CDAPTestAppSettings cdapTestAppSettings) { + GenericValidationResponse<CDAPTestAppSettings> 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/TCACalculatorMessageTypeTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCACalculatorMessageTypeTest.java new file mode 100644 index 0000000..ce2fc21 --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/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.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 new file mode 100644 index 0000000..a062b37 --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java @@ -0,0 +1,127 @@ +/* + * ===============================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.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.MetricsPerFunctionalRole; +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 String TEST_DOMAIN = "TEST_DOMAIN"; + private static final String TEST_FUNCTIONAL_ROLE = "TEST_FUNCIONAL_ROLE"; + + private ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable; + private TCACEFProcessorContext processorContext; + private EventListener eventListener; + private Event event; + private CommonEventHeader commonEventHeader; + private String functionalRole; + + + @Before + 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.getFunctionalRole()).thenReturn(TEST_FUNCTIONAL_ROLE); + 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 MetricsPerFunctionalRole metricsPerFunctionalRole = mock(MetricsPerFunctionalRole.class); + final Threshold threshold = mock(Threshold.class); + when(processorContext.getMetricsPerFunctionalRole()).thenReturn(metricsPerFunctionalRole); + when((metricsPerFunctionalRole.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 new file mode 100644 index 0000000..97fea09 --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/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.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<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)); + } + +} 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 new file mode 100644 index 0000000..d22f736 --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/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.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 new file mode 100644 index 0000000..f9c7eaf --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/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.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.<String>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 new file mode 100644 index 0000000..4441451 --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/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.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()); + } + +} + diff --git a/dcae-analytics-cdap-common/src/test/resources/data/json/cef_message.json b/dcae-analytics-cdap-common/src/test/resources/data/json/cef_message.json new file mode 100644 index 0000000..52cf53b --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/resources/data/json/cef_message.json @@ -0,0 +1,37 @@ +{ + "event": { + "measurementsForVfScalingFields": { + "measurementInterval": 10, + "measurementsForVfScalingVersion": 1.1, + "vNicUsageArray": [ + { + "bytesIn": 6086, + "multicastPacketsIn": 0, + "multicastPacketsOut": 0, + "unicastPacketsIn": 0, + "broadcastPacketsOut": 0, + "packetsOut": 42, + "bytesOut": 7156, + "packetsIn": 93, + "broadcastPacketsIn": 0, + "vNicIdentifier": "eth0", + "unicastPacketsOut": 0 + } + ] + }, + "commonEventHeader": { + "reportingEntityName": "vpp-test", + "startEpochMicrosec": 1477070210290442, + "eventId": "375", + "lastEpochMicrosec": 1477070220290442, + "priority": "Normal", + "sequence": 375, + "sourceName": "Dummy VM name - No Metadata available", + "domain": "measurementsForVfScaling", + "functionalRole": "vFirewall", + "reportingEntityId": "No UUID available", + "version": 1.1, + "sourceId": "Dummy VM UUID - No Metadata available" + } + } +} diff --git a/dcae-analytics-cdap-common/src/test/resources/data/json/tca_policy.json b/dcae-analytics-cdap-common/src/test/resources/data/json/tca_policy.json new file mode 100644 index 0000000..1bf9e83 --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/resources/data/json/tca_policy.json @@ -0,0 +1,53 @@ +{ + "domain": "measurementsForVfScaling", + "metricsPerFunctionalRole": [ + { + "functionalRole": "vFirewall", + "policyScope": "resource=vFirewall;type=configuration", + "policyName": "configuration.dcae.microservice.tca.xml", + "policyVersion": "v0.0.1", + "thresholds": [ + { + "closedLoopControlName": "CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.vNicUsageArray[*].bytesIn", + "thresholdValue": 4000, + "direction": "LESS_OR_EQUAL", + "severity": "MAJOR" + }, + { + "closedLoopControlName": "CL-FRWL-HIGH-TRAFFIC-SIG-EA36FE84-9342-5E13-A656-EC5F21309A09", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.vNicUsageArray[*].bytesIn", + "thresholdValue": 20000, + "direction": "GREATER_OR_EQUAL", + "severity": "CRITICAL" + } + ] + }, + { + "functionalRole": "vLoadBalancer", + "policyScope": "resource=vLoadBalancer;type=configuration", + "policyName": "configuration.dcae.microservice.tca.xml", + "policyVersion": "v0.0.1", + "thresholds": [ + { + "closedLoopControlName": "CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn", + "thresholdValue": 500, + "direction": "LESS_OR_EQUAL", + "severity": "MAJOR" + }, + { + "closedLoopControlName": "CL-LBAL-LOW-TRAFFIC-SIG-0C5920A6-B564-8035-C878-0E814352BC2B", + "version": "1.0.2", + "fieldPath": "$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn", + "thresholdValue": 5000, + "direction": "GREATER_OR_EQUAL", + "severity": "CRITICAL" + } + ] + } + ] +} diff --git a/dcae-analytics-cdap-common/src/test/resources/logback-test.xml b/dcae-analytics-cdap-common/src/test/resources/logback-test.xml new file mode 100644 index 0000000..f6d96bf --- /dev/null +++ b/dcae-analytics-cdap-common/src/test/resources/logback-test.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + ~ ===============================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=========================================== + --> +<configuration> + + <!-- + Disabling some chatty loggers. + --> + <logger name="org.apache.commons.beanutils" level="ERROR"/> + <logger name="org.apache.zookeeper.server" level="ERROR"/> + <logger name="org.apache.zookeeper" level="ERROR"/> + <logger name="com.ning" level="WARN"/> + <logger name="org.apache.spark" level="WARN"/> + <logger name="org.spark-project" level="WARN"/> + <logger name="org.apache.hadoop" level="WARN"/> + <logger name="org.apache.hive" level="WARN"/> + <logger name="org.quartz.core" level="WARN"/> + <logger name="org.eclipse.jetty" level="WARN"/> + <logger name="io.netty.util.internal" level="WARN"/> + + <logger name="org.apache.twill" level="WARN"/> + <logger name="co.cask.cdap" level="INFO"/> + <logger name="org.openecomp.dcae.apod.analytics" level="DEBUG"/> + + <appender name="Console" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n</pattern> + </encoder> + </appender> + + <root level="ERROR"> + <appender-ref ref="Console"/> + </root> + + +</configuration> + |