From 06044df56fb07f4b368888581752855595e7b147 Mon Sep 17 00:00:00 2001 From: an4828 Date: Tue, 26 Sep 2017 14:35:17 -0400 Subject: TCA: Support for VES/A&AI enrichment Change-Id: I75e0f8e034b9334e918304739e4d73dd12c1ff62 Signed-off-by: an4828 Issue-ID: DCAEGEN2-116 --- .../common/BaseAnalyticsCommonUnitTest.java | 130 ++++----- .../filter/GenericJsonMessageFilterTest.java | 302 ++++++++++----------- .../processor/AbstractMessageProcessorTest.java | 136 +++++----- .../processor/AbstractProcessorContextTest.java | 158 +++++------ .../GenericMessageChainProcessorTest.java | 192 ++++++------- .../processor/GenericProcessorInfoTest.java | 106 ++++---- .../processor/TestEarlyTerminatingProcessor.java | 78 +++--- .../service/processor/TestMessageProcessor1.java | 82 +++--- .../service/processor/TestMessageProcessor2.java | 82 +++--- .../service/processor/TestProcessorContext.java | 168 ++++++------ .../apod/analytics/common/utils/HTTPUtilsTest.java | 96 +++---- .../common/utils/MessageProcessorUtilsTest.java | 124 ++++----- .../common/utils/PersistenceUtilsTest.java | 80 +++--- .../validation/GenericValidationResponseTest.java | 258 +++++++++--------- 14 files changed, 996 insertions(+), 996 deletions(-) (limited to 'dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics') diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java index 81c8b57..1cd59e8 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java @@ -1,65 +1,65 @@ -/* - * ===============================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.common; - -import org.openecomp.dcae.apod.analytics.common.service.processor.TestEarlyTerminatingProcessor; -import org.openecomp.dcae.apod.analytics.common.service.processor.TestMessageProcessor1; -import org.openecomp.dcae.apod.analytics.common.service.processor.TestMessageProcessor2; -import org.openecomp.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"; - - /* - * 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(); - } -} +/* + * ===============================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.common; + +import org.openecomp.dcae.apod.analytics.common.service.processor.TestEarlyTerminatingProcessor; +import org.openecomp.dcae.apod.analytics.common.service.processor.TestMessageProcessor1; +import org.openecomp.dcae.apod.analytics.common.service.processor.TestMessageProcessor2; +import org.openecomp.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"; + + /* + * 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/openecomp/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilterTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilterTest.java index db72a03..918407a 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilterTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilterTest.java @@ -1,151 +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.openecomp.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.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; -import org.openecomp.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(); - } -} +/* + * ===============================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.common.service.filter; + +import com.google.common.collect.ImmutableList; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; +import org.openecomp.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/openecomp/dcae/apod/analytics/common/service/processor/AbstractMessageProcessorTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractMessageProcessorTest.java index 6e8e146..5445150 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractMessageProcessorTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractMessageProcessorTest.java @@ -1,68 +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.openecomp.dcae.apod.analytics.common.service.processor; - -import org.junit.Test; -import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; -import org.openecomp.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)); - } - -} +/* + * ===============================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.common.service.processor; + +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; +import org.openecomp.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/openecomp/dcae/apod/analytics/common/service/processor/AbstractProcessorContextTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractProcessorContextTest.java index 6a4b500..b65a4f2 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractProcessorContextTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/AbstractProcessorContextTest.java @@ -1,79 +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.openecomp.dcae.apod.analytics.common.service.processor; - -import org.junit.Test; -import org.openecomp.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)); - } - -} +/* + * ===============================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.common.service.processor; + +import org.junit.Test; +import org.openecomp.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/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java index 2578406..afb3ed2 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericMessageChainProcessorTest.java @@ -1,96 +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.openecomp.dcae.apod.analytics.common.service.processor; - -import com.google.common.collect.ImmutableList; -import org.junit.Test; -import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; -import org.openecomp.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(); - } - -} +/* + * ===============================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.common.service.processor; + +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; +import org.openecomp.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/openecomp/dcae/apod/analytics/common/service/processor/GenericProcessorInfoTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericProcessorInfoTest.java index d52789e..eb7bae3 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericProcessorInfoTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/GenericProcessorInfoTest.java @@ -1,53 +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.openecomp.dcae.apod.analytics.common.service.processor; - -import org.junit.Test; -import org.openecomp.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)); - } - -} +/* + * ===============================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.common.service.processor; + +import org.junit.Test; +import org.openecomp.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/openecomp/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java index 814ea4b..807d890 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestEarlyTerminatingProcessor.java @@ -1,39 +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.openecomp.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; - } -} +/* + * ===============================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.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/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java index e8f8b0e..b663b69 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor1.java @@ -1,41 +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.openecomp.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; - } -} +/* + * ===============================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.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/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java index ce3a2dc..e8a29ff 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestMessageProcessor2.java @@ -1,41 +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.openecomp.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; - } -} +/* + * ===============================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.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/openecomp/dcae/apod/analytics/common/service/processor/TestProcessorContext.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestProcessorContext.java index 9ed7f4c..caaae82 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestProcessorContext.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/service/processor/TestProcessorContext.java @@ -1,84 +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.openecomp.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; - } - -} +/* + * ===============================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.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/openecomp/dcae/apod/analytics/common/utils/HTTPUtilsTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/utils/HTTPUtilsTest.java index 23cc4fb..9c5fe14 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/utils/HTTPUtilsTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/utils/HTTPUtilsTest.java @@ -1,48 +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.openecomp.dcae.apod.analytics.common.utils; - -import org.junit.Assert; -import org.junit.Test; -import org.openecomp.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)); - } - - -} +/* + * ===============================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.common.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.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/openecomp/dcae/apod/analytics/common/utils/MessageProcessorUtilsTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/utils/MessageProcessorUtilsTest.java index 5333150..1a44571 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/utils/MessageProcessorUtilsTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/utils/MessageProcessorUtilsTest.java @@ -1,62 +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.openecomp.dcae.apod.analytics.common.utils; - -import com.google.common.collect.ImmutableSet; -import org.junit.Assert; -import org.junit.Test; -import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; -import org.openecomp.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); - } - -} +/* + * ===============================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.common.utils; + +import com.google.common.collect.ImmutableSet; +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.dcae.apod.analytics.common.BaseAnalyticsCommonUnitTest; +import org.openecomp.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/openecomp/dcae/apod/analytics/common/utils/PersistenceUtilsTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/utils/PersistenceUtilsTest.java index d6d4ded..f8251b0 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/utils/PersistenceUtilsTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/utils/PersistenceUtilsTest.java @@ -1,40 +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.openecomp.dcae.apod.analytics.common.utils; - -import org.junit.Assert; -import org.junit.Test; -import org.openecomp.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); - } - -} +/* + * ===============================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.common.utils; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.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/openecomp/dcae/apod/analytics/common/validation/GenericValidationResponseTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/validation/GenericValidationResponseTest.java index fc2a27b..190dce7 100644 --- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/validation/GenericValidationResponseTest.java +++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/validation/GenericValidationResponseTest.java @@ -1,129 +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.openecomp.dcae.apod.analytics.common.validation; - -import org.junit.Test; -import org.openecomp.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; - } - -} +/* + * ===============================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.common.validation; + +import org.junit.Test; +import org.openecomp.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