+ @Test
+ void testUndeployRappInstanceNoInvokers() {
+ UUID rappId = UUID.randomUUID();
+ UUID apfId = UUID.randomUUID();
+ List<String> serviceApis = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
+ Map<String, String> providerFuncs = Map.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()),
+ String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
+ Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
+ .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+ mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(0))))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(1))))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockServer.expect(ExpectedCount.once(),
+ requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[0])))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockServer.expect(ExpectedCount.once(),
+ requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[1])))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ RappInstance rappInstance = getRappInstance();
+ rappInstance.getSme().setApfId(String.valueOf(apfId));
+ rappInstance.getSme().setProviderFunctionIds(providerFuncs.values().stream().toList());
+ rappInstance.getSme().setServiceApiIds(serviceApis);
+ rappInstance.getSme().setInvokerIds(null);
+ rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
+ boolean undeployRapp = smeDeployer.undeployRappInstance(rapp, rappInstance);
+ mockServer.verify();
+ assertTrue(undeployRapp);
+ }
+
+ @Test
+ void testUndeployRappInstanceNoProviders() {
+ UUID rappId = UUID.randomUUID();
+ UUID apfId = UUID.randomUUID();
+ List<String> invokers = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
+ Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
+ .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
+ mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(0))))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(1))))
+ .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
+ RappInstance rappInstance = getRappInstance();
+ rappInstance.getSme().setApfId(String.valueOf(apfId));
+ rappInstance.getSme().setProviderFunctionIds(null);
+ rappInstance.getSme().setServiceApiIds(null);
+ rappInstance.getSme().setInvokerIds(invokers);
+ rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
+ boolean undeployRapp = smeDeployer.undeployRappInstance(rapp, rappInstance);
+ mockServer.verify();
+ assertTrue(undeployRapp);
+ }
+