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