aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-controlloop
diff options
context:
space:
mode:
authorbrunomilitzer <bruno.militzer@est.tech>2021-12-06 10:53:26 +0000
committerbrunomilitzer <bruno.militzer@est.tech>2021-12-08 10:13:43 +0000
commit50851a5ef93cbb2a92119db532dc813214752456 (patch)
tree670e5fb7f5e5ed5b0ef116a4135985c7928f0b98 /runtime-controlloop
parent1bbfdd94d92e3278317d4fdc56e069ccb8cf6706 (diff)
Add Delete JUnit Tests
Added Delete InstanceProperties Tests Added Change OrderState Tests Included Issue-Id: POLICY-3570 Issue-Id: POLICY-3567 Change-Id: I7cf72f78bf1a0d0e695a1721c1a8423a02cf61af Signed-off-by: brunomilitzer <bruno.militzer@est.tech>
Diffstat (limited to 'runtime-controlloop')
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java113
1 files changed, 113 insertions, 0 deletions
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
index ea7dde4fe..5d5f4fc55 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -39,6 +39,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ServiceTemplateProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ControlLoopRepository;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopOrderStateResponse;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopPrimedResponse;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstancePropertiesResponse;
@@ -90,6 +91,9 @@ class InstantiationControllerTest extends CommonRestController {
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
@Autowired
+ private ControlLoopRepository controlLoopRepository;
+
+ @Autowired
private ServiceTemplateProvider serviceTemplateProvider;
@Autowired
@@ -310,6 +314,69 @@ class InstantiationControllerTest extends CommonRestController {
}
@Test
+ void testDeleteInstanceProperties() throws Exception {
+ Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
+ Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+
+ invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME + "&version=" + ID_VERSION);
+ resp = invocationBuilder.delete();
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+ var instanceResponse = resp.readEntity(InstantiationResponse.class);
+ assertEquals(ID_NAME, instanceResponse.getAffectedControlLoops().get(0).getName());
+ ControlLoops controlLoopsGet = instantiationProvider.getControlLoops(ID_NAME, ID_VERSION);
+ assertThat(controlLoopsGet.getControlLoopList()).isEmpty();
+ }
+
+ @Test
+ void testDeleteInstancePropertiesBadRequest() throws Exception {
+ Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
+ Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+
+ invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name=" + ID_NAME);
+ resp = invocationBuilder.delete();
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
+ }
+
+ @Test
+ void testDeleteInstancePropertiesPassiveMode() throws Exception {
+ Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
+ Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+
+ var controlLoops = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Command");
+ instantiationProvider.createControlLoops(controlLoops);
+
+ var participants = CommonTestData.createParticipants();
+ for (var participant : participants) {
+ participantProvider.saveParticipant(participant);
+ }
+
+ InstantiationCommand command =
+ InstantiationUtils.getInstantiationCommandFromResource(CL_INSTANTIATION_CHANGE_STATE_JSON, "Command");
+
+ invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
+ resp = invocationBuilder.put(Entity.json(command));
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
+ InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
+ InstantiationUtils.assertInstantiationResponse(instResponse, command);
+
+ // check passive state on DB and delete properties
+ for (ToscaConceptIdentifier toscaConceptIdentifier : command.getControlLoopIdentifierList()) {
+ ControlLoops controlLoopsGet = instantiationProvider.getControlLoops(toscaConceptIdentifier.getName(),
+ toscaConceptIdentifier.getVersion());
+ assertThat(controlLoopsGet.getControlLoopList()).hasSize(1);
+ assertEquals(command.getOrderedState(), controlLoopsGet.getControlLoopList().get(0).getOrderedState());
+
+ invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES + "?name="
+ + toscaConceptIdentifier.getName() + "&version=" + toscaConceptIdentifier.getVersion());
+ resp = invocationBuilder.delete();
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
+ }
+ }
+
+ @Test
void testCommand_NotFound1() throws Exception {
Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
Response resp = invocationBuilder.put(Entity.json(new InstantiationCommand()));
@@ -383,7 +450,53 @@ class InstantiationControllerTest extends CommonRestController {
assertThat(controlLoopsGet.getControlLoopList()).isEmpty();
}
+ @Test
+ void testChangeOrderStateFromUninitializedPassiveMode() throws Exception {
+ Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
+ Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+
+ var controlLoops = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON,
+ "CommandPassive");
+ instantiationProvider.createControlLoops(controlLoops);
+
+ var participants = CommonTestData.createParticipants();
+ for (var participant : participants) {
+ participantProvider.saveParticipant(participant);
+ }
+
+ InstantiationCommand command =
+ InstantiationUtils.getInstantiationCommandFromResource(CL_INSTANTIATION_CHANGE_STATE_JSON,
+ "CommandPassive");
+
+ invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
+ resp = invocationBuilder.put(Entity.json(command));
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), resp.getStatus());
+ InstantiationResponse instResponse = resp.readEntity(InstantiationResponse.class);
+ InstantiationUtils.assertInstantiationResponse(instResponse, command);
+ }
+
+ @Test
+ void testChangeOrderStateWithoutRegisteredParticipants() throws Exception {
+ Invocation.Builder invocationBuilder = super.sendRequest(INSTANTIATION_PROPERTIES);
+ Response resp = invocationBuilder.post(Entity.json(serviceTemplate));
+ assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+
+ var controlLoops = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON,
+ "CommandPassive");
+ instantiationProvider.createControlLoops(controlLoops);
+
+ InstantiationCommand command =
+ InstantiationUtils.getInstantiationCommandFromResource(CL_INSTANTIATION_CHANGE_STATE_JSON,
+ "CommandPassive");
+
+ invocationBuilder = super.sendRequest(INSTANTIATION_COMMAND_ENDPOINT);
+ resp = invocationBuilder.put(Entity.json(command));
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
+ }
+
private synchronized void deleteEntryInDB() throws Exception {
+ controlLoopRepository.deleteAll();
var list = serviceTemplateProvider.getAllServiceTemplates();
if (!list.isEmpty()) {
serviceTemplateProvider.deleteServiceTemplate(list.get(0).getName(), list.get(0).getVersion());