2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.onap.vid.job.command;
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;
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;
46 public class InstanceGroupCommandTest {
48 @Mock(answer = Answers.RETURNS_MOCKS)
49 RestMsoImplementation restMso;
51 @Mock InstanceGroup instanceGroupRequest;
53 @Mock(answer = Answers.RETURNS_MOCKS)
54 MsoResultHandlerService msoResultHandlerService;
56 @Mock WatchChildrenJobsBL watchChildrenJobsBL;
58 @Mock(answer = Answers.RETURNS_MOCKS)
59 AsyncInstantiationBusinessLogic asyncInstantiationBL;
61 @Mock InProgressStatusService inProgressStatusService;
64 private InstanceGroupCommand command;
67 public void initMocks() {
69 MockitoAnnotations.initMocks(this);
73 public void createMyself_callsMso() {
74 final ModelInfo serviceModelInfo = setStrings(new ModelInfo());
75 final String serviceInstanceId = "service-instance-id";
76 final String userId = "ff3223";
78 command.init(new JobSharedData(
79 null, userId, instanceGroupRequest
81 "resourceModelInfos", ImmutableMap.of("SERVICE_MODEL_INFO", serviceModelInfo),
82 "resourceInstancesIds", ImmutableMap.of("SERVICE_INSTANCE_ID", serviceInstanceId)
85 command.createMyself();
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()));
93 private ModelInfo setStrings(ModelInfo object) {
94 return TestUtils.setStringsInStringProperties(object);