aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test/java
diff options
context:
space:
mode:
authorsaul.gill <saul.gill@est.tech>2023-01-10 11:11:08 +0000
committersaul.gill <saul.gill@est.tech>2023-01-12 13:44:44 +0000
commitadfe6d2d2e5b11a24208b3bce5383f1c38cec61e (patch)
treea9dd70e6e6a5f759bce1936201820aadb62ff280 /runtime-acm/src/test/java
parent0b1764cac4b0071b66295cf14bf43b22ed3bc20d (diff)
Add participant controller in ACM
Added participant controller Altered openapi spec Added participantId Issue-ID: POLICY-4496 Change-Id: I0c0ea93dacb6927e6f16bd4638d03db6266be3bd Signed-off-by: saul.gill <saul.gill@est.tech>
Diffstat (limited to 'runtime-acm/src/test/java')
-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
3 files changed, 201 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());
}
}