Merge from ECOMP's repository
[vid.git] / vid-app-common / src / test / java / org / onap / vid / asdc / parser / ToscaParserImpl2Test.java
1 package org.onap.vid.asdc.parser;
2
3 import com.fasterxml.jackson.core.JsonProcessingException;
4 import com.fasterxml.jackson.databind.ObjectMapper;
5 import com.fasterxml.jackson.databind.SerializationFeature;
6 import com.google.common.collect.ImmutableList;
7 import com.google.common.collect.ImmutableMap;
8 import net.javacrumbs.jsonunit.JsonAssert;
9 import org.apache.commons.io.IOUtils;
10 import org.apache.log4j.LogManager;
11 import org.apache.log4j.Logger;
12 import org.json.JSONObject;
13 import org.json.JSONTokener;
14 import org.mockito.InjectMocks;
15 import org.mockito.Mock;
16 import org.mockito.MockitoAnnotations;
17 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
18 import org.onap.sdc.toscaparser.api.Group;
19 import org.onap.sdc.toscaparser.api.NodeTemplate;
20 import org.onap.sdc.toscaparser.api.Property;
21 import org.onap.sdc.toscaparser.api.elements.Metadata;
22 import org.onap.vid.asdc.AsdcCatalogException;
23 import org.onap.vid.asdc.AsdcClient;
24 import org.onap.vid.asdc.local.LocalAsdcClient;
25 import org.onap.vid.controller.ToscaParserMockHelper;
26 import org.onap.vid.model.*;
27 import org.onap.vid.properties.Features;
28 import org.testng.Assert;
29 import org.testng.annotations.BeforeClass;
30 import org.testng.annotations.BeforeMethod;
31 import org.testng.annotations.DataProvider;
32 import org.testng.annotations.Test;
33 import org.togglz.core.manager.FeatureManager;
34
35 import java.io.IOException;
36 import java.io.InputStream;
37 import java.nio.file.Path;
38 import java.util.*;
39 import java.util.stream.Collectors;
40 import java.util.stream.Stream;
41
42 import static com.google.common.collect.Lists.newArrayList;
43 import static org.hamcrest.Matchers.*;
44 import static org.junit.Assert.assertEquals;
45 import static org.junit.Assert.assertThat;
46 import static org.mockito.Mockito.mock;
47 import static org.mockito.Mockito.when;
48 import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.ECOMP_GENERATED_NAMING_PROPERTY;
49 import static org.onap.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls;
50
51 public class ToscaParserImpl2Test {
52
53     private final String myUUID = "myUUID";
54     private static final Logger log = LogManager.getLogger(ToscaParserImpl2Test.class);
55
56     @InjectMocks
57     private ToscaParserImpl2 toscaParserImpl2;
58
59     private AsdcClient asdcClient;
60     private ObjectMapper om = new ObjectMapper();
61
62     @Mock
63     private VidNotionsBuilder vidNotionsBuilder;
64
65     @BeforeClass
66     void init() throws IOException {
67
68         final InputStream asdcServicesFile = this.getClass().getClassLoader().getResourceAsStream("sdcservices.json");
69
70         final JSONTokener jsonTokener = new JSONTokener(IOUtils.toString(asdcServicesFile));
71         final JSONObject sdcServicesCatalog = new JSONObject(jsonTokener);
72
73         asdcClient = new LocalAsdcClient.Builder().catalog(sdcServicesCatalog).build();
74
75     }
76
77     @BeforeMethod
78     public void initMocks() {
79         MockitoAnnotations.initMocks(this);
80     }
81
82     @Test(dataProvider = "expectedServiceModel")
83     public void assertEqualsBetweenServices(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
84         Service expectedService = mockHelper.getNewServiceModel().getService();
85         Service actualService = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getService();
86         assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedService), om.writeValueAsString(actualService));
87     }
88
89     @Test(dataProvider = "expectedServiceModel")
90     public void assertEqualBetweenObjects(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
91         final Path csarPath = getCsarPath(mockHelper.getUuid());
92         log.info("Comparing for csar " + csarPath);
93         ServiceModel actualServiceModel = toscaParserImpl2.makeServiceModel(csarPath, getServiceByUuid(mockHelper.getUuid()));
94         assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(mockHelper.getNewServiceModel()), om.writeValueAsString(actualServiceModel));
95     }
96
97     @Test(dataProvider = "expectedServiceModel")
98     public void assertEqualsBetweenNetworkNodes(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
99         Map<String, Network> expectedNetworksMap = mockHelper.getNewServiceModel().getNetworks();
100         Map<String, Network> actualNetworksMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getNetworks();
101         for (Map.Entry<String, Network> entry : expectedNetworksMap.entrySet()) {
102             Network expectedNetwork = entry.getValue();
103             Network actualNetwork = actualNetworksMap.get(entry.getKey());
104             Assert.assertEquals(expectedNetwork.getModelCustomizationName(), actualNetwork.getModelCustomizationName());
105             verifyBaseNodeMetadata(expectedNetwork, actualNetwork);
106             compareProperties(expectedNetwork.getProperties(), actualNetwork.getProperties());
107         }
108     }
109
110     //Because we are not supporting the old flow, the JSON are different by definition.
111     @Test(dataProvider = "expectedServiceModel")
112     public void assertEqualsBetweenVnfsOfTosca(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
113         Map<String, VNF> expectedVnfsMap = mockHelper.getNewServiceModel().getVnfs();
114         Map<String, VNF> actualVnfsMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVnfs();
115         for (Map.Entry<String, VNF> entry : expectedVnfsMap.entrySet()) {
116             VNF expectedVnf = entry.getValue();
117             VNF actualVnf = actualVnfsMap.get(entry.getKey());
118             verifyBaseNodeMetadata(expectedVnf, actualVnf);
119             Assert.assertEquals(expectedVnf.getModelCustomizationName(), actualVnf.getModelCustomizationName());
120             compareProperties(expectedVnf.getProperties(), actualVnf.getProperties());
121             assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVnf), om.writeValueAsString(actualVnf));
122         }
123     }
124
125     @Test(dataProvider = "expectedServiceModel")
126     public void assertEqualsBetweenCollectionResourcesOfTosca(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
127             Map<String, CR> expectedVnfsMap = mockHelper.getNewServiceModel().getCollectionResource();
128             Map<String, CR> actualCRsMap = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getCollectionResource();
129             if(!actualCRsMap.isEmpty()) {
130                 for (Map.Entry<String, CR> entry : expectedVnfsMap.entrySet()) {
131                     CR expectedCR = entry.getValue();
132                     CR actualCR = actualCRsMap.get(entry.getKey());
133                     verifyCollectionResource(expectedCR, actualCR);
134                     Assert.assertEquals(expectedCR.getName(), actualCR.getName());
135                     compareProperties(expectedCR.getProperties(), actualCR.getProperties());
136                     assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedCR), om.writeValueAsString(actualCR));
137                 }
138             }
139     }
140
141 //    @Test
142 //    public void verifyFabricConfiguration() throws Exception {
143 //        ToscaParserMockHelper toscaParserMockHelper = Arrays.stream(getExpectedServiceModel()).filter(x -> x.getUuid().equals(Constants.fabricConfigurationUuid)).findFirst().get();
144 //        ServiceModel actualServiceModel = toscaParserImpl2.makeServiceModel(getCsarPath(Constants.fabricConfigurationUuid), getServiceByUuid(Constants.fabricConfigurationUuid));
145 //        final Map<String, Node> fabricConfigurations = actualServiceModel.getFabricConfigurations();
146 //        String fabricConfigName = "Fabric Configuration 0";
147 //        Map<String, Node> expectedFC = toscaParserMockHelper.getNewServiceModel().getFabricConfigurations();
148 //        verifyBaseNodeMetadata(expectedFC.get(fabricConfigName), fabricConfigurations.get(fabricConfigName));
149 //    }
150
151     private void verifyCollectionResource(CR expectedCR, CR actualCR) {
152         verifyBaseNodeMetadata(expectedCR, actualCR);
153         Assert.assertEquals(expectedCR.getCategory(), actualCR.getCategory());
154         Assert.assertEquals(expectedCR.getSubcategory(), actualCR.getSubcategory());
155         Assert.assertEquals(expectedCR.getResourceVendor(), actualCR.getResourceVendor());
156         Assert.assertEquals(expectedCR.getResourceVendorRelease(), actualCR.getResourceVendorRelease());
157         Assert.assertEquals(expectedCR.getResourceVendorModelNumber(), actualCR.getResourceVendorModelNumber());
158         Assert.assertEquals(expectedCR.getCustomizationUUID(), actualCR.getCustomizationUUID());
159         verifyNetworkCollections(expectedCR.getNetworksCollection(), actualCR.getNetworksCollection());
160     }
161
162     private void verifyNetworkCollections(Map<String, NetworkCollection> expectedNetworksCollection, Map<String, NetworkCollection> actualNetworksCollection) {
163         for (Map.Entry<String, NetworkCollection> property : expectedNetworksCollection.entrySet()) {
164             NetworkCollection expectedValue = property.getValue();
165             String key = property.getKey();
166             NetworkCollection actualValue = actualNetworksCollection.get(key);
167             verifyNetworkCollection(expectedValue, actualValue);
168         }
169     }
170
171     private void verifyNetworkCollection(NetworkCollection expectedValue, NetworkCollection actualValue) {
172         Assert.assertEquals(expectedValue.getInvariantUuid(), actualValue.getInvariantUuid());
173         Assert.assertEquals(expectedValue.getName(), actualValue.getName());
174         Assert.assertEquals(expectedValue.getUuid(), actualValue.getUuid());
175         Assert.assertEquals(expectedValue.getVersion(), actualValue.getVersion());
176         Assert.assertEquals(expectedValue.getNetworkCollectionProperties().getNetworkCollectionDescription(), actualValue.getNetworkCollectionProperties().getNetworkCollectionDescription());
177         Assert.assertEquals(expectedValue.getNetworkCollectionProperties().getNetworkCollectionFunction(), actualValue.getNetworkCollectionProperties().getNetworkCollectionFunction());
178     }
179
180
181     @Test(dataProvider = "expectedServiceModel")
182     public void assertEqualsBetweenVolumeGroups(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
183             Map<String, VolumeGroup> actualVolumeGroups = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVolumeGroups();
184             Map<String, VolumeGroup> expectedVolumeGroups = mockHelper.getNewServiceModel().getVolumeGroups();
185             assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVolumeGroups), om.writeValueAsString(actualVolumeGroups));
186     }
187
188     @Test(dataProvider = "expectedServiceModel")
189     public void assertEqualsBetweenVfModules(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
190             Map<String, VfModule> actualVfModules = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVfModules();
191             Map<String, VfModule> expectedVfModules = mockHelper.getNewServiceModel().getVfModules();
192             assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVfModules), om.writeValueAsString(actualVfModules));
193     }
194
195     @Test(dataProvider = "expectedServiceModel")
196     public void assertEqualsBetweenPolicyConfigurationNodes(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
197             Map<String, PortMirroringConfig> actualConfigurations = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getConfigurations();
198             Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getNewServiceModel().getConfigurations();
199             JsonAssert.assertJsonEquals(actualConfigurations, expectedConfigurations);
200     }
201
202     @Test
203     public void assertEqualsBetweenPolicyConfigurationByPolicyFalse() throws Exception {
204         ToscaParserMockHelper mockHelper = new ToscaParserMockHelper(Constants.configurationByPolicyFalseUuid, Constants.configurationByPolicyFalseFilePath);
205         Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getNewServiceModel().getConfigurations();
206         Map<String, PortMirroringConfig> actualConfigurations = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getConfigurations();
207
208         setPprobeServiceProxy(expectedConfigurations);
209
210         JsonAssert.assertJsonEquals(expectedConfigurations, actualConfigurations);
211     }
212
213     @Test
214     public void once5GInNewInstantiationFlagIsActive_vidNotionsIsAppended() throws Exception {
215         FeatureManager featureManager = mock(FeatureManager.class);
216         when(featureManager.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)).thenReturn(true);
217
218         ToscaParserImpl2 toscaParserImpl2_local = new ToscaParserImpl2(new VidNotionsBuilder(featureManager));
219
220         final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper(Constants.vlUuid, Constants.vlFilePath);
221         final ServiceModel serviceModel = toscaParserImpl2_local.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid()));
222
223         assertThat(serviceModel.getService().getVidNotions().getInstantiationUI(), is(VidNotions.InstantiationUI.LEGACY));
224         assertThat(serviceModel.getService().getVidNotions().getModelCategory(), is(VidNotions.ModelCategory.OTHER));
225         assertJsonStringEqualsIgnoreNulls("{ service: { vidNotions: { instantiationUI: \"legacy\", modelCategory: \"other\" } } }", om.writeValueAsString(serviceModel));
226     }
227
228     @Test
229     public void modelWithAnnotatedInputWithTwoProperties_vfModuleGetsTheInput() throws Exception {
230         final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper("90fe6842-aa76-4b68-8329-5c86ff564407", "empty.json");
231         final ServiceModel serviceModel = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid()));
232
233         assertJsonStringEqualsIgnoreNulls("{ vfModules: { 201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vRE_BV..module-1: { inputs: { availability_zone_0: { } } } } }", om.writeValueAsString(serviceModel));
234     }
235
236     @Test
237     public void modelWithNfNamingWithToValues_ecompGeneratedNamingIsExtracted() throws Exception {
238         final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper("90fe6842-aa76-4b68-8329-5c86ff564407", "empty.json");
239         final ServiceModel serviceModel = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid()));
240
241         assertJsonStringEqualsIgnoreNulls("" +
242                 "{ vnfs: " +
243                 "  { \"201712-488_ADIOD-vPE-1 0\": " +
244                 "    { properties: { " +
245                 "      ecomp_generated_naming: \"true\", " +
246                 "      nf_naming: \"{naming_policy=SDNC_Policy.Config_MS_1806SRIOV_VPE_ADIoDJson, ecomp_generated_naming=true}\" " +
247                 "} } } }", om.writeValueAsString(serviceModel));
248     }
249
250     private void setPprobeServiceProxy(Map<String, PortMirroringConfig> expectedConfigurations){
251         //Port Mirroring Configuration By Policy 0 doesn't contains pProbe.
252         // But due to sdc design if pProbe not exists parser expects to get it from other source.
253         // In a follow implementation provided the expected pProbe.
254         PortMirroringConfig pmconfig = expectedConfigurations.get("Port Mirroring Configuration By Policy 0");
255         pmconfig.setCollectorNodes(new ArrayList<>(Arrays.asList("pprobeservice_proxy 4")));
256
257     }
258     @Test(dataProvider = "expectedServiceModel")
259     public void assertEqualsBetweenServiceProxyNodes(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
260             Map<String, ServiceProxy> actualServiceProxies = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getServiceProxies();
261             Map<String, ServiceProxy> expectedServiceProxies = mockHelper.getNewServiceModel().getServiceProxies();
262             JsonAssert.assertJsonEquals(actualServiceProxies, expectedServiceProxies);
263     }
264
265     @Test(dataProvider = "expectedServiceModel")
266     public void assertEqualsBetweenVnfGroups(String uuid, ToscaParserMockHelper mockHelper) throws Exception {
267         Map<String, ResourceGroup> actualVnfGroups = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVnfGroups();
268         Map<String, ResourceGroup> expectedVnfGroups = mockHelper.getNewServiceModel().getVnfGroups();
269         JsonAssert.assertJsonEquals(actualVnfGroups, expectedVnfGroups);
270     }
271
272     private void verifyBaseNodeMetadata(Node expectedNode, Node actualNode) {
273         Assert.assertEquals(expectedNode.getName(), actualNode.getName());
274         Assert.assertEquals(expectedNode.getCustomizationUuid(), actualNode.getCustomizationUuid());
275         Assert.assertEquals(expectedNode.getDescription(), actualNode.getDescription());
276         Assert.assertEquals(expectedNode.getInvariantUuid(), actualNode.getInvariantUuid());
277         Assert.assertEquals(expectedNode.getUuid(), actualNode.getUuid());
278         Assert.assertEquals(expectedNode.getVersion(), actualNode.getVersion());
279     }
280
281     private void compareProperties(Map<String, String> expectedProperties, Map<String, String> actualProperties) {
282         JsonAssert.assertJsonEquals(expectedProperties, actualProperties);
283     }
284
285     @DataProvider
286     public Object[][] expectedServiceModel() throws IOException {
287         return Stream.of(getExpectedServiceModel())
288                         .map(l -> ImmutableList.of(l.getUuid(), l).toArray()).collect(Collectors.toList()).toArray(new Object[][]{});
289     }
290
291
292     private ToscaParserMockHelper[] getExpectedServiceModel() throws IOException {
293         ToscaParserMockHelper[] mockHelpers = {
294                 new ToscaParserMockHelper(Constants.vlUuid, Constants.vlFilePath),
295                 new ToscaParserMockHelper(Constants.vfUuid, Constants.vfFilePath),
296                 new ToscaParserMockHelper(Constants.crUuid, Constants.crFilePath),
297                 new ToscaParserMockHelper(Constants.vfWithAnnotationUuid, Constants.vfWithAnnotationFilePath),
298                 new ToscaParserMockHelper(Constants.vfWithVfcGroup, Constants.vfWithVfcGroupFilePath),
299                 new ToscaParserMockHelper(Constants.configurationUuid, Constants.configurationFilePath),
300 //                new ToscaParserMockHelper(Constants.fabricConfigurationUuid, Constants.fabricConfigurationFilePath),
301 //                new ToscaParserMockHelper(Constants.vlanTaggingUuid, Constants.vlanTaggingFilePath),
302 //                new ToscaParserMockHelper(Constants.vnfGroupingUuid, Constants.vnfGroupingFilePath)
303         };
304
305         return mockHelpers;
306     }
307
308
309     private Path getCsarPath(String uuid) throws AsdcCatalogException {
310         return asdcClient.getServiceToscaModel(UUID.fromString(uuid));
311     }
312
313     private org.onap.vid.asdc.beans.Service getServiceByUuid(String uuid) throws AsdcCatalogException {
314         return asdcClient.getService(UUID.fromString(uuid));
315     }
316
317     public class Constants {
318         public static final String configurationUuid = "ee6d61be-4841-4f98-8f23-5de9da846ca7";
319         public static final String configurationFilePath = "policy-configuration-csar.JSON";
320         static final String vfUuid = "48a52540-8772-4368-9cdb-1f124ea5c931";    //service-vf-csar.zip
321         static final String vfWithAnnotationUuid = "f4d84bb4-a416-4b4e-997e-0059973630b9";
322         static final String vlUuid = "cb49608f-5a24-4789-b0f7-2595473cb997";
323         static final String crUuid = "76f27dfe-33e5-472f-8e0b-acf524adc4f0";
324         static final String vfWithVfcGroup = "6bce7302-70bd-4057-b48e-8d5b99e686ca"; //service-VdbeSrv-csar.zip
325         //        public static final String PNFUuid = "68101369-6f08-4e99-9a28-fa6327d344f3";
326         static final String vfFilePath = "vf-csar.JSON";
327         static final String vlFilePath = "vl-csar.JSON";
328         static final String crFilePath = "cr-csar.JSON";
329         static final String vfWithAnnotationFilePath = "vf-with-annotation-csar.json";
330         static final String vfWithVfcGroupFilePath = "vf-with-vfcInstanceGroups.json";
331         public static final String configurationByPolicyFalseUuid = "ee6d61be-4841-4f98-8f23-5de9da845544";
332         public static final String configurationByPolicyFalseFilePath = "policy-configuration-by-policy-false.JSON";
333         //public static final String fabricConfigurationUuid = "12344bb4-a416-4b4e-997e-0059973630b9";
334         //public static final String fabricConfigurationFilePath = "fabric-configuration.json";
335         //public static final String vlanTaggingUuid = "1837481c-fa7d-4362-8ce1-d05fafc87bd1";
336         //public static final String vlanTaggingFilePath = "vlan-tagging.json";
337         //public static final String vnfGroupingUuid = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc";
338         //public static final String vnfGroupingFilePath = "vnf-grouping-csar.json";
339
340     }
341
342
343
344     @Test
345     public void testGetNFModuleFromVf() {
346         ISdcCsarHelper csarHelper = getMockedSdcCsarHelper(myUUID);
347
348         Map<String, VfModule> vfModulesFromVF = toscaParserImpl2.getVfModulesFromVF(csarHelper, myUUID);
349
350         assertThat(vfModulesFromVF, allOf(
351                 aMapWithSize(2),
352                 hasKey("withoutVol"),
353                 hasKey("withVol")
354         ));
355     }
356
357     @Test
358     public void testGetVolumeGroupsFromVF() {
359         ISdcCsarHelper csarHelper = getMockedSdcCsarHelper(myUUID);
360
361         Map<String, VolumeGroup> volumeGroupsFromVF = toscaParserImpl2.getVolumeGroupsFromVF(csarHelper, myUUID);
362
363         assertThat(volumeGroupsFromVF, allOf(
364                 aMapWithSize(1),
365                 hasKey("withVol")
366         ));
367     }
368
369 //    @DataProvider
370 //    public Object[][] expectedPoliciesTargets() {
371 //        return new Object[][] {
372 //                {Constants.vnfGroupingUuid, newArrayList("groupingservicefortest..ResourceInstanceGroup..0", "groupingservicefortest..ResourceInstanceGroup..1")},
373 //                {Constants.vfUuid, newArrayList()},
374 //                {Constants.vlanTaggingUuid, newArrayList()}
375 //        };
376 //    }
377 //
378 //    @Test(dataProvider = "expectedPoliciesTargets")
379 //    public void testExtractNamingPoliciesTargets(String uuid, ArrayList<String> expectedTargets) throws AsdcCatalogException, SdcToscaParserException {
380 //        ISdcCsarHelper sdcCsarHelper = toscaParserImpl2.getSdcCsarHelper(getCsarPath(uuid));
381 //        List<String> policiesTargets = toscaParserImpl2.extractNamingPoliciesTargets(sdcCsarHelper);
382 //
383 //        assertEquals(expectedTargets, policiesTargets);
384 //    }
385
386     @DataProvider
387     public Object[][] expectedEcompGeneratedNaming() {
388         return new Object[][] {
389                 {"nf_naming property false", "nf_naming", "false", "false"},
390                 {"nf_naming property true", "nf_naming", "true", "true"},
391                 {"nf_naming property doesn't exist", "nf_naming", null, "false"},
392                 {"exVL_naming property false", "exVL_naming", "false", "false"},
393                 {"exVL_naming property true", "exVL_naming", "true", "true"},
394                 {"exVL_naming property doesn't exist", "exVL_naming", null, "false"},
395         };
396     }
397
398     @Test(dataProvider = "expectedEcompGeneratedNaming")
399     public void testEcompGeneratedNamingForNode(String description, String parentProperty, String ecompNamingProperty, String expectedResult) {
400         Property property = mock(Property.class);
401         when(property.getName()).thenReturn("any_key");
402         when(property.getValue()).thenReturn("any_value");
403         ArrayList<Property> properties = newArrayList(property);
404
405         if (ecompNamingProperty != null) {
406             Property nfNamingProperty = mock(Property.class);
407             when(nfNamingProperty.getName()).thenReturn(parentProperty);
408             when(nfNamingProperty.getValue()).thenReturn(ImmutableMap.of(ECOMP_GENERATED_NAMING_PROPERTY, ecompNamingProperty));
409             properties.add(nfNamingProperty);
410         }
411
412         NodeTemplate node = mock(NodeTemplate.class);
413         when(node.getName()).thenReturn("node_name");
414         when(node.getPropertiesObjects()).thenReturn(properties);
415
416         String result = ToscaNamingPolicy.getEcompNamingValueForNode(node, parentProperty);
417         assertEquals(expectedResult, result);
418     }
419
420     public static ISdcCsarHelper getMockedSdcCsarHelper(String myUUID) {
421         ISdcCsarHelper csarHelper = mock(ISdcCsarHelper.class);
422
423         Group withVol = createMinimalGroup("withVol", true);
424         Group withoutVol = createMinimalGroup("withoutVol", false);
425
426         when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
427                 "instantiationType", "A-La-Carte"
428         )));
429
430         when(csarHelper.getVfModulesByVf(myUUID))
431                 .thenReturn(ImmutableList.of(withVol, withoutVol));
432
433         return csarHelper;
434     }
435
436     private static Group createMinimalGroup(String name, boolean isVolumeGroup) {
437         LinkedHashMap<String, Object>
438                 templates,
439                 properties,
440                 metadata,
441                 customDef,
442                 vfModule,
443                 vfModuleProperties,
444                 volumeGroup;
445
446         templates = new LinkedHashMap<>();
447         templates.put("type", "org.onap.groups.VfModule");
448
449         properties = addNewNamedMap(templates, "properties");
450         properties.put("volume_group", isVolumeGroup);
451
452         metadata = addNewNamedMap(templates, "metadata");
453
454         ArrayList<NodeTemplate> memberNodes = new ArrayList<>();
455
456         customDef = new LinkedHashMap<>();
457         vfModule = addNewNamedMap(customDef, "org.onap.groups.VfModule");
458         vfModuleProperties = addNewNamedMap(vfModule, "properties");
459
460         volumeGroup = addNewNamedMap(vfModuleProperties, "volume_group");
461         volumeGroup.put("type", "boolean");
462         volumeGroup.put("default", false);
463         volumeGroup.put("required", true);
464
465
466         Group group = new Group(
467                 name,
468                 templates,
469                 memberNodes,
470                 customDef
471         );
472
473         try {
474             log.info(String.format("Built a group: %s",
475                     (new ObjectMapper())
476                             .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
477                             .writeValueAsString(group)
478             ));
479         } catch (JsonProcessingException e) {
480             throw new RuntimeException(e);
481         }
482
483         return group;
484     }
485
486     private static LinkedHashMap<String, Object> addNewNamedMap(LinkedHashMap<String, Object> root, String key) {
487         LinkedHashMap<String, Object> properties = new LinkedHashMap<>();
488         root.put(key, properties);
489         return properties;
490     }
491
492 }