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 com.google.common.collect.ImmutableList;
24 import com.google.common.collect.ImmutableMap;
25 import org.apache.commons.lang3.tuple.Pair;
26 import org.jetbrains.annotations.NotNull;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
32 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
33 import org.onap.sdc.toscaparser.api.NodeTemplate;
34 import org.onap.sdc.toscaparser.api.Property;
35 import org.onap.sdc.toscaparser.api.elements.Metadata;
36 import org.onap.vid.model.*;
37 import org.onap.vid.properties.Features;
38 import org.onap.vid.testUtils.TestUtils;
39 import org.testng.annotations.AfterMethod;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.DataProvider;
42 import org.testng.annotations.Test;
43 import org.togglz.core.manager.FeatureManager;
46 import java.io.IOException;
47 import java.nio.file.Path;
48 import java.nio.file.Paths;
50 import java.util.function.BiConsumer;
52 import static java.util.Collections.emptyList;
53 import static java.util.Collections.emptyMap;
54 import static org.hamcrest.MatcherAssert.assertThat;
55 import static org.hamcrest.Matchers.hasProperty;
56 import static org.hamcrest.Matchers.is;
57 import static org.mockito.ArgumentMatchers.any;
58 import static org.mockito.Mockito.mock;
59 import static org.mockito.Mockito.when;
60 import static org.onap.vid.model.VidNotions.*;
61 import static org.testng.AssertJUnit.assertEquals;
63 public class VidNotionsBuilderTest {
66 VidNotionsBuilder vidNotionsBuilder;
69 private FeatureManager featureManagerMock;
71 private ServiceModel serviceModel;
73 private ISdcCsarHelper csarHelper;
76 public void initMocks() {
77 MockitoAnnotations.initMocks(this);
82 Mockito.reset(featureManagerMock);
86 public void VLNetworkWithPropertyNetworkTechnologyOVS_UIHintIsPositive() {
87 ISdcCsarHelper csarHelper = mockForNonLegacyInstantiationUI();
89 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS));
90 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL));
94 private ISdcCsarHelper mockForNonLegacyInstantiationUI() {
95 ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString());
97 NodeTemplate nodeTemplate = mock(NodeTemplate.class);
99 when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
100 "dummy_val", mock(Property.class),
101 "network_technology", new Property(Pair.of("network_technology","ovs"))
104 when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
105 when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
110 public static Object[][] anyAlacarteDataProvider() {
111 return new Object[][] {
112 {"A-La-Carte", InstantiationUI.ANY_ALACARTE_NEW_UI},
113 {"Macro", InstantiationUI.LEGACY},
117 @Test(dataProvider = "anyAlacarteDataProvider")
118 public void FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI_is_active_UIHintIsPositive(String instantiationType, InstantiationUI expectedInstantiationUI) {
119 initServiceModelAndscarHelperWithMocks();
121 when(featureManagerMock.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI)).thenReturn(true);
122 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
123 "instantiationType", instantiationType
125 NodeTemplate nodeTemplate = mock(NodeTemplate.class);
127 when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
128 "dummy_val", mock(Property.class),
129 "network_technology", new Property(Pair.of("network_technology","ovs"))
132 when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
134 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(expectedInstantiationUI));
138 public void VLNetworkWithPropertyNetworkTechnologyNot5G_UIHintIsNegative() {
139 initServiceModelAndscarHelperWithMocks();
141 NodeTemplate nodeTemplate = mock(NodeTemplate.class);
143 when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
144 "dummy_val", mock(Property.class),
145 "network_technology", new Property(Pair.of("network_technology","old_value"))
148 when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
150 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
151 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.OTHER));
155 public void withoutMocks_givenZippedToscaFile_hasAnyNetworkWithPropertyEqualsToAnyOfYieldsTrue() throws SdcToscaParserException, IOException {
156 initServiceModelAndscarHelperWithRealCsar("/csars/service-vl-csar.zip");
157 assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
158 assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "unexpected_property_name"), is(false));
159 assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "network_technology","Standard-SR-IOV"), is(true));
160 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
164 public void withoutMocks_givenZippedToscaFile_hasFabricConfigurationYieldsTrue() throws SdcToscaParserException, IOException {
165 initServiceModelAndscarHelperWithRealCsar("/csars/service-fabric-configuration.zip");
166 assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
167 assertThat(vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(true));
168 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
171 @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
172 public void withoutMocks_givenZippedToscaFileOfTransportService_InstantiationUIAndCategoryAreRight(boolean flagValue) throws SdcToscaParserException, IOException {
173 initServiceModelAndscarHelperWithRealCsar("/csars/csarTransportWithPnfs.zip");
175 when(featureManagerMock.isActive(Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI)).thenReturn(flagValue);
177 assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
178 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.TRANSPORT_SERVICE : InstantiationUI.LEGACY));
179 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.Transport));
182 @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
183 public void withoutMocks_givenZippedToscaFileOfInfraStructureVpn_InstantiationUIIsRight(boolean flagValue) throws SdcToscaParserException, IOException {
184 initServiceModelAndscarHelperWithRealCsar("/csars/service-Infravpn-csar.zip");
185 when(featureManagerMock.isActive(Features.FLAG_1908_INFRASTRUCTURE_VPN)).thenReturn(flagValue);
186 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.INFRASTRUCTURE_VPN : InstantiationUI.LEGACY));
187 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.INFRASTRUCTURE_VPN));
191 public void uuidIsExactly1ffce89fEtc_UIHintIsPositive() {
192 initServiceModelAndscarHelperWithMocks();
194 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
195 "UUID", "95eb2c44-bff2-4e8b-ad5d-8266870b7717"
197 when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
198 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de));
201 @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
202 public void buildVidNotions_nullByFlag(boolean flagValue) {
203 initServiceModelAndscarHelperWithMocks();
205 when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(flagValue);
206 assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel), hasProperty("instantiationUI", is(InstantiationUI.LEGACY)));
210 public static Object[][] ServiceRoleTypesDataProvider() {
211 return new Object[][] {
212 {"gROUPING", InstantiationUI.SERVICE_WITH_VNF_GROUPING},
213 {"", InstantiationUI.LEGACY},
217 @Test(dataProvider = "ServiceRoleTypesDataProvider")
218 public void testGetViewEditUITypeForResourceGroup(String serviceRole, InstantiationUI expectedViewEditUI) {
219 initServiceModelAndscarHelperWithMocks();
220 when(featureManagerMock.isActive(Features.FLAG_1902_VNF_GROUPING)).thenReturn(true);
221 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
222 "serviceRole", serviceRole
225 assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel), is(expectedViewEditUI));
229 public static Object[][] macroToViewEditDataProvider() {
230 return new Object[][] {
231 {"macro service + not excluded + needed flags are open", true, false, true, InstantiationUI.MACRO_SERVICE},
232 {"not macro service", false, true, true, InstantiationUI.LEGACY},
233 {"macro that shall be excluded because it has pnf", true, true, true, InstantiationUI.LEGACY},
234 {"macro service + FLAG_1902_NEW_VIEW_EDIT off", true, false, false, InstantiationUI.LEGACY},
238 @Test(dataProvider="macroToViewEditDataProvider")
239 public void whenServiceIsMacro_viewEditIsRight(
240 String testDescription,
243 boolean isFlag1902NewViewEdit,
244 InstantiationUI expectedViewEditUi) {
246 initServiceModelAndscarHelperWithMocks();
249 String instantiationType = isMacro ? ToscaParserImpl2.Constants.MACRO : ToscaParserImpl2.Constants.A_LA_CARTE;
250 Service service = mock(Service.class);
251 when(serviceModel.getService()).thenReturn(service);
252 when(service.getInstantiationType()).thenReturn(instantiationType);
253 when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(isFlag1902NewViewEdit);
255 //mock for isExcluded
257 when(serviceModel.getPnfs()).thenReturn(ImmutableMap.of("a", mock(Node.class)));
260 InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel);
261 assertEquals(expectedViewEditUi, result);
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 Service service = mock(Service.class);
286 when(serviceModel.getService()).thenReturn(service);
287 when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.A_LA_CARTE);
289 InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel);
290 assertEquals(expectedViewEditUi, result);
294 public static Object[][] mockerForMacroExcluded() {
295 return new Object[][] {
296 {"service with pnfs", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->when(serviceModel.getPnfs()).thenReturn(ImmutableMap.of("a", mock(Node.class))), true},
297 {"service with collection resource", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm) -> when(serviceModel.getCollectionResources()).thenReturn(ImmutableMap.of("a", mock(CR.class))), true},
298 {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION false ", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{
299 when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class)));
300 when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(false);}
302 {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION true", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{
303 when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class)));
304 when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(true);}
306 {"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},
310 @Test(dataProvider="mockerForMacroExcluded")
311 public void testIsMacroExcludedFromAsyncFlow(String testDescription, BiConsumer<ServiceModel, FeatureManager> mocker, boolean shallBeExcluded) {
312 ServiceModel serviceModel = mock(ServiceModel.class);
313 mocker.accept(serviceModel, featureManagerMock);
314 assertEquals(shallBeExcluded, vidNotionsBuilder.isMacroExcludedFromAsyncFlow(serviceModel));
318 public static Object[][] toscaParserInstantiationTypeToVidNotion() {
319 return new Object[][] {
320 {ToscaParserImpl2.Constants.MACRO, InstantiationType.Macro},
321 {ToscaParserImpl2.Constants.A_LA_CARTE, InstantiationType.ALaCarte},
322 {ToscaParserImpl2.Constants.CLIENT_CONFIG, InstantiationType.ClientConfig},
323 {"I dont know", InstantiationType.ClientConfig},
324 {"", InstantiationType.ClientConfig}
328 @Test(dataProvider="toscaParserInstantiationTypeToVidNotion")
329 public void testSuggestInstantiationTypeWhenInstantiationUiLegacy(String toscaParserInstantiationType, InstantiationType expectedInstantiationType) {
330 ServiceModel serviceModel = mock(ServiceModel.class);
331 Service service = mock(Service.class);
332 when(serviceModel.getService()).thenReturn(service);
333 when(service.getInstantiationType()).thenReturn(toscaParserInstantiationType);
334 assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER));
338 public static Object[][] instantiationUIAndFeatureFlagsForInstantiationType() {
339 return new Object[][] {
340 {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, true, InstantiationType.Macro},
341 {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, false, InstantiationType.ALaCarte},
342 {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.Macro},
343 {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, false, InstantiationType.ALaCarte},
344 {ModelCategory.OTHER, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.ALaCarte}, //not mapped InstantiationUI
348 @Test(dataProvider="instantiationUIAndFeatureFlagsForInstantiationType")
349 public void testSuggestInstantiationTypeByModelCategoryAndFeatureFlags(
350 ModelCategory instantiationUI,
351 Features featureFlag,
353 InstantiationType expectedInstantiationType) {
354 ServiceModel serviceModel = mock(ServiceModel.class);
355 Service service = mock(Service.class);
356 when(serviceModel.getService()).thenReturn(service);
357 when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.A_LA_CARTE);
358 when(featureManagerMock.isActive(featureFlag)).thenReturn(isFeatureOn);
359 assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, instantiationUI));
363 public static Object[][] FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions() {
364 return new Object[][] {
365 {true, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.SERVICE_WITH_COLLECTION_RESOURCE, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE},
366 {true, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER},
367 {true, null, InstantiationUI.LEGACY, ModelCategory.OTHER},
368 {false, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.LEGACY, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE},
369 {false, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER},
370 {false, null, InstantiationUI.LEGACY, ModelCategory.OTHER}
374 @Test(dataProvider="FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions")
375 public void testSuggestInstantiationUiAndModelCategoryByCollectionResourceAndFeatureFlag_FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI(
376 boolean featureFlagValue,
377 Map<String, CR> collectionResource,
378 VidNotions.InstantiationUI expectedInstantiationUi,
379 VidNotions.ModelCategory expectedModelCategory) {
380 initServiceModelAndscarHelperWithMocks();
382 Service service = mock(Service.class);
383 when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.MACRO);
384 when(serviceModel.getService()).thenReturn(service);
385 when(serviceModel.getCollectionResources()).thenReturn(collectionResource);
386 when(featureManagerMock.isActive(Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI)).thenReturn(featureFlagValue);
387 VidNotions vidNotions = vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel);
388 assertEquals(expectedInstantiationUi, vidNotions.getInstantiationUI());
389 assertEquals(expectedModelCategory, vidNotions.getModelCategory());
390 assertEquals(InstantiationUI.LEGACY, vidNotions.getViewEditUI());
391 assertEquals(InstantiationType.Macro, vidNotions.getInstantiationType());
395 public static Object[][] givenCollectionResourceServiceDataProvider() {
396 return new Object[][]{
397 {false, true, InstantiationUI.LEGACY},
398 {true, false, InstantiationUI.LEGACY},
399 {true, true, InstantiationUI.SERVICE_WITH_COLLECTION_RESOURCE}
403 @Test(dataProvider = "givenCollectionResourceServiceDataProvider")
404 public void givenCollectionResourceService_whenSuggestViewEdit_thenResultAccordingFeatureFlag(
405 boolean crFlag, boolean resumeFlag, VidNotions.InstantiationUI expectedViewEditUi) {
407 //mock service with CR
408 ServiceModel mockServiceModel = mock(ServiceModel.class);
409 when(mockServiceModel.getCollectionResources()).thenReturn(ImmutableMap.of("a", mock(CR.class)));
412 when(featureManagerMock.isActive(Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI)).thenReturn(crFlag);
413 when(featureManagerMock.isActive(Features.FLAG_1908_RESUME_MACRO_SERVICE)).thenReturn(resumeFlag);
415 assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(mock(ISdcCsarHelper.class), mockServiceModel));
419 public void whenServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
420 assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(null, ModelCategory.OTHER));
424 public void whenServiceInServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
425 assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(mock(ServiceModel.class), ModelCategory.OTHER));
429 public void whenInstantiationTypeInServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
430 initServiceModelAndscarHelperWithMocks();
431 Service service = mock(Service.class);
432 when(serviceModel.getService()).thenReturn(service);
433 when(service.getInstantiationType()).thenReturn(null);
434 assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER));
437 private void initServiceModelAndscarHelperWithRealCsar(String path) throws SdcToscaParserException, IOException {
438 Path csarPath = Paths.get(new File(getClass().getResource(path).getPath()).getCanonicalPath());
439 ToscaParserImpl2 toscaParser = new ToscaParserImpl2(vidNotionsBuilder);
440 org.onap.vid.asdc.beans.Service asdcServiceMetadata = mock(org.onap.vid.asdc.beans.Service.class);
441 when(asdcServiceMetadata.getVersion()).thenReturn("versions");
442 serviceModel = toscaParser.makeServiceModel(csarPath, asdcServiceMetadata);
443 csarHelper = toscaParser.getSdcCsarHelper(csarPath);
446 private void initServiceModelAndscarHelperWithMocks() {
447 csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString());
448 serviceModel = mock(ServiceModel.class);
452 public static Object[][] VnfNcIndicationDataProvider() {
453 return new Object[][] {
454 {true, "VNF", InstantiationUI.A_LA_CARTE_VNF_SERVICE_ROLE},
455 {false, "VNF", InstantiationUI.LEGACY},
456 {false, "notVNF", InstantiationUI.LEGACY},
457 {true, null, InstantiationUI.LEGACY},
458 {true, "notVNF", InstantiationUI.LEGACY},
459 {true, "vnf", InstantiationUI.A_LA_CARTE_VNF_SERVICE_ROLE},
463 @Test (dataProvider = "VnfNcIndicationDataProvider")
464 public void whenServiceRoleVnf_thenInstantiationTypeNewUI(boolean flagOn, String serviceRole, InstantiationUI expectedViewEditUi){
465 initServiceModelAndscarHelperWithMocks();
467 when(featureManagerMock.isActive(Features.FLAG_1908_A_LA_CARTE_VNF_NEW_INSTANTIATION_UI)).thenReturn(flagOn);
469 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(serviceRole == null ?
470 emptyMap() : ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_ROLE, serviceRole)
473 assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel));
476 private static NodeTemplate mockNodeTemplateChild(boolean withFabricConfiguration) {
477 NodeTemplate child = mock(NodeTemplate.class);
478 when(child.getType()).thenReturn(withFabricConfiguration ? ToscaParserImpl2.Constants.FABRIC_CONFIGURATION_TYPE : "nothing");
482 private static ISdcCsarHelper mockServiceNodeTemplates(ISdcCsarHelper csarHelper, ImmutableList<NodeTemplate> children) {
483 when(csarHelper.getNodeTemplateChildren(any())).thenReturn(children);
485 NodeTemplate parent = mock(NodeTemplate.class);
486 List<NodeTemplate> nodeTemplates = ImmutableList.of(parent);
488 when(csarHelper.getServiceNodeTemplates()).thenReturn(nodeTemplates);
493 public static Object[][] csarHelpersForFabricConfiguration() {
494 ISdcCsarHelper csarHelperWithNoNodes = mock(ISdcCsarHelper.class);
495 when(csarHelperWithNoNodes.getServiceNodeTemplates()).thenReturn(emptyList());
497 return new Object[][] {
498 { "zero nodes", false, csarHelperWithNoNodes },
499 { "single node with no child", false, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of()) },
500 { "single node with single fabric child", true, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of(mockNodeTemplateChild(true))) },
501 { "single node with single fabric child and single non-fabric", true, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of(
502 mockNodeTemplateChild(true), mockNodeTemplateChild(true))) },
506 @Test (dataProvider = "csarHelpersForFabricConfiguration")
507 public void hasFabricConfiguration(String desc, boolean shouldHaveFabricConfiguration, ISdcCsarHelper csarHelper) {
508 assertThat(desc, vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(shouldHaveFabricConfiguration));