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.asdc.parser;
23 import static java.util.Collections.emptyList;
24 import static java.util.Collections.emptyMap;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.hamcrest.Matchers.hasProperty;
27 import static org.hamcrest.Matchers.is;
28 import static org.mockito.ArgumentMatchers.any;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.when;
31 import static org.onap.vid.model.VidNotions.InstantiationType;
32 import static org.onap.vid.model.VidNotions.InstantiationUI;
33 import static org.onap.vid.model.VidNotions.ModelCategory;
34 import static org.testng.AssertJUnit.assertEquals;
36 import com.google.common.collect.ImmutableList;
37 import com.google.common.collect.ImmutableMap;
39 import java.io.IOException;
40 import java.nio.file.Path;
41 import java.nio.file.Paths;
42 import java.util.Collections;
43 import java.util.LinkedHashMap;
44 import java.util.List;
46 import java.util.UUID;
47 import java.util.function.BiConsumer;
48 import org.apache.commons.lang3.tuple.Pair;
49 import org.jetbrains.annotations.NotNull;
50 import org.mockito.InjectMocks;
51 import org.mockito.Mock;
52 import org.mockito.Mockito;
53 import org.mockito.MockitoAnnotations;
54 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
55 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
56 import org.onap.sdc.toscaparser.api.NodeTemplate;
57 import org.onap.sdc.toscaparser.api.Property;
58 import org.onap.sdc.toscaparser.api.elements.Metadata;
59 import org.onap.vid.asdc.parser.ToscaParserImpl2.Constants;
60 import org.onap.vid.model.CR;
61 import org.onap.vid.model.Network;
62 import org.onap.vid.model.Node;
63 import org.onap.vid.model.Service;
64 import org.onap.vid.model.ServiceModel;
65 import org.onap.vid.model.VidNotions;
66 import org.onap.vid.properties.Features;
67 import org.onap.vid.testUtils.TestUtils;
68 import org.testng.annotations.AfterMethod;
69 import org.testng.annotations.BeforeClass;
70 import org.testng.annotations.DataProvider;
71 import org.testng.annotations.Test;
72 import org.togglz.core.manager.FeatureManager;
74 public class VidNotionsBuilderTest {
77 VidNotionsBuilder vidNotionsBuilder;
80 private FeatureManager featureManagerMock;
82 private ServiceModel serviceModel;
84 private ISdcCsarHelper csarHelper;
87 public void initMocks() {
88 MockitoAnnotations.initMocks(this);
93 Mockito.reset(featureManagerMock);
97 public void VLNetworkWithPropertyNetworkTechnologyOVS_UIHintIsPositive() {
98 ISdcCsarHelper csarHelper = mockForNonLegacyInstantiationUI();
100 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS));
101 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL));
105 private ISdcCsarHelper mockForNonLegacyInstantiationUI() {
106 ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString());
108 NodeTemplate nodeTemplate = mock(NodeTemplate.class);
110 when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
111 "dummy_val", mock(Property.class),
112 "network_technology", new Property(Pair.of("network_technology","ovs"))
115 when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
116 when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
121 public static Object[][] anyAlacarteDataProvider() {
122 return new Object[][] {
123 {"A-La-Carte", InstantiationUI.ANY_ALACARTE_NEW_UI},
124 {"Macro", InstantiationUI.LEGACY},
128 @Test(dataProvider = "anyAlacarteDataProvider")
129 public void FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI_is_active_UIHintIsPositive(String instantiationType, InstantiationUI expectedInstantiationUI) {
130 initServiceModelAndscarHelperWithMocks();
132 when(featureManagerMock.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI)).thenReturn(true);
133 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
134 "instantiationType", instantiationType
136 NodeTemplate nodeTemplate = mock(NodeTemplate.class);
138 when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
139 "dummy_val", mock(Property.class),
140 "network_technology", new Property(Pair.of("network_technology","ovs"))
143 when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
145 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(expectedInstantiationUI));
149 public void VLNetworkWithPropertyNetworkTechnologyNot5G_UIHintIsNegative() {
150 initServiceModelAndscarHelperWithMocks();
152 NodeTemplate nodeTemplate = mock(NodeTemplate.class);
154 when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
155 "dummy_val", mock(Property.class),
156 "network_technology", new Property(Pair.of("network_technology","old_value"))
159 when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
161 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
162 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.OTHER));
166 public void withoutMocks_givenZippedToscaFile_hasAnyNetworkWithPropertyEqualsToAnyOfYieldsTrue() throws SdcToscaParserException, IOException {
167 initServiceModelAndscarHelperWithRealCsar("/csars/service-vl-csar.zip");
168 assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
169 assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "unexpected_property_name"), is(false));
170 assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "network_technology","Standard-SR-IOV"), is(true));
171 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
175 public void withoutMocks_givenZippedToscaFile_hasFabricConfigurationYieldsTrue() throws SdcToscaParserException, IOException {
176 initServiceModelAndscarHelperWithRealCsar("/csars/service-fabric-configuration.zip");
177 assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
178 assertThat(vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(true));
179 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
182 @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
183 public void withoutMocks_givenZippedToscaFileOfTransportService_InstantiationUIAndCategoryAreRight(boolean flagValue) throws SdcToscaParserException, IOException {
184 initServiceModelAndscarHelperWithRealCsar("/csars/csarTransportWithPnfs.zip");
186 when(featureManagerMock.isActive(Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI)).thenReturn(flagValue);
188 assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
189 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.TRANSPORT_SERVICE : InstantiationUI.LEGACY));
190 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.Transport));
193 @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
194 public void withoutMocks_givenZippedToscaFileOfInfraStructureVpn_InstantiationUIIsRight(boolean flagValue) throws SdcToscaParserException, IOException {
195 initServiceModelAndscarHelperWithRealCsar("/csars/service-Infravpn-csar.zip");
196 when(featureManagerMock.isActive(Features.FLAG_1908_INFRASTRUCTURE_VPN)).thenReturn(flagValue);
197 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.INFRASTRUCTURE_VPN : InstantiationUI.LEGACY));
198 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.INFRASTRUCTURE_VPN));
202 public void withoutMocks_givenToscaOfPortMirroring_InstantiationUIIsLegacyAndCategoryIsPortMirroring() throws SdcToscaParserException, IOException {
203 initServiceModelAndscarHelperWithRealCsar("/csars/portMirroringService.zip");
204 when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(true);
205 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
206 assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
207 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.PORT_MIRRORING));
211 public void withoutMocks_givenToscaOfVLanTagging_InstantiationUIIsLegacyAndCategoryIsVlanTagging() throws SdcToscaParserException, IOException {
212 initServiceModelAndscarHelperWithRealCsar("/csars/service-VdorotheaSrv-csar.zip");
213 when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(true);
214 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
215 assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
216 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.VLAN_TAGGING));
221 public void uuidIsExactly1ffce89fEtc_UIHintIsPositive() {
222 initServiceModelAndscarHelperWithMocks();
224 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
225 "UUID", "95eb2c44-bff2-4e8b-ad5d-8266870b7717"
227 when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
228 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de));
231 @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
232 public void buildVidNotions_nullByFlag(boolean flagValue) {
233 initServiceModelAndscarHelperWithMocks();
235 when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(flagValue);
236 assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel), hasProperty("instantiationUI", is(InstantiationUI.LEGACY)));
239 private void mockInstantiationType(ServiceModel serviceModel, String aLaCarte) {
240 Service mockService = mock(Service.class);
241 when(serviceModel.getService()).thenReturn(mockService);
242 when(mockService.getInstantiationType()).thenReturn(aLaCarte);
246 public static Object[][] ServiceRoleTypesDataProvider() {
247 return new Object[][] {
248 {"gROUPING", InstantiationUI.SERVICE_WITH_VNF_GROUPING},
249 {"", InstantiationUI.LEGACY},
253 @Test(dataProvider = "ServiceRoleTypesDataProvider")
254 public void testGetViewEditUITypeForResourceGroup(String serviceRole, InstantiationUI expectedViewEditUI) {
255 initServiceModelAndscarHelperWithMocks();
256 when(featureManagerMock.isActive(Features.FLAG_1902_VNF_GROUPING)).thenReturn(true);
257 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
258 "serviceRole", serviceRole
261 assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel), is(expectedViewEditUI));
265 public static Object[][] instantiationUIToViewEditDataProvider() {
266 return new Object[][] {
267 {"network cloud(5G) service + needed flags are open", true, true, InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS},
268 {"mocked service + needed flags are open", false, true, InstantiationUI.LEGACY},
269 {"network cloud(5G) service + FLAG_1902_NEW_VIEW_EDIT is off", true, false, InstantiationUI.LEGACY},
274 @Test(dataProvider="instantiationUIToViewEditDataProvider")
275 public void whenInstantiationUIIsNotLegacy_viewEditIsRight(
276 String testDescription,
277 boolean isInstantiationUINotLegacy,
278 boolean isFlag1902NewViewEdit,
279 InstantiationUI expectedViewEditUi) {
281 ISdcCsarHelper csarHelper = isInstantiationUINotLegacy ? mockForNonLegacyInstantiationUI() : mock(ISdcCsarHelper.class);
282 when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(isFlag1902NewViewEdit);
284 ServiceModel serviceModel = mock(ServiceModel.class);
285 mockInstantiationType(serviceModel, Constants.A_LA_CARTE);
287 InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel);
288 assertEquals(expectedViewEditUi, result);
292 public static Object[][] mockerForMacroExcluded() {
293 return new Object[][] {
294 {"service with pnfs", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->when(serviceModel.getPnfs()).thenReturn(ImmutableMap.of("a", mock(Node.class))), true},
295 {"service with collection resource", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm) -> when(serviceModel.getCollectionResources()).thenReturn(ImmutableMap.of("a", mock(CR.class))), true},
296 {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION false ", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{
297 when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class)));
298 when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(false);}
300 {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION true", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{
301 when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class)));
302 when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(true);}
304 {"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},
308 @Test(dataProvider="mockerForMacroExcluded")
309 public void testIsMacroExcludedFromAsyncFlow(String testDescription, BiConsumer<ServiceModel, FeatureManager> mocker, boolean shallBeExcluded) {
310 ServiceModel serviceModel = mock(ServiceModel.class);
311 mocker.accept(serviceModel, featureManagerMock);
312 assertEquals(shallBeExcluded, vidNotionsBuilder.isMacroExcludedFromAsyncFlow(serviceModel));
316 public static Object[][] toscaParserInstantiationTypeToVidNotion() {
317 return new Object[][] {
318 {ToscaParserImpl2.Constants.MACRO, InstantiationType.Macro},
319 {ToscaParserImpl2.Constants.A_LA_CARTE, InstantiationType.ALaCarte},
320 {ToscaParserImpl2.Constants.CLIENT_CONFIG, InstantiationType.ClientConfig},
321 {"I dont know", InstantiationType.ClientConfig},
322 {"", InstantiationType.ClientConfig}
326 @Test(dataProvider="toscaParserInstantiationTypeToVidNotion")
327 public void testSuggestInstantiationTypeWhenInstantiationUiLegacy(String toscaParserInstantiationType, InstantiationType expectedInstantiationType) {
328 ServiceModel serviceModel = mock(ServiceModel.class);
329 mockInstantiationType(serviceModel, toscaParserInstantiationType);
330 assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER));
334 public static Object[][] instantiationUIAndFeatureFlagsForInstantiationType() {
335 return new Object[][] {
336 {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, true, InstantiationType.Macro},
337 {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, false, InstantiationType.ALaCarte},
338 {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.Macro},
339 {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, false, InstantiationType.ALaCarte},
340 {ModelCategory.OTHER, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.ALaCarte}, //not mapped InstantiationUI
344 @Test(dataProvider="instantiationUIAndFeatureFlagsForInstantiationType")
345 public void testSuggestInstantiationTypeByModelCategoryAndFeatureFlags(
346 ModelCategory instantiationUI,
347 Features featureFlag,
349 InstantiationType expectedInstantiationType) {
350 ServiceModel serviceModel = mock(ServiceModel.class);
351 mockInstantiationType(serviceModel, Constants.A_LA_CARTE);
352 when(featureManagerMock.isActive(featureFlag)).thenReturn(isFeatureOn);
353 assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, instantiationUI));
357 public static Object[][] FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions() {
358 return new Object[][] {
359 {true, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.SERVICE_WITH_COLLECTION_RESOURCE, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE},
360 {true, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER},
361 {true, null, InstantiationUI.LEGACY, ModelCategory.OTHER},
362 {false, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.LEGACY, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE},
363 {false, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER},
364 {false, null, InstantiationUI.LEGACY, ModelCategory.OTHER}
368 @Test(dataProvider="FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions")
369 public void testSuggestInstantiationUiAndModelCategoryByCollectionResourceAndFeatureFlag_FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI(
370 boolean featureFlagValue,
371 Map<String, CR> collectionResource,
372 VidNotions.InstantiationUI expectedInstantiationUi,
373 VidNotions.ModelCategory expectedModelCategory) {
374 initServiceModelAndscarHelperWithMocks();
376 Service service = mock(Service.class);
377 when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.MACRO);
378 when(serviceModel.getService()).thenReturn(service);
379 when(serviceModel.getCollectionResources()).thenReturn(collectionResource);
380 when(featureManagerMock.isActive(Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI)).thenReturn(featureFlagValue);
381 VidNotions vidNotions = vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel);
382 assertEquals(expectedInstantiationUi, vidNotions.getInstantiationUI());
383 assertEquals(expectedModelCategory, vidNotions.getModelCategory());
384 assertEquals(InstantiationUI.LEGACY, vidNotions.getViewEditUI());
385 assertEquals(InstantiationType.Macro, vidNotions.getInstantiationType());
389 public void whenServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
390 assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(null, ModelCategory.OTHER));
394 public void whenServiceInServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
395 assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(mock(ServiceModel.class), ModelCategory.OTHER));
399 public void whenInstantiationTypeInServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
400 initServiceModelAndscarHelperWithMocks();
401 mockInstantiationType(serviceModel, null);
402 assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER));
405 private void initServiceModelAndscarHelperWithRealCsar(String path) throws SdcToscaParserException, IOException {
406 Path csarPath = Paths.get(new File(getClass().getResource(path).getPath()).getCanonicalPath());
407 ToscaParserImpl2 toscaParser = new ToscaParserImpl2(vidNotionsBuilder);
408 org.onap.vid.asdc.beans.Service asdcServiceMetadata = mock(org.onap.vid.asdc.beans.Service.class);
409 when(asdcServiceMetadata.getVersion()).thenReturn("versions");
410 serviceModel = toscaParser.makeServiceModel(csarPath, asdcServiceMetadata);
411 csarHelper = toscaParser.getSdcCsarHelper(csarPath);
414 private void initServiceModelAndscarHelperWithMocks() {
415 csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString());
416 serviceModel = mock(ServiceModel.class);
420 public static Object[][] VnfNcIndicationDataProvider() {
421 return new Object[][] {
422 {true, "VNF", InstantiationUI.A_LA_CARTE_VNF_SERVICE_ROLE},
423 {false, "VNF", InstantiationUI.LEGACY},
424 {false, "notVNF", InstantiationUI.LEGACY},
425 {true, null, InstantiationUI.LEGACY},
426 {true, "notVNF", InstantiationUI.LEGACY},
427 {true, "vnf", InstantiationUI.A_LA_CARTE_VNF_SERVICE_ROLE},
431 @Test (dataProvider = "VnfNcIndicationDataProvider")
432 public void whenServiceRoleVnf_thenInstantiationTypeNewUI(boolean flagOn, String serviceRole, InstantiationUI expectedViewEditUi){
433 initServiceModelAndscarHelperWithMocks();
435 when(featureManagerMock.isActive(Features.FLAG_1908_A_LA_CARTE_VNF_NEW_INSTANTIATION_UI)).thenReturn(flagOn);
437 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(serviceRole == null ?
438 emptyMap() : ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_ROLE, serviceRole)
441 assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel));
444 private static NodeTemplate mockNodeTemplateChild(boolean withFabricConfiguration) {
445 NodeTemplate child = mock(NodeTemplate.class);
446 when(child.getType()).thenReturn(withFabricConfiguration ? ToscaParserImpl2.Constants.FABRIC_CONFIGURATION_TYPE : "nothing");
450 private static ISdcCsarHelper mockServiceNodeTemplates(ISdcCsarHelper csarHelper, ImmutableList<NodeTemplate> children) {
451 when(csarHelper.getNodeTemplateChildren(any())).thenReturn(children);
453 NodeTemplate parent = mock(NodeTemplate.class);
454 List<NodeTemplate> nodeTemplates = ImmutableList.of(parent);
456 when(csarHelper.getServiceNodeTemplates()).thenReturn(nodeTemplates);
461 public static Object[][] csarHelpersForFabricConfiguration() {
462 ISdcCsarHelper csarHelperWithNoNodes = mock(ISdcCsarHelper.class);
463 when(csarHelperWithNoNodes.getServiceNodeTemplates()).thenReturn(emptyList());
465 return new Object[][] {
466 { "zero nodes", false, csarHelperWithNoNodes },
467 { "single node with no child", false, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of()) },
468 { "single node with single fabric child", true, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of(mockNodeTemplateChild(true))) },
469 { "single node with single fabric child and single non-fabric", true, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of(
470 mockNodeTemplateChild(true), mockNodeTemplateChild(true))) },
474 @Test (dataProvider = "csarHelpersForFabricConfiguration")
475 public void hasFabricConfiguration(String desc, boolean shouldHaveFabricConfiguration, ISdcCsarHelper csarHelper) {
476 assertThat(desc, vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(shouldHaveFabricConfiguration));
480 public static Object[][] macroTransportDataProvider() {
481 return new Object[][]{
482 {"transport service flag is open", true, true, true, InstantiationUI.LEGACY},
483 {"macro service flag is open", true, false, true, InstantiationUI.MACRO_SERVICE},
484 {"macro service flag is closed", false, true, true, InstantiationUI.LEGACY},
485 {"transport service flag is closed", false, false, true, InstantiationUI.LEGACY},
486 {"not a macro service", true, false, false, InstantiationUI.LEGACY}
490 @Test (dataProvider = "macroTransportDataProvider")
491 public void viewEditMacroService_transportOrNotTransport(String desc, boolean flagActive, boolean isTransport, boolean isMacro, InstantiationUI expectedViewEditUi) {
492 initServiceModelAndscarHelperWithMocks();
493 Service service = mock(Service.class);
495 String instantiationType = isMacro ? ToscaParserImpl2.Constants.MACRO : ToscaParserImpl2.Constants.A_LA_CARTE;
496 when(serviceModel.getService()).thenReturn(service);
497 when(service.getInstantiationType()).thenReturn(instantiationType);
498 when(featureManagerMock.isActive(Features.FLAG_1908_MACRO_NOT_TRANSPORT_NEW_VIEW_EDIT)).thenReturn(flagActive);
499 when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(false);
500 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(isTransport ? ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_TYPE, "TRANSPORT") : emptyMap()
503 assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel));