1 package org.onap.vid.job.command;
3 import com.google.common.collect.ImmutableMap;
4 import org.mockito.InjectMocks;
5 import org.mockito.Mock;
6 import org.mockito.MockitoAnnotations;
7 import org.onap.vid.asdc.AsdcCatalogException;
8 import org.onap.vid.model.GroupProperties;
9 import org.onap.vid.model.ServiceModel;
10 import org.onap.vid.model.VfModule;
11 import org.onap.vid.services.VidService;
12 import org.testng.annotations.AfterMethod;
13 import org.testng.annotations.BeforeClass;
14 import org.testng.annotations.DataProvider;
15 import org.testng.annotations.Test;
17 import java.util.Collections;
19 import java.util.UUID;
21 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.equalTo;
24 import static org.mockito.Mockito.*;
26 public class CommandUtilsTest {
29 CommandUtils commandUtils;
32 VidService vidService;
35 public void initMocks() {
36 MockitoAnnotations.initMocks(this);
40 public void resetVidService() {
45 public static Object[][] trueAndFalse() {
46 return new Object[][]{ {true}, {false} };
49 @Test(dataProvider="trueAndFalse")
50 void testIsVfModelIsBaseModule(boolean isBase) throws AsdcCatalogException {
51 final String serviceModelUuid = UUID.randomUUID().toString();
52 final String vfModuleUuid = UUID.randomUUID().toString();
54 ServiceModel mockedServiceModel = mock(ServiceModel.class);
55 VfModule mockedVfModule = mock(VfModule.class);
56 GroupProperties mockedGroupProperties = mock(GroupProperties.class);
57 Map<String, VfModule> vfModulesMap = ImmutableMap.of(randomAlphanumeric(10), mockedVfModule);
59 when(vidService.getService(serviceModelUuid)).thenReturn(mockedServiceModel);
60 when(mockedServiceModel.getVfModules()).thenReturn(vfModulesMap);
61 when(mockedVfModule.getUuid()).thenReturn(vfModuleUuid);
62 when(mockedVfModule.getProperties()).thenReturn(mockedGroupProperties);
63 when(mockedGroupProperties.getBaseModule()).thenReturn(isBase);
65 assertThat(commandUtils.isVfModuleBaseModule(serviceModelUuid, vfModuleUuid), equalTo(isBase));
68 @Test(expectedExceptions = AsdcCatalogException.class)
69 void whenCantFindModelInSdc_thenExceptionIsThrown() throws AsdcCatalogException {
70 String serviceModelUuid = UUID.randomUUID().toString();
71 when(vidService.getService(serviceModelUuid)).thenReturn(null);
72 commandUtils.isVfModuleBaseModule(serviceModelUuid, "abc");
75 @Test(expectedExceptions = AsdcCatalogException.class)
76 void whenCantFindVfModuleInModel_thenExceptionIsThrown() throws AsdcCatalogException {
78 String serviceModelUuid = UUID.randomUUID().toString();
80 ServiceModel mockedServiceModel = mock(ServiceModel.class);
81 Map<String, VfModule> emptyMap = Collections.emptyMap();
83 when(vidService.getService(serviceModelUuid)).thenReturn(mockedServiceModel);
84 when(mockedServiceModel.getVfModules()).thenReturn(emptyMap);
86 commandUtils.isVfModuleBaseModule(serviceModelUuid, "abc");