From 952fa4a24a47b648b68f6d86b73e2cc05e044d46 Mon Sep 17 00:00:00 2001 From: Vijay Venkatesh Kumar Date: Fri, 20 Jan 2023 15:31:48 -0500 Subject: VESCollector Test optimization Fix test failure in win Add check for docker\linux dependency on related test Change-Id: I5be1fa860a69fc6479d9c0b202eabbb0336ea0c4 Signed-off-by: Vijay Venkatesh Kumar Issue-ID: DCAEGEN2-3334 Signed-off-by: Vijay Venkatesh Kumar --- Changelog.md | 4 +- pom.xml | 5 +-- .../java/org/onap/dcae/ApplicationSettings.java | 5 ++- .../org/onap/dcae/ApplicationSettingsTest.java | 46 ++++++++++++++++------ .../java/org/onap/dcae/common/EventSenderTest.java | 13 +++--- .../java/org/onap/dcae/common/JsonDataLoader.java | 14 ++++--- .../org/onap/dcae/common/model/VesEventTest.java | 14 ++++--- .../dcae/common/publishing/DMaapContainer.java | 20 ++++++++-- .../onap/dcae/common/publishing/PublisherTest.java | 16 ++++++-- .../validator/StndDefinedDataValidatorTest.java | 19 ++++++--- .../MultipleStreamReducerTest.java | 12 ++++-- .../onap/dcae/restapi/VesRestControllerTest.java | 35 +++++++++------- version.properties | 2 +- 13 files changed, 139 insertions(+), 66 deletions(-) diff --git a/Changelog.md b/Changelog.md index 1a317ab4..0bcc63d0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,7 +3,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). - +## [1.12.2] - 2023/01/20 + - [DCAEGEN2-3334] - Update tests execution to be platform agnostic + ## [1.12.1] - 2022/12/05 - [DCAEGEN2-3257] - Align DCAE components with the new logging GR. diff --git a/pom.xml b/pom.xml index 1b460601..213f63e6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ ============LICENSE_START======================================================= dcaegen2-collectors-ves ================================================================================ - Copyright (c) 2017-2019,2021-2022 AT&T Intellectual Property. All rights reserved. + Copyright (c) 2017-2019,2021-2023 AT&T Intellectual Property. All rights reserved. Copyright (c) 2020-2022 Nokia. All rights reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -22,11 +22,10 @@ org.onap.oparent oparent 3.2.0 - org.onap.dcaegen2.collectors.ves VESCollector - 1.12.1-SNAPSHOT + 1.12.2-SNAPSHOT dcaegen2-collectors-ves VESCollector diff --git a/src/main/java/org/onap/dcae/ApplicationSettings.java b/src/main/java/org/onap/dcae/ApplicationSettings.java index 0acbbe26..303fb008 100644 --- a/src/main/java/org/onap/dcae/ApplicationSettings.java +++ b/src/main/java/org/onap/dcae/ApplicationSettings.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * VES Collector * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017,2023 AT&T Intellectual Property. All rights reserved. * Copyright (C) 2018 - 2021 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -80,7 +80,8 @@ public class ApplicationSettings { loadPropertiesFromFile(); parsedArgs.filterKeys(k -> !"c".equals(k)).forEach(this::addOrUpdate); String collectorSchemaFile = properties.getString("collector.schema.file", - format("{\"%s\":\"etc/CommonEventFormat_28.4.1.json\"}", FALLBACK_VES_VERSION)); + format("{\"%s\":\"./etc/CommonEventFormat_28.4.1.json\"}", FALLBACK_VES_VERSION)); + loadedJsonSchemas = new JSonSchemasSupplier().loadJsonSchemas(collectorSchemaFile); eventTransformations = loadEventTransformations(); responseCompatibility = getResponseCompatibilityFlag(); diff --git a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java index d5877619..f35bc1d8 100644 --- a/src/test/java/org/onap/dcae/ApplicationSettingsTest.java +++ b/src/test/java/org/onap/dcae/ApplicationSettingsTest.java @@ -3,7 +3,7 @@ * org.onap.dcaegen2.collectors.ves * ================================================================================ * Copyright (C) 2018 - 2021 Nokia. All rights reserved. - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018,2023 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. @@ -31,6 +31,8 @@ import org.junit.Test; import java.io.File; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -46,6 +48,16 @@ import static org.onap.dcae.CLIUtils.processCmdLine; import static org.onap.dcae.TestingUtilities.createTemporaryFile; public class ApplicationSettingsTest { + + /** + * The Unix separator character. + */ + private static final char UNIX_SEPARATOR = '/'; + + /** + * The Windows separator character. + */ + private static final char WINDOWS_SEPARATOR = '\\'; private static final String SAMPLE_JSON_SCHEMA = "{" + " \"type\": \"object\"," @@ -53,6 +65,19 @@ public class ApplicationSettingsTest { + " \"state\": { \"type\": \"string\" }" + " }" + "}"; + + /** + * Converts all separators to the Unix separator of forward slash. + * + * @param path the path to be changed, null ignored + * @return the updated path + */ + private static String separatorsToUnix(final String path) { + if (path == null || path.indexOf(WINDOWS_SEPARATOR) == -1) { + return path; + } + return path.replace(WINDOWS_SEPARATOR, UNIX_SEPARATOR); + } @Test public void shouldMakeApplicationSettingsOutOfCLIArguments() { @@ -113,7 +138,6 @@ public class ApplicationSettingsTest { // when int applicationPort = fromTemporaryConfiguration("collector.service.port=8090") .httpPort(); - // then assertEquals(8090, applicationPort); } @@ -252,13 +276,13 @@ public class ApplicationSettingsTest { } @Test - public void shouldReportValidateJSONSchemaErrorWhenJsonContainsIntegerValueNotString() throws IOException { + public void shouldReportValidateJSONSchemaErrorWhenJsonContainsIntegerValueNotString() throws IOException, URISyntaxException { // when Path temporarySchemaFile = createTemporaryFile(SAMPLE_JSON_SCHEMA); - + String normalizedSchemaFile = separatorsToUnix(temporarySchemaFile.toString()); // when JsonSchema schema = fromTemporaryConfiguration( - String.format("collector.schema.file={\"v1\": \"%s\"}", temporarySchemaFile)) + String.format("collector.schema.file={\"v1\": \"%s\"}", normalizedSchemaFile)) .jsonSchema("v1"); // then @@ -272,10 +296,10 @@ public class ApplicationSettingsTest { public void shouldDoNotReportAnyValidateJSONSchemaError() throws IOException { // when Path temporarySchemaFile = createTemporaryFile(SAMPLE_JSON_SCHEMA); - + String normalizedSchemaFile = separatorsToUnix(temporarySchemaFile.toString()); // when JsonSchema schema = fromTemporaryConfiguration( - String.format("collector.schema.file={\"v1\": \"%s\"}", temporarySchemaFile)) + String.format("collector.schema.file={\"v1\": \"%s\"}", normalizedSchemaFile)) .jsonSchema("v1"); // then @@ -409,7 +433,7 @@ public class ApplicationSettingsTest { .getExternalSchemaSchemasLocation(); //then - assertEquals(sanitizePath("./etc/externalRepo"), externalSchemaSchemasLocation); + assertEquals("./etc/externalRepo", externalSchemaSchemasLocation); } @Test @@ -419,7 +443,7 @@ public class ApplicationSettingsTest { .getExternalSchemaMappingFileLocation(); //then - assertEquals(sanitizePath("./etc/externalRepo/schema-map.json"), externalSchemaMappingFileLocation); + assertEquals("./etc/externalRepo/schema-map.json", externalSchemaMappingFileLocation); } @Test @@ -429,7 +453,7 @@ public class ApplicationSettingsTest { .getExternalSchemaSchemaRefPath(); //then - assertEquals(sanitizePath("/event/stndDefinedFields/schemaReference"), externalSchemaSchemaRefPath); + assertEquals("/event/stndDefinedFields/schemaReference", externalSchemaSchemaRefPath); } @Test @@ -439,7 +463,7 @@ public class ApplicationSettingsTest { .getExternalSchemaStndDefinedDataPath(); //then - assertEquals(sanitizePath("/event/stndDefinedFields/data"), externalSchemaStndDefinedDataPath); + assertEquals("/event/stndDefinedFields/data", externalSchemaStndDefinedDataPath); } @Test diff --git a/src/test/java/org/onap/dcae/common/EventSenderTest.java b/src/test/java/org/onap/dcae/common/EventSenderTest.java index 6d508d0a..b0e5d494 100644 --- a/src/test/java/org/onap/dcae/common/EventSenderTest.java +++ b/src/test/java/org/onap/dcae/common/EventSenderTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * VES Collector * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017,2023 AT&T Intellectual Property. All rights reserved. * Copyright (C) 2018-2021 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,6 +32,7 @@ import org.onap.dcae.common.publishing.DMaaPEventPublisher; import org.onap.dcae.restapi.EventValidatorException; import java.io.IOException; +import java.net.URISyntaxException; import java.util.List; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -48,7 +49,7 @@ public class EventSenderTest { @Test - public void shouldNotSendEventWhenStreamIdIsNotDefined() throws IOException { + public void shouldNotSendEventWhenStreamIdIsNotDefined() throws IOException, URISyntaxException { // given EventSender eventSender = givenConfiguredEventSender(HashMap.empty()); List eventToSend = createEventToSend("/eventsAfterTransformation/ves7_valid_event.json"); @@ -62,7 +63,7 @@ public class EventSenderTest { } @Test - public void shouldSendStdDefinedEventAtStreamAssignedToEventDomain() throws IOException { + public void shouldSendStdDefinedEventAtStreamAssignedToEventDomain() throws IOException, URISyntaxException { // given EventSender eventSender = givenConfiguredEventSender( HashMap.of("3GPP-FaultSupervision", "ves-3gpp-fault-supervision") @@ -77,7 +78,7 @@ public class EventSenderTest { } @Test - public void shouldNotSendStndEventWhenStreamIsNotDefined() throws IOException { + public void shouldNotSendStndEventWhenStreamIsNotDefined() throws IOException, URISyntaxException { // given EventSender eventSender = givenConfiguredEventSender(HashMap.empty()); List eventToSend = createEventToSend("/eventsAfterTransformation/ves_stdnDefined_valid.json"); @@ -91,7 +92,7 @@ public class EventSenderTest { } @Test - public void shouldReportThatNoStndDefinedNamespaceParameterIsDefinedInEvent() throws IOException { + public void shouldReportThatNoStndDefinedNamespaceParameterIsDefinedInEvent() throws IOException, URISyntaxException { // given EventSender eventSender = givenConfiguredEventSender(HashMap.empty()); List eventToSend = createEventToSend( @@ -106,7 +107,7 @@ public class EventSenderTest { verifyThatEventWasNotSendAtStream(); } - private List createEventToSend(String path) throws IOException { + private List createEventToSend(String path) throws IOException, URISyntaxException { String event = JsonDataLoader.loadContent(path); return givenEventToSend(event); } diff --git a/src/test/java/org/onap/dcae/common/JsonDataLoader.java b/src/test/java/org/onap/dcae/common/JsonDataLoader.java index 8c2fdd6d..fd06025a 100644 --- a/src/test/java/org/onap/dcae/common/JsonDataLoader.java +++ b/src/test/java/org/onap/dcae/common/JsonDataLoader.java @@ -2,7 +2,8 @@ * ============LICENSE_START======================================================= * VES Collector * ================================================================================ - * Copyright (C) 2020 Nokia. All rights reserved.s + * Copyright (C) 2020 Nokia. All rights reserved. + * Copyright (C) 2023 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. @@ -20,6 +21,8 @@ package org.onap.dcae.common; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -27,7 +30,7 @@ import java.nio.file.Paths; /** * This class is static and does not have public constructor. - * It is responsible for data loading fot test cases. + * It is responsible for data loading for test cases. * * @author Zebek */ @@ -42,10 +45,11 @@ public final class JsonDataLoader { * @param path to file that will be loaded * @return contend of the file located under path, given in parameters, as string * @throws IOException when file under given path was not found + * @throws URISyntaxException */ - public static String loadContent(String path) throws IOException { - URL resource = JsonDataLoader.class.getResource(path); - Path resourcePath = Paths.get(resource.getPath()); + public static String loadContent(String path) throws IOException, URISyntaxException { + URI resource = JsonDataLoader.class.getResource(path).toURI(); + Path resourcePath = Paths.get(resource); return new String(Files.readAllBytes(resourcePath)); } } diff --git a/src/test/java/org/onap/dcae/common/model/VesEventTest.java b/src/test/java/org/onap/dcae/common/model/VesEventTest.java index c66e0a9b..be0cf088 100644 --- a/src/test/java/org/onap/dcae/common/model/VesEventTest.java +++ b/src/test/java/org/onap/dcae/common/model/VesEventTest.java @@ -2,7 +2,8 @@ * ============LICENSE_START======================================================= * VES Collector * ================================================================================ - * Copyright (C) 2020 Nokia. All rights reserved.s + * Copyright (C) 2020 Nokia. All rights reserved. + * Copyright (C) 2023 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. @@ -25,6 +26,7 @@ import org.junit.Test; import org.onap.dcae.common.JsonDataLoader; import java.io.IOException; +import java.net.URISyntaxException; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -36,7 +38,7 @@ public class VesEventTest { private static final String STND_DEFINED_STREAM_ID = "3GPP-FaultSupervision"; @Test - public void shouldReturnsOriginalDomainForNonStdEvent() throws IOException { + public void shouldReturnsOriginalDomainForNonStdEvent() throws IOException, URISyntaxException { // given final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves7_valid_event.json"); @@ -46,7 +48,7 @@ public class VesEventTest { } @Test - public void shouldReturnsDomainStoredInStndDefinedNamespaceParameterForNonStdEvent() throws IOException { + public void shouldReturnsDomainStoredInStndDefinedNamespaceParameterForNonStdEvent() throws IOException, URISyntaxException { // given final VesEvent vesEvent = createVesEvent("/eventsAfterTransformation/ves_stdnDefined_valid.json"); @@ -57,7 +59,7 @@ public class VesEventTest { @Test - public void shouldReportThatStndDefinedNamespaceParameterIsNotDefinedInEvent() throws IOException { + public void shouldReportThatStndDefinedNamespaceParameterIsNotDefinedInEvent() throws IOException, URISyntaxException { // given final VesEvent vesEvent = createVesEvent( "/eventsAfterTransformation/ves_stdnDefined_missing_namespace_invalid.json" @@ -72,7 +74,7 @@ public class VesEventTest { } @Test - public void shouldReportThatStndDefinedNamespaceParameterHasEmptyValue() throws IOException { + public void shouldReportThatStndDefinedNamespaceParameterHasEmptyValue() throws IOException, URISyntaxException { // given final VesEvent vesEvent = createVesEvent( "/eventsAfterTransformation/ves_stdnDefined_empty_namespace_invalid.json" @@ -85,7 +87,7 @@ public class VesEventTest { }); } - private VesEvent createVesEvent(String path) throws IOException { + private VesEvent createVesEvent(String path) throws IOException, URISyntaxException { String event = JsonDataLoader.loadContent(path); return new VesEvent(new JSONObject(event)); } diff --git a/src/test/java/org/onap/dcae/common/publishing/DMaapContainer.java b/src/test/java/org/onap/dcae/common/publishing/DMaapContainer.java index 9ece10b5..404b0ed7 100644 --- a/src/test/java/org/onap/dcae/common/publishing/DMaapContainer.java +++ b/src/test/java/org/onap/dcae/common/publishing/DMaapContainer.java @@ -3,6 +3,7 @@ * VES Collector * ========================================================= * Copyright (C) 2019-2021 Nokia. All rights reserved. + * Copyright (C) 2023 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. @@ -20,9 +21,14 @@ package org.onap.dcae.common.publishing; +import org.onap.dcae.FileReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.DockerComposeContainer; import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; final class DMaapContainer { @@ -30,13 +36,21 @@ final class DMaapContainer { private static final String DOCKER_COMPOSE_FILE_PATH = getDockerComposeFilePath(MR_COMPOSE_RESOURCE_NAME); static final int DMAAP_SERVICE_EXPOSED_PORT = 3904; static final String DMAAP_SERVICE_NAME = "onap-dmaap"; - + private static final Logger log = LoggerFactory.getLogger(DMaapContainer.class); + private DMaapContainer() {} - public static DockerComposeContainer createContainerInstance(){ + public static DockerComposeContainer createContainerInstance() { + + URI dockercomposeuri = null; + try { + dockercomposeuri = new URI(DOCKER_COMPOSE_FILE_PATH); + } catch (URISyntaxException e) { + log.error("Error while opening docker compose file.", e); + } return new DockerComposeContainer( - new File(DOCKER_COMPOSE_FILE_PATH)) + new File(dockercomposeuri.getPath())) .withExposedService(DMAAP_SERVICE_NAME, DMAAP_SERVICE_EXPOSED_PORT) .withLocalCompose(true); } diff --git a/src/test/java/org/onap/dcae/common/publishing/PublisherTest.java b/src/test/java/org/onap/dcae/common/publishing/PublisherTest.java index f269b942..be768941 100644 --- a/src/test/java/org/onap/dcae/common/publishing/PublisherTest.java +++ b/src/test/java/org/onap/dcae/common/publishing/PublisherTest.java @@ -3,6 +3,7 @@ * VES Collector * ================================================================================ * Copyright (C) 2021 Nokia. All rights reserved. + * Copyright (C) 2023 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. @@ -23,6 +24,9 @@ import com.google.gson.JsonElement; import io.vavr.collection.List; import io.vavr.control.Option; import org.junit.jupiter.api.Test; +import org.junit.Assume; +import org.junit.Before; + import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishResponse; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse; import org.testcontainers.containers.DockerComposeContainer; @@ -37,14 +41,20 @@ import static org.onap.dcae.common.publishing.DMaapContainer.createContainerInst import static org.onap.dcae.common.publishing.DmaapRequestConfiguration.getAsJsonElements; -@Testcontainers -public class PublisherTest { +@Testcontainers(disabledWithoutDocker = true) +public class PublisherTest { @Container private final DockerComposeContainer CONTAINER = createContainerInstance(); + + @Before + public void linuxOnly() { + Assume.assumeFalse + (System.getProperty("os.name").toLowerCase().startsWith("win")); + } @Test - void publishEvent_shouldSuccessfullyPublishSingleMessage() { + public void publishEvent_shouldSuccessfullyPublishSingleMessage() { //given final Publisher publisher = new Publisher(); final String simpleEvent = "{\"message\":\"message1\"}"; diff --git a/src/test/java/org/onap/dcae/common/validator/StndDefinedDataValidatorTest.java b/src/test/java/org/onap/dcae/common/validator/StndDefinedDataValidatorTest.java index 1058b21f..306d4cf3 100644 --- a/src/test/java/org/onap/dcae/common/validator/StndDefinedDataValidatorTest.java +++ b/src/test/java/org/onap/dcae/common/validator/StndDefinedDataValidatorTest.java @@ -3,6 +3,7 @@ * org.onap.dcaegen2.collectors.ves * ================================================================================ * Copyright (C) 2020 Nokia. All rights reserved. + * Copyright (C) 2023 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. @@ -22,6 +23,7 @@ package org.onap.dcae.common.validator; import org.jetbrains.annotations.NotNull; import org.json.JSONObject; +import org.junit.Assume; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -37,6 +39,8 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; +import java.nio.file.Paths; + @ExtendWith(MockitoExtension.class) public class StndDefinedDataValidatorTest { @@ -58,6 +62,7 @@ public class StndDefinedDataValidatorTest { @Test public void shouldReturnTrueWhenEventIsValid() throws EventValidatorException { + Assume.assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win")); //given VesEvent event = getVesEvent("src/test/resources/ves_stdnDefined_valid.json"); @@ -82,6 +87,7 @@ public class StndDefinedDataValidatorTest { @Test void shouldReturnErrorWhenMissingLocalSchemaReferenceInMappingFile() { + Assume.assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win")); //given VesEvent event = getVesEvent("src/test/resources/ves_stdnDefined_missing_local_schema_reference.json"); try { @@ -95,6 +101,7 @@ public class StndDefinedDataValidatorTest { @Test void shouldReturnErrorWhenIncorrectInternalFileReference() { + Assume.assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win")); //given VesEvent event = getVesEvent("src/test/resources/ves_stdnDefined_wrong_internal_file_reference.json"); try { @@ -123,7 +130,7 @@ public class StndDefinedDataValidatorTest { void shouldNotReturnErrorWhenValidatingInvalidEventAndStndDefinedReferenceMissing() { //given VesEvent event = getVesEvent("src/test/resources/ves_stdnDefined_without_schema_reference.json"); - + //when //then assertDoesNotThrow(() -> stndDefinedDataValidator.validate(event)); @@ -131,8 +138,8 @@ public class StndDefinedDataValidatorTest { @NotNull private VesEvent getVesEvent(String filename) { - JSONObject jsonObjectEvent = getJsonObjectEvent(filename); - return new VesEvent(jsonObjectEvent); + JSONObject jsonObjectEvent = getJsonObjectEvent(filename); + return new VesEvent(jsonObjectEvent); } private JSONObject getJsonObjectEvent(String fileName) { @@ -141,9 +148,9 @@ public class StndDefinedDataValidatorTest { } private void mockStndDefinedValidationProps() { - when(settings.getExternalSchemaMappingFileLocation()).thenReturn(MAPPING_FILE_LOCATION); + when(settings.getExternalSchemaMappingFileLocation()).thenReturn(Paths.get(MAPPING_FILE_LOCATION).toString()); when(settings.getExternalSchemaSchemaRefPath()).thenReturn(SCHEMA_REF_PATH); - when(settings.getExternalSchemaSchemasLocation()).thenReturn(SCHEMA_FILES_LOCATION); + when(settings.getExternalSchemaSchemasLocation()).thenReturn(Paths.get(SCHEMA_FILES_LOCATION).toString()); when(settings.getExternalSchemaStndDefinedDataPath()).thenReturn(STND_DEFINED_DATA_PATH); } -} \ No newline at end of file +} diff --git a/src/test/java/org/onap/dcae/multiplestreamreducer/MultipleStreamReducerTest.java b/src/test/java/org/onap/dcae/multiplestreamreducer/MultipleStreamReducerTest.java index d085eb13..5a529ec2 100644 --- a/src/test/java/org/onap/dcae/multiplestreamreducer/MultipleStreamReducerTest.java +++ b/src/test/java/org/onap/dcae/multiplestreamreducer/MultipleStreamReducerTest.java @@ -3,6 +3,7 @@ * VES Collector * ================================================================================ * Copyright (C) 2021 Nokia. All rights reserved. + * Copyright (C) 2023 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. @@ -21,9 +22,11 @@ package org.onap.dcae.multiplestreamreducer; import io.vavr.collection.HashMap; import io.vavr.collection.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; class MultipleStreamReducerTest { @@ -52,12 +55,13 @@ class MultipleStreamReducerTest { @Test void shouldReturnInfoAboutDomainToStreamsConfig() { + String newLine = System.getProperty("line.separator"); //given final Map domainToStreamsAfterReduce = multipleStreamReducer.reduce(domainToStreams); String expectedRedundantStreamsInfo = - "Domain: fault has active stream: ves-fault\n" + - "Domain: log has active stream: ves-syslog\n" + - "Domain: test has active stream: stream6\n"; + "Domain: fault has active stream: ves-fault" + newLine + + "Domain: log has active stream: ves-syslog" + newLine + + "Domain: test has active stream: stream6" + newLine; //when final String domainToStreamsConfigInfo = multipleStreamReducer.getDomainToStreamsInfo(domainToStreamsAfterReduce); diff --git a/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java b/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java index 9b436871..8b28e978 100644 --- a/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java +++ b/src/test/java/org/onap/dcae/restapi/VesRestControllerTest.java @@ -3,6 +3,7 @@ * VES Collector * ================================================================================ * Copyright (C) 2020-2021 Nokia. All rights reserved. + * Copyright (C) 2023 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. @@ -55,6 +56,8 @@ import org.springframework.web.context.request.ServletRequestAttributes; import java.io.FileReader; import java.io.IOException; import java.lang.reflect.Type; +import java.net.URI; +import java.net.URISyntaxException; import java.util.List; import java.util.Map; import java.util.stream.Stream; @@ -69,6 +72,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.nio.file.Paths; @ExtendWith(MockitoExtension.class) public class VesRestControllerTest { @@ -125,7 +129,7 @@ public class VesRestControllerTest { } @Test - void shouldTransformEventAccordingToEventTransformFile() throws IOException { + void shouldTransformEventAccordingToEventTransformFile() throws IOException, URISyntaxException{ //given configureEventTransformations(); configureHeadersForEventListener(); @@ -145,7 +149,7 @@ public class VesRestControllerTest { @Test - void shouldSendBatchEvent() throws IOException { + void shouldSendBatchEvent() throws IOException, URISyntaxException { //given configureEventTransformations(); configureHeadersForEventListener(); @@ -164,7 +168,7 @@ public class VesRestControllerTest { } @Test - void shouldSendStndDomainEventIntoDomainStream() throws IOException { + void shouldSendStndDomainEventIntoDomainStream() throws IOException, URISyntaxException{ //given configureEventTransformations(); configureHeadersForEventListener(); @@ -186,7 +190,7 @@ public class VesRestControllerTest { @Test - void shouldReportThatStndDomainEventHasntGotNamespaceParameter() throws IOException { + void shouldReportThatStndDomainEventHasntGotNamespaceParameter() throws IOException, URISyntaxException { //given configureEventTransformations(); configureHeadersForEventListener(); @@ -211,7 +215,7 @@ public class VesRestControllerTest { } @Test - void shouldReportThatStndDomainEventNamespaceParameterIsEmpty() throws IOException { + void shouldReportThatStndDomainEventNamespaceParameterIsEmpty() throws IOException, URISyntaxException { //given configureEventTransformations(); configureHeadersForEventListener(); @@ -236,7 +240,7 @@ public class VesRestControllerTest { } @Test - void shouldNotSendStndDomainEventWhenTopicCannotBeFoundInConfiguration() throws IOException { + void shouldNotSendStndDomainEventWhenTopicCannotBeFoundInConfiguration() throws IOException, URISyntaxException { //given configureEventTransformations(); configureHeadersForEventListener(); @@ -253,7 +257,7 @@ public class VesRestControllerTest { } @Test - void shouldExecuteStndDefinedValidationWhenFlagIsOnTrue() throws IOException { + void shouldExecuteStndDefinedValidationWhenFlagIsOnTrue() throws IOException, URISyntaxException{ //given configureEventTransformations(); configureHeadersForEventListener(); @@ -272,7 +276,7 @@ public class VesRestControllerTest { } @Test - void shouldNotExecuteStndDefinedValidationWhenFlagIsOnFalse() throws IOException { + void shouldNotExecuteStndDefinedValidationWhenFlagIsOnFalse() throws IOException, URISyntaxException { //given configureEventTransformations(); configureHeadersForEventListener(); @@ -292,7 +296,7 @@ public class VesRestControllerTest { } @Test - void shouldReturn413WhenPayloadIsTooLarge() throws IOException { + void shouldReturn413WhenPayloadIsTooLarge() throws IOException, URISyntaxException { //given configureEventTransformations(); configureHeadersForEventListener(); @@ -316,7 +320,7 @@ public class VesRestControllerTest { @ParameterizedTest @MethodSource("errorsCodeAndResponseBody") - void shouldMapErrorTo503AndReturnOriginalBody(ApiException apiException,String bodyVariable,String bodyVariable2) throws IOException { + void shouldMapErrorTo503AndReturnOriginalBody(ApiException apiException,String bodyVariable,String bodyVariable2) throws IOException, URISyntaxException { //given configureEventTransformations(); configureHeadersForEventListener(); @@ -376,7 +380,7 @@ public class VesRestControllerTest { return map.get("requestError").get("ServiceException"); } - private void configureEventTransformations() throws IOException { + private void configureEventTransformations() throws IOException, URISyntaxException { final List eventTransformations = loadEventTransformations(); when(applicationSettings.isVersionSupported(VERSION_V7)).thenReturn(true); when(applicationSettings.eventTransformingEnabled()).thenReturn(true); @@ -415,12 +419,13 @@ public class VesRestControllerTest { return request; } - private List loadEventTransformations() throws IOException { + private List loadEventTransformations() throws IOException, URISyntaxException { Type EVENT_TRANSFORM_LIST_TYPE = new TypeToken>() { }.getType(); - try (FileReader fr = new FileReader(this.getClass().getResource(EVENT_TRANSFORM_FILE_PATH).getPath())) { - return new Gson().fromJson(fr, EVENT_TRANSFORM_LIST_TYPE); - } + URI resource = this.getClass().getResource(EVENT_TRANSFORM_FILE_PATH).toURI(); + try (FileReader fr = new FileReader(resource.getPath())) { + return new Gson().fromJson(fr, EVENT_TRANSFORM_LIST_TYPE); + } } } diff --git a/version.properties b/version.properties index a00a7fb9..d7c8cf39 100644 --- a/version.properties +++ b/version.properties @@ -1,6 +1,6 @@ major=1 minor=12 -patch=1 +patch=2 base_version=${major}.${minor}.${patch} release_version=${base_version} snapshot_version=${base_version}-SNAPSHOT -- cgit 1.2.3-korg