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