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/BaseAnalyticsCommonUnitTest.java | 81 +++++++++++ .../filter/GenericJsonMessageFilterTest.java | 151 +++++++++++++++++++++ .../processor/AbstractMessageProcessorTest.java | 68 ++++++++++ .../processor/AbstractProcessorContextTest.java | 79 +++++++++++ .../GenericMessageChainProcessorTest.java | 96 +++++++++++++ .../processor/GenericProcessorInfoTest.java | 53 ++++++++ .../processor/TestEarlyTerminatingProcessor.java | 39 ++++++ .../service/processor/TestMessageProcessor1.java | 41 ++++++ .../service/processor/TestMessageProcessor2.java | 41 ++++++ .../service/processor/TestProcessorContext.java | 84 ++++++++++++ .../apod/analytics/common/utils/HTTPUtilsTest.java | 48 +++++++ .../common/utils/MessageProcessorUtilsTest.java | 62 +++++++++ .../common/utils/PersistenceUtilsTest.java | 40 ++++++ .../validation/GenericValidationResponseTest.java | 129 ++++++++++++++++++ 14 files changed, 1012 insertions(+) create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilterTest.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/AbstractMessageProcessorTest.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/AbstractProcessorContextTest.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/GenericProcessorInfoTest.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestProcessorContext.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/HTTPUtilsTest.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/MessageProcessorUtilsTest.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/PersistenceUtilsTest.java create mode 100644 dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/validation/GenericValidationResponseTest.java (limited to 'dcae-analytics-common/src/test/java/org/onap') diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java new file mode 100644 index 0000000..e30e0af --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java @@ -0,0 +1,81 @@ +/* + * ===============================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.common; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Suppliers; +import org.junit.BeforeClass; +import org.onap.dcae.apod.analytics.common.service.processor.TestEarlyTerminatingProcessor; +import org.onap.dcae.apod.analytics.common.service.processor.TestMessageProcessor1; +import org.onap.dcae.apod.analytics.common.service.processor.TestMessageProcessor2; +import org.onap.dcae.apod.analytics.model.util.json.AnalyticsModelObjectMapperSupplier; +import org.onap.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest; + +/** + * Base class from all DCEA Analytics Common Module Unit Tests + *

+ * @author Rajiv Singla . Creation Date: 10/6/2016. + */ +public abstract class BaseAnalyticsCommonUnitTest extends BaseDCAEAnalyticsUnitTest { + + + protected static final String TEST_MESSAGE_PROCESSOR_MESSAGE = "Test Processor Message"; + + protected static final String CEF_MESSAGE_FILE_PATH = "data/json/cef/cef_message.json"; + + protected static ObjectMapper objectMapper; + + /** + * Before running test cases need to assign object mapper. + */ + @BeforeClass + public static void beforeClass() { + final AnalyticsModelObjectMapperSupplier analyticsModelObjectMapperSupplier = + new AnalyticsModelObjectMapperSupplier(); + objectMapper = Suppliers.memoize(analyticsModelObjectMapperSupplier).get(); + } + + /* + * Test implementation for {@link CDAPAppSettings} + */ + protected class CDAPTestAppSettings { + + private String settingsField; + + public String getSettingsField() { + return settingsField; + } + + public void setSettingsField(String settingsField) { + this.settingsField = settingsField; + } + } + + protected TestMessageProcessor1 getTestMessageProcessor1() { + return new TestMessageProcessor1(); + } + protected TestMessageProcessor2 getTestMessageProcessor2() { + return new TestMessageProcessor2(); + } + protected TestEarlyTerminatingProcessor getTestEarlyTerminationProcessor() { + return new TestEarlyTerminatingProcessor(); + } +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilterTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilterTest.java new file mode 100644 index 0000000..bca3730 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilterTest.java @@ -0,0 +1,151 @@ +/* + * ===============================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.common.service.filter; + +import com.google.common.collect.ImmutableList; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onap.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; +import org.onap.dcae.apod.analytics.common.service.processor.GenericMessageChainProcessor; + +import static org.junit.Assert.assertEquals; + +/** + * @author Rajiv Singla . Creation Date: 2/10/2017. + */ +public class GenericJsonMessageFilterTest extends BaseAnalyticsCommonUnitTest { + + private String jsonMessage; + + @Before + public void before() throws Exception { + jsonMessage = fromStream(CEF_MESSAGE_FILE_PATH); + + } + + @Test + public void testJsonMessageFilterWhenAllFiltersPassed() throws Exception { + + final JsonMessageFilterProcessorContext finalMessageProcessorContext = + processJsonMessageFilterChain(jsonMessage, + "domainFilter", "$.event.commonEventHeader.domain", "measurementsForVfScaling", + "eventNameFilter", "$.event.commonEventHeader.eventName", "Mfvs_eNodeB_RANKPI"); + + assertJsonMessageAssertions(jsonMessage, finalMessageProcessorContext, true, true, 2); + + } + + @Test + public void testJsonMessageFilterWhenJsonPathValueIsANumber() throws Exception { + + final JsonMessageFilterProcessorContext finalMessageProcessorContext = + processJsonMessageFilterChain(jsonMessage, + "domainFilter", "$.event.commonEventHeader.sequence", "0", + "eventNameFilter", "$.event.commonEventHeader.eventName", "Mfvs_eNodeB_RANKPI"); + + assertJsonMessageAssertions(jsonMessage, finalMessageProcessorContext, true, true, 2); + } + + @Test + public void testJsonMessageFilterWhenOneFilterDoesNotMatch() throws Exception { + + final JsonMessageFilterProcessorContext finalMessageProcessorContext = + processJsonMessageFilterChain(jsonMessage, + "domainFilter", "$.event.commonEventHeader.domain", "xxxxxxxxxxx", + "functionalRoleFilter", "$.event.commonEventHeader.eventName", "vFirewall"); + + assertJsonMessageAssertions(jsonMessage, finalMessageProcessorContext, false, false, 1); + } + + @Test + public void testJsonMessageFilterWhenJsonPathDoesNotExist() throws Exception { + + final JsonMessageFilterProcessorContext finalMessageProcessorContext = + processJsonMessageFilterChain(jsonMessage, + "domainFilter", "$.event.commonEventHeader.xxxxxxx", "measurementsForVfScaling", + "functionalRoleFilter", "$.event.commonEventHeader.eventName", "vFirewall"); + + assertJsonMessageAssertions(jsonMessage, finalMessageProcessorContext, false, false, 1); + } + + @Test + public void testJsonMessageFilterWhenIncomingMessageIsBlank() throws Exception { + + final JsonMessageFilterProcessorContext finalMessageProcessorContext = + processJsonMessageFilterChain("", + "domainFilter", "$.event.commonEventHeader.domain", "measurementsForVfScaling", + "functionalRoleFilter", "$.event.commonEventHeader.eventName", "vFirewall"); + + assertJsonMessageAssertions("", finalMessageProcessorContext, false, null, 1); + + } + + @Test + public void testJsonMessageFilterWhenIncomingMessageIsNotValidJson() throws Exception { + + final JsonMessageFilterProcessorContext finalMessageProcessorContext = + processJsonMessageFilterChain("invalidJson", + "domainFilter", "$.event.commonEventHeader.domain", "measurementsForVfScaling", + "functionalRoleFilter", "$.event.commonEventHeader.eventName", "vFirewall"); + + assertJsonMessageAssertions("invalidJson", finalMessageProcessorContext, false, null, 1); + + } + + + private static void assertJsonMessageAssertions( + final String jsonMessage, final JsonMessageFilterProcessorContext finalMessageProcessorContext, + final Boolean canProcessingContinueFlag, final Boolean matchedFlag, + final int messageProcessorCount) throws Exception { + + assertJson(jsonMessage, finalMessageProcessorContext.getMessage()); + Assert.assertEquals(canProcessingContinueFlag, finalMessageProcessorContext.canProcessingContinue()); + assertEquals(matchedFlag, finalMessageProcessorContext.getMatched()); + Assert.assertEquals(finalMessageProcessorContext.getMessageProcessors().size(), messageProcessorCount); + + } + + + private static JsonMessageFilterProcessorContext processJsonMessageFilterChain( + final String jsonMessage, + final String firstFilterName, final String firstFilterPath, final String firstFilterValue, + final String secondFilterName, final String secondFilterPath, final String secondFilterValue) { + + // create processors + final GenericJsonMessageFilter firstFilter = new GenericJsonMessageFilter(firstFilterName, firstFilterPath, + firstFilterValue); + final GenericJsonMessageFilter secondFilter = new GenericJsonMessageFilter(secondFilterName, + secondFilterPath, secondFilterValue); + + // create initial processor context containing the json message that need to be processed + final JsonMessageFilterProcessorContext initialProcessorContext = + new JsonMessageFilterProcessorContext(jsonMessage); + + // create a generic message chain processor and feed it list of processors and initialProcessor context + final GenericMessageChainProcessor messageChainProcessor = + new GenericMessageChainProcessor<>(ImmutableList.of(firstFilter, secondFilter), + initialProcessorContext); + + // process the generic message chain + return messageChainProcessor.processChain(); + } +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/AbstractMessageProcessorTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/AbstractMessageProcessorTest.java new file mode 100644 index 0000000..ea7b2d6 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/AbstractMessageProcessorTest.java @@ -0,0 +1,68 @@ +/* + * ===============================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.common.service.processor; + +import org.junit.Test; +import org.onap.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; +import org.onap.dcae.apod.analytics.common.exception.MessageProcessingException; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +/** + * @author Rajiv Singla . Creation Date: 12/12/2016. + */ +public class AbstractMessageProcessorTest extends BaseAnalyticsCommonUnitTest { + + + @Test + public void testPreProcessorWhenProcessingContextFlagIsTrue() throws Exception { + TestMessageProcessor1 messageProcessor1 = new TestMessageProcessor1(); + final TestProcessorContext processorContext = + new TestProcessorContext(TEST_MESSAGE_PROCESSOR_MESSAGE, true); + final TestProcessorContext testProcessorContext = messageProcessor1.preProcessor(processorContext); + assertThat("Processing flag must be true", + testProcessorContext.canProcessingContinue(), is(true)); + } + + @Test(expected = MessageProcessingException.class) + public void testPreProcessorWhenProcessingContextFlagIsFalse() throws Exception { + TestMessageProcessor1 messageProcessor1 = new TestMessageProcessor1(); + final TestProcessorContext testProcessorContext = + new TestProcessorContext(TEST_MESSAGE_PROCESSOR_MESSAGE, false); + messageProcessor1.preProcessor(testProcessorContext); + } + + @Test + public void testPostProcessorWhenProcessingStateIsNotFinishedSuccessfully() throws Exception { + TestMessageProcessor1 messageProcessor1 = new TestMessageProcessor1(); + final ProcessingState processingState = messageProcessor1.getProcessingState(); + assertTrue("Processing state is not processing finished successfully", + processingState != ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY); + final TestProcessorContext processorContext = + new TestProcessorContext(TEST_MESSAGE_PROCESSOR_MESSAGE, true); + final TestProcessorContext testProcessorContext = messageProcessor1.postProcessor(processorContext); + assertThat("Processing flag must be false", + testProcessorContext.canProcessingContinue(), is(false)); + } + +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/AbstractProcessorContextTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/AbstractProcessorContextTest.java new file mode 100644 index 0000000..2710b75 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/AbstractProcessorContextTest.java @@ -0,0 +1,79 @@ +/* + * ===============================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.common.service.processor; + +import org.junit.Test; +import org.onap.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; + +import java.util.List; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author Rajiv Singla . Creation Date: 12/12/2016. + */ +public class AbstractProcessorContextTest extends BaseAnalyticsCommonUnitTest { + + class TestAbstractMessageProcessorContext extends AbstractProcessorContext { + + public TestAbstractMessageProcessorContext(String message, boolean canProcessingContinue) { + super(message, canProcessingContinue); + } + } + + + @Test + public void testGetMessage() throws Exception { + TestAbstractMessageProcessorContext testProcessorContext = + new TestAbstractMessageProcessorContext(TEST_MESSAGE_PROCESSOR_MESSAGE, true); + final String message = testProcessorContext.getMessage(); + assertThat("Message Processor message must match", message, is(TEST_MESSAGE_PROCESSOR_MESSAGE)); + } + + @Test + public void testCanProcessingContinue() throws Exception { + TestAbstractMessageProcessorContext testProcessorContext = + new TestAbstractMessageProcessorContext(TEST_MESSAGE_PROCESSOR_MESSAGE, true); + final boolean canProcessingContinue = testProcessorContext.canProcessingContinue(); + assertThat("Message Can Processing flag must be true", canProcessingContinue, is(true)); + } + + @Test + public void testSetProcessingContinueFlag() throws Exception { + TestAbstractMessageProcessorContext testProcessorContext = + new TestAbstractMessageProcessorContext(TEST_MESSAGE_PROCESSOR_MESSAGE, true); + testProcessorContext.setProcessingContinueFlag(false); + assertThat("Message Can processing flag must be false", + testProcessorContext.canProcessingContinue(), is(false)); + + } + + @Test + public void testGetMessageProcessors() throws Exception { + TestAbstractMessageProcessorContext testProcessorContext = + new TestAbstractMessageProcessorContext(TEST_MESSAGE_PROCESSOR_MESSAGE, true); + final List> messageProcessors = + testProcessorContext.getMessageProcessors(); + assertThat("Message processor processing message must match", messageProcessors.size(), is(0)); + } + +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java new file mode 100644 index 0000000..3a466c2 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java @@ -0,0 +1,96 @@ +/* + * ===============================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.common.service.processor; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.onap.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; +import org.onap.dcae.apod.analytics.common.exception.MessageProcessingException; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + + +/** + * + * @author Rajiv Singla . Creation Date: 11/8/2016. + */ +public class GenericMessageChainProcessorTest extends BaseAnalyticsCommonUnitTest { + + + @Test + public void testProcessChainWhenProcessChainHasNoEarlyTermination() throws Exception { + + final TestMessageProcessor1 testMessageProcessor1 = getTestMessageProcessor1(); + final TestMessageProcessor2 testMessageProcessor2 = getTestMessageProcessor2(); + final ImmutableList> testMessageChain = + ImmutableList.of(testMessageProcessor1, testMessageProcessor2); + + final TestProcessorContext testProcessorContext = new TestProcessorContext("Hello", true); + + final GenericMessageChainProcessor genericMessageChainProcessor = + new GenericMessageChainProcessor<>(testMessageChain, testProcessorContext); + + final TestProcessorContext finalProcessorContext = genericMessageChainProcessor.processChain(); + + final String result = finalProcessorContext.getResult(); + assertThat("Final Result must be Hello World! Again", result, is("Hello World! Again")); + assertThat("TestProcessor1 state is correct", testMessageProcessor1.getProcessingState(), + is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY)); + assertThat("TestProcessor2 state is correct", testMessageProcessor2.getProcessingState(), + is(ProcessingState.PROCESSING_FINISHED_SUCCESSFULLY)); + } + + + @Test + public void testProcessChainWhenProcessChainEarlyTermination() throws Exception { + + final TestEarlyTerminatingProcessor testEarlyTerminatingProcessor = getTestEarlyTerminationProcessor(); + final ImmutableList> testMessageChain = + ImmutableList.of(testEarlyTerminatingProcessor, getTestMessageProcessor2()); + final TestProcessorContext testProcessorContext = new TestProcessorContext("Hello", true); + + final GenericMessageChainProcessor genericMessageChainProcessor = + new GenericMessageChainProcessor<>(testMessageChain, testProcessorContext); + + final TestProcessorContext finalProcessorContext = genericMessageChainProcessor.processChain(); + final String result = finalProcessorContext.getResult(); + assertNull("Final Result must be null", result); + assertThat("TestEarlyTerminatingProcessor state is correct", + testEarlyTerminatingProcessor.getProcessingState(), is(ProcessingState.PROCESSING_TERMINATED_EARLY)); + } + + @Test(expected = MessageProcessingException.class) + public void testProcessChainWhenIncomingMessageContextIsNull() throws Exception { + + final TestEarlyTerminatingProcessor testEarlyTerminatingProcessor = getTestEarlyTerminationProcessor(); + final ImmutableList> testMessageChain = + ImmutableList.of(testEarlyTerminatingProcessor, getTestMessageProcessor2()); + final TestProcessorContext testProcessorContext = null; + + final GenericMessageChainProcessor genericMessageChainProcessor = + new GenericMessageChainProcessor<>(testMessageChain, testProcessorContext); + + genericMessageChainProcessor.processChain(); + } + +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/GenericProcessorInfoTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/GenericProcessorInfoTest.java new file mode 100644 index 0000000..f0bc30e --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/GenericProcessorInfoTest.java @@ -0,0 +1,53 @@ +/* + * ===============================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.common.service.processor; + +import org.junit.Test; +import org.onap.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author Rajiv Singla . Creation Date: 12/12/2016. + */ +public class GenericProcessorInfoTest extends BaseAnalyticsCommonUnitTest { + + + @Test + public void getProcessorName() throws Exception { + final String processorName = "testProcessorName"; + final String processorDescription = "testProcessorDescription"; + GenericProcessorInfo genericProcessorInfo = new GenericProcessorInfo(processorName, processorDescription); + assertThat("Processor Name must match", genericProcessorInfo.getProcessorName(), is(processorName)); + + } + + @Test + public void getProcessorDescription() throws Exception { + final String processorName = "testProcessorName"; + final String processorDescription = "testProcessorDescription"; + GenericProcessorInfo genericProcessorInfo = new GenericProcessorInfo(processorName, processorDescription); + assertThat("Processor Description must match", genericProcessorInfo.getProcessorDescription(), + is(processorDescription)); + } + +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java new file mode 100644 index 0000000..80d2341 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java @@ -0,0 +1,39 @@ +/* + * ===============================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.common.service.processor; + +/** + * + * @author Rajiv Singla . Creation Date: 11/8/2016. + */ +public class TestEarlyTerminatingProcessor extends AbstractMessageProcessor { + + @Override + public String getProcessorDescription() { + return "Terminates the chain early"; + } + + @Override + public TestProcessorContext processMessage(TestProcessorContext processorContext) { + setTerminatingProcessingMessage("Terminating early", processorContext); + return processorContext; + } +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java new file mode 100644 index 0000000..4850ad5 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java @@ -0,0 +1,41 @@ +/* + * ===============================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.common.service.processor; + +/** + * + * @author Rajiv Singla . Creation Date: 11/8/2016. + */ +public class TestMessageProcessor1 extends AbstractMessageProcessor { + + @Override + public String getProcessorDescription() { + return "Appends \" World!\" to the message string and set it to result string"; + } + + @Override + public TestProcessorContext processMessage(TestProcessorContext processorContext) { + final String message = processorContext.getMessage(); + processorContext.setResult(message + " World!"); + setFinishedProcessingMessage("Finished Appending world", processorContext); + return processorContext; + } +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java new file mode 100644 index 0000000..7c0312a --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java @@ -0,0 +1,41 @@ +/* + * ===============================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.common.service.processor; + +/** + * + * @author Rajiv Singla . Creation Date: 11/8/2016. + */ +public class TestMessageProcessor2 extends AbstractMessageProcessor { + + @Override + public String getProcessorDescription() { + return "Appends \" Again\" to the result string"; + } + + @Override + public TestProcessorContext processMessage(TestProcessorContext processorContext) { + final String result = processorContext.getResult(); + processorContext.setResult(result + " Again"); + setFinishedProcessingMessage("Finished Appending again to result", processorContext); + return processorContext; + } +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestProcessorContext.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestProcessorContext.java new file mode 100644 index 0000000..6f849f5 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/service/processor/TestProcessorContext.java @@ -0,0 +1,84 @@ +/* + * ===============================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.common.service.processor; + +import java.util.LinkedList; +import java.util.List; + +/** + * + * @author Rajiv Singla . Creation Date: 11/8/2016. + */ +public class TestProcessorContext implements ProcessorContext { + + private String message; + private boolean continueProcessingFlag; + private String result; + private List> messageProcessors; + + public TestProcessorContext(String message, boolean continueProcessingFlag) { + this.message = message; + this.continueProcessingFlag = continueProcessingFlag; + this.messageProcessors = new LinkedList<>(); + } + + @Override + public String getMessage() { + return message; + } + + @Override + public boolean canProcessingContinue() { + return continueProcessingFlag; + } + + @Override + public void setProcessingContinueFlag(boolean canProcessingContinue) { + this.continueProcessingFlag = canProcessingContinue; + } + + @Override + public List> getMessageProcessors() { + return messageProcessors; + } + + + public void setMessage(String message) { + this.message = message; + } + + public boolean isContinueProcessingFlag() { + return continueProcessingFlag; + } + + public void setContinueProcessingFlag(boolean continueProcessingFlag) { + this.continueProcessingFlag = continueProcessingFlag; + } + + public String getResult() { + return result; + } + + public void setResult(String result) { + this.result = result; + } + +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/HTTPUtilsTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/HTTPUtilsTest.java new file mode 100644 index 0000000..0e02c2a --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/HTTPUtilsTest.java @@ -0,0 +1,48 @@ +/* + * ===============================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.common.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; + +import static org.hamcrest.CoreMatchers.is; + +/** + * @author Rajiv Singla . Creation Date: 12/12/2016. + */ +public class HTTPUtilsTest extends BaseAnalyticsCommonUnitTest { + + + @Test + public void testIsSuccessfulResponseCodeWhenResponseCodeIsSuccessful() throws Exception { + final boolean successfulResponseCode = HTTPUtils.isSuccessfulResponseCode(200); + Assert.assertThat("200 Response code must return true", successfulResponseCode, is(true)); + } + + @Test + public void testIsSuccessfulResponseCodeWhenResponseCodeIsNotSuccessful() throws Exception { + final boolean successfulResponseCode = HTTPUtils.isSuccessfulResponseCode(301); + Assert.assertThat("301 Response code must return false", successfulResponseCode, is(false)); + } + + +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/MessageProcessorUtilsTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/MessageProcessorUtilsTest.java new file mode 100644 index 0000000..5edf851 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/MessageProcessorUtilsTest.java @@ -0,0 +1,62 @@ +/* + * ===============================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.common.utils; + +import com.google.common.collect.ImmutableSet; +import org.junit.Assert; +import org.junit.Test; +import org.onap.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; +import org.onap.dcae.apod.analytics.common.service.filter.JsonMessageFilterProcessorContext; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * @author Rajiv Singla . Creation Date: 3/3/2017. + */ +public class MessageProcessorUtilsTest extends BaseAnalyticsCommonUnitTest { + + + @Test + public void testProcessJsonFilterMappings() throws Exception { + final String jsonMessage = fromStream(CEF_MESSAGE_FILE_PATH); + + final Map> jsonFilterMappings = new HashMap<>(); + jsonFilterMappings.put("$.event.commonEventHeader.domain", ImmutableSet.of("measurementsForVfScaling")); + jsonFilterMappings.put("$.event.commonEventHeader.eventName", + ImmutableSet.of("vFirewall", "vLoadBalancer", "Mfvs_eNodeB_RANKPI")); + + final JsonMessageFilterProcessorContext jsonMessageFilterProcessorContext = + MessageProcessorUtils.processJsonFilterMappings(jsonMessage, jsonFilterMappings); + final Boolean matched = jsonMessageFilterProcessorContext.getMatched(); + Assert.assertNotNull(matched); + Assert.assertTrue(matched); + } + + @Test(expected = IllegalStateException.class) + public void testProcessJsonFilterMappingsWhenMappingsAreEmpty() throws Exception { + final String jsonMessage = fromStream(CEF_MESSAGE_FILE_PATH); + final Map> jsonFilterMappings = new HashMap<>(); + MessageProcessorUtils.processJsonFilterMappings(jsonMessage, jsonFilterMappings); + } + +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/PersistenceUtilsTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/PersistenceUtilsTest.java new file mode 100644 index 0000000..54e3770 --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/utils/PersistenceUtilsTest.java @@ -0,0 +1,40 @@ +/* + * ===============================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.common.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; + +/** + * @author Rajiv Singla . Creation Date: 12/12/2016. + */ +public class PersistenceUtilsTest extends BaseAnalyticsCommonUnitTest { + + @Test + public void testGetCurrentTimeReverseSubKey() throws Exception { + + final String currentTimeReverseSubKey = PersistenceUtils.getCurrentTimeReverseSubKey(); + Assert.assertNotNull("Sub Key must not be null", currentTimeReverseSubKey); + Assert.assertTrue("Sub Key Length must be 25", currentTimeReverseSubKey.length() == 25); + } + +} diff --git a/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/validation/GenericValidationResponseTest.java b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/validation/GenericValidationResponseTest.java new file mode 100644 index 0000000..e8e505e --- /dev/null +++ b/dcae-analytics-common/src/test/java/org/onap/dcae/apod/analytics/common/validation/GenericValidationResponseTest.java @@ -0,0 +1,129 @@ +/* + * ===============================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.common.validation; + +import org.junit.Test; +import org.onap.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * @author Rajiv Singla . Creation Date: 12/12/2016. + */ +public class GenericValidationResponseTest extends BaseAnalyticsCommonUnitTest { + + + @Test + public void testHasErrorsWhenResponseHasErrors() throws Exception { + + final String fieldName = "testField"; + final String errorMessage = "Some error message"; + final GenericValidationResponse validationResponse = + createTestValidationResponse(fieldName, errorMessage); + + validationResponse.addErrorMessage("testField", "Some error message"); + assertThat("Validation Response must has errors", validationResponse.hasErrors(), is(true)); + } + + @Test + public void testHasErrorsWhenResponseDoesNotHaveErrors() throws Exception { + GenericValidationResponse validationResponse = new + GenericValidationResponse<>(); + assertThat("Validation Response must has errors", validationResponse.hasErrors(), is(false)); + } + + @Test + public void testGetFieldNamesWithError() throws Exception { + + final String fieldName = "testField"; + final String errorMessage = "Some error message"; + final GenericValidationResponse validationResponse = + createTestValidationResponse(fieldName, errorMessage); + + assertThat("Validation Response must has errors", validationResponse.hasErrors(), is(true)); + assertThat("Validation Field Name must match", + validationResponse.getFieldNamesWithError().iterator().next(), is(fieldName)); + } + + @Test + public void testGetErrorMessages() throws Exception { + + final String fieldName = "testField"; + final String errorMessage = "Some error message"; + final GenericValidationResponse validationResponse = + createTestValidationResponse(fieldName, errorMessage); + + assertThat("Validation Response must has errors", validationResponse.hasErrors(), is(true)); + assertThat("Validation Error Message must match", + validationResponse.getErrorMessages().iterator().next(), is(errorMessage)); + } + + @Test + public void getValidationResultsAsMap() throws Exception { + final String fieldName = "testField"; + final String errorMessage = "Some error message"; + final GenericValidationResponse validationResponse = + createTestValidationResponse(fieldName, errorMessage); + assertThat("Validation Response must has errors", validationResponse.hasErrors(), is(true)); + assertThat("Validation Field Name must match", + validationResponse.getValidationResultsAsMap().keySet().iterator().next(), is(fieldName)); + assertThat("Validation Error Message must match", + validationResponse.getValidationResultsAsMap().values().iterator().next(), is(errorMessage)); + } + + @Test + public void getAllErrorMessage() throws Exception { + final String fieldName = "testField"; + final String errorMessage = "Some error message"; + final GenericValidationResponse validationResponse = + createTestValidationResponse(fieldName, errorMessage); + final String allErrorMessage = validationResponse.getAllErrorMessage(); + assertThat("All Error messages should match", allErrorMessage, is(errorMessage)); + } + + @Test + public void addErrorMessage() throws Exception { + final String fieldName = "testField"; + final String errorMessage = "Some error message"; + GenericValidationResponse validationResponse = new + GenericValidationResponse<>(); + validationResponse.addErrorMessage(fieldName, errorMessage); + + assertThat("Validation Response must has errors", validationResponse.hasErrors(), is(true)); + assertThat("Validation Field Name must match", + validationResponse.getValidationResultsAsMap().keySet().iterator().next(), is(fieldName)); + assertThat("Validation Error Message must match", + validationResponse.getValidationResultsAsMap().values().iterator().next(), is(errorMessage)); + } + + private static GenericValidationResponse createTestValidationResponse( + final String fieldName, final String errorMessage) { + GenericValidationResponse validationResponse = new + GenericValidationResponse<>(); + if (fieldName != null || errorMessage != null) { + validationResponse.addErrorMessage(fieldName, errorMessage); + } + + return validationResponse; + } + +} -- cgit 1.2.3-korg