diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-06-27 13:04:21 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-06-27 13:21:58 +0000 |
commit | e7772aebff2f84a619788ddb287fbfcef8569964 (patch) | |
tree | 26e4ad98a563522fbcc1c8b5aa276cbe2b49ebe7 /participant/participant-impl | |
parent | 56b2759cee1931b3d3fb2da5197e47c32982cd19 (diff) |
Code coverage and sonar fixes for ACM
Code coverage and sonar fixes in classes
that was not involved in recent implementations.
Issue-ID: POLICY-5065
Change-Id: Ib23da6f242b0a7eaa98f14abc6617ff9e12e10d9
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl')
3 files changed, 83 insertions, 10 deletions
diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java index 1b0fe60d9..39db8c3e1 100644 --- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessageHandlerTest.java @@ -57,7 +57,12 @@ class MessageHandlerTest { var bridge = createMockElementService(ElementType.BRIDGE); var messageHandler = createMessageHandler(List.of(starter, bridge)); - assertThatThrownBy(() -> messageHandler.getActiveService()) + assertThatThrownBy(() -> messageHandler.active(null)) + .isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> messageHandler.update(null)) + .isInstanceOf(NullPointerException.class); + + assertThatThrownBy(messageHandler::getActiveService) .isInstanceOf(AutomationCompositionRuntimeException.class); var elementConfig = new ElementConfig(); diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessagePublisherTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessagePublisherTest.java new file mode 100644 index 000000000..dafb01651 --- /dev/null +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/handler/MessagePublisherTest.java @@ -0,0 +1,54 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.acm.element.handler; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.messages.kafka.element.ElementMessage; +import org.onap.policy.clamp.models.acm.messages.kafka.element.ElementMessageType; +import org.onap.policy.common.endpoints.event.comm.TopicSink; + + +class MessagePublisherTest { + + @Test + void testActiveEmpty() { + var messagePublisher = new MessagePublisher(); + var list = List.<TopicSink>of(); + assertThatThrownBy(() -> messagePublisher.active(list)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void testPublishMsg() { + var topic = mock(TopicSink.class); + var messagePublisher = new MessagePublisher(); + messagePublisher.active(List.of(topic)); + messagePublisher.publishMsg(new ElementMessage(ElementMessageType.STATUS)); + messagePublisher.stop(); + verify(topic).send(any()); + } +} diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java index 5ccee7b31..453ccc916 100644 --- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Nordix Foundation. + * Copyright (C) 2022-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,6 +45,8 @@ class ActuatorControllerTest extends CommonActuatorController { private static final String PROMETHEUS_ENDPOINT = "onap/policy/clamp/acelement/v2/prometheus"; private static final String SWAGGER_ENDPOINT = "onap/policy/clamp/acelement/v2/v3/api-docs"; + private static final String WRONG_ENDPOINT = "onap/policy/clamp/acelement/v2/wrong"; + @LocalServerPort private int randomServerPort; @@ -76,28 +78,40 @@ class ActuatorControllerTest extends CommonActuatorController { @Test void testGetHealth() { var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test void testGetMetrics() { var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test void testGetPrometheus() { var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } } @Test void testGetSwagger() { var invocationBuilder = super.sendActRequest(SWAGGER_ENDPOINT); - var rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + } + } + + @Test + void testWrongEndPoint() { + var invocationBuilder = super.sendActRequest(WRONG_ENDPOINT); + try (var rawresp = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus()); + } } } |