b4a5c64f57db64f75ee7154464b9e69aa05132e6
[vid.git] / vid-app-common / src / test / java / org / onap / vid / job / command / InstanceGroupCommandTest.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.any;
24 import static org.mockito.Mockito.eq;
25 import static org.mockito.Mockito.only;
26 import static org.mockito.Mockito.same;
27 import static org.mockito.Mockito.verify;
28
29 import com.google.common.collect.ImmutableMap;
30 import java.util.Optional;
31 import org.mockito.Answers;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.vid.job.impl.JobSharedData;
36 import org.onap.vid.model.RequestReferencesContainer;
37 import org.onap.vid.model.serviceInstantiation.InstanceGroup;
38 import org.onap.vid.mso.RestMsoImplementation;
39 import org.onap.vid.mso.model.ModelInfo;
40 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
41 import org.onap.vid.testUtils.TestUtils;
42 import org.springframework.http.HttpMethod;
43 import org.testng.annotations.BeforeMethod;
44 import org.testng.annotations.Test;
45
46 public class InstanceGroupCommandTest {
47
48     @Mock(answer = Answers.RETURNS_MOCKS)
49     RestMsoImplementation restMso;
50
51     @Mock InstanceGroup instanceGroupRequest;
52
53     @Mock(answer = Answers.RETURNS_MOCKS)
54     MsoResultHandlerService msoResultHandlerService;
55
56     @Mock WatchChildrenJobsBL watchChildrenJobsBL;
57
58     @Mock(answer = Answers.RETURNS_MOCKS)
59     AsyncInstantiationBusinessLogic asyncInstantiationBL;
60
61     @Mock InProgressStatusService inProgressStatusService;
62
63     @InjectMocks
64     private InstanceGroupCommand command;
65
66     @BeforeMethod
67     public void initMocks() {
68         command = null;
69         MockitoAnnotations.initMocks(this);
70     }
71
72     @Test
73     public void createMyself_callsMso() {
74         final ModelInfo serviceModelInfo = setStrings(new ModelInfo());
75         final String serviceInstanceId = "service-instance-id";
76         final String userId = "ff3223";
77
78         command.init(new JobSharedData(
79                 null, userId, instanceGroupRequest
80         ), ImmutableMap.of(
81                 "resourceModelInfos", ImmutableMap.of("SERVICE_MODEL_INFO", serviceModelInfo),
82                 "resourceInstancesIds", ImmutableMap.of("SERVICE_INSTANCE_ID", serviceInstanceId)
83         ));
84
85         command.createMyself();
86
87         verify(asyncInstantiationBL).generateInstanceGroupInstantiationRequest(
88                 same(instanceGroupRequest), eq(serviceModelInfo), eq(serviceInstanceId), eq(userId));
89         verify(restMso, only()).restCall(eq(HttpMethod.POST), eq(RequestReferencesContainer.class), any(), any(), eq(Optional.empty()));
90
91     }
92
93     private ModelInfo setStrings(ModelInfo object) {
94         return TestUtils.setStringsInStringProperties(object);
95     }
96 }