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 java.util.Collections.emptyMap;
24 import static java.util.Collections.singletonMap;
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.hamcrest.MatcherAssert.assertThat;
27 import static org.hamcrest.Matchers.equalTo;
28 import static org.mockito.Mockito.mock;
29 import static org.mockito.Mockito.reset;
30 import static org.mockito.Mockito.when;
31 import static org.onap.vid.testUtils.TestUtils.setStringsInStringFields;
33 import java.util.UUID;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.MockitoAnnotations;
37 import org.onap.vid.model.GroupProperties;
38 import org.onap.vid.model.ServiceModel;
39 import org.onap.vid.model.VfModule;
40 import org.onap.vid.mso.model.ModelInfo;
41 import org.onap.vid.services.VidService;
42 import org.testng.annotations.AfterMethod;
43 import org.testng.annotations.BeforeClass;
44 import org.testng.annotations.DataProvider;
45 import org.testng.annotations.Test;
47 public class CommandUtilsTest {
50 CommandUtils commandUtils;
53 VidService vidService;
56 public void initMocks() {
57 MockitoAnnotations.initMocks(this);
61 public void resetVidService() {
66 public static Object[][] vfModuleModelInfos() {
67 ModelInfo modelInfoMatchByUuid = setStringsInStringFields(new ModelInfo());
68 modelInfoMatchByUuid.setModelCustomizationId("toscaCustomizationUuid");
70 ModelInfo modelInfoMatchByName = setStringsInStringFields(new ModelInfo());
71 modelInfoMatchByName.setModelCustomizationName("toscaCustomizationName");
73 ModelInfo modelInfoDontMatch = setStringsInStringFields(new ModelInfo());
75 return new Object[][]{
76 {true, modelInfoMatchByUuid, true},
77 {false, modelInfoMatchByUuid, false},
79 {true, modelInfoMatchByName, true},
80 {false, modelInfoMatchByName, false},
82 {true, modelInfoDontMatch, false},
83 {false, modelInfoDontMatch, false},
87 @Test(dataProvider="vfModuleModelInfos")
88 void isVfModuleBaseModule_vfModuleIsMatchedByEitherNameOrUuid(boolean isBaseInTosca, ModelInfo instanceModelInfo, boolean expected) {
89 GroupProperties mockedGroupProperties = mock(GroupProperties.class);
90 when(mockedGroupProperties.getBaseModule()).thenReturn(isBaseInTosca);
92 VfModule toscaVfModuleModelInfo = mock(VfModule.class);
93 when(toscaVfModuleModelInfo.getCustomizationUuid()).thenReturn("toscaCustomizationUuid");
94 when(toscaVfModuleModelInfo.getModelCustomizationName()).thenReturn("toscaCustomizationName");
95 when(toscaVfModuleModelInfo.getProperties()).thenReturn(mockedGroupProperties);
98 ServiceModel mockedServiceModel = mock(ServiceModel.class);
99 when(mockedServiceModel.getVfModules()).thenReturn(singletonMap("some-name", toscaVfModuleModelInfo));
101 String serviceModelUuid = UUID.randomUUID().toString();
102 when(vidService.getServiceModelOrThrow(serviceModelUuid)).thenReturn(mockedServiceModel);
104 assertThat(commandUtils.isVfModuleBaseModule(serviceModelUuid, instanceModelInfo), equalTo(expected));
108 void isVfModuleBaseModule_whenCantFindVfModulesInModel_resultIsFalse() {
109 String serviceModelUuid = UUID.randomUUID().toString();
111 ServiceModel mockedServiceModel = mock(ServiceModel.class);
113 when(vidService.getServiceModelOrThrow(serviceModelUuid)).thenReturn(mockedServiceModel);
114 when(mockedServiceModel.getVfModules()).thenReturn(emptyMap());
117 commandUtils.isVfModuleBaseModule(serviceModelUuid, mock(ModelInfo.class)), is(false));