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.equalTo;
27 import static org.hamcrest.Matchers.hasProperty;
28 import static org.hamcrest.Matchers.is;
29 import static org.mockito.ArgumentMatchers.any;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
32 import static org.onap.vid.model.VidNotions.InstantiationType;
33 import static org.onap.vid.model.VidNotions.InstantiationUI;
34 import static org.onap.vid.model.VidNotions.ModelCategory;
35 import static org.testng.AssertJUnit.assertEquals;
37 import com.google.common.collect.ImmutableList;
38 import com.google.common.collect.ImmutableMap;
40 import java.io.IOException;
41 import java.nio.file.Path;
42 import java.nio.file.Paths;
43 import java.util.Collections;
44 import java.util.LinkedHashMap;
45 import java.util.List;
47 import java.util.UUID;
48 import java.util.function.BiConsumer;
49 import org.apache.commons.lang3.tuple.Pair;
50 import org.jetbrains.annotations.NotNull;
51 import org.mockito.InjectMocks;
52 import org.mockito.Mock;
53 import org.mockito.Mockito;
54 import org.mockito.MockitoAnnotations;
55 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
56 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
57 import org.onap.sdc.toscaparser.api.NodeTemplate;
58 import org.onap.sdc.toscaparser.api.Property;
59 import org.onap.sdc.toscaparser.api.elements.Metadata;
60 import org.onap.vid.asdc.parser.ToscaParserImpl2.Constants;
61 import org.onap.vid.model.CR;
62 import org.onap.vid.model.Network;
63 import org.onap.vid.model.Node;
64 import org.onap.vid.model.Service;
65 import org.onap.vid.model.ServiceModel;
66 import org.onap.vid.model.VidNotions;
67 import org.onap.vid.properties.Features;
68 import org.onap.vid.testUtils.TestUtils;
69 import org.testng.annotations.AfterMethod;
70 import org.testng.annotations.BeforeClass;
71 import org.testng.annotations.DataProvider;
72 import org.testng.annotations.Test;
73 import org.togglz.core.manager.FeatureManager;
75 public class VidNotionsBuilderTest {
78 VidNotionsBuilder vidNotionsBuilder;
81 private FeatureManager featureManagerMock;
83 private ServiceModel serviceModel;
85 private ISdcCsarHelper csarHelper;
88 public void initMocks() {
89 MockitoAnnotations.initMocks(this);
94 Mockito.reset(featureManagerMock);
98 public void VLNetworkWithPropertyNetworkTechnologyOVS_UIHintIsPositive() {
99 ISdcCsarHelper csarHelper = mockForNonLegacyInstantiationUI();
101 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS));
102 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL));
106 private ISdcCsarHelper mockForNonLegacyInstantiationUI() {
107 ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString());
109 NodeTemplate nodeTemplate = mock(NodeTemplate.class);
111 when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
112 "dummy_val", mock(Property.class),
113 "network_technology", new Property(Pair.of("network_technology","ovs"))
116 when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
117 when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
122 public static Object[][] anyAlacarteDataProvider() {
123 return new Object[][] {
124 {"A-La-Carte", InstantiationUI.ANY_ALACARTE_NEW_UI},
125 {"Macro", InstantiationUI.LEGACY},
129 @Test(dataProvider = "anyAlacarteDataProvider")
130 public void FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI_is_active_UIHintIsPositive(String instantiationType, InstantiationUI expectedInstantiationUI) {
131 initServiceModelAndscarHelperWithMocks();
133 when(featureManagerMock.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI)).thenReturn(true);
134 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
135 "instantiationType", instantiationType
137 NodeTemplate nodeTemplate = mock(NodeTemplate.class);
139 when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
140 "dummy_val", mock(Property.class),
141 "network_technology", new Property(Pair.of("network_technology","ovs"))
144 when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
146 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(expectedInstantiationUI));
150 public void VLNetworkWithPropertyNetworkTechnologyNot5G_UIHintIsNegative() {
151 initServiceModelAndscarHelperWithMocks();
153 NodeTemplate nodeTemplate = mock(NodeTemplate.class);
155 when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
156 "dummy_val", mock(Property.class),
157 "network_technology", new Property(Pair.of("network_technology","old_value"))
160 when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
162 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(InstantiationUI.LEGACY));
163 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.OTHER));
167 public void withoutMocks_givenZippedToscaFile_hasAnyNetworkWithPropertyEqualsToAnyOfYieldsTrue() throws SdcToscaParserException, IOException {
168 initServiceModelAndscarHelperWithRealCsar("/csars/service-vl-csar.zip");
169 assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
170 assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "unexpected_property_name"), is(false));
171 assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "network_technology","Standard-SR-IOV"), is(true));
172 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(InstantiationUI.LEGACY));
176 public void withoutMocks_givenZippedToscaFile_hasFabricConfigurationYieldsTrue() throws SdcToscaParserException, IOException {
177 initServiceModelAndscarHelperWithRealCsar("/csars/service-fabric-configuration.zip");
178 assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
179 assertThat(vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(true));
180 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(InstantiationUI.LEGACY));
183 @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
184 public void withoutMocks_givenZippedToscaFileOfTransportService_InstantiationUIAndCategoryAreRight(boolean flagValue) throws SdcToscaParserException, IOException {
185 initServiceModelAndscarHelperWithRealCsar("/csars/csarTransportWithPnfs.zip");
187 when(featureManagerMock.isActive(Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI)).thenReturn(flagValue);
189 assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
190 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(flagValue ? InstantiationUI.TRANSPORT_SERVICE : InstantiationUI.LEGACY));
191 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.Transport));
194 @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
195 public void withoutMocks_givenZippedToscaFileOfInfraStructureVpn_InstantiationUIIsRight(boolean flagValue) throws SdcToscaParserException, IOException {
196 initServiceModelAndscarHelperWithRealCsar("/csars/service-Infravpn-csar.zip");
197 when(featureManagerMock.isActive(Features.FLAG_1908_INFRASTRUCTURE_VPN)).thenReturn(flagValue);
198 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(flagValue ? InstantiationUI.INFRASTRUCTURE_VPN : InstantiationUI.LEGACY));
199 assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.INFRASTRUCTURE_VPN));
203 public void withoutMocks_givenToscaOfPortMirroring_InstantiationUIIsLegacyAndCategoryIsPortMirroring() throws SdcToscaParserException, IOException {
204 initServiceModelAndscarHelperWithRealCsar("/csars/portMirroringService.zip");
205 when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(true);
206 assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel),
207 equalTo(new VidNotions(InstantiationUI.LEGACY, ModelCategory.PORT_MIRRORING, InstantiationUI.LEGACY, InstantiationType.ClientConfig)));
212 public void withoutMocks_givenToscaOfVLanTagging_InstantiationUIIsLegacyAndCategoryIsVlanTagging() throws SdcToscaParserException, IOException {
213 initServiceModelAndscarHelperWithRealCsar("/csars/service-VdorotheaSrv-csar.zip");
214 when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(true);
215 assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel),
216 equalTo(new VidNotions(InstantiationUI.LEGACY, ModelCategory.VLAN_TAGGING, InstantiationUI.LEGACY, InstantiationType.ALaCarte)));
220 public void withoutMocks_givenToscaWithoutTypeAndFlagOn_InstantiationUIisAlacarte()
221 throws SdcToscaParserException, IOException {
222 initServiceModelAndscarHelperWithRealCsar("/csars/service-Vocg1804Svc.zip");
223 when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(true);
224 assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel),
225 equalTo(new VidNotions(
226 InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED,
228 InstantiationUI.LEGACY,
229 InstantiationType.ClientConfig)));
233 public static Object[][] anyAlaCarteDataProvider() {
234 return new Object[][] {
235 {true, Constants.A_LA_CARTE, InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED},
236 {false, Constants.A_LA_CARTE, InstantiationUI.LEGACY},
237 {true, Constants.MACRO, InstantiationUI.LEGACY},
238 {true, Constants.CLIENT_CONFIG, InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED},
239 {true, null, InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED},
240 {true, "", InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED}
244 @Test(dataProvider = "anyAlaCarteDataProvider")
245 public void testAnyAlaCarteNewUI_byInstantiationTypeAndFeatureFlag(boolean flag, String instantiationType, InstantiationUI expected) {
246 initServiceModelAndscarHelperWithMocks();
247 mockInstantiationType(serviceModel, instantiationType);
248 when(featureManagerMock.isActive(Features.FLAG_2002_ANY_ALACARTE_BESIDES_EXCLUDED_NEW_INSTANTIATION_UI)).thenReturn(flag);
249 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(expected));
253 public void uuidIsExactly1ffce89fEtc_UIHintIsPositive() {
254 initServiceModelAndscarHelperWithMocks();
256 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
257 "UUID", "95eb2c44-bff2-4e8b-ad5d-8266870b7717"
259 when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
260 assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel, ModelCategory.OTHER), is(InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de));
263 @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
264 public void buildVidNotions_nullByFlag(boolean flagValue) {
265 initServiceModelAndscarHelperWithMocks();
267 when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(flagValue);
268 assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel), hasProperty("instantiationUI", is(InstantiationUI.LEGACY)));
271 private void mockInstantiationType(ServiceModel serviceModel, String instantiationType) {
272 Service mockService = mock(Service.class);
273 when(serviceModel.getService()).thenReturn(mockService);
274 when(mockService.getInstantiationType()).thenReturn(instantiationType);
278 public static Object[][] ServiceRoleTypesDataProvider() {
279 return new Object[][] {
280 {"gROUPING", InstantiationUI.SERVICE_WITH_VNF_GROUPING},
281 {"", InstantiationUI.LEGACY},
285 @Test(dataProvider = "ServiceRoleTypesDataProvider")
286 public void testGetViewEditUITypeForResourceGroup(String serviceRole, InstantiationUI expectedViewEditUI) {
287 initServiceModelAndscarHelperWithMocks();
288 when(featureManagerMock.isActive(Features.FLAG_1902_VNF_GROUPING)).thenReturn(true);
289 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
290 "serviceRole", serviceRole
293 assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel, ModelCategory.OTHER), is(expectedViewEditUI));
297 public static Object[][] instantiationUIToViewEditDataProvider() {
298 return new Object[][] {
299 {"network cloud(5G) service + needed flags are open", true, true, InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS},
300 {"mocked service + needed flags are open", false, true, InstantiationUI.LEGACY},
301 {"network cloud(5G) service + FLAG_1902_NEW_VIEW_EDIT is off", true, false, InstantiationUI.LEGACY},
306 @Test(dataProvider="instantiationUIToViewEditDataProvider")
307 public void whenInstantiationUIIsNotLegacy_viewEditIsRight(
308 String testDescription,
309 boolean isInstantiationUINotLegacy,
310 boolean isFlag1902NewViewEdit,
311 InstantiationUI expectedViewEditUi) {
313 ISdcCsarHelper csarHelper = isInstantiationUINotLegacy ? mockForNonLegacyInstantiationUI() : mock(ISdcCsarHelper.class);
314 when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(isFlag1902NewViewEdit);
316 ServiceModel serviceModel = mock(ServiceModel.class);
317 mockInstantiationType(serviceModel, Constants.A_LA_CARTE);
319 InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel, ModelCategory.OTHER);
320 assertEquals(expectedViewEditUi, result);
324 public static Object[][] mockerForMacroExcluded() {
325 return new Object[][] {
326 {"service with pnfs", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->when(serviceModel.getPnfs()).thenReturn(ImmutableMap.of("a", mock(Node.class))), true},
327 {"service with collection resource", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm) -> when(serviceModel.getCollectionResources()).thenReturn(ImmutableMap.of("a", mock(CR.class))), true},
328 {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION false ", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{
329 when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class)));
330 when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(false);}
332 {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION true", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{
333 when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class)));
334 when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(true);}
336 {"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},
340 @Test(dataProvider="mockerForMacroExcluded")
341 public void testIsMacroExcludedFromAsyncFlow(String testDescription, BiConsumer<ServiceModel, FeatureManager> mocker, boolean shallBeExcluded) {
342 ServiceModel serviceModel = mock(ServiceModel.class);
343 mocker.accept(serviceModel, featureManagerMock);
344 assertEquals(shallBeExcluded, vidNotionsBuilder.isMacroExcludedFromAsyncFlow(serviceModel));
348 public static Object[][] toscaParserInstantiationTypeToVidNotion() {
349 return new Object[][] {
350 {ToscaParserImpl2.Constants.MACRO, InstantiationType.Macro},
351 {ToscaParserImpl2.Constants.A_LA_CARTE, InstantiationType.ALaCarte},
352 {ToscaParserImpl2.Constants.CLIENT_CONFIG, InstantiationType.ClientConfig},
353 {"I dont know", InstantiationType.ClientConfig},
354 {"", InstantiationType.ClientConfig}
358 @Test(dataProvider="toscaParserInstantiationTypeToVidNotion")
359 public void testSuggestInstantiationTypeWhenInstantiationUiLegacy(String toscaParserInstantiationType, InstantiationType expectedInstantiationType) {
360 ServiceModel serviceModel = mock(ServiceModel.class);
361 mockInstantiationType(serviceModel, toscaParserInstantiationType);
362 assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER));
366 public static Object[][] instantiationUIAndFeatureFlagsForInstantiationType() {
367 return new Object[][] {
368 {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, true, InstantiationType.Macro},
369 {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, false, InstantiationType.ALaCarte},
370 {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.Macro},
371 {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, false, InstantiationType.ALaCarte},
372 {ModelCategory.OTHER, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.ALaCarte}, //not mapped InstantiationUI
376 @Test(dataProvider="instantiationUIAndFeatureFlagsForInstantiationType")
377 public void testSuggestInstantiationTypeByModelCategoryAndFeatureFlags(
378 ModelCategory instantiationUI,
379 Features featureFlag,
381 InstantiationType expectedInstantiationType) {
382 ServiceModel serviceModel = mock(ServiceModel.class);
383 mockInstantiationType(serviceModel, Constants.A_LA_CARTE);
384 when(featureManagerMock.isActive(featureFlag)).thenReturn(isFeatureOn);
385 assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, instantiationUI));
389 public static Object[][] FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions() {
390 return new Object[][] {
391 {true, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.SERVICE_WITH_COLLECTION_RESOURCE, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE},
392 {true, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER},
393 {true, null, InstantiationUI.LEGACY, ModelCategory.OTHER},
394 {false, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.LEGACY, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE},
395 {false, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER},
396 {false, null, InstantiationUI.LEGACY, ModelCategory.OTHER}
400 @Test(dataProvider="FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions")
401 public void testSuggestInstantiationUiAndModelCategoryByCollectionResourceAndFeatureFlag_FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI(
402 boolean featureFlagValue,
403 Map<String, CR> collectionResource,
404 VidNotions.InstantiationUI expectedInstantiationUi,
405 VidNotions.ModelCategory expectedModelCategory) {
406 initServiceModelAndscarHelperWithMocks();
408 Service service = mock(Service.class);
409 when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.MACRO);
410 when(serviceModel.getService()).thenReturn(service);
411 when(serviceModel.getCollectionResources()).thenReturn(collectionResource);
412 when(featureManagerMock.isActive(Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI)).thenReturn(featureFlagValue);
413 VidNotions vidNotions = vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel);
414 assertEquals(expectedInstantiationUi, vidNotions.getInstantiationUI());
415 assertEquals(expectedModelCategory, vidNotions.getModelCategory());
416 assertEquals(InstantiationUI.LEGACY, vidNotions.getViewEditUI());
417 assertEquals(InstantiationType.Macro, vidNotions.getInstantiationType());
421 public void whenServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
422 assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(null, ModelCategory.OTHER));
426 public void whenServiceInServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
427 assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(mock(ServiceModel.class), ModelCategory.OTHER));
431 public void whenInstantiationTypeInServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
432 initServiceModelAndscarHelperWithMocks();
433 mockInstantiationType(serviceModel, 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, ModelCategory.OTHER));
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));
512 public static Object[][] macroTransportDataProvider() {
513 return new Object[][]{
514 {"transport service flag is open", true, true, true, InstantiationUI.LEGACY},
515 {"macro service flag is open", true, false, true, InstantiationUI.MACRO_SERVICE},
516 {"macro service flag is closed", false, true, true, InstantiationUI.LEGACY},
517 {"transport service flag is closed", false, false, true, InstantiationUI.LEGACY},
518 {"not a macro service", true, false, false, InstantiationUI.LEGACY}
522 @Test (dataProvider = "macroTransportDataProvider")
523 public void viewEditMacroService_transportOrNotTransport(String desc, boolean flagActive, boolean isTransport, boolean isMacro, InstantiationUI expectedViewEditUi) {
524 initServiceModelAndscarHelperWithMocks();
525 Service service = mock(Service.class);
527 String instantiationType = isMacro ? ToscaParserImpl2.Constants.MACRO : ToscaParserImpl2.Constants.A_LA_CARTE;
528 when(serviceModel.getService()).thenReturn(service);
529 when(service.getInstantiationType()).thenReturn(instantiationType);
530 when(featureManagerMock.isActive(Features.FLAG_1908_MACRO_NOT_TRANSPORT_NEW_VIEW_EDIT)).thenReturn(flagActive);
531 when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(false);
532 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(isTransport ? ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_TYPE, "TRANSPORT") : emptyMap()
535 assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel, ModelCategory.OTHER));