From 17b63f0c432f9edf407e4c9f465a295bfd870485 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Thu, 5 Mar 2020 17:25:34 +0200 Subject: isVfModuleBaseModule() will not throw on model mismatch In addition, the model-info comparision is by customization id or customization name instead of the version id. Issue-ID: VID-603 Change-Id: I8efee06f470e5d5681c264de01ed1315ee1f8cc6 Signed-off-by: Ittay Stern --- .../org/onap/vid/job/command/CommandUtilsTest.java | 89 ++++++++++++---------- 1 file changed, 50 insertions(+), 39 deletions(-) (limited to 'vid-app-common/src/test/java/org/onap/vid/job/command') diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/CommandUtilsTest.java b/vid-app-common/src/test/java/org/onap/vid/job/command/CommandUtilsTest.java index ee43d1f72..d1d9b5e4f 100644 --- a/vid-app-common/src/test/java/org/onap/vid/job/command/CommandUtilsTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/job/command/CommandUtilsTest.java @@ -20,29 +20,30 @@ package org.onap.vid.job.command; -import com.google.common.collect.ImmutableMap; +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonMap; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.when; +import static org.onap.vid.testUtils.TestUtils.setStringsInStringFields; + +import java.util.UUID; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.model.GroupProperties; import org.onap.vid.model.ServiceModel; import org.onap.vid.model.VfModule; +import org.onap.vid.mso.model.ModelInfo; import org.onap.vid.services.VidService; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import java.util.Collections; -import java.util.Map; -import java.util.UUID; - -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.mockito.Mockito.*; - public class CommandUtilsTest { @InjectMocks @@ -62,47 +63,57 @@ public class CommandUtilsTest { } @DataProvider - public static Object[][] trueAndFalse() { - return new Object[][]{ {true}, {false} }; - } + public static Object[][] vfModuleModelInfos() { + ModelInfo modelInfoMatchByUuid = setStringsInStringFields(new ModelInfo()); + modelInfoMatchByUuid.setModelCustomizationId("toscaCustomizationUuid"); - @Test(dataProvider="trueAndFalse") - void testIsVfModelIsBaseModule(boolean isBase) throws AsdcCatalogException { - final String serviceModelUuid = UUID.randomUUID().toString(); - final String vfModuleUuid = UUID.randomUUID().toString(); + ModelInfo modelInfoMatchByName = setStringsInStringFields(new ModelInfo()); + modelInfoMatchByName.setModelCustomizationName("toscaCustomizationName"); - ServiceModel mockedServiceModel = mock(ServiceModel.class); - VfModule mockedVfModule = mock(VfModule.class); - GroupProperties mockedGroupProperties = mock(GroupProperties.class); - Map vfModulesMap = ImmutableMap.of(randomAlphanumeric(10), mockedVfModule); + ModelInfo modelInfoDontMatch = setStringsInStringFields(new ModelInfo()); + + return new Object[][]{ + {true, modelInfoMatchByUuid, true}, + {false, modelInfoMatchByUuid, false}, - when(vidService.getService(serviceModelUuid)).thenReturn(mockedServiceModel); - when(mockedServiceModel.getVfModules()).thenReturn(vfModulesMap); - when(mockedVfModule.getUuid()).thenReturn(vfModuleUuid); - when(mockedVfModule.getProperties()).thenReturn(mockedGroupProperties); - when(mockedGroupProperties.getBaseModule()).thenReturn(isBase); + {true, modelInfoMatchByName, true}, + {false, modelInfoMatchByName, false}, - assertThat(commandUtils.isVfModuleBaseModule(serviceModelUuid, vfModuleUuid), equalTo(isBase)); + {true, modelInfoDontMatch, false}, + {false, modelInfoDontMatch, false}, + }; } - @Test(expectedExceptions = AsdcCatalogException.class) - void whenCantFindModelInSdc_thenExceptionIsThrown() throws AsdcCatalogException { + @Test(dataProvider="vfModuleModelInfos") + void isVfModuleBaseModule_vfModuleIsMatchedByEitherNameOrUuid(boolean isBaseInTosca, ModelInfo instanceModelInfo, boolean expected) { + GroupProperties mockedGroupProperties = mock(GroupProperties.class); + when(mockedGroupProperties.getBaseModule()).thenReturn(isBaseInTosca); + + VfModule toscaVfModuleModelInfo = mock(VfModule.class); + when(toscaVfModuleModelInfo.getCustomizationUuid()).thenReturn("toscaCustomizationUuid"); + when(toscaVfModuleModelInfo.getModelCustomizationName()).thenReturn("toscaCustomizationName"); + when(toscaVfModuleModelInfo.getProperties()).thenReturn(mockedGroupProperties); + + + ServiceModel mockedServiceModel = mock(ServiceModel.class); + when(mockedServiceModel.getVfModules()).thenReturn(singletonMap("some-name", toscaVfModuleModelInfo)); + String serviceModelUuid = UUID.randomUUID().toString(); - when(vidService.getService(serviceModelUuid)).thenReturn(null); - commandUtils.isVfModuleBaseModule(serviceModelUuid, "abc"); - } + when(vidService.getServiceModelOrThrow(serviceModelUuid)).thenReturn(mockedServiceModel); - @Test(expectedExceptions = AsdcCatalogException.class) - void whenCantFindVfModuleInModel_thenExceptionIsThrown() throws AsdcCatalogException { + assertThat(commandUtils.isVfModuleBaseModule(serviceModelUuid, instanceModelInfo), equalTo(expected)); + } + @Test + void isVfModuleBaseModule_whenCantFindVfModulesInModel_resultIsFalse() { String serviceModelUuid = UUID.randomUUID().toString(); ServiceModel mockedServiceModel = mock(ServiceModel.class); - Map emptyMap = Collections.emptyMap(); - when(vidService.getService(serviceModelUuid)).thenReturn(mockedServiceModel); - when(mockedServiceModel.getVfModules()).thenReturn(emptyMap); + when(vidService.getServiceModelOrThrow(serviceModelUuid)).thenReturn(mockedServiceModel); + when(mockedServiceModel.getVfModules()).thenReturn(emptyMap()); - commandUtils.isVfModuleBaseModule(serviceModelUuid, "abc"); + assertThat( + commandUtils.isVfModuleBaseModule(serviceModelUuid, mock(ModelInfo.class)), is(false)); } } -- cgit 1.2.3-korg