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.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.onap.vid.asdc.AsdcCatalogException;
28 import org.onap.vid.model.GroupProperties;
29 import org.onap.vid.model.ServiceModel;
30 import org.onap.vid.model.VfModule;
31 import org.onap.vid.services.VidService;
32 import org.testng.annotations.AfterMethod;
33 import org.testng.annotations.BeforeClass;
34 import org.testng.annotations.DataProvider;
35 import org.testng.annotations.Test;
37 import java.util.Collections;
39 import java.util.UUID;
41 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
42 import static org.hamcrest.MatcherAssert.assertThat;
43 import static org.hamcrest.Matchers.equalTo;
44 import static org.mockito.Mockito.*;
46 public class CommandUtilsTest {
49 CommandUtils commandUtils;
52 VidService vidService;
55 public void initMocks() {
56 MockitoAnnotations.initMocks(this);
60 public void resetVidService() {
65 public static Object[][] trueAndFalse() {
66 return new Object[][]{ {true}, {false} };
69 @Test(dataProvider="trueAndFalse")
70 void testIsVfModelIsBaseModule(boolean isBase) throws AsdcCatalogException {
71 final String serviceModelUuid = UUID.randomUUID().toString();
72 final String vfModuleUuid = UUID.randomUUID().toString();
74 ServiceModel mockedServiceModel = mock(ServiceModel.class);
75 VfModule mockedVfModule = mock(VfModule.class);
76 GroupProperties mockedGroupProperties = mock(GroupProperties.class);
77 Map<String, VfModule> vfModulesMap = ImmutableMap.of(randomAlphanumeric(10), mockedVfModule);
79 when(vidService.getService(serviceModelUuid)).thenReturn(mockedServiceModel);
80 when(mockedServiceModel.getVfModules()).thenReturn(vfModulesMap);
81 when(mockedVfModule.getUuid()).thenReturn(vfModuleUuid);
82 when(mockedVfModule.getProperties()).thenReturn(mockedGroupProperties);
83 when(mockedGroupProperties.getBaseModule()).thenReturn(isBase);
85 assertThat(commandUtils.isVfModuleBaseModule(serviceModelUuid, vfModuleUuid), equalTo(isBase));
88 @Test(expectedExceptions = AsdcCatalogException.class)
89 void whenCantFindModelInSdc_thenExceptionIsThrown() throws AsdcCatalogException {
90 String serviceModelUuid = UUID.randomUUID().toString();
91 when(vidService.getService(serviceModelUuid)).thenReturn(null);
92 commandUtils.isVfModuleBaseModule(serviceModelUuid, "abc");
95 @Test(expectedExceptions = AsdcCatalogException.class)
96 void whenCantFindVfModuleInModel_thenExceptionIsThrown() throws AsdcCatalogException {
98 String serviceModelUuid = UUID.randomUUID().toString();
100 ServiceModel mockedServiceModel = mock(ServiceModel.class);
101 Map<String, VfModule> emptyMap = Collections.emptyMap();
103 when(vidService.getService(serviceModelUuid)).thenReturn(mockedServiceModel);
104 when(mockedServiceModel.getVfModules()).thenReturn(emptyMap);
106 commandUtils.isVfModuleBaseModule(serviceModelUuid, "abc");