Merge "edit of macro services in new view edit screen"
[vid.git] / vid-app-common / src / test / java / org / onap / vid / asdc / parser / VidNotionsBuilderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.vid.asdc.parser;
22
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;
35
36 import com.google.common.collect.ImmutableList;
37 import com.google.common.collect.ImmutableMap;
38 import java.io.File;
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;
45 import java.util.Map;
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.model.CR;
60 import org.onap.vid.model.Network;
61 import org.onap.vid.model.Node;
62 import org.onap.vid.model.Service;
63 import org.onap.vid.model.ServiceModel;
64 import org.onap.vid.model.VidNotions;
65 import org.onap.vid.properties.Features;
66 import org.onap.vid.testUtils.TestUtils;
67 import org.testng.annotations.AfterMethod;
68 import org.testng.annotations.BeforeClass;
69 import org.testng.annotations.DataProvider;
70 import org.testng.annotations.Test;
71 import org.togglz.core.manager.FeatureManager;
72
73 public class VidNotionsBuilderTest {
74
75     @InjectMocks
76     VidNotionsBuilder vidNotionsBuilder;
77
78     @Mock
79     private FeatureManager featureManagerMock;
80
81     private ServiceModel serviceModel;
82
83     private ISdcCsarHelper csarHelper;
84
85     @BeforeClass
86     public void initMocks() {
87         MockitoAnnotations.initMocks(this);
88     }
89
90     @AfterMethod
91     public void reset() {
92         Mockito.reset(featureManagerMock);
93     }
94
95     @Test
96     public void VLNetworkWithPropertyNetworkTechnologyOVS_UIHintIsPositive() {
97         ISdcCsarHelper csarHelper = mockForNonLegacyInstantiationUI();
98
99         assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS));
100         assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL));
101     }
102
103     @NotNull
104     private ISdcCsarHelper mockForNonLegacyInstantiationUI() {
105         ISdcCsarHelper csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString());
106
107         NodeTemplate nodeTemplate = mock(NodeTemplate.class);
108
109         when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
110                 "dummy_val", mock(Property.class),
111                 "network_technology", new Property(Pair.of("network_technology","ovs"))
112         )));
113
114         when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
115         when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
116         return csarHelper;
117     }
118
119     @DataProvider
120     public static Object[][] anyAlacarteDataProvider() {
121         return new Object[][] {
122                 {"A-La-Carte", InstantiationUI.ANY_ALACARTE_NEW_UI},
123                 {"Macro", InstantiationUI.LEGACY},
124         };
125     }
126
127     @Test(dataProvider = "anyAlacarteDataProvider")
128     public void FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI_is_active_UIHintIsPositive(String instantiationType, InstantiationUI expectedInstantiationUI) {
129         initServiceModelAndscarHelperWithMocks();
130
131         when(featureManagerMock.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI)).thenReturn(true);
132         when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
133                 "instantiationType", instantiationType
134         )));
135         NodeTemplate nodeTemplate = mock(NodeTemplate.class);
136
137         when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
138                 "dummy_val", mock(Property.class),
139                 "network_technology", new Property(Pair.of("network_technology","ovs"))
140         )));
141
142         when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
143
144         assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(expectedInstantiationUI));
145     }
146
147     @Test
148     public void VLNetworkWithPropertyNetworkTechnologyNot5G_UIHintIsNegative() {
149         initServiceModelAndscarHelperWithMocks();
150
151         NodeTemplate nodeTemplate = mock(NodeTemplate.class);
152
153         when(nodeTemplate.getProperties()).thenReturn(new LinkedHashMap<>(ImmutableMap.of(
154                 "dummy_val", mock(Property.class),
155                 "network_technology", new Property(Pair.of("network_technology","old_value"))
156         )));
157
158         when(csarHelper.getServiceVlList()).thenReturn(ImmutableList.of(nodeTemplate));
159
160         assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
161         assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel) , is(ModelCategory.OTHER));
162     }
163
164     @Test
165     public void withoutMocks_givenZippedToscaFile_hasAnyNetworkWithPropertyEqualsToAnyOfYieldsTrue() throws SdcToscaParserException, IOException {
166         initServiceModelAndscarHelperWithRealCsar("/csars/service-vl-csar.zip");
167         assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
168         assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "unexpected_property_name"), is(false));
169         assertThat(vidNotionsBuilder.hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "network_technology","Standard-SR-IOV"), is(true));
170         assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
171     }
172
173     @Test
174     public void withoutMocks_givenZippedToscaFile_hasFabricConfigurationYieldsTrue() throws SdcToscaParserException, IOException {
175         initServiceModelAndscarHelperWithRealCsar("/csars/service-fabric-configuration.zip");
176         assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
177         assertThat(vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(true));
178         assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.LEGACY));
179     }
180
181     @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
182     public void withoutMocks_givenZippedToscaFileOfTransportService_InstantiationUIAndCategoryAreRight(boolean flagValue) throws SdcToscaParserException, IOException {
183         initServiceModelAndscarHelperWithRealCsar("/csars/csarTransportWithPnfs.zip");
184
185         when(featureManagerMock.isActive(Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI)).thenReturn(flagValue);
186
187         assertThat(vidNotionsBuilder.isALaCarte(csarHelper), is(false));
188         assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.TRANSPORT_SERVICE : InstantiationUI.LEGACY));
189         assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.Transport));
190     }
191
192     @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
193     public void withoutMocks_givenZippedToscaFileOfInfraStructureVpn_InstantiationUIIsRight(boolean flagValue) throws SdcToscaParserException, IOException {
194         initServiceModelAndscarHelperWithRealCsar("/csars/service-Infravpn-csar.zip");
195         when(featureManagerMock.isActive(Features.FLAG_1908_INFRASTRUCTURE_VPN)).thenReturn(flagValue);
196         assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(flagValue ? InstantiationUI.INFRASTRUCTURE_VPN : InstantiationUI.LEGACY));
197         assertThat(vidNotionsBuilder.suggestModelCategory(csarHelper, serviceModel), is(ModelCategory.INFRASTRUCTURE_VPN));
198     }
199
200     @Test
201     public void uuidIsExactly1ffce89fEtc_UIHintIsPositive() {
202         initServiceModelAndscarHelperWithMocks();
203
204         when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
205                 "UUID", "95eb2c44-bff2-4e8b-ad5d-8266870b7717"
206         )));
207         when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
208         assertThat(vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel), is(InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de));
209     }
210
211     @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
212     public void buildVidNotions_nullByFlag(boolean flagValue) {
213         initServiceModelAndscarHelperWithMocks();
214
215         when(featureManagerMock.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(flagValue);
216         assertThat(vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel), hasProperty("instantiationUI", is(InstantiationUI.LEGACY)));
217     }
218
219     @DataProvider
220     public static Object[][] ServiceRoleTypesDataProvider() {
221         return new Object[][] {
222                 {"gROUPING", InstantiationUI.SERVICE_WITH_VNF_GROUPING},
223                 {"", InstantiationUI.LEGACY},
224         };
225     }
226
227     @Test(dataProvider = "ServiceRoleTypesDataProvider")
228     public void testGetViewEditUITypeForResourceGroup(String serviceRole, InstantiationUI expectedViewEditUI) {
229         initServiceModelAndscarHelperWithMocks();
230         when(featureManagerMock.isActive(Features.FLAG_1902_VNF_GROUPING)).thenReturn(true);
231         when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
232                 "serviceRole", serviceRole
233         )));
234
235         assertThat(vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel), is(expectedViewEditUI));
236     }
237
238     @DataProvider
239     public static Object[][] instantiationUIToViewEditDataProvider() {
240         return new Object[][] {
241                 {"network cloud(5G) service + needed flags are open", true, true, InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS},
242                 {"mocked service + needed flags are open", false, true, InstantiationUI.LEGACY},
243                 {"network cloud(5G) service + FLAG_1902_NEW_VIEW_EDIT is off", true, false, InstantiationUI.LEGACY},
244         };
245     }
246
247
248     @Test(dataProvider="instantiationUIToViewEditDataProvider")
249     public void whenInstantiationUIIsNotLegacy_viewEditIsRight(
250             String testDescription,
251             boolean isInstantiationUINotLegacy,
252             boolean isFlag1902NewViewEdit,
253             InstantiationUI expectedViewEditUi) {
254
255         ISdcCsarHelper csarHelper = isInstantiationUINotLegacy ?  mockForNonLegacyInstantiationUI() : mock(ISdcCsarHelper.class);
256         when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(isFlag1902NewViewEdit);
257
258         ServiceModel serviceModel = mock(ServiceModel.class);
259         Service service = mock(Service.class);
260         when(serviceModel.getService()).thenReturn(service);
261         when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.A_LA_CARTE);
262
263         InstantiationUI result = vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel);
264         assertEquals(expectedViewEditUi, result);
265     }
266
267     @DataProvider
268     public static Object[][] mockerForMacroExcluded() {
269         return new Object[][] {
270                 {"service with pnfs", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->when(serviceModel.getPnfs()).thenReturn(ImmutableMap.of("a", mock(Node.class))), true},
271                 {"service with collection resource", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm) -> when(serviceModel.getCollectionResources()).thenReturn(ImmutableMap.of("a", mock(CR.class))), true},
272                 {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION false ", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{
273                     when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class)));
274                     when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(false);}
275                         , true},
276                 {"service with network + FLAG_NETWORK_TO_ASYNC_INSTANTIATION true", (BiConsumer<ServiceModel, FeatureManager>) (serviceModel, fm)->{
277                     when(serviceModel.getNetworks()).thenReturn(ImmutableMap.of("a", mock(Network.class)));
278                     when(fm.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)).thenReturn(true);}
279                         , false},
280                 {"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},
281         };
282     }
283
284     @Test(dataProvider="mockerForMacroExcluded")
285     public void testIsMacroExcludedFromAsyncFlow(String testDescription, BiConsumer<ServiceModel, FeatureManager> mocker, boolean shallBeExcluded) {
286         ServiceModel serviceModel = mock(ServiceModel.class);
287         mocker.accept(serviceModel, featureManagerMock);
288         assertEquals(shallBeExcluded, vidNotionsBuilder.isMacroExcludedFromAsyncFlow(serviceModel));
289     }
290
291     @DataProvider
292     public static Object[][] toscaParserInstantiationTypeToVidNotion() {
293         return new Object[][] {
294                 {ToscaParserImpl2.Constants.MACRO, InstantiationType.Macro},
295                 {ToscaParserImpl2.Constants.A_LA_CARTE, InstantiationType.ALaCarte},
296                 {ToscaParserImpl2.Constants.CLIENT_CONFIG, InstantiationType.ClientConfig},
297                 {"I dont know", InstantiationType.ClientConfig},
298                 {"", InstantiationType.ClientConfig}
299         };
300     }
301
302     @Test(dataProvider="toscaParserInstantiationTypeToVidNotion")
303     public void testSuggestInstantiationTypeWhenInstantiationUiLegacy(String toscaParserInstantiationType, InstantiationType expectedInstantiationType) {
304         ServiceModel serviceModel = mock(ServiceModel.class);
305         Service service = mock(Service.class);
306         when(serviceModel.getService()).thenReturn(service);
307         when(service.getInstantiationType()).thenReturn(toscaParserInstantiationType);
308         assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER));
309     }
310
311     @DataProvider
312     public static Object[][] instantiationUIAndFeatureFlagsForInstantiationType() {
313         return new Object[][] {
314                 {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, true, InstantiationType.Macro},
315                 {ModelCategory.Transport, Features.FLAG_1908_TRANSPORT_SERVICE_NEW_INSTANTIATION_UI, false, InstantiationType.ALaCarte},
316                 {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.Macro},
317                 {ModelCategory.INFRASTRUCTURE_VPN, Features.FLAG_1908_INFRASTRUCTURE_VPN, false, InstantiationType.ALaCarte},
318                 {ModelCategory.OTHER, Features.FLAG_1908_INFRASTRUCTURE_VPN, true, InstantiationType.ALaCarte}, //not mapped InstantiationUI
319         };
320     }
321
322     @Test(dataProvider="instantiationUIAndFeatureFlagsForInstantiationType")
323     public void testSuggestInstantiationTypeByModelCategoryAndFeatureFlags(
324             ModelCategory instantiationUI,
325             Features featureFlag,
326             boolean isFeatureOn,
327             InstantiationType expectedInstantiationType) {
328         ServiceModel serviceModel = mock(ServiceModel.class);
329         Service service = mock(Service.class);
330         when(serviceModel.getService()).thenReturn(service);
331         when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.A_LA_CARTE);
332         when(featureManagerMock.isActive(featureFlag)).thenReturn(isFeatureOn);
333         assertEquals(expectedInstantiationType, vidNotionsBuilder.suggestInstantiationType(serviceModel, instantiationUI));
334     }
335
336     @DataProvider
337     public static Object[][] FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions() {
338         return new Object[][] {
339                 {true, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.SERVICE_WITH_COLLECTION_RESOURCE, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE},
340                 {true, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER},
341                 {true, null, InstantiationUI.LEGACY, ModelCategory.OTHER},
342                 {false, ImmutableMap.of("Some string", mock(CR.class)), InstantiationUI.LEGACY, ModelCategory.SERVICE_WITH_COLLECTION_RESOURCE},
343                 {false, Collections.EMPTY_MAP, InstantiationUI.LEGACY, ModelCategory.OTHER},
344                 {false, null, InstantiationUI.LEGACY, ModelCategory.OTHER}
345         };
346     }
347
348     @Test(dataProvider="FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UIValueAndCollectionResourceForVidNotions")
349     public void testSuggestInstantiationUiAndModelCategoryByCollectionResourceAndFeatureFlag_FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI(
350             boolean featureFlagValue,
351             Map<String, CR> collectionResource,
352             VidNotions.InstantiationUI expectedInstantiationUi,
353             VidNotions.ModelCategory expectedModelCategory) {
354         initServiceModelAndscarHelperWithMocks();
355
356         Service service = mock(Service.class);
357         when(service.getInstantiationType()).thenReturn(ToscaParserImpl2.Constants.MACRO);
358         when(serviceModel.getService()).thenReturn(service);
359         when(serviceModel.getCollectionResources()).thenReturn(collectionResource);
360         when(featureManagerMock.isActive(Features.FLAG_1908_COLLECTION_RESOURCE_NEW_INSTANTIATION_UI)).thenReturn(featureFlagValue);
361         VidNotions vidNotions = vidNotionsBuilder.buildVidNotions(csarHelper, serviceModel);
362         assertEquals(expectedInstantiationUi, vidNotions.getInstantiationUI());
363         assertEquals(expectedModelCategory, vidNotions.getModelCategory());
364         assertEquals(InstantiationUI.LEGACY, vidNotions.getViewEditUI());
365         assertEquals(InstantiationType.Macro, vidNotions.getInstantiationType());
366     }
367
368     @Test
369     public void whenServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
370         assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(null, ModelCategory.OTHER));
371     }
372
373     @Test
374     public void whenServiceInServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
375         assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(mock(ServiceModel.class), ModelCategory.OTHER));
376     }
377
378     @Test
379     public void whenInstantiationTypeInServiceModelIsNull_thenInstantiationTypeIsClientConfig() {
380         initServiceModelAndscarHelperWithMocks();
381         Service service = mock(Service.class);
382         when(serviceModel.getService()).thenReturn(service);
383         when(service.getInstantiationType()).thenReturn(null);
384         assertEquals( InstantiationType.ClientConfig, vidNotionsBuilder.suggestInstantiationType(serviceModel, ModelCategory.OTHER));
385     }
386
387     private void initServiceModelAndscarHelperWithRealCsar(String path) throws SdcToscaParserException, IOException {
388         Path csarPath = Paths.get(new File(getClass().getResource(path).getPath()).getCanonicalPath());
389         ToscaParserImpl2 toscaParser = new ToscaParserImpl2(vidNotionsBuilder);
390         org.onap.vid.asdc.beans.Service asdcServiceMetadata = mock(org.onap.vid.asdc.beans.Service.class);
391         when(asdcServiceMetadata.getVersion()).thenReturn("versions");
392         serviceModel = toscaParser.makeServiceModel(csarPath, asdcServiceMetadata);
393         csarHelper = toscaParser.getSdcCsarHelper(csarPath);
394     }
395
396     private void initServiceModelAndscarHelperWithMocks() {
397         csarHelper = ToscaParserImpl2Test.getMockedSdcCsarHelper(UUID.randomUUID().toString());
398         serviceModel = mock(ServiceModel.class);
399     }
400
401     @DataProvider
402     public static Object[][] VnfNcIndicationDataProvider() {
403         return new Object[][] {
404                 {true, "VNF",  InstantiationUI.A_LA_CARTE_VNF_SERVICE_ROLE},
405                 {false, "VNF", InstantiationUI.LEGACY},
406                 {false, "notVNF", InstantiationUI.LEGACY},
407                 {true, null, InstantiationUI.LEGACY},
408                 {true, "notVNF", InstantiationUI.LEGACY},
409                 {true, "vnf", InstantiationUI.A_LA_CARTE_VNF_SERVICE_ROLE},
410         };
411     }
412
413     @Test (dataProvider = "VnfNcIndicationDataProvider")
414     public void whenServiceRoleVnf_thenInstantiationTypeNewUI(boolean flagOn, String serviceRole, InstantiationUI expectedViewEditUi){
415         initServiceModelAndscarHelperWithMocks();
416
417         when(featureManagerMock.isActive(Features.FLAG_1908_A_LA_CARTE_VNF_NEW_INSTANTIATION_UI)).thenReturn(flagOn);
418
419         when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(serviceRole == null ?
420                 emptyMap() : ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_ROLE, serviceRole)
421         ));
422
423         assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestInstantiationUI(csarHelper, serviceModel));
424     }
425
426     private static NodeTemplate mockNodeTemplateChild(boolean withFabricConfiguration) {
427         NodeTemplate child = mock(NodeTemplate.class);
428         when(child.getType()).thenReturn(withFabricConfiguration ? ToscaParserImpl2.Constants.FABRIC_CONFIGURATION_TYPE : "nothing");
429         return child;
430     }
431
432     private static ISdcCsarHelper mockServiceNodeTemplates(ISdcCsarHelper csarHelper, ImmutableList<NodeTemplate> children) {
433         when(csarHelper.getNodeTemplateChildren(any())).thenReturn(children);
434
435         NodeTemplate parent = mock(NodeTemplate.class);
436         List<NodeTemplate> nodeTemplates = ImmutableList.of(parent);
437
438         when(csarHelper.getServiceNodeTemplates()).thenReturn(nodeTemplates);
439         return csarHelper;
440     }
441
442     @DataProvider
443     public static Object[][] csarHelpersForFabricConfiguration() {
444         ISdcCsarHelper csarHelperWithNoNodes = mock(ISdcCsarHelper.class);
445         when(csarHelperWithNoNodes.getServiceNodeTemplates()).thenReturn(emptyList());
446
447         return new Object[][] {
448                 { "zero nodes", false, csarHelperWithNoNodes },
449                 { "single node with no child", false, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of()) },
450                 { "single node with single fabric child", true, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of(mockNodeTemplateChild(true))) },
451                 { "single node with single fabric child and single non-fabric", true, mockServiceNodeTemplates(mock(ISdcCsarHelper.class), ImmutableList.of(
452                         mockNodeTemplateChild(true), mockNodeTemplateChild(true))) },
453         };
454     }
455
456     @Test (dataProvider = "csarHelpersForFabricConfiguration")
457     public void hasFabricConfiguration(String desc, boolean shouldHaveFabricConfiguration, ISdcCsarHelper csarHelper) {
458         assertThat(desc, vidNotionsBuilder.hasFabricConfiguration(csarHelper), is(shouldHaveFabricConfiguration));
459     }
460
461     @DataProvider
462     public static Object[][] macroTransportDataProvider() {
463         return new Object[][]{
464             {"transport service flag is open", true, true, true, InstantiationUI.LEGACY},
465             {"macro service flag is open", true, false, true, InstantiationUI.MACRO_SERVICE},
466             {"macro service flag is closed", false, true, true, InstantiationUI.LEGACY},
467             {"transport service flag is closed", false, false, true, InstantiationUI.LEGACY},
468             {"not a macro service", true, false, false, InstantiationUI.LEGACY}
469         };
470     }
471
472     @Test (dataProvider = "macroTransportDataProvider")
473     public void viewEditMacroService_transportOrNotTransport(String desc, boolean flagActive, boolean isTransport, boolean isMacro, InstantiationUI expectedViewEditUi) {
474         initServiceModelAndscarHelperWithMocks();
475         Service service = mock(Service.class);
476
477         String instantiationType = isMacro ? ToscaParserImpl2.Constants.MACRO : ToscaParserImpl2.Constants.A_LA_CARTE;
478         when(serviceModel.getService()).thenReturn(service);
479         when(service.getInstantiationType()).thenReturn(instantiationType);
480         when(featureManagerMock.isActive(Features.FLAG_1908_MACRO_NOT_TRANSPORT_NEW_VIEW_EDIT)).thenReturn(flagActive);
481         when(featureManagerMock.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)).thenReturn(false);
482         when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(isTransport ? ImmutableMap.of(ToscaParserImpl2.Constants.SERVICE_TYPE, "TRANSPORT") : emptyMap()
483         ));
484
485         assertEquals(expectedViewEditUi, vidNotionsBuilder.suggestViewEditUI(csarHelper, serviceModel));
486     }
487 }