Implant vid-app-common org.onap.vid.job (main and test)
[vid.git] / vid-app-common / src / test / java / org / onap / vid / job / command / MsoResultHandlerServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T 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
21 package org.onap.vid.job.command;
22
23 import static org.mockito.ArgumentMatchers.eq;
24 import static org.mockito.Mockito.verify;
25 import static org.onap.vid.job.impl.AsyncInstantiationIntegrationTest.createResponse;
26 import static org.testng.AssertJUnit.assertEquals;
27
28 import java.util.UUID;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.mockito.MockitoAnnotations;
33 import org.onap.vid.job.Job;
34 import org.onap.vid.job.impl.JobSharedData;
35 import org.onap.vid.model.RequestReferencesContainer;
36 import org.onap.vid.mso.RestObject;
37 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
38 import org.onap.vid.services.AuditService;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.DataProvider;
41 import org.testng.annotations.Test;
42
43 public class MsoResultHandlerServiceTest {
44
45     @Mock
46     private AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic;
47
48     @Mock
49     private AuditService auditService;
50
51     @InjectMocks
52     private MsoResultHandlerService underTest;
53
54     @BeforeClass
55     public void initMocks() {
56         MockitoAnnotations.initMocks(this);
57     }
58
59     @DataProvider
60     public static Object[][] okStatusCodes() {
61         return new Object[][]{
62                 {200}, {202} , {300}, {399}
63         };
64     }
65
66     @Test(dataProvider = "okStatusCodes")
67     public void whenOkResponseFromMso_getResultsWithIdsAndCompleteWithNoAction(int statusCode) {
68         String instanceId = UUID.randomUUID().toString();
69         String requestId = UUID.randomUUID().toString();
70         JobSharedData sharedData = new JobSharedData();
71         RestObject<RequestReferencesContainer> msoResponse = createResponse(statusCode, instanceId, requestId);
72         MsoResult expectedResult = new MsoResult(Job.JobStatus.COMPLETED_WITH_NO_ACTION, new MsoResourceIds(requestId, instanceId));
73         MsoResult actualMsoResult = underTest.handleResponse(sharedData, msoResponse, "test desc");
74         assertEquals(expectedResult, actualMsoResult);
75         verify(asyncInstantiationBusinessLogic).addResourceInfo(eq(sharedData), eq(Job.JobStatus.IN_PROGRESS), eq(instanceId));
76     }
77
78     @DataProvider
79     public static Object[][] notOkStatusCodes() {
80         return new Object[][]{
81                 {199}, {400} , {404}, {500}
82         };
83     }
84
85     @Test(dataProvider = "notOkStatusCodes")
86     public void whenNotOkFromMso_getResultsWithFailedStatus(int statusCode) {
87         Mockito.reset(asyncInstantiationBusinessLogic);
88         JobSharedData sharedData = new JobSharedData();
89         RestObject<RequestReferencesContainer> msoResponse = createResponse(statusCode);
90         MsoResult expectedResult = new MsoResult(Job.JobStatus.FAILED);
91         MsoResult actualMsoResult = underTest.handleResponse(new JobSharedData(), msoResponse, "test desc");
92         assertEquals(expectedResult, actualMsoResult);
93         verify(asyncInstantiationBusinessLogic).addFailedResourceInfo(eq(sharedData), eq(msoResponse));
94     }
95 }