2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.vid.reports;
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;
38 import static org.assertj.core.api.Assertions.assertThat;
39 import static org.mockito.Mockito.mock;
40 import static org.mockito.Mockito.when;
42 @RunWith(MockitoJUnitRunner.class)
43 public class DeploymentReportGeneratorTest {
46 private MsoBusinessLogic msoBusinessLogic;
48 private VidService vidService;
51 private DeploymentReportGenerator deploymentReportGenerator;
54 public void shouldReturnTrueIfConditionsOfGenerationAreFulfilled() {
56 ReportCreationParameters parameters = new ReportCreationParameters();
57 parameters.setRequestId("request_id");
58 parameters.setServiceUuid("service_uuid");
61 boolean actualResult = deploymentReportGenerator.canGenerate(parameters);
64 assertThat(actualResult).isTrue();
68 public void shouldGetOrchestrationRequestFromMso() {
70 final String requestId = "request_id";
71 MsoResponseWrapper expectedOrchestrationRequest = mock(MsoResponseWrapper.class);
73 when(msoBusinessLogic.getOrchestrationRequest(requestId)).thenReturn(expectedOrchestrationRequest);
76 MsoResponseWrapper actualOrchestrationRequest =
77 deploymentReportGenerator.getOrchestrationRequestFromMso(requestId);
80 assertThat(actualOrchestrationRequest).isEqualTo(expectedOrchestrationRequest);
84 public void shouldGetServiceDetails() throws AsdcCatalogException {
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);
91 when(vidService.getService(SERVICE_UUID)).thenReturn(serviceModel);
92 when(serviceModel.getService()).thenReturn(expectedService);
95 Map<String, Object> actualServiceDetails = deploymentReportGenerator.getServiceDetails(SERVICE_UUID);
98 assertThat(actualServiceDetails).isEqualTo(expectedServiceDetails);
102 public void shouldGetNullPointerExceptionInfoInMapWhenWrongUuidIsGiven() {
104 final String NOT_EXISTING_UUID = "8ad001d0-1111-2222-3333-123412341234";
105 NullPointerException expectedException = new NullPointerException("msg");
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)
114 Map<String, Object> actualResult =
115 deploymentReportGenerator.generateServiceDetailsExceptionResponse(NOT_EXISTING_UUID, expectedException);
118 assertThat(actualResult).isEqualTo(expectedResult);