aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java
blob: 09f0fd3572e51ffc71836640aebb3b7b66838e64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*-
 * ============LICENSE_START=======================================================
 * VID
 * ================================================================================
 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.vid.controller;

import static java.lang.String.format;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.when;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.jeasy.random.EasyRandom;
import org.jeasy.random.EasyRandomParameters;
import org.jeasy.random.randomizers.misc.BooleanRandomizer;
import org.jeasy.random.randomizers.text.StringRandomizer;
import org.junit.Before;
import org.junit.Test;
import org.onap.vid.model.RequestReferencesContainer;
import org.onap.vid.mso.MsoBusinessLogic;
import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapper2;
import org.onap.vid.mso.RestMsoImplementation;
import org.onap.vid.mso.RestObject;
import org.onap.vid.mso.rest.Request;
import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.mso.rest.RequestDetailsWrapper;
import org.onap.vid.mso.rest.Task;
import org.onap.vid.services.CloudOwnerService;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

public class MsoControllerTest {

    private static final long STATIC_SEED = 5336L;
    private EasyRandomParameters parameters = new EasyRandomParameters()
        .randomize(Boolean.class, new BooleanRandomizer(STATIC_SEED))
        .randomize(String.class, new StringRandomizer(4, 4, STATIC_SEED))
        .collectionSizeRange(2, 3);
    private EasyRandom modelGenerator = new EasyRandom(parameters);
    private ObjectMapper objectMapper = new ObjectMapper();

    private MockMvc mockMvc;
    private MsoBusinessLogic msoBusinessLogic;
    private CloudOwnerService cloudService;
    private RestMsoImplementation msoRestClient;

    @Before
    public void setUp() {
        msoBusinessLogic = mock(MsoBusinessLogic.class);
        cloudService = mock(CloudOwnerService.class);
        msoRestClient = mock(RestMsoImplementation.class);
        MsoController msoController = new MsoController(msoBusinessLogic, msoRestClient, cloudService);

        mockMvc = MockMvcBuilders.standaloneSetup(msoController).build();
    }

    @Test
    public void shouldGetOrchestrationRequest() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String requestId = "bc305d54-75b4-431b-adb2-eb6b9e546014";

        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
        given(msoBusinessLogic
            .getOrchestrationRequest(requestId))
            .willReturn(expectedResponse);

        // when & then
        mockMvc.perform(get(format("/mso/mso_get_orch_req/%s", requestId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));

        then(cloudService).shouldHaveZeroInteractions();
    }

    @Test
    public void shouldDelegateNewServiceInstantiation() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);

        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
        given(msoBusinessLogic
            .createSvcInstance(objectEqualTo(requestDetails)))
            .willReturn(expectedResponse);

        // when & then
        mockMvc.perform(post("/mso/mso_create_svc_instance")
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldCreateVfModuleInstance() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String vnfInstanceId = "fe9000-0009-9999";

        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
        given(msoBusinessLogic
            .createVfModuleInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId)))
            .willReturn(expectedResponse);

        // when & then
        mockMvc.perform(post(format("/mso/mso_create_vfmodule_instance/%s/vnfs/%s", serviceInstanceId, vnfInstanceId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }
    
    @Test
    public void shouldCreateConfigurationInstance() throws Exception {
        // given
        RequestDetailsWrapper requestDetails = modelGenerator.nextObject(RequestDetailsWrapper.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";

        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
        given(msoBusinessLogic
            .createConfigurationInstance(objectEqualTo(requestDetails), eq(serviceInstanceId)))
            .willReturn(expectedResponse);

        // when & then
        mockMvc.perform(post(format("/mso/mso_create_configuration_instance/%s/configurations/", serviceInstanceId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails.getRequestDetails()));
    }

    @Test
    public void shouldDeleteE2eSvcInstance() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String configurationId = "28630972-d548-4d5f-acc2-ad1d748d023d";

        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
        given(msoBusinessLogic
            .setConfigurationActiveStatus(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId), eq(true)))
            .willReturn(expectedResponse);

        // when & then
        mockMvc.perform(post(format("/mso/mso_activate_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldDeactivateConfiguration() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String configurationId = "28630972-d548-4d5f-acc2-ad1d748d023d";

        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
        given(msoBusinessLogic
            .setConfigurationActiveStatus(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId), eq(false)))
            .willReturn(expectedResponse);

        // when & then
        mockMvc.perform(post(format("/mso/mso_deactivate_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldDisablePortOnConfiguration() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String configurationId = "28630972-d548-4d5f-acc2-ad1d748d023d";

        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
        given(msoBusinessLogic
            .setPortOnConfigurationStatus(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId), eq(false)))
            .willReturn(expectedResponse);

        // when & then
        mockMvc.perform(post(format("/mso/mso_disable_port_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldEnablePortOnConfiguration() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String configurationId = "28630972-d548-4d5f-acc2-ad1d748d023d";

        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
        given(msoBusinessLogic
            .setPortOnConfigurationStatus(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId), eq(true)))
            .willReturn(expectedResponse);

        // when & then
        mockMvc.perform(post(format("/mso/mso_enable_port_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldCreateVolumeInstance() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String vnfInstanceId = "fe9000-0009-9999";

        MsoResponseWrapper expectedResponse = new MsoResponseWrapper(200, "test");
        given(msoBusinessLogic
            .createVolumeGroupInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId)))
            .willReturn(expectedResponse);

        // when & then
        mockMvc.perform(post(format("/mso/mso_create_volumegroup_instance/%s/vnfs/%s", serviceInstanceId, vnfInstanceId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldReturnOrchestrationRequestsForDashboard() throws Exception {
        // given
        List<Request> orchestrationRequests = modelGenerator
            .objects(Request.class, 2)
            .collect(Collectors.toList());

        given(msoBusinessLogic.getOrchestrationRequestsForDashboard()).willReturn(orchestrationRequests);

        // when & then
        mockMvc.perform(get("/mso/mso_get_orch_reqs/dashboard"))
            .andExpect(status().isOk())
            .andExpect(content().json(objectMapper.writeValueAsString(orchestrationRequests)));

        then(cloudService).shouldHaveZeroInteractions();
    }

    @Test
    public void shouldReturnManualTasksById() throws Exception {
        // given
        List<Task> manualTasks = modelGenerator
            .objects(Task.class, 2)
            .collect(Collectors.toList());

        String originalRequestId = "za1234d1-5a33-55df-13ab-12abad84e335";
        given(msoBusinessLogic.getManualTasksByRequestId(originalRequestId)).willReturn(manualTasks);

        // when & then
        mockMvc.perform(get("/mso/mso_get_man_task/{id}", originalRequestId))
            .andExpect(status().isOk())
            .andExpect(content().json(objectMapper.writeValueAsString(manualTasks)));

        then(cloudService).shouldHaveZeroInteractions();
    }

    @Test
    public void shouldDelegateE2EServiceInstantiation() throws Exception {
        // given
        String requestDetails = "some request details";
        Map<String, Object> payload = new LinkedHashMap<>();
        payload.put("requestDetails", requestDetails);

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.createE2eSvcInstance(requestDetails)).willReturn(wrapper);

        // when & then
        mockMvc.perform(post("/mso/mso_create_e2e_svc_instance")
            .content(asJson(payload))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).shouldHaveZeroInteractions();
    }

    @Test
    public void shouldDelegateServiceInstantiation() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.createSvcInstance(objectEqualTo(requestDetails))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post("/mso/mso_create_svc_instance")
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldDelegateVnfInstantiation() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.createVnf(objectEqualTo(requestDetails), eq(serviceInstanceId))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post("/mso/mso_create_vnf_instance/" + serviceInstanceId)
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldDeleteVfModuleInstance() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String vnfInstanceId = "fe9000-0009-9999";
        String vfModuleId = "abeeee-abeeee-abeeee";

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.deleteVfModule(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId), eq(vfModuleId))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post(format("/mso/mso_delete_vfmodule_instance/%s/vnfs/%s/vfModules/%s", serviceInstanceId, vnfInstanceId, vfModuleId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldDeleteVolumeGroup() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String vnfInstanceId = "fe9000-0009-9999";
        String volumeGroupId = "abeeee-abeeee-abeeee";

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.deleteVolumeGroupInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId), eq(volumeGroupId))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post(format("/mso/mso_delete_volumegroup_instance/%s/vnfs/%s/volumeGroups/%s", serviceInstanceId, vnfInstanceId, volumeGroupId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldDeleteInstance() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String networkInstanceId = "fe9000-0009-9999";

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.deleteNwInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(networkInstanceId))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post(format("/mso/mso_delete_nw_instance/%s/networks/%s", serviceInstanceId, networkInstanceId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldDeleteServiceInstance() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String serviceStatus = "ACTIVE";

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.deleteSvcInstance(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(serviceStatus))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post(format("/mso/mso_delete_svc_instance/%s", serviceInstanceId))
            .param("serviceStatus", serviceStatus)
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).shouldHaveZeroInteractions();
    }

    @Test
    public void shouldDeleteVnf() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String vnfInstanceId = "fe9000-0009-9999";

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.deleteVnf(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(vnfInstanceId))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post(format("/mso/mso_delete_vnf_instance/%s/vnfs/%s", serviceInstanceId, vnfInstanceId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldDeleteConfiguration() throws Exception {
        // given
        RequestDetailsWrapper requestDetails = modelGenerator.nextObject(RequestDetailsWrapper.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";
        String configurationId = "fe9000-0009-9999";

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.deleteConfiguration(objectEqualTo(requestDetails), eq(serviceInstanceId), eq(configurationId))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post(format("/mso/mso_delete_configuration/%s/configurations/%s", serviceInstanceId, configurationId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails.getRequestDetails()));
    }

    @Test
    public void shouldDelegateNewInstanceCreation() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.createNwInstance(objectEqualTo(requestDetails), eq(serviceInstanceId))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post("/mso/mso_create_nw_instance/" + serviceInstanceId)
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).should(only()).enrichRequestWithCloudOwner(objectEqualTo(requestDetails));
    }

    @Test
    public void shouldCompleteManualTask() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String taskId = "bc305d54-75b4-431b-adb2-eb6b9e546014";

        MsoResponseWrapper wrapper = mock(MsoResponseWrapper.class);
        given(wrapper.getResponse()).willReturn("some response");
        given(msoBusinessLogic.completeManualTask(objectEqualTo(requestDetails), eq(taskId))).willReturn(wrapper);

        // when & then
        mockMvc.perform(post("/mso/mso_post_man_task/" + taskId)
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("some response"));

        then(cloudService).shouldHaveZeroInteractions();
    }

    @Test
    public void shouldActivateFabricConfiguration() throws Exception {
        // given
        RequestDetails requestDetails = modelGenerator.nextObject(RequestDetails.class);
        String serviceInstanceId = "bc305d54-75b4-431b-adb2-eb6b9e546014";

        String path = "/mso/path";
        given(msoBusinessLogic.getActivateFabricConfigurationPath(eq(serviceInstanceId))).willReturn(path);

        RestObject<RequestReferencesContainer> response = new RestObject<>();
        response.set(mock(RequestReferencesContainer.class));
        response.setRaw("some response");
        response.setStatusCode(200);

        given(msoRestClient.PostForObject(objectEqualTo(requestDetails), eq(path), eq(RequestReferencesContainer.class))).willReturn(response);

        // when & then
        mockMvc.perform(post(format("/mso/mso_activate_fabric_configuration/%s", serviceInstanceId))
            .content(asJson(requestDetails))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().string("{\"status\":200,\"entity\":{}}"));

        then(cloudService).shouldHaveZeroInteractions();
    }

    private <T> String asJson(T value) {
        try {
            return objectMapper.writeValueAsString(value);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    private <T> T objectEqualTo(T expected) {
        return argThat(given -> asJson(given).equals(asJson(expected)));
    }

    @Test
    public void testActivateFabricConfiguration() throws Exception {

        String serviceInstanceId = "tempId";

        //define mock response object
        String responseString = "{" +
            "      \"requestReferences\": {" +
            "        \"instanceId\": \"tempId\"," +
            "        \"requestId\": \"dbe54591-c8ed-46d3-abc7-d3a24873dfbd\"" +
            "      }" +
            "    }";
        final RestObject<RequestReferencesContainer> restObject = new RestObject<>();
        restObject.set(objectMapper.readValue(responseString, RequestReferencesContainer.class));
        restObject.setStatusCode(200);

        //register mock
        String msoPath = "justAFakePath";

        when(msoBusinessLogic.getActivateFabricConfigurationPath(serviceInstanceId)).thenReturn(msoPath);
        when(msoRestClient.PostForObject(new RequestDetails(), msoPath, RequestReferencesContainer.class)).thenReturn(restObject);

        //expected response
        MsoResponseWrapper2<RequestReferencesContainer> expectedResponse = new MsoResponseWrapper2<>(restObject);

        //get response from controller
        // when & then
        mockMvc.perform(post(format("/mso/mso_activate_fabric_configuration/%s", serviceInstanceId))
            .content(asJson(new RequestDetails()))
            .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(content().json(asJson(expectedResponse)));
    }
}