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 com.google.common.collect.ImmutableMap;
24 import org.apache.commons.beanutils.BeanUtils;
25 import org.mockito.Answers;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mock;
28 import org.mockito.MockitoAnnotations;
29 import org.onap.vid.job.impl.JobSharedData;
30 import org.onap.vid.model.RequestReferencesContainer;
31 import org.onap.vid.model.serviceInstantiation.InstanceGroup;
32 import org.onap.vid.mso.RestMsoImplementation;
33 import org.onap.vid.mso.model.ModelInfo;
34 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
35 import org.springframework.http.HttpMethod;
36 import org.testng.annotations.BeforeMethod;
37 import org.testng.annotations.Test;
39 import java.util.Optional;
42 import static java.util.function.Function.identity;
43 import static java.util.stream.Collectors.toMap;
44 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
45 import static org.mockito.ArgumentMatchers.any;
46 import static org.mockito.Mockito.*;
48 public class InstanceGroupCommandTest {
50 @Mock(answer = Answers.RETURNS_MOCKS)
51 RestMsoImplementation restMso;
53 @Mock InstanceGroup instanceGroupRequest;
55 @Mock(answer = Answers.RETURNS_MOCKS)
56 MsoResultHandlerService msoResultHandlerService;
58 @Mock WatchChildrenJobsBL watchChildrenJobsBL;
60 @Mock(answer = Answers.RETURNS_MOCKS)
61 AsyncInstantiationBusinessLogic asyncInstantiationBL;
63 @Mock InProgressStatusService inProgressStatusService;
66 private InstanceGroupCommand command;
69 public void initMocks() {
71 MockitoAnnotations.initMocks(this);
75 public void createMyself_callsMso() {
76 final ModelInfo serviceModelInfo = setRandomStrings(new ModelInfo());
77 final String serviceInstanceId = "service-instance-id";
78 final String userId = "ff3223";
80 command.init(new JobSharedData(
81 null, userId, instanceGroupRequest
83 "resourceModelInfos", ImmutableMap.of("SERVICE_MODEL_INFO", serviceModelInfo),
84 "resourceInstancesIds", ImmutableMap.of("SERVICE_INSTANCE_ID", serviceInstanceId)
87 command.createMyself();
89 verify(asyncInstantiationBL).generateInstanceGroupInstantiationRequest(
90 same(instanceGroupRequest), eq(serviceModelInfo), eq(serviceInstanceId), eq(userId));
91 verify(restMso, only()).restCall(eq(HttpMethod.POST), eq(RequestReferencesContainer.class), any(), any(), eq(Optional.empty()));
95 private ModelInfo setRandomStrings(ModelInfo object) {
97 Set<String> fields = BeanUtils.describe(object).keySet();
98 BeanUtils.populate(object,
99 fields.stream().collect(toMap(identity(), s -> randomAlphanumeric(4))));
101 } catch (Exception e) {
102 throw new RuntimeException(e);