summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test
diff options
context:
space:
mode:
authorRamesh Murugan Iyer <ramesh.murugan.iyer@est.tech>2024-06-17 14:44:13 +0000
committerGerrit Code Review <gerrit@onap.org>2024-06-17 14:44:13 +0000
commit29d86f951b30f4941ee63b0d2badef810b856e53 (patch)
treed00335fa3f9588cad9cd1d5aacb7f27b0bee10bf /runtime-acm/src/test
parent94328f3eb1b573193eb3d201368efee0b9fbb0b6 (diff)
parent45b94ba92d2ea581f1415ee57a005383bc6629e1 (diff)
Merge "Improve code in ACM"
Diffstat (limited to 'runtime-acm/src/test')
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivatorTest.java1
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java3
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java71
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java2
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java4
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java3
6 files changed, 40 insertions, 44 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivatorTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivatorTest.java
index 66595c89a..7e79c6e03 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivatorTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivatorTest.java
@@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java
index 8639dffcd..564723b7c 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-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.
@@ -34,7 +34,6 @@ import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
index f8443de33..4842a77a8 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-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,7 +45,6 @@ import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
@@ -104,61 +103,61 @@ class ParticipantControllerTest extends CommonRestController {
@Test
void testQueryParticipant() {
participantProvider.saveParticipant(inputParticipants.get(0));
- UUID participantId = participantProvider.getParticipants().get(0).getParticipantId();
+ var participantId = participantProvider.getParticipants().get(0).getParticipantId();
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + participantId);
- var response = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
- var entityList = response.readEntity(ParticipantInformation.class);
- assertNotNull(entityList);
+ try (var response = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ var entityList = response.readEntity(ParticipantInformation.class);
+ assertNotNull(entityList);
+ }
}
@Test
void testBadQueryParticipant() {
participantProvider.saveParticipant(inputParticipants.get(0));
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + UUID.randomUUID());
- var response = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ try (var response = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
}
@Test
void getAllParticipants() {
- inputParticipants.forEach(p -> {
- participantProvider.saveParticipant(p);
- });
+ inputParticipants.forEach(p -> participantProvider.saveParticipant(p));
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT);
- var response = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
- List<ParticipantInformation> entityList = response.readEntity(new GenericType<>() {});
- assertThat(entityList).isNotEmpty();
- var participantIds = entityList.stream().map(ParticipantInformation::getParticipant)
- .map(Participant::getParticipantId).collect(Collectors.toSet());
- inputParticipants.forEach(p -> {
- assertThat(participantIds).contains(p.getParticipantId());
- });
+ try (var response = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ List<ParticipantInformation> entityList = response.readEntity(new GenericType<>() {});
+ assertThat(entityList).isNotEmpty();
+ var participantIds =
+ entityList.stream().map(ParticipantInformation::getParticipant).map(Participant::getParticipantId)
+ .collect(Collectors.toSet());
+ inputParticipants.forEach(p -> assertThat(participantIds).contains(p.getParticipantId()));
+ }
}
@Test
- void testOrderParticipantReport() throws PfModelException {
+ void testOrderParticipantReport() {
participantProvider.saveParticipant(inputParticipants.get(0));
- UUID participantId = participantProvider.getParticipants().get(0).getParticipantId();
+ var participantId = participantProvider.getParticipants().get(0).getParticipantId();
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT
+ "/"
+ participantId);
- var response = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
- +
- "", MediaType.APPLICATION_JSON));
- assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
+ try (var response = invocationBuilder.header("Content-Length", 0)
+ .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
+ }
}
@Test
- void testBadOrderParticipantReport() throws PfModelException {
+ void testBadOrderParticipantReport() {
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT
+ "/"
+ UUID.randomUUID());
- var response = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
- +
- "", MediaType.APPLICATION_JSON));
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ try (var response = invocationBuilder.header("Content-Length", 0)
+ .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
}
@Test
@@ -167,9 +166,9 @@ class ParticipantControllerTest extends CommonRestController {
participantProvider.saveParticipant(p);
});
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT);
- var response = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
- +
- "", MediaType.APPLICATION_JSON));
- assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
+ try (var response = invocationBuilder.header("Content-Length", 0)
+ .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
+ }
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
index 41f1c9c31..e352d2f2a 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
@@ -78,7 +78,7 @@ class SupervisionParticipantHandlerTest {
handler.handleParticipantMessage(participantDeregisterMessage);
- verify(participantProvider).updateParticipant(any());
+ verify(participantProvider).saveParticipant(any());
verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
index 3c9f91785..690ad9672 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
@@ -47,10 +47,10 @@ class SupervisionParticipantScannerTest {
participant.setParticipantState(ParticipantState.OFF_LINE);
supervisionScanner.run();
- verify(participantProvider, times(0)).updateParticipant(any());
+ verify(participantProvider, times(0)).saveParticipant(any());
participant.setParticipantState(ParticipantState.ON_LINE);
supervisionScanner.run();
- verify(participantProvider, times(1)).updateParticipant(any());
+ verify(participantProvider, times(1)).saveParticipant(any());
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index 31cd659b3..766380ac4 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -28,7 +28,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -36,7 +35,6 @@ import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
-import org.onap.policy.clamp.acm.runtime.main.parameters.Topics;
import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
@@ -107,6 +105,7 @@ class SupervisionMessagesTest {
acDeregisterAckPublisher.stop();
}
+ @Test
void testSendParticipantDeregisterAckNoActive() {
var acDeregisterAckPublisher = new ParticipantDeregisterAckPublisher();
assertThatThrownBy(() -> acDeregisterAckPublisher.send(new ParticipantDeregisterAck()))