Fix sonar code smells
[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.rapp.Rapp;
32 import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler;
33 import com.oransc.rappmanager.models.rappinstance.RappInstance;
34 import com.oransc.rappmanager.models.rappinstance.RappSMEInstance;
35 import com.oransc.rappmanager.models.rapp.RappState;
36 import com.oransc.rappmanager.models.cache.RappCacheService;
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     RappCacheService rappCacheService;
84     @Autowired
85     ObjectMapper objectMapper;
86     private final String validRappFile = "valid-rapp-package.csar";
87     String URI_PROVIDER_REGISTRATIONS, URI_PROVIDER_REGISTRATION, URI_PUBLISH_APIS, URI_PUBLISH_API, URI_INVOKERS,
88             URI_INVOKER;
89
90     @BeforeAll
91     void initSmeUri() {
92         URI_PROVIDER_REGISTRATIONS =
93                 smeConfiguration.getBaseUrl() + smeConfiguration.getProviderBasePath() + "registrations";
94         URI_PROVIDER_REGISTRATION =
95                 smeConfiguration.getBaseUrl() + smeConfiguration.getProviderBasePath() + "registrations/%s";
96         URI_PUBLISH_APIS = smeConfiguration.getBaseUrl() + smeConfiguration.getPublishApiBasePath() + "%s/service-apis";
97         URI_PUBLISH_API =
98                 smeConfiguration.getBaseUrl() + smeConfiguration.getPublishApiBasePath() + "%s/service-apis/%s";
99         URI_INVOKERS = smeConfiguration.getBaseUrl() + smeConfiguration.getInvokerBasePath() + "onboardedInvokers";
100         URI_INVOKER = smeConfiguration.getBaseUrl() + smeConfiguration.getInvokerBasePath() + "onboardedInvokers/%s";
101     }
102
103     @BeforeEach
104     public void init() {
105         mockServer = MockRestServiceServer.createServer(restTemplate);
106     }
107
108     @Test
109     void testCreateAMF() throws JsonProcessingException {
110         String apiProvDomId = UUID.randomUUID().toString();
111         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = new APIProviderEnrolmentDetails(apiProvDomId);
112         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
113                 .andExpect(method(HttpMethod.POST)).andRespond(
114                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
115                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
116         APIProviderEnrolmentDetails apiProviderEnrolmentResponse = smeDeployer.createAMF();
117         mockServer.verify();
118         assertEquals(apiProvDomId, apiProviderEnrolmentResponse.getApiProvDomId());
119     }
120
121     @Test
122     void testCreateAMFFailure() {
123         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
124                 .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
125         APIProviderEnrolmentDetails apiProviderEnrolmentResponse = smeDeployer.createAMF();
126         mockServer.verify();
127         assertNull(apiProviderEnrolmentResponse);
128     }
129
130     @Test
131     void testDeleteAMF() throws JsonProcessingException {
132         String apiProvDomId = UUID.randomUUID().toString();
133         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = new APIProviderEnrolmentDetails(apiProvDomId);
134         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
135                 .andExpect(method(HttpMethod.POST)).andRespond(
136                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
137                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
138         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PROVIDER_REGISTRATION, apiProvDomId)))
139                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
140         smeDeployer.createAMF();
141         smeDeployer.deleteAMF();
142         mockServer.verify();
143     }
144
145     @Test
146     void testCreateProviderDomain() throws Exception {
147         UUID rappId = UUID.randomUUID();
148         Rapp rapp =
149                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
150                         .state(RappState.COMMISSIONED).build();
151         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
152         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
153                 .andExpect(method(HttpMethod.POST)).andRespond(
154                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
155                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
156         RappInstance rappInstance = getRappInstance();
157         boolean createProviderDomain = smeDeployer.createProviderDomain(rapp, rappInstance);
158         mockServer.verify();
159         assertTrue(createProviderDomain);
160     }
161
162     @Test
163     void testCreateProviderDomainFailure() throws Exception {
164         UUID rappId = UUID.randomUUID();
165         Rapp rapp =
166                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
167                         .state(RappState.COMMISSIONED).build();
168         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
169                 .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
170         RappInstance rappInstance = getRappInstance();
171         boolean createProviderDomain = smeDeployer.createProviderDomain(rapp, rappInstance);
172         mockServer.verify();
173         assertFalse(createProviderDomain);
174     }
175
176     @Test
177     void testDeleteProviderFunc() {
178         UUID registrationId = UUID.randomUUID();
179         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PROVIDER_REGISTRATION, registrationId)))
180                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
181         smeDeployer.deleteProviderFunc(String.valueOf(registrationId));
182         mockServer.verify();
183     }
184
185     @Test
186     void testCreatePublishApi() throws Exception {
187         UUID rappId = UUID.randomUUID();
188         UUID apfId = UUID.randomUUID();
189         Rapp rapp =
190                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
191                         .state(RappState.COMMISSIONED).build();
192         ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
193         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_APIS, apfId)))
194                 .andExpect(method(HttpMethod.POST)).andRespond(
195                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
196                                 .body(objectMapper.writeValueAsString(serviceAPIDescription)));
197         RappInstance rappInstance = getRappInstance();
198         rappInstance.getSme().setApfId(String.valueOf(apfId));
199         boolean publishApi = smeDeployer.createPublishApi(rapp, rappInstance);
200         mockServer.verify();
201         assertTrue(publishApi);
202     }
203
204
205     @Test
206     void testCreatePublishApiFailure() throws Exception {
207         UUID rappId = UUID.randomUUID();
208         UUID apfId = UUID.randomUUID();
209         Rapp rapp =
210                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
211                         .state(RappState.COMMISSIONED).build();
212         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_APIS, apfId)))
213                 .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
214         RappInstance rappInstance = getRappInstance();
215         rappInstance.getSme().setApfId(String.valueOf(apfId));
216         boolean publishApi = smeDeployer.createPublishApi(rapp, rappInstance);
217         mockServer.verify();
218         assertFalse(publishApi);
219     }
220
221     @Test
222     void testDeletePublishApi() {
223         String serviceApiId = String.valueOf(UUID.randomUUID());
224         String apfId = String.valueOf(UUID.randomUUID());
225         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApiId)))
226                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
227         smeDeployer.deletePublishApi(serviceApiId, apfId);
228         mockServer.verify();
229     }
230
231     @Test
232     void testCreateInvoker() throws Exception {
233         UUID rappId = UUID.randomUUID();
234         Rapp rapp =
235                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
236                         .state(RappState.COMMISSIONED).build();
237         APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails = getApiInvokerEnrollmentDetails();
238         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST)).andRespond(
239                 withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
240                         .body(objectMapper.writeValueAsString(apiInvokerEnrolmentDetails)));
241         RappInstance rappInstance = getRappInstance();
242         boolean createInvoker = smeDeployer.createInvoker(rapp, rappInstance);
243         mockServer.verify();
244         assertTrue(createInvoker);
245     }
246
247     @Test
248     void testCreateInvokerFailure() throws Exception {
249         UUID rappId = UUID.randomUUID();
250         Rapp rapp =
251                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
252                         .state(RappState.COMMISSIONED).build();
253         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST))
254                 .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
255         RappInstance rappInstance = getRappInstance();
256         boolean createInvoker = smeDeployer.createInvoker(rapp, rappInstance);
257         mockServer.verify();
258         assertFalse(createInvoker);
259     }
260
261     @Test
262     void testDeleteInvoker() {
263         String invokerId = String.valueOf(UUID.randomUUID());
264         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokerId)))
265                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
266         smeDeployer.deleteInvoker(invokerId);
267         mockServer.verify();
268     }
269
270     @Test
271     void testDeployRappInstance() throws Exception {
272         UUID rappId = UUID.randomUUID();
273         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
274         APIProviderFunctionDetails apfProviderFunctionDetails = apiProviderEnrolmentDetails.getApiProvFuncs().stream()
275                                                                         .filter(apiProviderFunctionDetails -> apiProviderFunctionDetails.getApiProvFuncRole()
276                                                                                                                       .equals(ApiProviderFuncRole.APF))
277                                                                         .findFirst().get();
278         Rapp rapp =
279                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
280                         .state(RappState.COMMISSIONED).build();
281         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
282                 .andExpect(method(HttpMethod.POST)).andRespond(
283                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
284                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
285         ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
286         mockServer.expect(ExpectedCount.once(),
287                         requestTo(String.format(URI_PUBLISH_APIS, apfProviderFunctionDetails.getApiProvFuncId())))
288                 .andExpect(method(HttpMethod.POST)).andRespond(
289                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
290                                 .body(objectMapper.writeValueAsString(serviceAPIDescription)));
291         APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails = getApiInvokerEnrollmentDetails();
292         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST)).andRespond(
293                 withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
294                         .body(objectMapper.writeValueAsString(apiInvokerEnrolmentDetails)));
295         RappInstance rappInstance = getRappInstance();
296         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
297         boolean deployRapp = smeDeployer.deployRappInstance(rapp, rappInstance);
298         mockServer.verify();
299         assertTrue(deployRapp);
300     }
301
302     @Test
303     void testDeployRappFailure() throws Exception {
304         UUID rappId = UUID.randomUUID();
305         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
306         APIProviderFunctionDetails apfProviderFunctionDetails = apiProviderEnrolmentDetails.getApiProvFuncs().stream()
307                                                                         .filter(apiProviderFunctionDetails -> apiProviderFunctionDetails.getApiProvFuncRole()
308                                                                                                                       .equals(ApiProviderFuncRole.APF))
309                                                                         .findFirst().get();
310         Rapp rapp =
311                 Rapp.builder().rappId(rappId).name("").packageName(validRappFile).packageLocation(validCsarFileLocation)
312                         .state(RappState.COMMISSIONED).build();
313         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
314                 .andExpect(method(HttpMethod.POST)).andRespond(
315                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
316                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
317         ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
318         mockServer.expect(ExpectedCount.once(),
319                         requestTo(String.format(URI_PUBLISH_APIS, apfProviderFunctionDetails.getApiProvFuncId())))
320                 .andExpect(method(HttpMethod.POST)).andRespond(
321                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
322                                 .body(objectMapper.writeValueAsString(serviceAPIDescription)));
323         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST))
324                 .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
325         RappInstance rappInstance = getRappInstance();
326         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
327         boolean deployRapp = smeDeployer.deployRappInstance(rapp, rappInstance);
328         mockServer.verify();
329         assertFalse(deployRapp);
330     }
331
332     @Test
333     void testUndeployRappInstance() {
334         UUID rappId = UUID.randomUUID();
335         UUID apfId = UUID.randomUUID();
336         List<String> invokers = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
337         List<String> serviceApis = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
338         Map<String, String> providerFuncs = Map.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()),
339                 String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
340         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
341                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
342         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(0))))
343                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
344         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(1))))
345                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
346         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(0))))
347                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
348         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(1))))
349                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
350         mockServer.expect(ExpectedCount.once(),
351                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[0])))
352                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
353         mockServer.expect(ExpectedCount.once(),
354                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[1])))
355                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
356         RappInstance rappInstance = getRappInstance();
357         rappInstance.getSme().setApfId(String.valueOf(apfId));
358         rappInstance.getSme().setProviderFunctionIds(providerFuncs.values().stream().toList());
359         rappInstance.getSme().setServiceApiIds(serviceApis);
360         rappInstance.getSme().setInvokerIds(invokers);
361         rappInstanceStateMachine.onboardRappInstance(rappInstance.getRappInstanceId());
362         boolean undeployRapp = smeDeployer.undeployRappInstance(rapp, rappInstance);
363         mockServer.verify();
364         assertTrue(undeployRapp);
365     }
366
367     @Test
368     void testUndeployRappInstanceFailure() throws Exception {
369         UUID rappId = UUID.randomUUID();
370         UUID apfId = UUID.randomUUID();
371         List<String> invokers = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
372         List<String> serviceApis = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
373         Map<String, String> providerFuncs = Map.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()),
374                 String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
375         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
376                             .packageLocation(validCsarFileLocation).state(RappState.COMMISSIONED).build();
377         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(0))))
378                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
379         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(1))))
380                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
381         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(0))))
382                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
383         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(1))))
384                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
385         mockServer.expect(ExpectedCount.once(),
386                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[0])))
387                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
388         mockServer.expect(ExpectedCount.once(),
389                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[1])))
390                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
391         RappInstance rappInstance = getRappInstance();
392         rappInstance.getSme().setApfId(String.valueOf(apfId));
393         rappInstance.getSme().setProviderFunctionIds(providerFuncs.values().stream().toList());
394         rappInstance.getSme().setServiceApiIds(serviceApis);
395         rappInstance.getSme().setInvokerIds(invokers);
396         boolean undeployRapp = smeDeployer.undeployRappInstance(rapp, rappInstance);
397         mockServer.verify();
398         assertFalse(undeployRapp);
399     }
400
401     RappInstance getRappInstance() {
402         RappSMEInstance rappSMEInstance = new RappSMEInstance();
403         rappSMEInstance.setInvokers("invoker-app1");
404         rappSMEInstance.setServiceApis("api-set-1");
405         rappSMEInstance.setAefId("TEST_AEF_ID");
406         rappSMEInstance.setApfId(String.valueOf(UUID.randomUUID()));
407         rappSMEInstance.setProviderFunction("aef-provider-function");
408         RappInstance rappInstance = new RappInstance();
409         rappInstance.setSme(rappSMEInstance);
410         return rappInstance;
411     }
412
413     APIProviderEnrolmentDetails getProviderDomainApiEnrollmentDetails() {
414         APIProviderEnrolmentDetails apiProviderEnrolmentDetails =
415                 new APIProviderEnrolmentDetails(UUID.randomUUID().toString());
416         APIProviderFunctionDetails apiProviderFunctionDetailsAEF = new APIProviderFunctionDetails();
417         apiProviderFunctionDetailsAEF.setApiProvFuncInfo("AEF");
418         apiProviderFunctionDetailsAEF.setApiProvFuncRole(ApiProviderFuncRole.AEF);
419         apiProviderFunctionDetailsAEF.setApiProvFuncId(String.valueOf(UUID.randomUUID()));
420         APIProviderFunctionDetails apiProviderFunctionDetailsAPF = new APIProviderFunctionDetails();
421         apiProviderFunctionDetailsAPF.setApiProvFuncInfo("APF");
422         apiProviderFunctionDetailsAPF.setApiProvFuncRole(ApiProviderFuncRole.APF);
423         apiProviderFunctionDetailsAPF.setApiProvFuncId(String.valueOf(UUID.randomUUID()));
424         apiProviderEnrolmentDetails.setApiProvFuncs(
425                 List.of(apiProviderFunctionDetailsAEF, apiProviderFunctionDetailsAPF));
426         return apiProviderEnrolmentDetails;
427     }
428
429
430     ServiceAPIDescription getServiceApiDescription() {
431         ServiceAPIDescription serviceAPIDescription = new ServiceAPIDescription();
432         serviceAPIDescription.setApiId(String.valueOf(UUID.randomUUID()));
433         AefProfile aefProfile = new AefProfile();
434         aefProfile.setAefId(String.valueOf(UUID.randomUUID()));
435         serviceAPIDescription.setAefProfiles(List.of(aefProfile));
436         return serviceAPIDescription;
437     }
438
439     APIInvokerEnrolmentDetails getApiInvokerEnrollmentDetails() {
440         APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails =
441                 new APIInvokerEnrolmentDetails(String.valueOf(UUID.randomUUID()));
442         com.oransc.rappmanager.sme.invoker.data.ServiceAPIDescription serviceAPIDescription =
443                 new com.oransc.rappmanager.sme.invoker.data.ServiceAPIDescription();
444         serviceAPIDescription.setApiId(String.valueOf(UUID.randomUUID()));
445         apiInvokerEnrolmentDetails.setApiList(List.of(serviceAPIDescription));
446         return apiInvokerEnrolmentDetails;
447     }
448 }