diff options
author | Stanislav Marszalek <s.marszalek2@partner.samsung.com> | 2021-08-13 12:24:19 +0200 |
---|---|---|
committer | Stanislav Marszalek <s.marszalek2@partner.samsung.com> | 2021-08-25 07:43:33 +0200 |
commit | 27866180d7fa5444878209c93b95ae8b2c1fcdf1 (patch) | |
tree | fd4e32c5dac2694588cdc7ee902e62f04a7d36ce /src/test/java/org | |
parent | a800ace09fe6ebe64cc455e4ba5ccb3abcfd79fc (diff) |
Fix sonar issues in PM Mapper
Issue-ID: DCAEGEN2-2887
Signed-off-by: Stanislav Marszalek <s.marszalek2@partner.samsung.com>
Change-Id: I02d3684c98d563d7f386de2fdf032e930ac18b9f
Diffstat (limited to 'src/test/java/org')
4 files changed, 30 insertions, 19 deletions
diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandlerTest.java index 9b7bc4d..180da4d 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandlerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/datarouter/DeliveryHandlerTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2021 Samsung Electronics. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -125,10 +126,10 @@ class DeliveryHandlerTest { objUnderTest.handleRequest(httpServerExchange); verify(eventReceiver, times(1)).receive(any(Event.class)); - assertEquals(logAppender.list.get(0).getMarker().getName(), "ENTRY"); + assertEquals("ENTRY", logAppender.list.get(0).getMarker().getName()); assertNotNull(logAppender.list.get(0).getMDCPropertyMap().get("InvocationID")); assertNotNull(logAppender.list.get(0).getMDCPropertyMap().get("RequestID")); - assertEquals(logAppender.list.get(1).getMarker().getName(), "EXIT"); + assertEquals("EXIT", logAppender.list.get(1).getMarker().getName()); logAppender.stop(); } }
\ No newline at end of file diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java index 26cb648..9c0d67c 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/mapping/MapperTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. * Copyright (C) 2021 Nokia. + * Copyright (C) 2021 Samsung Electronics. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +31,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.gson.Gson; + import freemarker.core.Environment; import freemarker.template.Template; import freemarker.template.TemplateException; @@ -59,6 +61,7 @@ import org.onap.dcaegen2.services.pmmapper.model.Event; import org.onap.dcaegen2.services.pmmapper.model.EventMetadata; import org.onap.dcaegen2.services.pmmapper.utils.MeasConverter; import org.powermock.reflect.Whitebox; + import utils.ArgumentCreator; import utils.EventUtils; @@ -74,8 +77,8 @@ class MapperTest { private static final Path schema = Paths.get("src/test/resources/mapper_test/CommonEventFormat_30.1-ONAP.json"); private static final Path METADATA_DIRECTORY = Paths.get("src/test/resources/metadata/"); - private static final Path FIFTH_GENERATION_METADATA = Paths.get(METADATA_DIRECTORY.toString()+"/valid_5g_metadata.json"); - private static final Path FOURTH_GENERATION_METADATA = Paths.get(METADATA_DIRECTORY.toString()+"/valid_4g_metadata.json"); + private static final Path FIFTH_GENERATION_METADATA = Paths.get(METADATA_DIRECTORY.toString() + "/valid_5g_metadata.json"); + private static final Path FOURTH_GENERATION_METADATA = Paths.get(METADATA_DIRECTORY.toString() + "/valid_4g_metadata.json"); private static final Path TEMPLATES_DIRECTORY = Paths.get("src/main/resources/templates/"); private static final Path dataDirectory = Paths.get("src/test/resources/mapper_test/mapping_data/"); @@ -88,7 +91,7 @@ class MapperTest { String fourthGenMetadataFileContents = new String(Files.readAllBytes(FOURTH_GENERATION_METADATA)); fourthGenerationMetadata = new Gson().fromJson(fourthGenMetadataFileContents, EventMetadata.class); String fifthGenMetadataFileContents = new String(Files.readAllBytes(FIFTH_GENERATION_METADATA)); - fifthGenerationMetadata = new Gson().fromJson(fifthGenMetadataFileContents, EventMetadata.class); + fifthGenerationMetadata = new Gson().fromJson(fifthGenMetadataFileContents, EventMetadata.class); converter = new MeasConverter(); } @@ -131,25 +134,27 @@ class MapperTest { @Test void testFailureToParseLte() { - assertThrows(MappingException.class, () -> - objUnderTest.map(EventUtils.makeMockEvent("not xml", fourthGenerationMetadata))); + assertThrows(MappingException.class, () -> EventUtils.makeMockEvent("not xml", fourthGenerationMetadata)); } @Test void testFailureToParseNr() { - assertThrows(MappingException.class, () -> - objUnderTest.map(EventUtils.makeMockEvent("not xml", fifthGenerationMetadata))); + assertThrows(MappingException.class, () -> EventUtils.makeMockEvent("not xml", fifthGenerationMetadata)); } @Test void testInvalidPath() { - assertThrows(IllegalArgumentException.class, () -> new Mapper(Paths.get("not a path"),converter)); + Path path = Paths.get("not a path"); + assertThrows(IllegalArgumentException.class, () -> new Mapper(path, converter)); } @Test void testInvalidTemplateDirectory() { - assertThrows(IllegalArgumentException.class, () -> new Mapper(Paths.get("fake dir"), new MeasConverter())); + Path path = Paths.get("fake dir"); + MeasConverter measConverter = new MeasConverter(); + assertThrows(IllegalArgumentException.class, () -> new Mapper(path, measConverter)); } + @Test void testTemplateNotFound() { EventMetadata testMetadata = mock(EventMetadata.class); @@ -161,7 +166,7 @@ class MapperTest { @Test void testNullPath() { - assertThrows(NullPointerException.class, () -> new Mapper(null,converter)); + assertThrows(NullPointerException.class, () -> new Mapper(null, converter)); } @Test @@ -176,8 +181,8 @@ class MapperTest { static List<Arguments> getValidEvents() { ArgumentCreator creator = (Path path, EventMetadata metadata) -> { - Path testEventPath = Paths.get(path.toString()+"/test.xml"); - Path metadataPath = Paths.get(path.toString()+"/metadata.json"); + Path testEventPath = Paths.get(path.toString() + "/test.xml"); + Path metadataPath = Paths.get(path.toString() + "/metadata.json"); EventMetadata eventMetadata = null; try { eventMetadata = new Gson().fromJson(new String(Files.readAllBytes(metadataPath)), EventMetadata.class); diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasFilterConfigAdapterTest.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasFilterConfigAdapterTest.java index a2d53de..0fda499 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasFilterConfigAdapterTest.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/MeasFilterConfigAdapterTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2021 Samsung Electronics. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,20 +64,23 @@ class MeasFilterConfigAdapterTest { @Test void testInvalidConfigObject() throws IOException { String filter = "{\"filters\": \"invalid\"}"; - assertThrows(JsonSyntaxException.class, () -> objUnderTest.read(new JsonReader(new StringReader(filter)))); + JsonReader jsonReader = new JsonReader(new StringReader(filter)); + assertThrows(JsonSyntaxException.class, () -> objUnderTest.read(jsonReader)); } @Test void testInvalidConfigString() throws IOException { - String filter ="\"{\\\"filters\\\": [{\"pmDefVsn\":\\\"V9\\\", \\\"nfType\\\": \\\"NrRadio\\\"," + + String filter = "\"{\\\"filters\\\": [{\"pmDefVsn\":\\\"V9\\\", \\\"nfType\\\": \\\"NrRadio\\\"," + "\\\"vendor\\\": \\\"Ericsson\\\", \\\"measTypes\\\": [\\\"A\\\", \\\"B\\\"]}]}\""; - assertThrows(JsonSyntaxException.class, () -> objUnderTest.read(new JsonReader(new StringReader(filter)))); + JsonReader jsonReader = new JsonReader(new StringReader(filter)); + assertThrows(JsonSyntaxException.class, () -> objUnderTest.read(jsonReader)); } @Test void testUnsupportedJSONType() throws IOException { String filter = "[]"; - assertThrows(UnsupportedOperationException.class, () -> objUnderTest.read(new JsonReader(new StringReader(filter)))); + JsonReader jsonReader = new JsonReader(new StringReader(filter)); + assertThrows(UnsupportedOperationException.class, () -> objUnderTest.read(jsonReader)); } @Test diff --git a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java index 8541824..091794e 100644 --- a/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java +++ b/src/test/java/org/onap/dcaegen2/services/pmmapper/utils/RequestSenderTests.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. * Copyright (C) 2021 Nokia. + * Copyright (C) 2021 Samsung Electronics. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,7 +87,7 @@ public class RequestSenderTests { String result = new RequestSender().send(url); client.verify(req, VerificationTimes.atLeast(1)); - assertEquals(result, "ResponseBody"); + assertEquals("ResponseBody", result); assertTrue(logAppender.list.get(1).getMessage().contains("Sending")); assertTrue(logAppender.list.get(2).getMessage().contains("Received")); logAppender.stop(); |