identify macro services without instantiation type in BE by feature flag
[vid.git] / vid-app-common / src / test / java / org / onap / vid / reports / DeploymentReportGeneratorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.vid.reports;
21
22 import com.google.common.collect.ImmutableMap;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.onap.vid.asdc.AsdcCatalogException;
29 import org.onap.vid.model.Service;
30 import org.onap.vid.model.ServiceModel;
31 import org.onap.vid.model.errorReport.ReportCreationParameters;
32 import org.onap.vid.mso.MsoBusinessLogic;
33 import org.onap.vid.mso.MsoResponseWrapper;
34 import org.onap.vid.services.VidService;
35
36 import java.util.Map;
37
38 import static org.assertj.core.api.Assertions.assertThat;
39 import static org.mockito.Mockito.mock;
40 import static org.mockito.Mockito.when;
41
42 @RunWith(MockitoJUnitRunner.class)
43 public class DeploymentReportGeneratorTest {
44
45         @Mock
46         private MsoBusinessLogic msoBusinessLogic;
47         @Mock
48         private VidService vidService;
49
50         @InjectMocks
51         private DeploymentReportGenerator deploymentReportGenerator;
52
53         @Test
54         public void shouldReturnTrueIfConditionsOfGenerationAreFulfilled() {
55                 //given
56                 ReportCreationParameters parameters = new ReportCreationParameters();
57                 parameters.setRequestId("request_id");
58                 parameters.setServiceUuid("service_uuid");
59
60                 //when
61                 boolean actualResult = deploymentReportGenerator.canGenerate(parameters);
62
63                 //then
64                 assertThat(actualResult).isTrue();
65         }
66
67         @Test
68         public void shouldGetOrchestrationRequestFromMso() {
69                 //given
70                 final String requestId = "request_id";
71                 MsoResponseWrapper expectedOrchestrationRequest = mock(MsoResponseWrapper.class);
72
73                 when(msoBusinessLogic.getOrchestrationRequest(requestId)).thenReturn(expectedOrchestrationRequest);
74
75                 //when
76                 MsoResponseWrapper actualOrchestrationRequest =
77                                 deploymentReportGenerator.getOrchestrationRequestFromMso(requestId);
78
79                 //then
80                 assertThat(actualOrchestrationRequest).isEqualTo(expectedOrchestrationRequest);
81         }
82
83         @Test
84         public void shouldGetServiceDetails() throws AsdcCatalogException {
85                 //given
86                 final String SERVICE_UUID = "service_uuid";
87                 ServiceModel serviceModel = mock(ServiceModel.class);
88                 Service expectedService = new Service();
89                 ImmutableMap<String, Object> expectedServiceDetails = ImmutableMap.of("details", expectedService);
90
91                 when(vidService.getService(SERVICE_UUID)).thenReturn(serviceModel);
92                 when(serviceModel.getService()).thenReturn(expectedService);
93
94                 //when
95                 Map<String, Object> actualServiceDetails = deploymentReportGenerator.getServiceDetails(SERVICE_UUID);
96
97                 //then
98                 assertThat(actualServiceDetails).isEqualTo(expectedServiceDetails);
99         }
100
101         @Test
102         public void shouldGetNullPointerExceptionInfoInMapWhenWrongUuidIsGiven() {
103                 //given
104                 final String NOT_EXISTING_UUID = "8ad001d0-1111-2222-3333-123412341234";
105                 NullPointerException expectedException = new NullPointerException("msg");
106
107                 Map<String, Object> expectedResult = ImmutableMap.<String, Object>builder()
108                                 .put("message", "Service details for given uuid were not found")
109                                 .put("exception", expectedException.toString())
110                                 .put("serviceUuid", NOT_EXISTING_UUID)
111                                 .build();
112
113                 //when
114                 Map<String, Object> actualResult =
115                                 deploymentReportGenerator.generateServiceDetailsExceptionResponse(NOT_EXISTING_UUID, expectedException);
116
117                 //then
118                 assertThat(actualResult).isEqualTo(expectedResult);
119         }
120 }