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