Merge "Remove workarounds in ACM installation"
[nonrtric/plt/rappmanager.git] / rapp-manager-sme / src / test / java / com / oransc / rappmanager / sme / service / SmeDeployerTest.java
1 /*-
2  * ============LICENSE_START======================================================================
3  * Copyright (C) 2023 Nordix Foundation. All rights reserved.
4  * ===============================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END========================================================================
17  */
18
19 package com.oransc.rappmanager.sme.service;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertFalse;
23 import static org.junit.jupiter.api.Assertions.assertNull;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
26 import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
27 import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
28
29 import com.fasterxml.jackson.core.JsonProcessingException;
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import com.oransc.rappmanager.models.cache.RappCacheService;
32 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
33 import com.oransc.rappmanager.models.rapp.Rapp;
34 import com.oransc.rappmanager.models.rapp.RappState;
35 import com.oransc.rappmanager.models.rappinstance.RappInstance;
36 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
37 import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachine;
38 import com.oransc.rappmanager.models.statemachine.RappInstanceStateMachineConfig;
39 import com.oransc.rappmanager.sme.configuration.SmeConfiguration;
40 import com.oransc.rappmanager.sme.invoker.data.APIInvokerEnrolmentDetails;
41 import com.oransc.rappmanager.sme.provider.data.APIProviderEnrolmentDetails;
42 import com.oransc.rappmanager.sme.provider.data.APIProviderFunctionDetails;
43 import com.oransc.rappmanager.sme.provider.data.ApiProviderFuncRole;
44 import com.oransc.rappmanager.sme.publishservice.data.AefProfile;
45 import com.oransc.rappmanager.sme.publishservice.data.ServiceAPIDescription;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.UUID;
49 import org.junit.jupiter.api.BeforeAll;
50 import org.junit.jupiter.api.BeforeEach;
51 import org.junit.jupiter.api.Test;
52 import org.junit.jupiter.api.TestInstance;
53 import org.springframework.beans.factory.annotation.Autowired;
54 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
55 import org.springframework.boot.test.context.SpringBootTest;
56 import org.springframework.boot.test.mock.mockito.SpyBean;
57 import org.springframework.http.HttpMethod;
58 import org.springframework.http.HttpStatus;
59 import org.springframework.http.MediaType;
60 import org.springframework.test.web.client.ExpectedCount;
61 import org.springframework.test.web.client.MockRestServiceServer;
62 import org.springframework.web.client.RestTemplate;
63
64 @SpringBootTest(classes = {SmeConfiguration.class, SmeDeployer.class, BeanTestConfiguration.class,
65         RappCsarConfigurationHandler.class, RappCacheService.class, RappInstanceStateMachineConfig.class,
66         RappInstanceStateMachine.class})
67 @TestInstance(TestInstance.Lifecycle.PER_CLASS)
68 @AutoConfigureMockMvc
69 class SmeDeployerTest {
70
71     MockRestServiceServer mockServer;
72     @Autowired
73     @SpyBean
74     SmeDeployer smeDeployer;
75     @Autowired
76     RestTemplate restTemplate;
77     @Autowired
78     SmeConfiguration smeConfiguration;
79     String validCsarFileLocation = "src/test/resources/";
80     @Autowired
81     RappInstanceStateMachine rappInstanceStateMachine;
82     @Autowired
83     ObjectMapper objectMapper;
84     private final String validRappFile = "valid-rapp-package.csar";
85     String URI_PROVIDER_REGISTRATIONS, URI_PROVIDER_REGISTRATION, URI_PUBLISH_APIS, URI_PUBLISH_API, URI_INVOKERS,
86             URI_INVOKER;
87
88     @BeforeAll
89     void initSmeUri() {
90         URI_PROVIDER_REGISTRATIONS =
91                 smeConfiguration.getBaseUrl() + smeConfiguration.getProviderBasePath() + "registrations";
92         URI_PROVIDER_REGISTRATION =
93                 smeConfiguration.getBaseUrl() + smeConfiguration.getProviderBasePath() + "registrations/%s";
94         URI_PUBLISH_APIS = smeConfiguration.getBaseUrl() + smeConfiguration.getPublishApiBasePath() + "%s/service-apis";
95         URI_PUBLISH_API =
96                 smeConfiguration.getBaseUrl() + smeConfiguration.getPublishApiBasePath() + "%s/service-apis/%s";
97         URI_INVOKERS = smeConfiguration.getBaseUrl() + smeConfiguration.getInvokerBasePath() + "onboardedInvokers";
98         URI_INVOKER = smeConfiguration.getBaseUrl() + smeConfiguration.getInvokerBasePath() + "onboardedInvokers/%s";
99     }
100
101     @BeforeEach
102     public void init() {
103         mockServer = MockRestServiceServer.createServer(restTemplate);
104     }
105
106     @Test
107     void testCreateAMF() throws JsonProcessingException {
108         String apiProvDomId = UUID.randomUUID().toString();
109         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = new APIProviderEnrolmentDetails(apiProvDomId);
110         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
111                 .andExpect(method(HttpMethod.POST)).andRespond(
112                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
113                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
114         APIProviderEnrolmentDetails apiProviderEnrolmentResponse = smeDeployer.createAMF();
115         mockServer.verify();
116         assertEquals(apiProvDomId, apiProviderEnrolmentResponse.getApiProvDomId());
117     }
118
119     @Test
120     void testCreateAMFFailure() {
121         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
122                 .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
123         APIProviderEnrolmentDetails apiProviderEnrolmentResponse = smeDeployer.createAMF();
124         mockServer.verify();
125         assertNull(apiProviderEnrolmentResponse);
126     }
127
128     @Test
129     void testDeleteAMF() throws JsonProcessingException {
130         String apiProvDomId = UUID.randomUUID().toString();
131         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = new APIProviderEnrolmentDetails(apiProvDomId);
132         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
133                 .andExpect(method(HttpMethod.POST)).andRespond(
134                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
135                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
136         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PROVIDER_REGISTRATION, apiProvDomId)))
137                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
138         smeDeployer.createAMF();
139         smeDeployer.deleteAMF();
140         mockServer.verify();
141     }
142
143     @Test
144     void testCreateProviderDomain() throws Exception {
145         UUID rappId = UUID.randomUUID();
146         Rapp rapp =
147                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
148                         .state(RappState.COMMISSIONED).build();
149         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
150         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
151                 .andExpect(method(HttpMethod.POST)).andRespond(
152                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
153                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
154         RappInstance rappInstance = getRappInstance();
155         boolean createProviderDomain = smeDeployer.createProviderDomain(rapp, rappInstance);
156         mockServer.verify();
157         assertTrue(createProviderDomain);
158     }
159
160     @Test
161     void testCreateProviderDomainFailure() throws Exception {
162         UUID rappId = UUID.randomUUID();
163         Rapp rapp =
164                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
165                         .state(RappState.COMMISSIONED).build();
166         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
167                 .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
168         RappInstance rappInstance = getRappInstance();
169         boolean createProviderDomain = smeDeployer.createProviderDomain(rapp, rappInstance);
170         mockServer.verify();
171         assertFalse(createProviderDomain);
172     }
173
174     @Test
175     void testDeleteProviderFunc() {
176         UUID registrationId = UUID.randomUUID();
177         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PROVIDER_REGISTRATION, registrationId)))
178                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
179         smeDeployer.deleteProviderFunc(String.valueOf(registrationId));
180         mockServer.verify();
181     }
182
183     @Test
184     void testCreatePublishApi() throws Exception {
185         UUID rappId = UUID.randomUUID();
186         UUID apfId = UUID.randomUUID();
187         Rapp rapp =
188                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
189                         .state(RappState.COMMISSIONED).build();
190         ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
191         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_APIS, apfId)))
192                 .andExpect(method(HttpMethod.POST)).andRespond(
193                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
194                                 .body(objectMapper.writeValueAsString(serviceAPIDescription)));
195         RappInstance rappInstance = getRappInstance();
196         rappInstance.getSme().setApfId(String.valueOf(apfId));
197         boolean publishApi = smeDeployer.createPublishApi(rapp, rappInstance);
198         mockServer.verify();
199         assertTrue(publishApi);
200     }
201
202
203     @Test
204     void testCreatePublishApiFailure() throws Exception {
205         UUID rappId = UUID.randomUUID();
206         UUID apfId = UUID.randomUUID();
207         Rapp rapp =
208                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
209                         .state(RappState.COMMISSIONED).build();
210         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_APIS, apfId)))
211                 .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
212         RappInstance rappInstance = getRappInstance();
213         rappInstance.getSme().setApfId(String.valueOf(apfId));
214         boolean publishApi = smeDeployer.createPublishApi(rapp, rappInstance);
215         mockServer.verify();
216         assertFalse(publishApi);
217     }
218
219     @Test
220     void testDeletePublishApi() {
221         String serviceApiId = String.valueOf(UUID.randomUUID());
222         String apfId = String.valueOf(UUID.randomUUID());
223         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApiId)))
224                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
225         smeDeployer.deletePublishApi(serviceApiId, apfId);
226         mockServer.verify();
227     }
228
229     @Test
230     void testCreateInvoker() throws Exception {
231         UUID rappId = UUID.randomUUID();
232         Rapp rapp =
233                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
234                         .state(RappState.COMMISSIONED).build();
235         APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails = getApiInvokerEnrollmentDetails();
236         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST)).andRespond(
237                 withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
238                         .body(objectMapper.writeValueAsString(apiInvokerEnrolmentDetails)));
239         RappInstance rappInstance = getRappInstance();
240         boolean createInvoker = smeDeployer.createInvoker(rapp, rappInstance);
241         mockServer.verify();
242         assertTrue(createInvoker);
243     }
244
245     @Test
246     void testCreateInvokerFailure() {
247         UUID rappId = UUID.randomUUID();
248         Rapp rapp =
249                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
250                         .state(RappState.COMMISSIONED).build();
251         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST))
252                 .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
253         RappInstance rappInstance = getRappInstance();
254         boolean createInvoker = smeDeployer.createInvoker(rapp, rappInstance);
255         mockServer.verify();
256         assertFalse(createInvoker);
257     }
258
259     @Test
260     void testDeleteInvoker() {
261         String invokerId = String.valueOf(UUID.randomUUID());
262         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokerId)))
263                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
264         smeDeployer.deleteInvoker(invokerId);
265         mockServer.verify();
266     }
267
268     @Test
269     void testDeployRappInstance() throws Exception {
270         UUID rappId = UUID.randomUUID();
271         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
272         APIProviderFunctionDetails apfProviderFunctionDetails = apiProviderEnrolmentDetails.getApiProvFuncs().stream()
273                                                                         .filter(apiProviderFunctionDetails -> apiProviderFunctionDetails.getApiProvFuncRole()
274                                                                                                                       .equals(ApiProviderFuncRole.APF))
275                                                                         .findFirst().get();
276         Rapp rapp =
277                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
278                         .state(RappState.COMMISSIONED).build();
279         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
280                 .andExpect(method(HttpMethod.POST)).andRespond(
281                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
282                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
283         ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
284         mockServer.expect(ExpectedCount.once(),
285                         requestTo(String.format(URI_PUBLISH_APIS, apfProviderFunctionDetails.getApiProvFuncId())))
286                 .andExpect(method(HttpMethod.POST)).andRespond(
287                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
288                                 .body(objectMapper.writeValueAsString(serviceAPIDescription)));
289         APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails = getApiInvokerEnrollmentDetails();
290         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST)).andRespond(
291                 withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
292                         .body(objectMapper.writeValueAsString(apiInvokerEnrolmentDetails)));
293         RappInstance rappInstance = getRappInstance();
294         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
295         boolean deployRapp = smeDeployer.deployRappInstance(rapp, rappInstance);
296         mockServer.verify();
297         assertTrue(deployRapp);
298     }
299
300     @Test
301     void testDeployRappFailure() throws Exception {
302         UUID rappId = UUID.randomUUID();
303         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
304         APIProviderFunctionDetails apfProviderFunctionDetails = apiProviderEnrolmentDetails.getApiProvFuncs().stream()
305                                                                         .filter(apiProviderFunctionDetails -> apiProviderFunctionDetails.getApiProvFuncRole()
306                                                                                                                       .equals(ApiProviderFuncRole.APF))
307                                                                         .findFirst().get();
308         Rapp rapp =
309                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
310                         .state(RappState.COMMISSIONED).build();
311         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
312                 .andExpect(method(HttpMethod.POST)).andRespond(
313                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
314                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
315         ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
316         mockServer.expect(ExpectedCount.once(),
317                         requestTo(String.format(URI_PUBLISH_APIS, apfProviderFunctionDetails.getApiProvFuncId())))
318                 .andExpect(method(HttpMethod.POST)).andRespond(
319                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
320                                 .body(objectMapper.writeValueAsString(serviceAPIDescription)));
321         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST))
322                 .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
323         RappInstance rappInstance = getRappInstance();
324         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
325         boolean deployRapp = smeDeployer.deployRappInstance(rapp, rappInstance);
326         mockServer.verify();
327         assertFalse(deployRapp);
328     }
329
330     @Test
331     void testUndeployRappInstance() {
332         UUID rappId = UUID.randomUUID();
333         UUID apfId = UUID.randomUUID();
334         List<String> invokers = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
335         List<String> serviceApis = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
336         Map<String, String> providerFuncs = Map.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()),
337                 String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
338         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
339                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
340         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(0))))
341                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
342         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(1))))
343                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
344         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(0))))
345                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
346         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(1))))
347                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
348         mockServer.expect(ExpectedCount.once(),
349                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[0])))
350                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
351         mockServer.expect(ExpectedCount.once(),
352                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[1])))
353                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
354         RappInstance rappInstance = getRappInstance();
355         rappInstance.getSme().setApfId(String.valueOf(apfId));
356         rappInstance.getSme().setProviderFunctionIds(providerFuncs.values().stream().toList());
357         rappInstance.getSme().setServiceApiIds(serviceApis);
358         rappInstance.getSme().setInvokerIds(invokers);
359         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
360         boolean undeployRapp = smeDeployer.undeployRappInstance(rapp, rappInstance);
361         mockServer.verify();
362         assertTrue(undeployRapp);
363     }
364
365     @Test
366     void testUndeployRappInstanceFailure() {
367         UUID rappId = UUID.randomUUID();
368         UUID apfId = UUID.randomUUID();
369         List<String> invokers = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
370         List<String> serviceApis = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
371         Map<String, String> providerFuncs = Map.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()),
372                 String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
373         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
374                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
375         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(0))))
376                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
377         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(1))))
378                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
379         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(0))))
380                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
381         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(1))))
382                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
383         mockServer.expect(ExpectedCount.once(),
384                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[0])))
385                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
386         mockServer.expect(ExpectedCount.once(),
387                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[1])))
388                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
389         RappInstance rappInstance = getRappInstance();
390         rappInstance.getSme().setApfId(String.valueOf(apfId));
391         rappInstance.getSme().setProviderFunctionIds(providerFuncs.values().stream().toList());
392         rappInstance.getSme().setServiceApiIds(serviceApis);
393         rappInstance.getSme().setInvokerIds(invokers);
394         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
395         boolean undeployRapp = smeDeployer.undeployRappInstance(rapp, rappInstance);
396         mockServer.verify();
397         assertFalse(undeployRapp);
398     }
399
400     @Test
401     void testPrimingAndDeprimingDoesNothing() {
402         assertTrue(smeDeployer.primeRapp(null));
403         assertTrue(smeDeployer.deprimeRapp(null));
404     }
405
406     RappInstance getRappInstance() {
407         RappSMEInstance rappSMEInstance = new RappSMEInstance();
408         rappSMEInstance.setInvokers("invoker-app1");
409         rappSMEInstance.setServiceApis("api-set-1");
410         rappSMEInstance.setAefId("TEST_AEF_ID");
411         rappSMEInstance.setApfId(String.valueOf(UUID.randomUUID()));
412         rappSMEInstance.setProviderFunction("aef-provider-function");
413         RappInstance rappInstance = new RappInstance();
414         rappInstance.setSme(rappSMEInstance);
415         return rappInstance;
416     }
417
418     APIProviderEnrolmentDetails getProviderDomainApiEnrollmentDetails() {
419         APIProviderEnrolmentDetails apiProviderEnrolmentDetails =
420                 new APIProviderEnrolmentDetails(UUID.randomUUID().toString());
421         APIProviderFunctionDetails apiProviderFunctionDetailsAEF = new APIProviderFunctionDetails();
422         apiProviderFunctionDetailsAEF.setApiProvFuncInfo("AEF");
423         apiProviderFunctionDetailsAEF.setApiProvFuncRole(ApiProviderFuncRole.AEF);
424         apiProviderFunctionDetailsAEF.setApiProvFuncId(String.valueOf(UUID.randomUUID()));
425         APIProviderFunctionDetails apiProviderFunctionDetailsAPF = new APIProviderFunctionDetails();
426         apiProviderFunctionDetailsAPF.setApiProvFuncInfo("APF");
427         apiProviderFunctionDetailsAPF.setApiProvFuncRole(ApiProviderFuncRole.APF);
428         apiProviderFunctionDetailsAPF.setApiProvFuncId(String.valueOf(UUID.randomUUID()));
429         apiProviderEnrolmentDetails.setApiProvFuncs(
430                 List.of(apiProviderFunctionDetailsAEF, apiProviderFunctionDetailsAPF));
431         return apiProviderEnrolmentDetails;
432     }
433
434
435     ServiceAPIDescription getServiceApiDescription() {
436         ServiceAPIDescription serviceAPIDescription = new ServiceAPIDescription();
437         serviceAPIDescription.setApiId(String.valueOf(UUID.randomUUID()));
438         AefProfile aefProfile = new AefProfile();
439         aefProfile.setAefId(String.valueOf(UUID.randomUUID()));
440         serviceAPIDescription.setAefProfiles(List.of(aefProfile));
441         return serviceAPIDescription;
442     }
443
444     APIInvokerEnrolmentDetails getApiInvokerEnrollmentDetails() {
445         APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails =
446                 new APIInvokerEnrolmentDetails(String.valueOf(UUID.randomUUID()));
447         com.oransc.rappmanager.sme.invoker.data.ServiceAPIDescription serviceAPIDescription =
448                 new com.oransc.rappmanager.sme.invoker.data.ServiceAPIDescription();
449         serviceAPIDescription.setApiId(String.valueOf(UUID.randomUUID()));
450         apiInvokerEnrolmentDetails.setApiList(List.of(serviceAPIDescription));
451         return apiInvokerEnrolmentDetails;
452     }
453 }