Add initial version of code
[nonrtric/plt/rappmanager.git] / rapp-manager-application / 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 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
29
30 import com.fasterxml.jackson.core.JsonProcessingException;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32 import com.oransc.rappmanager.configuration.RappManagerConfiguration;
33 import com.oransc.rappmanager.models.Rapp;
34 import com.oransc.rappmanager.models.RappState;
35 import com.oransc.rappmanager.models.cache.RappCacheService;
36 import com.oransc.rappmanager.models.statemachine.RappStateMachine;
37 import com.oransc.rappmanager.sme.configuration.SmeConfiguration;
38 import com.oransc.rappmanager.sme.invoker.data.APIInvokerEnrolmentDetails;
39 import com.oransc.rappmanager.sme.provider.data.APIProviderEnrolmentDetails;
40 import com.oransc.rappmanager.sme.provider.data.APIProviderFunctionDetails;
41 import com.oransc.rappmanager.sme.provider.data.ApiProviderFuncRole;
42 import com.oransc.rappmanager.sme.publishservice.data.AefProfile;
43 import com.oransc.rappmanager.sme.publishservice.data.ServiceAPIDescription;
44 import java.io.File;
45 import java.io.FileInputStream;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.UUID;
49 import org.apache.http.entity.ContentType;
50 import org.junit.jupiter.api.BeforeAll;
51 import org.junit.jupiter.api.BeforeEach;
52 import org.junit.jupiter.api.Test;
53 import org.junit.jupiter.api.TestInstance;
54 import org.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
56 import org.springframework.boot.test.context.SpringBootTest;
57 import org.springframework.boot.test.mock.mockito.SpyBean;
58 import org.springframework.http.HttpMethod;
59 import org.springframework.http.HttpStatus;
60 import org.springframework.http.MediaType;
61 import org.springframework.mock.web.MockMultipartFile;
62 import org.springframework.test.context.TestPropertySource;
63 import org.springframework.test.web.client.ExpectedCount;
64 import org.springframework.test.web.client.MockRestServiceServer;
65 import org.springframework.test.web.servlet.MockMvc;
66 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
67 import org.springframework.web.client.RestTemplate;
68
69 @SpringBootTest
70 @TestPropertySource(properties = "rappmanager.csarlocation=src/test/resources")
71 @TestInstance(TestInstance.Lifecycle.PER_CLASS)
72 @AutoConfigureMockMvc
73 public class SmeDeployerTest {
74
75     MockRestServiceServer mockServer;
76     @SpyBean
77     SmeDeployer smeDeployer;
78     @Autowired
79     RestTemplate restTemplate;
80     @Autowired
81     SmeConfiguration smeConfiguration;
82     @Autowired
83     RappManagerConfiguration rappManagerConfiguration;
84     @Autowired
85     private MockMvc mockMvc;
86     @Autowired
87     RappCacheService rappCacheService;
88     @SpyBean
89     RappStateMachine rappStateMachine;
90     private final String validRappFile = "valid-rapp-package.csar";
91     ObjectMapper objectMapper = new ObjectMapper();
92     String URI_PROVIDER_REGISTRATIONS, URI_PROVIDER_REGISTRATION, URI_PUBLISH_APIS, URI_PUBLISH_API, URI_INVOKERS,
93             URI_INVOKER;
94
95     @BeforeAll
96     void initSmeUri() {
97         URI_PROVIDER_REGISTRATIONS =
98                 smeConfiguration.getBaseUrl() + smeConfiguration.getProviderBasePath() + "registrations";
99         URI_PROVIDER_REGISTRATION =
100                 smeConfiguration.getBaseUrl() + smeConfiguration.getProviderBasePath() + "registrations/%s";
101         URI_PUBLISH_APIS = smeConfiguration.getBaseUrl() + smeConfiguration.getPublishApiBasePath() + "%s/service-apis";
102         URI_PUBLISH_API =
103                 smeConfiguration.getBaseUrl() + smeConfiguration.getPublishApiBasePath() + "%s/service-apis/%s";
104         URI_INVOKERS = smeConfiguration.getBaseUrl() + smeConfiguration.getInvokerBasePath() + "onboardedInvokers";
105         URI_INVOKER = smeConfiguration.getBaseUrl() + smeConfiguration.getInvokerBasePath() + "onboardedInvokers/%s";
106     }
107
108     @BeforeEach
109     public void init() {
110         mockServer = MockRestServiceServer.createServer(restTemplate);
111     }
112
113     @Test
114     void testCreateAMF() throws JsonProcessingException {
115         String apiProvDomId = UUID.randomUUID().toString();
116         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = new APIProviderEnrolmentDetails(apiProvDomId);
117         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
118                 .andExpect(method(HttpMethod.POST)).andRespond(
119                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
120                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
121         APIProviderEnrolmentDetails apiProviderEnrolmentResponse = smeDeployer.createAMF();
122         mockServer.verify();
123         assertEquals(apiProvDomId, apiProviderEnrolmentResponse.getApiProvDomId());
124     }
125
126     @Test
127     void testCreateAMFFailure() {
128         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
129                 .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
130         APIProviderEnrolmentDetails apiProviderEnrolmentResponse = smeDeployer.createAMF();
131         mockServer.verify();
132         assertNull(apiProviderEnrolmentResponse);
133     }
134
135     @Test
136     void testDeleteAMF() throws JsonProcessingException {
137         String apiProvDomId = UUID.randomUUID().toString();
138         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = new APIProviderEnrolmentDetails(apiProvDomId);
139         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
140                 .andExpect(method(HttpMethod.POST)).andRespond(
141                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
142                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
143         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PROVIDER_REGISTRATION, apiProvDomId)))
144                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
145         smeDeployer.createAMF();
146         smeDeployer.deleteAMF();
147         mockServer.verify();
148     }
149
150     @Test
151     void testCreateProviderDomain() throws Exception {
152         UUID rappId = UUID.randomUUID();
153         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
154                             .packageLocation(rappManagerConfiguration.getCsarLocation()).state(RappState.ONBOARDED)
155                             .build();
156         onBoardRappCsar(rappId);
157         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
158         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
159                 .andExpect(method(HttpMethod.POST)).andRespond(
160                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
161                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
162         boolean createProviderDomain = smeDeployer.createProviderDomain(rapp);
163         mockServer.verify();
164         assertTrue(createProviderDomain);
165     }
166
167     @Test
168     void testCreateProviderDomainFailure() throws Exception {
169         UUID rappId = UUID.randomUUID();
170         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
171                             .packageLocation(rappManagerConfiguration.getCsarLocation()).state(RappState.ONBOARDED)
172                             .build();
173         onBoardRappCsar(rappId);
174         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
175                 .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
176         boolean createProviderDomain = smeDeployer.createProviderDomain(rapp);
177         mockServer.verify();
178         assertFalse(createProviderDomain);
179     }
180
181     @Test
182     void testDeleteProviderFunc() {
183         UUID registrationId = UUID.randomUUID();
184         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PROVIDER_REGISTRATION, registrationId)))
185                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
186         smeDeployer.deleteProviderFunc(String.valueOf(registrationId));
187         mockServer.verify();
188     }
189
190     @Test
191     void testCreatePublishApi() throws Exception {
192         UUID rappId = UUID.randomUUID();
193         UUID apfId = UUID.randomUUID();
194         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
195                             .packageLocation(rappManagerConfiguration.getCsarLocation()).state(RappState.ONBOARDED)
196                             .smeApfId(String.valueOf(apfId)).build();
197         onBoardRappCsar(rappId);
198         ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
199         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_APIS, apfId)))
200                 .andExpect(method(HttpMethod.POST)).andRespond(
201                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
202                                 .body(objectMapper.writeValueAsString(serviceAPIDescription)));
203         boolean publishApi = smeDeployer.createPublishApi(rapp);
204         mockServer.verify();
205         assertTrue(publishApi);
206     }
207
208
209     @Test
210     void testCreatePublishApiFailure() throws Exception {
211         UUID rappId = UUID.randomUUID();
212         UUID apfId = UUID.randomUUID();
213         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
214                             .packageLocation(rappManagerConfiguration.getCsarLocation()).state(RappState.ONBOARDED)
215                             .smeApfId(String.valueOf(apfId)).build();
216         onBoardRappCsar(rappId);
217         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_APIS, apfId)))
218                 .andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
219         boolean publishApi = smeDeployer.createPublishApi(rapp);
220         mockServer.verify();
221         assertFalse(publishApi);
222     }
223
224     @Test
225     void testDeletePublishApi() {
226         String serviceApiId = String.valueOf(UUID.randomUUID());
227         String apfId = String.valueOf(UUID.randomUUID());
228         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApiId)))
229                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
230         smeDeployer.deletePublishApi(serviceApiId, apfId);
231         mockServer.verify();
232     }
233
234     @Test
235     void testCreateInvoker() throws Exception {
236         UUID rappId = UUID.randomUUID();
237         UUID apfId = UUID.randomUUID();
238         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
239                             .packageLocation(rappManagerConfiguration.getCsarLocation()).state(RappState.ONBOARDED)
240                             .smeApfId(String.valueOf(apfId)).build();
241         onBoardRappCsar(rappId);
242         APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails = getApiInvokerEnrollmentDetails();
243         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST)).andRespond(
244                 withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
245                         .body(objectMapper.writeValueAsString(apiInvokerEnrolmentDetails)));
246         boolean createInvoker = smeDeployer.createInvoker(rapp);
247         mockServer.verify();
248         assertTrue(createInvoker);
249     }
250
251     @Test
252     void testCreateInvokerFailure() throws Exception {
253         UUID rappId = UUID.randomUUID();
254         UUID apfId = UUID.randomUUID();
255         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
256                             .packageLocation(rappManagerConfiguration.getCsarLocation()).state(RappState.ONBOARDED)
257                             .smeApfId(String.valueOf(apfId)).build();
258         onBoardRappCsar(rappId);
259         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST))
260                 .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
261         boolean createInvoker = smeDeployer.createInvoker(rapp);
262         mockServer.verify();
263         assertFalse(createInvoker);
264     }
265
266     @Test
267     void testDeleteInvoker() {
268         String invokerId = String.valueOf(UUID.randomUUID());
269         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokerId)))
270                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
271         smeDeployer.deleteInvoker(invokerId);
272         mockServer.verify();
273     }
274
275     @Test
276     void testDeployRapp() throws Exception {
277         UUID rappId = UUID.randomUUID();
278         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
279         APIProviderFunctionDetails apfProviderFunctionDetails = apiProviderEnrolmentDetails.getApiProvFuncs().stream()
280                                                                         .filter(apiProviderFunctionDetails -> apiProviderFunctionDetails.getApiProvFuncRole()
281                                                                                                                       .equals(ApiProviderFuncRole.APF))
282                                                                         .findFirst().get();
283         onBoardRappCsar(rappId);
284         Rapp rapp = rappCacheService.getRapp(String.valueOf(rappId)).get();
285         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
286                 .andExpect(method(HttpMethod.POST)).andRespond(
287                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
288                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
289         ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
290         mockServer.expect(ExpectedCount.once(),
291                         requestTo(String.format(URI_PUBLISH_APIS, apfProviderFunctionDetails.getApiProvFuncId())))
292                 .andExpect(method(HttpMethod.POST)).andRespond(
293                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
294                                 .body(objectMapper.writeValueAsString(serviceAPIDescription)));
295         APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails = getApiInvokerEnrollmentDetails();
296         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST)).andRespond(
297                 withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
298                         .body(objectMapper.writeValueAsString(apiInvokerEnrolmentDetails)));
299         boolean deployRapp = smeDeployer.deployRapp(rapp);
300         mockServer.verify();
301         assertTrue(deployRapp);
302     }
303
304     @Test
305     void testDeployRappFailure() throws Exception {
306         UUID rappId = UUID.randomUUID();
307         APIProviderEnrolmentDetails apiProviderEnrolmentDetails = getProviderDomainApiEnrollmentDetails();
308         APIProviderFunctionDetails apfProviderFunctionDetails = apiProviderEnrolmentDetails.getApiProvFuncs().stream()
309                                                                         .filter(apiProviderFunctionDetails -> apiProviderFunctionDetails.getApiProvFuncRole()
310                                                                                                                       .equals(ApiProviderFuncRole.APF))
311                                                                         .findFirst().get();
312         onBoardRappCsar(rappId);
313         Rapp rapp = rappCacheService.getRapp(String.valueOf(rappId)).get();
314         mockServer.expect(ExpectedCount.once(), requestTo(URI_PROVIDER_REGISTRATIONS))
315                 .andExpect(method(HttpMethod.POST)).andRespond(
316                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
317                                 .body(objectMapper.writeValueAsString(apiProviderEnrolmentDetails)));
318         ServiceAPIDescription serviceAPIDescription = getServiceApiDescription();
319         mockServer.expect(ExpectedCount.once(),
320                         requestTo(String.format(URI_PUBLISH_APIS, apfProviderFunctionDetails.getApiProvFuncId())))
321                 .andExpect(method(HttpMethod.POST)).andRespond(
322                         withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON)
323                                 .body(objectMapper.writeValueAsString(serviceAPIDescription)));
324         mockServer.expect(ExpectedCount.once(), requestTo(URI_INVOKERS)).andExpect(method(HttpMethod.POST))
325                 .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
326         boolean deployRapp = smeDeployer.deployRapp(rapp);
327         mockServer.verify();
328         assertFalse(deployRapp);
329     }
330
331     @Test
332     void testUndeployRapp() throws Exception {
333         UUID rappId = UUID.randomUUID();
334         UUID apfId = UUID.randomUUID();
335         List<String> invokers = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
336         List<String> serviceApis = List.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
337         Map<String, String> providerFuncs = Map.of(String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()),
338                 String.valueOf(UUID.randomUUID()), String.valueOf(UUID.randomUUID()));
339         Rapp rapp = Rapp.builder().rappId(rappId).name(rappId.toString()).packageName(validRappFile)
340                             .packageLocation(rappManagerConfiguration.getCsarLocation()).state(RappState.ONBOARDED)
341                             .smeApfId(String.valueOf(apfId)).smeInvokers(invokers).smeServiceApis(serviceApis)
342                             .smeProviderFunctions(providerFuncs).build();
343         onBoardRappCsar(rappId);
344         rapp.setRappId(rappCacheService.getRapp(String.valueOf(rappId)).get().getRappId());
345         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(0))))
346                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
347         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(1))))
348                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
349         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(0))))
350                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
351         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(1))))
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()[0])))
355                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
356         mockServer.expect(ExpectedCount.once(),
357                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[1])))
358                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
359
360         boolean undeployRapp = smeDeployer.undeployRapp(rapp);
361         mockServer.verify();
362         assertTrue(undeployRapp);
363     }
364
365     @Test
366     void testUndeployRappFailure() throws Exception {
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(rappManagerConfiguration.getCsarLocation()).state(RappState.ONBOARDED)
375                             .smeApfId(String.valueOf(apfId)).smeInvokers(invokers).smeServiceApis(serviceApis)
376                             .smeProviderFunctions(providerFuncs).build();
377         onBoardRappCsar(rappId);
378         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(0))))
379                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
380         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_INVOKER, invokers.get(1))))
381                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
382         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(0))))
383                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
384         mockServer.expect(ExpectedCount.once(), requestTo(String.format(URI_PUBLISH_API, apfId, serviceApis.get(1))))
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()[0])))
388                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.NO_CONTENT));
389         mockServer.expect(ExpectedCount.once(),
390                         requestTo(String.format(URI_PROVIDER_REGISTRATION, providerFuncs.values().toArray()[1])))
391                 .andExpect(method(HttpMethod.DELETE)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
392
393         boolean undeployRapp = smeDeployer.undeployRapp(rapp);
394         mockServer.verify();
395         assertFalse(undeployRapp);
396     }
397
398     APIProviderEnrolmentDetails getProviderDomainApiEnrollmentDetails() {
399         APIProviderEnrolmentDetails apiProviderEnrolmentDetails =
400                 new APIProviderEnrolmentDetails(UUID.randomUUID().toString());
401         APIProviderFunctionDetails apiProviderFunctionDetailsAEF = new APIProviderFunctionDetails();
402         apiProviderFunctionDetailsAEF.setApiProvFuncInfo("AEF");
403         apiProviderFunctionDetailsAEF.setApiProvFuncRole(ApiProviderFuncRole.AEF);
404         apiProviderFunctionDetailsAEF.setApiProvFuncId(String.valueOf(UUID.randomUUID()));
405         APIProviderFunctionDetails apiProviderFunctionDetailsAPF = new APIProviderFunctionDetails();
406         apiProviderFunctionDetailsAPF.setApiProvFuncInfo("APF");
407         apiProviderFunctionDetailsAPF.setApiProvFuncRole(ApiProviderFuncRole.APF);
408         apiProviderFunctionDetailsAPF.setApiProvFuncId(String.valueOf(UUID.randomUUID()));
409         apiProviderEnrolmentDetails.setApiProvFuncs(
410                 List.of(apiProviderFunctionDetailsAEF, apiProviderFunctionDetailsAPF));
411         return apiProviderEnrolmentDetails;
412     }
413
414
415     ServiceAPIDescription getServiceApiDescription() {
416         ServiceAPIDescription serviceAPIDescription = new ServiceAPIDescription();
417         AefProfile aefProfile = new AefProfile();
418         aefProfile.setAefId(String.valueOf(UUID.randomUUID()));
419         serviceAPIDescription.setAefProfiles(List.of(aefProfile));
420         return serviceAPIDescription;
421     }
422
423     APIInvokerEnrolmentDetails getApiInvokerEnrollmentDetails() {
424         APIInvokerEnrolmentDetails apiInvokerEnrolmentDetails = new APIInvokerEnrolmentDetails();
425         com.oransc.rappmanager.sme.invoker.data.ServiceAPIDescription serviceAPIDescription =
426                 new com.oransc.rappmanager.sme.invoker.data.ServiceAPIDescription();
427         serviceAPIDescription.setApiId(String.valueOf(UUID.randomUUID()));
428         apiInvokerEnrolmentDetails.setApiList(List.of(serviceAPIDescription));
429         return apiInvokerEnrolmentDetails;
430     }
431
432     void onBoardRappCsar(UUID rappId) throws Exception {
433         String rappCsarPath = rappManagerConfiguration.getCsarLocation() + File.separator + validRappFile;
434         MockMultipartFile multipartFile =
435                 new MockMultipartFile("file", validRappFile, ContentType.MULTIPART_FORM_DATA.getMimeType(),
436                         new FileInputStream(rappCsarPath));
437         mockMvc.perform(MockMvcRequestBuilders.multipart("/rapps/{rapp_id}/onboard", rappId).file(multipartFile))
438                 .andExpect(status().isAccepted());
439     }
440 }