aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2023-01-05 09:41:14 +0000
committerGerrit Code Review <gerrit@onap.org>2023-01-05 09:41:14 +0000
commitbce4edfb6a9140a07d12470d977352d7b3a4105c (patch)
treebec8d5ad77fa103c9f6082403de981dc2d6ad791 /runtime-acm/src/test
parent951196b4e0d4c64403f186693c2d1c53e25df3b1 (diff)
parenta76f5614e10f99658114ea1ff2eaf334e0df01c8 (diff)
Merge "Refactor Post instances to create and update ACM instances"
Diffstat (limited to 'runtime-acm/src/test')
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java38
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java25
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/stub/InstantiationControllerStubTest.java8
3 files changed, 22 insertions, 49 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index c14d64069..cd6e021c5 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -40,7 +40,6 @@ import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationUpdate;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
@@ -117,32 +116,24 @@ class AutomationCompositionInstantiationProviderTest {
assertThat(automationCompositionCreate)
.isEqualTo(automationCompositionsGet.getAutomationCompositionList().get(0));
- var instanceUpdate = new InstantiationUpdate();
var automationCompositionUpdate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
automationCompositionUpdate.setCompositionId(compositionId);
- instanceUpdate.setElements(automationCompositionUpdate.getElements());
when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId()))
.thenReturn(automationCompositionUpdate);
when(acProvider.updateAutomationComposition(automationCompositionUpdate))
.thenReturn(automationCompositionUpdate);
- instantiationResponse =
- instantiationProvider.updateAutomationComposition(automationCompositionUpdate.getCompositionId(),
- automationCompositionUpdate.getInstanceId(), instanceUpdate);
+ instantiationResponse = instantiationProvider.updateAutomationComposition(
+ automationCompositionUpdate.getCompositionId(), automationCompositionUpdate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate);
verify(acProvider).updateAutomationComposition(automationCompositionUpdate);
- var instanceUpdateCommand = new InstantiationUpdate();
var instantiationCommand =
InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON);
- instanceUpdateCommand.setInstantiationCommand(instantiationCommand);
- instantiationResponse =
- instantiationProvider.updateAutomationComposition(automationCompositionUpdate.getCompositionId(),
- automationCompositionUpdate.getInstanceId(), instanceUpdateCommand);
- InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate);
-
+ instantiationProvider.issueAutomationCompositionCommand(automationCompositionUpdate,
+ instantiationCommand);
verify(supervisionHandler).triggerAutomationCompositionSupervision(automationCompositionUpdate);
// in order to delete a automationComposition the state must be UNINITIALISED
@@ -262,11 +253,8 @@ class AutomationCompositionInstantiationProviderTest {
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
- var instanceUpdate = new InstantiationUpdate();
- instanceUpdate.setElements(automationComposition.getElements());
- var instanceId = automationComposition.getInstanceId();
- assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, instanceId, instanceUpdate))
+ assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, automationComposition))
.hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
}
@@ -288,17 +276,14 @@ class AutomationCompositionInstantiationProviderTest {
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
.hasMessageMatching(AC_DEFINITION_NOT_FOUND);
- var instanceUpdate = new InstantiationUpdate();
- instanceUpdate.setElements(automationComposition.getElements());
- var instanceId = automationComposition.getInstanceId();
- assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, instanceId, instanceUpdate))
+ assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, automationComposition))
.hasMessageMatching(AC_DEFINITION_NOT_FOUND);
var wrongCompositionId = UUID.randomUUID();
assertThatThrownBy(() -> provider.createAutomationComposition(wrongCompositionId, automationComposition))
.hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
- assertThatThrownBy(() -> provider.updateAutomationComposition(wrongCompositionId, instanceId, instanceUpdate))
+ assertThatThrownBy(() -> provider.updateAutomationComposition(wrongCompositionId, automationComposition))
.hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
}
@@ -310,17 +295,12 @@ class AutomationCompositionInstantiationProviderTest {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
participantProvider, acDefinitionProvider);
- var instanceUpdate = new InstantiationUpdate();
- instanceUpdate.setInstantiationCommand(new InstantiationCommand());
var automationComposition = InstantiationUtils
.getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound");
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
- var compositionId = automationComposition.getCompositionId();
- var instanceId = automationComposition.getInstanceId();
- assertThatThrownBy(
- () -> instantiationProvider.updateAutomationComposition(compositionId, instanceId, instanceUpdate))
- .hasMessageMatching(ORDERED_STATE_INVALID);
+ assertThatThrownBy(() -> instantiationProvider.issueAutomationCompositionCommand(automationComposition,
+ new InstantiationCommand())).hasMessageMatching(ORDERED_STATE_INVALID);
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
index 9bc29d9ce..d3a3f3eb8 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -41,10 +41,10 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.main.rest.InstantiationController;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
+import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationUpdate;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
@@ -218,7 +218,6 @@ class InstantiationControllerTest extends CommonRestController {
assertEquals(automationComposition, automationCompositionsQuery.getAutomationCompositionList().get(0));
}
- @Disabled
@Test
void testUpdate() {
var automationCompositionCreate =
@@ -231,10 +230,8 @@ class InstantiationControllerTest extends CommonRestController {
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Update");
automationComposition.setCompositionId(compositionId);
automationComposition.setInstanceId(response.getInstanceId());
- var instantiationUpdate = new InstantiationUpdate();
- instantiationUpdate.setElements(automationComposition.getElements());
- var invocationBuilder = super.sendRequest(getInstanceEndPoint(response.getInstanceId()));
- var resp = invocationBuilder.put(Entity.json(automationComposition));
+ var invocationBuilder = super.sendRequest(getInstanceEndPoint());
+ var resp = invocationBuilder.post(Entity.json(automationComposition));
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
var instResponse = resp.readEntity(InstantiationResponse.class);
@@ -285,7 +282,7 @@ class InstantiationControllerTest extends CommonRestController {
@Test
void testCommand_NotFound1() {
var invocationBuilder = super.sendRequest(getInstanceEndPoint(UUID.randomUUID()));
- var resp = invocationBuilder.put(Entity.json(new InstantiationUpdate()));
+ var resp = invocationBuilder.post(Entity.json(new AutomationComposition()));
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus());
}
@@ -298,9 +295,9 @@ class InstantiationControllerTest extends CommonRestController {
var instResponse = instantiationProvider.createAutomationComposition(compositionId, acFromRsc);
- var command = new InstantiationUpdate();
- command.setInstantiationCommand(new InstantiationCommand());
- command.getInstantiationCommand().setOrderedState(null);
+ var command = new AcInstanceStateUpdate();
+ command.setDeployOrder(null);
+ command.setLockOrder(null);
var invocationBuilder = super.sendRequest(getInstanceEndPoint(instResponse.getInstanceId()));
var resp = invocationBuilder.put(Entity.json(command));
@@ -320,9 +317,7 @@ class InstantiationControllerTest extends CommonRestController {
participantProvider.saveParticipant(participant);
}
- var instantiationUpdate = new InstantiationUpdate();
- var command = InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON);
- instantiationUpdate.setInstantiationCommand(command);
+ var instantiationUpdate = new AcInstanceStateUpdate();
var invocationBuilder = super.sendRequest(getInstanceEndPoint(instResponse.getInstanceId()));
var resp = invocationBuilder.put(Entity.json(instantiationUpdate));
@@ -335,8 +330,6 @@ class InstantiationControllerTest extends CommonRestController {
var automationCompositionsGet = instantiationProvider.getAutomationCompositions(compositionId,
toscaConceptIdentifier.getName(), toscaConceptIdentifier.getVersion());
assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
- assertEquals(command.getOrderedState(),
- automationCompositionsGet.getAutomationCompositionList().get(0).getOrderedState());
}
private synchronized void deleteEntryInDB() {
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/stub/InstantiationControllerStubTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/stub/InstantiationControllerStubTest.java
index afddc4d01..30c8ed173 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/stub/InstantiationControllerStubTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/stub/InstantiationControllerStubTest.java
@@ -28,7 +28,8 @@ 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.util.rest.CommonRestController;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationUpdate;
+import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
@@ -44,7 +45,6 @@ class InstantiationControllerStubTest extends CommonRestController {
private static final String INSTANTIATION_ENDPOINT = "instances";
private static final String COMPOSITION_ID = "1aeed185-a98b-45b6-af22-8d5d20485ea3";
private static final String INSTANCE_ID = "709c62b3-8918-41b9-a747-d21eb79c6c23";
- private static InstantiationUpdate instantiationUpdate = new InstantiationUpdate();
@LocalServerPort
private int randomServerPort;
@@ -79,7 +79,7 @@ class InstantiationControllerStubTest extends CommonRestController {
+ "/" + COMPOSITION_ID
+ "/" + INSTANTIATION_ENDPOINT
+ "/" + INSTANCE_ID);
- var respPost = invocationBuilder.put(Entity.json(instantiationUpdate));
+ var respPost = invocationBuilder.put(Entity.json(new AcInstanceStateUpdate()));
assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
}
@@ -88,7 +88,7 @@ class InstantiationControllerStubTest extends CommonRestController {
var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
+ "/" + COMPOSITION_ID
+ "/" + INSTANTIATION_ENDPOINT);
- var respPost = invocationBuilder.post(Entity.json(instantiationUpdate));
+ var respPost = invocationBuilder.post(Entity.json(new AutomationComposition()));
assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
}