diff options
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/asdc/parser')
3 files changed, 338 insertions, 117 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java index 91c480526..92d78d43e 100644 --- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java +++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java @@ -20,11 +20,33 @@ package org.onap.vid.asdc.parser; +import static com.google.common.collect.Lists.newArrayList; +import static org.hamcrest.Matchers.aMapWithSize; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.ECOMP_GENERATED_NAMING_PROPERTY; +import static org.onap.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.Stream; import net.javacrumbs.jsonunit.JsonAssert; import org.apache.commons.io.IOUtils; import org.apache.log4j.LogManager; @@ -43,7 +65,19 @@ import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.asdc.AsdcClient; import org.onap.vid.asdc.local.LocalAsdcClient; import org.onap.vid.controller.ToscaParserMockHelper; -import org.onap.vid.model.*; +import org.onap.vid.model.CR; +import org.onap.vid.model.Network; +import org.onap.vid.model.NetworkCollection; +import org.onap.vid.model.Node; +import org.onap.vid.model.PortMirroringConfig; +import org.onap.vid.model.ResourceGroup; +import org.onap.vid.model.Service; +import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.ServiceProxy; +import org.onap.vid.model.VNF; +import org.onap.vid.model.VfModule; +import org.onap.vid.model.VidNotions; +import org.onap.vid.model.VolumeGroup; import org.onap.vid.properties.Features; import org.testng.Assert; import org.testng.annotations.BeforeClass; @@ -52,22 +86,6 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.togglz.core.manager.FeatureManager; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static com.google.common.collect.Lists.newArrayList; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.ECOMP_GENERATED_NAMING_PROPERTY; -import static org.onap.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls; - public class ToscaParserImpl2Test { private final String myUUID = "myUUID"; @@ -101,7 +119,7 @@ public class ToscaParserImpl2Test { @Test(dataProvider = "expectedServiceModel") public void assertEqualsBetweenServices(String uuid, ToscaParserMockHelper mockHelper) throws Exception { - Service expectedService = mockHelper.getNewServiceModel().getService(); + Service expectedService = mockHelper.getServiceModel().getService(); Service actualService = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getService(); assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedService), om.writeValueAsString(actualService)); } @@ -111,12 +129,12 @@ public class ToscaParserImpl2Test { final Path csarPath = getCsarPath(mockHelper.getUuid()); log.info("Comparing for csar " + csarPath); ServiceModel actualServiceModel = toscaParserImpl2.makeServiceModel(csarPath, getServiceByUuid(mockHelper.getUuid())); - assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(mockHelper.getNewServiceModel()), om.writeValueAsString(actualServiceModel)); + assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(mockHelper.getServiceModel()), om.writeValueAsString(actualServiceModel)); } @Test(dataProvider = "expectedServiceModel") public void assertEqualsBetweenNetworkNodes(String uuid, ToscaParserMockHelper mockHelper) throws Exception { - Map<String, Network> expectedNetworksMap = mockHelper.getNewServiceModel().getNetworks(); + Map<String, Network> expectedNetworksMap = mockHelper.getServiceModel().getNetworks(); Map<String, Network> actualNetworksMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getNetworks(); for (Map.Entry<String, Network> entry : expectedNetworksMap.entrySet()) { Network expectedNetwork = entry.getValue(); @@ -130,7 +148,7 @@ public class ToscaParserImpl2Test { //Because we are not supporting the old flow, the JSON are different by definition. @Test(dataProvider = "expectedServiceModel") public void assertEqualsBetweenVnfsOfTosca(String uuid, ToscaParserMockHelper mockHelper) throws Exception { - Map<String, VNF> expectedVnfsMap = mockHelper.getNewServiceModel().getVnfs(); + Map<String, VNF> expectedVnfsMap = mockHelper.getServiceModel().getVnfs(); Map<String, VNF> actualVnfsMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVnfs(); for (Map.Entry<String, VNF> entry : expectedVnfsMap.entrySet()) { VNF expectedVnf = entry.getValue(); @@ -142,10 +160,12 @@ public class ToscaParserImpl2Test { } } + + @Test(dataProvider = "expectedServiceModel") public void assertEqualsBetweenCollectionResourcesOfTosca(String uuid, ToscaParserMockHelper mockHelper) throws Exception { - Map<String, CR> expectedVnfsMap = mockHelper.getNewServiceModel().getCollectionResource(); - Map<String, CR> actualCRsMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getCollectionResource(); + Map<String, CR> expectedVnfsMap = mockHelper.getServiceModel().getCollectionResources(); + Map<String, CR> actualCRsMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getCollectionResources(); if(!actualCRsMap.isEmpty()) { for (Map.Entry<String, CR> entry : expectedVnfsMap.entrySet()) { CR expectedCR = entry.getValue(); @@ -201,28 +221,28 @@ public class ToscaParserImpl2Test { @Test(dataProvider = "expectedServiceModel") public void assertEqualsBetweenVolumeGroups(String uuid, ToscaParserMockHelper mockHelper) throws Exception { Map<String, VolumeGroup> actualVolumeGroups = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVolumeGroups(); - Map<String, VolumeGroup> expectedVolumeGroups = mockHelper.getNewServiceModel().getVolumeGroups(); + Map<String, VolumeGroup> expectedVolumeGroups = mockHelper.getServiceModel().getVolumeGroups(); assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVolumeGroups), om.writeValueAsString(actualVolumeGroups)); } @Test(dataProvider = "expectedServiceModel") public void assertEqualsBetweenVfModules(String uuid, ToscaParserMockHelper mockHelper) throws Exception { Map<String, VfModule> actualVfModules = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVfModules(); - Map<String, VfModule> expectedVfModules = mockHelper.getNewServiceModel().getVfModules(); + Map<String, VfModule> expectedVfModules = mockHelper.getServiceModel().getVfModules(); assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVfModules), om.writeValueAsString(actualVfModules)); } @Test(dataProvider = "expectedServiceModel") public void assertEqualsBetweenPolicyConfigurationNodes(String uuid, ToscaParserMockHelper mockHelper) throws Exception { Map<String, PortMirroringConfig> actualConfigurations = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getConfigurations(); - Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getNewServiceModel().getConfigurations(); + Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getServiceModel().getConfigurations(); JsonAssert.assertJsonEquals(actualConfigurations, expectedConfigurations); } @Test public void assertEqualsBetweenPolicyConfigurationByPolicyFalse() throws Exception { ToscaParserMockHelper mockHelper = new ToscaParserMockHelper(Constants.configurationByPolicyFalseUuid, Constants.configurationByPolicyFalseFilePath); - Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getNewServiceModel().getConfigurations(); + Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getServiceModel().getConfigurations(); Map<String, PortMirroringConfig> actualConfigurations = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getConfigurations(); setPprobeServiceProxy(expectedConfigurations); @@ -250,7 +270,7 @@ public class ToscaParserImpl2Test { final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper("90fe6842-aa76-4b68-8329-5c86ff564407", "empty.json"); final ServiceModel serviceModel = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())); - assertJsonStringEqualsIgnoreNulls("{ vfModules: { 201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vRE_BV..module-1: { inputs: { availability_zone_0: { } } } } }", om.writeValueAsString(serviceModel)); + assertJsonStringEqualsIgnoreNulls("{ vfModules: { 201712488_pasqualevpe10..201712488PasqualeVpe1..PASQUALE_vRE_BV..module-1: { inputs: { availability_zone_0: { } } } } }", om.writeValueAsString(serviceModel)); } @Test @@ -260,7 +280,7 @@ public class ToscaParserImpl2Test { assertJsonStringEqualsIgnoreNulls("" + "{ vnfs: " + - " { \"201712-488_ADIOD-vPE-1 0\": " + + " { \"201712-488_PASQUALE-vPE-1 0\": " + " { properties: { " + " ecomp_generated_naming: \"true\", " + " nf_naming: \"{naming_policy=SDNC_Policy.Config_MS_1806SRIOV_VPE_ADIoDJson, ecomp_generated_naming=true}\" " + @@ -278,14 +298,14 @@ public class ToscaParserImpl2Test { @Test(dataProvider = "expectedServiceModel") public void assertEqualsBetweenServiceProxyNodes(String uuid, ToscaParserMockHelper mockHelper) throws Exception { Map<String, ServiceProxy> actualServiceProxies = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getServiceProxies(); - Map<String, ServiceProxy> expectedServiceProxies = mockHelper.getNewServiceModel().getServiceProxies(); + Map<String, ServiceProxy> expectedServiceProxies = mockHelper.getServiceModel().getServiceProxies(); JsonAssert.assertJsonEquals(actualServiceProxies, expectedServiceProxies); } @Test(dataProvider = "expectedServiceModel") public void assertEqualsBetweenVnfGroups(String uuid, ToscaParserMockHelper mockHelper) throws Exception { Map<String, ResourceGroup> actualVnfGroups = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVnfGroups(); - Map<String, ResourceGroup> expectedVnfGroups = mockHelper.getNewServiceModel().getVnfGroups(); + Map<String, ResourceGroup> expectedVnfGroups = mockHelper.getServiceModel().getVnfGroups(); JsonAssert.assertJsonEquals(actualVnfGroups, expectedVnfGroups); } @@ -342,7 +362,7 @@ public class ToscaParserImpl2Test { static final String vfWithAnnotationUuid = "f4d84bb4-a416-4b4e-997e-0059973630b9"; static final String vlUuid = "cb49608f-5a24-4789-b0f7-2595473cb997"; static final String crUuid = "76f27dfe-33e5-472f-8e0b-acf524adc4f0"; - static final String vfWithVfcGroup = "6bce7302-70bd-4057-b48e-8d5b99e686ca"; //service-VdbeSrv-csar.zip + static final String vfWithVfcGroup = "6bce7302-70bd-4057-b48e-8d5b99e686ca"; //service-VdorotheaSrv-csar.zip // public static final String PNFUuid = "68101369-6f08-4e99-9a28-fa6327d344f3"; static final String vfFilePath = "vf-csar.JSON"; static final String vlFilePath = "vl-csar.JSON"; @@ -358,6 +378,8 @@ public class ToscaParserImpl2Test { //public static final String vnfGroupingUuid = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc"; //public static final String vnfGroupingFilePath = "vnf-grouping-csar.json"; + public static final String QUANTITY = "quantity"; + } diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserInflatorTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserInflatorTest.java index 4c5cc9787..d6c080d55 100644 --- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserInflatorTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserInflatorTest.java @@ -20,7 +20,16 @@ package org.onap.vid.asdc.parser; +import static java.util.Collections.emptyMap; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + import com.google.common.collect.ImmutableMap; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import java.util.Map; +import java.util.UUID; import org.apache.commons.io.IOUtils; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; @@ -41,16 +50,6 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.Map; -import java.util.UUID; - -import static java.util.Collections.emptyMap; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - public class ToscaParserInflatorTest { private static final Logger log = LogManager.getLogger(ToscaParserInflatorTest.class); @@ -83,15 +82,15 @@ public class ToscaParserInflatorTest { @Test public void inflateFabricConfigurationModel_allIdsAreGiven() throws Exception { - final String fabricConfigurationUuid = "90fe6842-aa76-4b68-8329-5c86ff564407"; + final String fabricConfigurationUuid = "12344bb4-a416-4b4e-997e-0059973630b9"; final Map<String, Names> inflated = inflateModelByUuid(fabricConfigurationUuid); // see vf-with-annotation-csar.json assertThat(inflated, is(ImmutableMap.of( - "8df1892c-377d-460b-8a8d-fc8a116e9d92", doubleName("201712-488_ADIOD-vPE-1 0"), - "8d521692-7661-4296-b77e-a2058bb62e87", new Names("201712488AdiodVpe1..ADIOD_vRE_BV..module-1", "201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vRE_BV..module-1"), - "79fbee20-7fba-4166-ae4b-b94c869e7d8b", new Names("201712488AdiodVpe1..ADIOD_vPFE_BV..module-2","201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vPFE_BV..module-2"), - "806505b8-7a7c-47a2-acef-b4d26fe95a92", new Names("201712488AdiodVpe1..ADIOD_base_vPE_BV..module-0","201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_base_vPE_BV..module-0") + "ea81d6f7-0861-44a7-b7d5-d173b562c350", doubleName("2017-488_PASQUALE-vPE 0"), + "a5d8df05-11cb-4351-96e0-b6d4168ea4df", new Names("2017488PasqualeVpe..PASQUALE_vRE_BV..module-1", "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vRE_BV..module-1"), + "b3e8b26e-cff0-49fc-a4e6-f3e16c8440fe", new Names("2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2","2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2"), + "040e591e-5d30-4e0d-850f-7266e5a8e013", new Names("2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0","2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0") ))); } diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java index 788f78084..edaf7125f 100644 --- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/VidNotionsBuilderTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,28 +30,35 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; -import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.elements.Metadata; import org.onap.vid.model.*; import org.onap.vid.properties.Features; +import org.onap.vid.testUtils.TestUtils; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.togglz.core.manager.FeatureManager; -import java.util.LinkedHashMap; -import java.util.UUID; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; import java.util.function.BiConsumer; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.is; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.testng.Assert.assertEquals; +import static org.onap.vid.model.VidNotions.*; +import static org.testng.AssertJUnit.assertEquals; public class VidNotionsBuilderTest { @@ -61,6 +68,10 @@ public class VidNotionsBuilderTest { @Mock private FeatureManager featureManagerMock; + private ServiceModel serviceModel; + + private ISdcCsarHelper csarHelper; + @BeforeClass public void initMocks() { MockitoAnnotations.initMocks(this); @@ -75,12 +86,12 @@ public class VidNotionsBuilderTest { public void VLNetworkWithPropertyNetworkTechnologyOVS_UIHintIsPositive() { ISdcCsarHelper csarHelper = mockForNonLegacyInstantiationUI(); - assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper), is(VidNotions.InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS)); - assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper) , is(VidNotions.ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL)); + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS)); + assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL)); } @NotNull - protected ISdcCsarHelper mockForNonLegacyInstantiationUI() { + private ISdcCsarHelper mockForNonLegacyInstantiationUI() { ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString()); NodeTemplate nodeTemplate = mock(NodeTemplate.class); @@ -98,15 +109,16 @@ public class VidNotionsBuilderTest { @DataProvider public static Object[][] anyAlacarteDataProvider() { return new Object[][] { - {"A-La-Carte", VidNotions.InstantiationUI.ANY_ALACARTE_NEW_UI}, - {"Macro", VidNotions.InstantiationUI.LEGACY}, + {"A-La-Carte", InstantiationUI.ANY_ALACARTE_NEW_UI}, + {"Macro", InstantiationUI.LEGACY}, }; } @Test(dataProvider = "anyAlacarteDataProvider") - public void FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI_is_active_UIHintIsPositive(String instantiationType, VidNotions.InstantiationUI expectedInstantiationUI) { + public void FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI_is_active_UIHintIsPositive(String instantiationType, InstantiationUI expectedInstantiationUI) { + initServiceModelAndscarHelperWithMocks(); + when(featureManagerMock.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI)).thenReturn(true); - ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString()); when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of( "instantiationType", instantiationType ))); @@ -119,12 +131,12 @@ public class VidNotionsBuilderTest { when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate)); - assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper), is(expectedInstantiationUI)); + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(expectedInstantiationUI)); } @Test public void VLNetworkWithPropertyNetworkTechnologyNot5G_UIHintIsNegative() { - ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString()); + initServiceModelAndscarHelperWithMocks(); NodeTemplate nodeTemplate = mock(NodeTemplate.class); @@ -135,85 +147,91 @@ public class VidNotionsBuilderTest { when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate)); - assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper), is(VidNotions.InstantiationUI.LEGACY)); - assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper) , is(VidNotions.ModelCategory.OTHER)); + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY)); + assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.OTHER)); } @Test - public void withoutMocks_givenZippedToscaFile_hasAnyNetworkWithPropertyEqualsToAnyOfYieldsTrue() throws SdcToscaParserException { - SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - ISdcCsarHelper csarHelper = factory.getSdcCsarHelper(getClass().getClassLoader().getResource("service-vl-csar.zip").getPath(),false); - + public void withoutMocks_givenZippedToscaFile_hasAnyNetworkWithPropertyEqualsToAnyOfYieldsTrue() throws SdcToscaParserException, IOException { + initServiceModelAndscarHelperWithRealCsar("/csars/service-vl-csar.zip"); assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false)); assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "unexpected_property_name"), is(false)); assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "network_technology","Standard-SR-IOV"), is(true)); - assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper), is(VidNotions.InstantiationUI.LEGACY)); + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY)); } - //@Test - //public void withoutMocks_givenZippedToscaFile_hasFabricConfigurationYieldsTrue() throws SdcToscaParserException { - // SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); - // ISdcCsarHelper csarHelper = factory.getSdcCsarHelper(getClass().getClassLoader().getResource("service-fabric-configuration.zip").getPath(),false); - // - // assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false)); - // assertThat(vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(true)); - // assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper), is(VidNotions.InstantiationUI.LEGACY)); - //} + @Test + public void withoutMocks_givenZippedToscaFile_hasFabricConfigurationYieldsTrue() throws SdcToscaParserException, IOException { + initServiceModelAndscarHelperWithRealCsar("/csars/service-fabric-configuration.zip"); + assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false)); + assertThat(vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(true)); + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY)); + } + + @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class) + public void withoutMocks_givenZippedToscaFileOfTransportService_InstantiationUIAndCategoryAreRight(boolean flagValue) throws SdcToscaParserException, IOException { + initServiceModelAndscarHelperWithRealCsar("/csars/csarTransportWithPnfs.zip"); + when(featureManagerMock.isActive(Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI)).thenReturn(flagValue); + + assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false)); + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.TRANSPORT_SERVICE : InstantiationUI.LEGACY)); + assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.Transport)); + } + + @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class) + public void withoutMocks_givenZippedToscaFileOfInfraStructureVpn_InstantiationUIIsRight(boolean flagValue) throws SdcToscaParserException, IOException { + initServiceModelAndscarHelperWithRealCsar("/csars/service-Infravpn-csar.zip"); + when(featureManagerMock.isActive(Features.FLAG_1908_INFRASTRUCTURE_VPN)).thenReturn(flagValue); + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.INFRASTRUCTURE_VPN : InstantiationUI.LEGACY)); + assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.INFRASTRUCTURE_VPN)); + } @Test public void uuidIsExactly1ffce89fEtc_UIHintIsPositive() { - ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString()); + initServiceModelAndscarHelperWithMocks(); when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of( "UUID", "95eb2c44-bff2-4e8b-ad5d-8266870b7717" ))); when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true); - assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper), is(VidNotions.InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de)); - } - - - @DataProvider - public static Object[][] trueAndFalse() { - return new Object[][] {{true}, {false}}; + assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de)); } - @Test(dataProvider = "trueAndFalse") + @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class) public void buildVidNotions_nullByFlag(boolean flagValue) { - ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString()); + initServiceModelAndscarHelperWithMocks(); when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(flagValue); - assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, null), hasProperty("instantiationUI", is(VidNotions.InstantiationUI.LEGACY))); + assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel), hasProperty("instantiationUI", is(InstantiationUI.LEGACY))); } @DataProvider public static Object[][] ServiceRoleTypesDataProvider() { return new Object[][] { - {"gROUPING", VidNotions.InstantiationUI.SERVICE_WITH_VNF_GROUPING}, - {"", VidNotions.InstantiationUI.LEGACY}, + {"gROUPING", InstantiationUI.SERVICE_WITH_VNF_GROUPING}, + {"", InstantiationUI.LEGACY}, }; } @Test(dataProvider = "ServiceRoleTypesDataProvider") - public void testGetViewEditUITypeForResourceGroup(String serviceRole, VidNotions.InstantiationUI expectedViewEditUI) { - when(featureManagerMock.isActive(Features.FLAG_ASYNC_INSTANTIATION)).thenReturn(true); + public void testGetViewEditUITypeForResourceGroup(String serviceRole, InstantiationUI expectedViewEditUI) { + initServiceModelAndscarHelperWithMocks(); when(featureManagerMock.isActive(Features.FLAG_1902_VNF_GROUPING)).thenReturn(true); - ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString()); when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of( "serviceRole", serviceRole ))); - assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, null), is(expectedViewEditUI)); + assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel), is(expectedViewEditUI)); } @DataProvider public static Object[][] macroToViewEditDataProvider() { return new Object[][] { - {"macro service + not excluded + needed flags are open", true, false, true, true, VidNotions.InstantiationUI.MACRO_SERVICE}, - {"not macro service", false, false, true, true, VidNotions.InstantiationUI.LEGACY}, - {"macro that shall be excluded because it has pnf", true, true, true, true, VidNotions.InstantiationUI.LEGACY}, - {"macro service + FLAG_ASYNC_INSTANTIATION off", true, false, false, true, VidNotions.InstantiationUI.LEGACY}, - {"macro service + FLAG_1902_NEW_VIEW_EDIT off", true, false, true, false, VidNotions.InstantiationUI.LEGACY}, + {"macro service + not excluded + needed flags are open", true, false, true, InstantiationUI.MACRO_SERVICE}, + {"not macro service", false, true, true, InstantiationUI.LEGACY}, + {"macro that shall be excluded because it has pnf", true, true, true, InstantiationUI.LEGACY}, + {"macro service + FLAG_1902_NEW_VIEW_EDIT off", true, false, false, InstantiationUI.LEGACY}, }; } @@ -222,19 +240,16 @@ public class VidNotionsBuilderTest { String testDescription, boolean isMacro, boolean isExcluded, - boolean isFlagAsyncInstantiationActive, boolean isFlag1902NewViewEdit, - VidNotions.InstantiationUI expectedViewEditUi) { + InstantiationUI expectedViewEditUi) { - ISdcCsarHelper csarHelper = mock(ISdcCsarHelper.class); - ServiceModel serviceModel = mock(ServiceModel.class); + initServiceModelAndscarHelperWithMocks(); //mock for is Macro String instantiationType = isMacro ? ToscaParserImpl2.Constants.MACRO : ToscaParserImpl2.Constants.A_LA_CARTE; Service service = mock(Service.class); when(serviceModel.getService()).thenReturn(service); when(service.getInstantiationType()).thenReturn(instantiationType); - when(featureManagerMock.isActive(Features.FLAG_ASYNC_INSTANTIATION)).thenReturn(isFlagAsyncInstantiationActive); when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(isFlag1902NewViewEdit); //mock for isExcluded @@ -242,17 +257,16 @@ public class VidNotionsBuilderTest { when(serviceModel.getPnfs()).thenReturn(ImmutableMap.of("a", mock(Node.class))); } - VidNotions.InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel); + InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel); assertEquals(expectedViewEditUi, result); } @DataProvider public static Object[][] instantiationUIToViewEditDataProvider() { return new Object[][] { - {"network cloud(5G) service + needed flags are open", true, true, true, VidNotions.InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS}, - {"mocked service + needed flags are open", false, true, true, VidNotions.InstantiationUI.LEGACY}, - {"network cloud(5G) service + FLAG_ASYNC_INSTANTIATION is off", true, false, true, VidNotions.InstantiationUI.LEGACY}, - {"network cloud(5G) service + FLAG_1902_NEW_VIEW_EDIT is off", true, true, false, VidNotions.InstantiationUI.LEGACY}, + {"network cloud(5G) service + needed flags are open", true, true, InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS}, + {"mocked service + needed flags are open", false, true, InstantiationUI.LEGACY}, + {"network cloud(5G) service + FLAG_1902_NEW_VIEW_EDIT is off", true, false, InstantiationUI.LEGACY}, }; } @@ -261,12 +275,10 @@ public class VidNotionsBuilderTest { public void whenInstantiationUIIsNotLegacy_viewEditIsRight( String testDescription, boolean isInstantiationUINotLegacy, - boolean isFlagAsyncInstantiationActive, boolean isFlag1902NewViewEdit, - VidNotions.InstantiationUI expectedViewEditUi) { + InstantiationUI expectedViewEditUi) { ISdcCsarHelper csarHelper = isInstantiationUINotLegacy ? mockForNonLegacyInstantiationUI() : mock(ISdcCsarHelper.class); - when(featureManagerMock.isActive(Features.FLAG_ASYNC_INSTANTIATION)).thenReturn(isFlagAsyncInstantiationActive); when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(isFlag1902NewViewEdit); ServiceModel serviceModel = mock(ServiceModel.class); @@ -274,7 +286,7 @@ public class VidNotionsBuilderTest { when(serviceModel.getService()).thenReturn(service); when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.A_LA_CARTE); - VidNotions.InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel); + InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel); assertEquals(expectedViewEditUi, result); } @@ -282,7 +294,7 @@ public class VidNotionsBuilderTest { public static Object[][] mockerForMacroExcluded() { return new Object[][] { {"service with pnfs", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->when(serviceModel.getPnfs()).thenReturn(ImmutableMap.of("a", mock(Node.class))), true}, - {"service with collection resource", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->when(serviceModel.getCollectionResource()).thenReturn(ImmutableMap.of("a", mock(CR.class))), true}, + {"service with collection resource", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm) -> when(serviceModel.getCollectionResources()).thenReturn(ImmutableMap.of("a", mock(CR.class))), true}, {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION false ", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{ when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class))); when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(false);} @@ -290,7 +302,7 @@ public class VidNotionsBuilderTest { {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION true", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{ when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class))); when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(true);} - , false}, + , false}, {"empty service + FLAG_NETWORK_TO_ASYNC_INSTANTIATION false", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(false), false}, }; } @@ -302,9 +314,197 @@ public class VidNotionsBuilderTest { assertEquals(shallBeExcluded, vidNotionsBuilder.isMacroExcludedFromAsyncFlow(serviceModel)); } + @DataProvider + public static Object[][] toscaParserInstantiationTypeToVidNotion() { + return new Object[][] { + {ToscaParserImpl2.Constants.MACRO, InstantiationType.Macro}, + {ToscaParserImpl2.Constants.A_LA_CARTE, InstantiationType.ALaCarte}, + {ToscaParserImpl2.Constants.CLIENT_CONFIG, InstantiationType.ClientConfig}, + {"I dont know", InstantiationType.ClientConfig}, + {"", InstantiationType.ClientConfig} + }; + } + + @Test(dataProvider="toscaParserInstantiationTypeToVidNotion") + public void testSuggestInstantiationTypeWhenInstantiationUiLegacy(String toscaParserInstantiationType, InstantiationType expectedInstantiationType) { + ServiceModel serviceModel = mock(ServiceModel.class); + Service service = mock(Service.class); + when(serviceModel.getService()).thenReturn(service); + when(service.getInstantiationType()).thenReturn(toscaParserInstantiationType); + assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER)); + } + + @DataProvider + public static Object[][] instantiationUIAndFeatureFlagsForInstantiationType() { + return new Object[][] { + {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, true, InstantiationType.Macro}, + {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, false, InstantiationType.ALaCarte}, + {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.Macro}, + {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, false, InstantiationType.ALaCarte}, + {ModelCategory.OTHER, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.ALaCarte}, //not mapped InstantiationUI + }; + } + @Test(dataProvider="instantiationUIAndFeatureFlagsForInstantiationType") + public void testSuggestInstantiationTypeByModelCategoryAndFeatureFlags( + ModelCategory instantiationUI, + Features featureFlag, + boolean isFeatureOn, + InstantiationType expectedInstantiationType) { + ServiceModel serviceModel = mock(ServiceModel.class); + Service service = mock(Service.class); + when(serviceModel.getService()).thenReturn(service); + when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.A_LA_CARTE); + when(featureManagerMock.isActive(featureFlag)).thenReturn(isFeatureOn); + assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, instantiationUI)); + } + @DataProvider + public static Object[][] FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions() { + return new Object[][] { + {true, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.SERVICE_WITH_COLLECTION_RESOURCE, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE}, + {true, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER}, + {true, null, InstantiationUI.LEGACY, ModelCategory.OTHER}, + {false, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.LEGACY, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE}, + {false, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER}, + {false, null, InstantiationUI.LEGACY, ModelCategory.OTHER} + }; + } + @Test(dataProvider="FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions") + public void testSuggestInstantiationUiAndModelCategoryByCollectionResourceAndFeatureFlag_FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI( + boolean featureFlagValue, + Map<String, CR> collectionResource, + VidNotions.InstantiationUI expectedInstantiationUi, + VidNotions.ModelCategory expectedModelCategory) { + initServiceModelAndscarHelperWithMocks(); + Service service = mock(Service.class); + when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.MACRO); + when(serviceModel.getService()).thenReturn(service); + when(serviceModel.getCollectionResources()).thenReturn(collectionResource); + when(featureManagerMock.isActive(Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI)).thenReturn(featureFlagValue); + VidNotions vidNotions = vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel); + assertEquals(expectedInstantiationUi, vidNotions.getInstantiationUI()); + assertEquals(expectedModelCategory, vidNotions.getModelCategory()); + assertEquals(InstantiationUI.LEGACY, vidNotions.getViewEditUI()); + assertEquals(InstantiationType.Macro, vidNotions.getInstantiationType()); + } -} + @DataProvider + public static Object[][] givenCollectionResourceServiceDataProvider() { + return new Object[][]{ + {false, true, InstantiationUI.LEGACY}, + {true, false, InstantiationUI.LEGACY}, + {true, true, InstantiationUI.SERVICE_WITH_COLLECTION_RESOURCE} + }; + } + + @Test(dataProvider = "givenCollectionResourceServiceDataProvider") + public void givenCollectionResourceService_whenSuggestViewEdit_thenResultAccordingFeatureFlag( + boolean crFlag, boolean resumeFlag, VidNotions.InstantiationUI expectedViewEditUi) { + + //mock service with CR + ServiceModel mockServiceModel = mock(ServiceModel.class); + when(mockServiceModel.getCollectionResources()).thenReturn(ImmutableMap.of("a", mock(CR.class))); + + //mock feature flags + when(featureManagerMock.isActive(Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI)).thenReturn(crFlag); + when(featureManagerMock.isActive(Features.FLAG_1908_RESUME_MACRO_SERVICE)).thenReturn(resumeFlag); + + assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(mock(ISdcCsarHelper.class), mockServiceModel)); + } + + @Test + public void whenServiceModelIsNull_thenInstantiationTypeIsClientConfig() { + assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(null, ModelCategory.OTHER)); + } + + @Test + public void whenServiceInServiceModelIsNull_thenInstantiationTypeIsClientConfig() { + assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(mock(ServiceModel.class), ModelCategory.OTHER)); + } + + @Test + public void whenInstantiationTypeInServiceModelIsNull_thenInstantiationTypeIsClientConfig() { + initServiceModelAndscarHelperWithMocks(); + Service service = mock(Service.class); + when(serviceModel.getService()).thenReturn(service); + when(service.getInstantiationType()).thenReturn(null); + assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER)); + } + + private void initServiceModelAndscarHelperWithRealCsar(String path) throws SdcToscaParserException, IOException { + Path csarPath = Paths.get(new File(getClass().getResource(path).getPath()).getCanonicalPath()); + ToscaParserImpl2 toscaParser = new ToscaParserImpl2(vidNotionsBuilder); + org.onap.vid.asdc.beans.Service asdcServiceMetadata = mock(org.onap.vid.asdc.beans.Service.class); + when(asdcServiceMetadata.getVersion()).thenReturn("versions"); + serviceModel = toscaParser.makeServiceModel(csarPath, asdcServiceMetadata); + csarHelper = toscaParser.getSdcCsarHelper(csarPath); + } + + private void initServiceModelAndscarHelperWithMocks() { + csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString()); + serviceModel = mock(ServiceModel.class); + } + + @DataProvider + public static Object[][] VnfNcIndicationDataProvider() { + return new Object[][] { + {true, "VNF", InstantiationUI.A_LA_CARTE_VNF_SERVICE_ROLE}, + {false, "VNF", InstantiationUI.LEGACY}, + {false, "notVNF", InstantiationUI.LEGACY}, + {true, null, InstantiationUI.LEGACY}, + {true, "notVNF", InstantiationUI.LEGACY}, + {true, "vnf", InstantiationUI.A_LA_CARTE_VNF_SERVICE_ROLE}, + }; + } + + @Test (dataProvider = "VnfNcIndicationDataProvider") + public void whenServiceRoleVnf_thenInstantiationTypeNewUI(boolean flagOn, String serviceRole, InstantiationUI expectedViewEditUi){ + initServiceModelAndscarHelperWithMocks(); + + when(featureManagerMock.isActive(Features.FLAG_1908_A_LA_CARTE_VNF_NEW_INSTANTIATION_UI)).thenReturn(flagOn); + + when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(serviceRole == null ? + emptyMap() : ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_ROLE, serviceRole) + )); + + assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel)); + } + + private static NodeTemplate mockNodeTemplateChild(boolean withFabricConfiguration) { + NodeTemplate child = mock(NodeTemplate.class); + when(child.getType()).thenReturn(withFabricConfiguration ? ToscaParserImpl2.Constants.FABRIC_CONFIGURATION_TYPE : "nothing"); + return child; + } + + private static ISdcCsarHelper mockServiceNodeTemplates(ISdcCsarHelper csarHelper, ImmutableList<NodeTemplate> children) { + when(csarHelper.getNodeTemplateChildren(any())).thenReturn(children); + + NodeTemplate parent = mock(NodeTemplate.class); + List<NodeTemplate> nodeTemplates = ImmutableList.of(parent); + + when(csarHelper.getServiceNodeTemplates()).thenReturn(nodeTemplates); + return csarHelper; + } + + @DataProvider + public static Object[][] csarHelpersForFabricConfiguration() { + ISdcCsarHelper csarHelperWithNoNodes = mock(ISdcCsarHelper.class); + when(csarHelperWithNoNodes.getServiceNodeTemplates()).thenReturn(emptyList()); + + return new Object[][] { + { "zero nodes", false, csarHelperWithNoNodes }, + { "single node with no child", false, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of()) }, + { "single node with single fabric child", true, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of(mockNodeTemplateChild(true))) }, + { "single node with single fabric child and single non-fabric", true, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of( + mockNodeTemplateChild(true), mockNodeTemplateChild(true))) }, + }; + } + + @Test (dataProvider = "csarHelpersForFabricConfiguration") + public void hasFabricConfiguration(String desc, boolean shouldHaveFabricConfiguration, ISdcCsarHelper csarHelper) { + assertThat(desc, vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(shouldHaveFabricConfiguration)); + } +}
\ No newline at end of file |