1 package org.onap.vid.asdc.parser;
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;
35 import java.io.IOException;
36 import java.io.InputStream;
37 import java.nio.file.Path;
39 import java.util.stream.Collectors;
40 import java.util.stream.Stream;
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;
51 public class ToscaParserImpl2Test {
53 private final String myUUID = "myUUID";
54 private static final Logger log = LogManager.getLogger(ToscaParserImpl2Test.class);
57 private ToscaParserImpl2 toscaParserImpl2;
59 private AsdcClient asdcClient;
60 private ObjectMapper om = new ObjectMapper();
63 private VidNotionsBuilder vidNotionsBuilder;
66 void init() throws IOException {
68 final InputStream asdcServicesFile = this.getClass().getClassLoader().getResourceAsStream("sdcservices.json");
70 final JSONTokener jsonTokener = new JSONTokener(IOUtils.toString(asdcServicesFile));
71 final JSONObject sdcServicesCatalog = new JSONObject(jsonTokener);
73 asdcClient = new LocalAsdcClient.Builder().catalog(sdcServicesCatalog).build();
78 public void initMocks() {
79 MockitoAnnotations.initMocks(this);
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));
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));
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());
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));
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));
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));
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());
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);
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());
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));
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));
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);
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();
208 setPprobeServiceProxy(expectedConfigurations);
210 JsonAssert.assertJsonEquals(expectedConfigurations, actualConfigurations);
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);
218 ToscaParserImpl2 toscaParserImpl2_local = new ToscaParserImpl2(new VidNotionsBuilder(featureManager));
220 final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper(Constants.vlUuid, Constants.vlFilePath);
221 final ServiceModel serviceModel = toscaParserImpl2_local.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid()));
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));
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()));
233 assertJsonStringEqualsIgnoreNulls("{ vfModules: { 201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vRE_BV..module-1: { inputs: { availability_zone_0: { } } } } }", om.writeValueAsString(serviceModel));
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()));
241 assertJsonStringEqualsIgnoreNulls("" +
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));
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")));
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);
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);
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());
281 private void compareProperties(Map<String, String> expectedProperties, Map<String, String> actualProperties) {
282 JsonAssert.assertJsonEquals(expectedProperties, actualProperties);
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[][]{});
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)
309 private Path getCsarPath(String uuid) throws AsdcCatalogException {
310 return asdcClient.getServiceToscaModel(UUID.fromString(uuid));
313 private org.onap.vid.asdc.beans.Service getServiceByUuid(String uuid) throws AsdcCatalogException {
314 return asdcClient.getService(UUID.fromString(uuid));
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";
345 public void testGetNFModuleFromVf() {
346 ISdcCsarHelper csarHelper = getMockedSdcCsarHelper(myUUID);
348 Map<String, VfModule> vfModulesFromVF = toscaParserImpl2.getVfModulesFromVF(csarHelper, myUUID);
350 assertThat(vfModulesFromVF, allOf(
352 hasKey("withoutVol"),
358 public void testGetVolumeGroupsFromVF() {
359 ISdcCsarHelper csarHelper = getMockedSdcCsarHelper(myUUID);
361 Map<String, VolumeGroup> volumeGroupsFromVF = toscaParserImpl2.getVolumeGroupsFromVF(csarHelper, myUUID);
363 assertThat(volumeGroupsFromVF, allOf(
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()}
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);
383 // assertEquals(expectedTargets, policiesTargets);
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"},
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);
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);
412 NodeTemplate node = mock(NodeTemplate.class);
413 when(node.getName()).thenReturn("node_name");
414 when(node.getPropertiesObjects()).thenReturn(properties);
416 String result = ToscaNamingPolicy.getEcompNamingValueForNode(node, parentProperty);
417 assertEquals(expectedResult, result);
420 public static ISdcCsarHelper getMockedSdcCsarHelper(String myUUID) {
421 ISdcCsarHelper csarHelper = mock(ISdcCsarHelper.class);
423 Group withVol = createMinimalGroup("withVol", true);
424 Group withoutVol = createMinimalGroup("withoutVol", false);
426 when(csarHelper.getServiceMetadata()).thenReturn(new Metadata(ImmutableMap.of(
427 "instantiationType", "A-La-Carte"
430 when(csarHelper.getVfModulesByVf(myUUID))
431 .thenReturn(ImmutableList.of(withVol, withoutVol));
436 private static Group createMinimalGroup(String name, boolean isVolumeGroup) {
437 LinkedHashMap<String, Object>
446 templates = new LinkedHashMap<>();
447 templates.put("type", "org.onap.groups.VfModule");
449 properties = addNewNamedMap(templates, "properties");
450 properties.put("volume_group", isVolumeGroup);
452 metadata = addNewNamedMap(templates, "metadata");
454 ArrayList<NodeTemplate> memberNodes = new ArrayList<>();
456 customDef = new LinkedHashMap<>();
457 vfModule = addNewNamedMap(customDef, "org.onap.groups.VfModule");
458 vfModuleProperties = addNewNamedMap(vfModule, "properties");
460 volumeGroup = addNewNamedMap(vfModuleProperties, "volume_group");
461 volumeGroup.put("type", "boolean");
462 volumeGroup.put("default", false);
463 volumeGroup.put("required", true);
466 Group group = new Group(
474 log.info(String.format("Built a group: %s",
476 .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
477 .writeValueAsString(group)
479 } catch (JsonProcessingException e) {
480 throw new RuntimeException(e);
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);