aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-acm/src/test')
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java176
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java12
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java38
-rw-r--r--runtime-acm/src/test/resources/providers/TestParticipant.json15
-rw-r--r--runtime-acm/src/test/resources/providers/TestParticipant2.json15
5 files changed, 231 insertions, 25 deletions
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
new file mode 100644
index 000000000..e6f7118da
--- /dev/null
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java
@@ -0,0 +1,176 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.runtime.participant;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.onap.policy.clamp.acm.runtime.main.rest.ParticipantController;
+import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
+import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantInformation;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
+import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
+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.web.server.LocalServerPort;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+/**
+ * Class to perform unit test of {@link ParticipantController}.
+ *
+ */
+
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles({ "test", "default" })
+public class ParticipantControllerTest extends CommonRestController {
+ private static final String PARTICIPANTS_ENDPOINT = "participants";
+
+ @LocalServerPort
+ private int randomServerPort;
+
+ private static final Coder CODER = new StandardCoder();
+ private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json";
+ private static final String PARTICIPANT_JSON2 = "src/test/resources/providers/TestParticipant2.json";
+ private static final String LIST_IS_NULL = ".*. is marked .*ull but is null";
+
+ private static final List<Participant> inputParticipants = new ArrayList<>();
+ private static List<JpaParticipant> jpaParticipantList;
+ private static final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
+ private static final String originalJson2 = ResourceUtils.getResourceAsString(PARTICIPANT_JSON2);
+
+ @Autowired
+ private ParticipantProvider participantProvider;
+
+ /**
+ * Adds participants to the db from json file.
+ */
+ @BeforeAll
+ public static void setUpBeforeClass() throws CoderException {
+ inputParticipants.add(CODER.decode(originalJson, Participant.class));
+ inputParticipants.add(CODER.decode(originalJson2, Participant.class));
+ jpaParticipantList = ProviderUtils.getJpaAndValidateList(
+ inputParticipants, JpaParticipant::new, "participant");
+ }
+
+ @BeforeEach
+ public void setUpPort() {
+ super.setHttpPrefix(randomServerPort);
+ }
+
+ @Test
+ void testSwagger() {
+ super.testSwagger(PARTICIPANTS_ENDPOINT);
+ }
+
+ @Test
+ void testUnauthorizedQuery() {
+ assertUnauthorizedGet(PARTICIPANTS_ENDPOINT);
+ }
+
+ @Test
+ void testQueryParticipant() {
+ participantProvider.saveParticipant(inputParticipants.get(0));
+ UUID 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);
+ }
+
+ @Test
+ void testBadQueryParticipant() {
+ participantProvider.saveParticipant(inputParticipants.get(0));
+ UUID participantId = participantProvider.getParticipants().get(0).getParticipantId();
+ var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + UUID.randomUUID());
+ var response = invocationBuilder.buildGet().invoke();
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
+
+ @Test
+ void getAllParticipants() {
+ 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.size() == inputParticipants.size());
+ }
+
+ @Test
+ void testOrderParticipantReport() throws PfModelException {
+ participantProvider.saveParticipant(inputParticipants.get(0));
+ UUID 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());
+ }
+
+ @Test
+ void testBadOrderParticipantReport() throws PfModelException {
+ 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());
+ }
+
+ @Test
+ void testOrderAllParticipantReport() {
+ inputParticipants.forEach(p -> {
+ 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());
+ }
+}
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 9e35f2cf5..f7c18b67b 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
@@ -41,7 +41,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class SupervisionParticipantHandlerTest {
private static final ToscaConceptIdentifier PARTICIPANT_ID = new ToscaConceptIdentifier("ParticipantId", "1.0.0");
private static final ToscaConceptIdentifier PARTICIPANT_TYPE =
- new ToscaConceptIdentifier("ParticipantType", "1.0.0");
+ new ToscaConceptIdentifier("ParticipantType", "1.0.0");
@Test
void testHandleParticipantDeregister() {
@@ -59,11 +59,11 @@ class SupervisionParticipantHandlerTest {
participantDeregisterMessage.setParticipantType(PARTICIPANT_TYPE);
var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
var handler = new SupervisionParticipantHandler(participantProvider,
- mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher);
+ mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher);
handler.handleParticipantMessage(participantDeregisterMessage);
- verify(participantProvider).saveParticipant(any());
+ verify(participantProvider).updateParticipant(any());
verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
}
@@ -81,13 +81,13 @@ class SupervisionParticipantHandlerTest {
var participantProvider = mock(ParticipantProvider.class);
var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher,
- mock(ParticipantDeregisterAckPublisher.class));
+ mock(ParticipantDeregisterAckPublisher.class));
handler.handleParticipantMessage(participantRegisterMessage);
verify(participantProvider).saveParticipant(any());
verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), PARTICIPANT_ID,
- PARTICIPANT_TYPE);
+ PARTICIPANT_TYPE);
}
@Test
@@ -99,7 +99,7 @@ class SupervisionParticipantHandlerTest {
var participantProvider = mock(ParticipantProvider.class);
var handler = new SupervisionParticipantHandler(participantProvider,
- mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
+ mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
handler.handleParticipantMessage(participantStatusMessage);
verify(participantProvider).saveParticipant(any());
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index 0142f294c..1e07ec9cf 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -61,7 +61,7 @@ class SupervisionScannerTest {
private static UUID compositionId;
private static final ToscaConceptIdentifier PARTICIPANT_TYPE =
- new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyParticipant", PARTICIPANT_VERSION);
+ new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyParticipant", PARTICIPANT_VERSION);
@BeforeAll
public static void setUpBeforeAll() {
@@ -83,11 +83,11 @@ class SupervisionScannerTest {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
@@ -100,7 +100,7 @@ class SupervisionScannerTest {
automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
@@ -108,8 +108,8 @@ class SupervisionScannerTest {
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
@@ -120,7 +120,7 @@ class SupervisionScannerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition = new AutomationComposition();
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
var participantProvider = mock(ParticipantProvider.class);
var participant = new Participant();
@@ -133,8 +133,8 @@ class SupervisionScannerTest {
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
+ acRuntimeParameterGroup);
supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
supervisionScanner.run(true);
@@ -148,7 +148,7 @@ class SupervisionScannerTest {
automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
for (var element : automationComposition.getElements().values()) {
if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"
- .equals(element.getDefinition().getName())) {
+ .equals(element.getDefinition().getName())) {
element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
element.setState(AutomationCompositionState.UNINITIALISED);
} else {
@@ -159,7 +159,7 @@ class SupervisionScannerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
var participantProvider = mock(ParticipantProvider.class);
var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class);
@@ -167,8 +167,8 @@ class SupervisionScannerTest {
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
@@ -180,7 +180,7 @@ class SupervisionScannerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition = new AutomationComposition();
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant");
acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1);
@@ -199,14 +199,14 @@ class SupervisionScannerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
+ acRuntimeParameterGroup);
supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
supervisionScanner.run(true);
- verify(participantProvider, times(0)).saveParticipant(any());
+ verify(participantProvider, times(0)).updateParticipant(any());
supervisionScanner.run(true);
- verify(participantProvider, times(1)).saveParticipant(any());
+ verify(participantProvider, times(1)).updateParticipant(any());
}
}
diff --git a/runtime-acm/src/test/resources/providers/TestParticipant.json b/runtime-acm/src/test/resources/providers/TestParticipant.json
new file mode 100644
index 000000000..fe06ba091
--- /dev/null
+++ b/runtime-acm/src/test/resources/providers/TestParticipant.json
@@ -0,0 +1,15 @@
+{
+ "name": "dummy_participant1",
+ "version": "1.0.1",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHAutomationCompositionDefinition",
+ "version": "1.0.0"
+ },
+ "participantState": "ON_LINE",
+ "description": "A dummy PMSH participant1",
+ "participantId": "82fd8ef9-1d1e-4343-9b28-7f9564ee3de6",
+ "participantType": {
+ "name": "org.onap.domain.pmsh.PolicyAutomationCompositionDefinition",
+ "version": "1.0.0"
+ }
+}
diff --git a/runtime-acm/src/test/resources/providers/TestParticipant2.json b/runtime-acm/src/test/resources/providers/TestParticipant2.json
new file mode 100644
index 000000000..9a341844a
--- /dev/null
+++ b/runtime-acm/src/test/resources/providers/TestParticipant2.json
@@ -0,0 +1,15 @@
+{
+ "name": "dummy_participant2",
+ "version": "1.0.1",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHAutomationCompositionDefinition2",
+ "version": "1.0.0"
+ },
+ "participantState": "ON_LINE",
+ "description": "A dummy PMSH participant2",
+ "participantId": "cac01d0a-7ba8-4dda-b9be-6983c46c0546",
+ "participantType": {
+ "name": "org.onap.domain.pmsh.PolicyAutomationCompositionDefinition2",
+ "version": "1.0.0"
+ }
+}