- when(acmDeployer.undeployRappInstance(any(), any())).thenReturn(true);
- when(smeDeployer.undeployRappInstance(any(), any())).thenReturn(false);
- when(dmeDeployer.undeployRappInstance(any(), any())).thenReturn(true);
- assertEquals(HttpStatus.BAD_REQUEST, rappService.undeployRappInstance(rapp, rappInstance).getStatusCode());
+ assertEquals(HttpStatus.NO_CONTENT,
+ rappService.deleteRappInstance(rapp, rappInstance.getRappInstanceId()).getStatusCode());
+ }
+
+ @Test
+ void testDeleteRappInstanceFailure() {
+ Rapp rapp = Rapp.builder().rappId(UUID.randomUUID()).name("").packageName(validRappFile)
+ .packageLocation(validCsarFileLocation).state(RappState.PRIMED).build();
+ RappInstance rappInstance = new RappInstance();
+ rappInstance.setState(RappInstanceState.DEPLOYED);
+ UUID rappInstanceId = rappInstance.getRappInstanceId();
+ HashMap<UUID, RappInstance> rAppInstanceMap = new HashMap<>();
+ rAppInstanceMap.put(rappInstanceId, rappInstance);
+ rapp.setRappInstances(rAppInstanceMap);
+ rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
+ RappHandlerException rappHandlerException =
+ assertThrows(RappHandlerException.class, () -> rappService.deleteRappInstance(rapp, rappInstanceId));
+ assertEquals(HttpStatus.BAD_REQUEST, rappHandlerException.getStatusCode());
+ assertEquals(String.format("Unable to delete rApp instance %s as it is not in UNDEPLOYED state",
+ rappInstance.getRappInstanceId()), rappHandlerException.getMessage());
+ assertEquals(RappState.PRIMED, rapp.getState());