1 package org.onap.vid.asdc.parser;
3 import com.google.common.collect.ImmutableMap;
4 import org.apache.commons.io.IOUtils;
5 import org.apache.log4j.LogManager;
6 import org.apache.log4j.Logger;
7 import org.jetbrains.annotations.NotNull;
8 import org.json.JSONObject;
9 import org.json.JSONTokener;
10 import org.mockito.InjectMocks;
11 import org.mockito.Mock;
12 import org.mockito.MockitoAnnotations;
13 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
14 import org.onap.vid.asdc.AsdcCatalogException;
15 import org.onap.vid.asdc.AsdcClient;
16 import org.onap.vid.asdc.beans.Service;
17 import org.onap.vid.asdc.local.LocalAsdcClient;
18 import org.onap.vid.asdc.parser.ServiceModelInflator.Names;
19 import org.onap.vid.model.ServiceModel;
20 import org.testng.annotations.BeforeClass;
21 import org.testng.annotations.BeforeMethod;
22 import org.testng.annotations.Test;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.nio.file.Path;
28 import java.util.UUID;
30 import static java.util.Collections.emptyMap;
31 import static org.hamcrest.Matchers.is;
32 import static org.junit.Assert.assertThat;
34 public class ToscaParserInflatorTest {
36 private static final Logger log = LogManager.getLogger(ToscaParserInflatorTest.class);
39 private ToscaParserImpl2 toscaParserImpl2;
42 private VidNotionsBuilder vidNotionsBuilder;
44 private AsdcClient asdcClient;
47 void init() throws IOException {
49 final InputStream asdcServicesFile = this.getClass().getClassLoader().getResourceAsStream("sdcservices.json");
51 final JSONTokener jsonTokener = new JSONTokener(IOUtils.toString(asdcServicesFile));
52 final JSONObject sdcServicesCatalog = new JSONObject(jsonTokener);
54 asdcClient = new LocalAsdcClient.Builder().catalog(sdcServicesCatalog).build();
59 public void initMocks() {
60 MockitoAnnotations.initMocks(this);
65 public void inflateFabricConfigurationModel_allIdsAreGiven() throws Exception {
66 final String fabricConfigurationUuid = "90fe6842-aa76-4b68-8329-5c86ff564407";
67 final Map<String, Names> inflated = inflateModelByUuid(fabricConfigurationUuid);
69 // see vf-with-annotation-csar.json
70 assertThat(inflated, is(ImmutableMap.of(
71 "8df1892c-377d-460b-8a8d-fc8a116e9d92", doubleName("201712-488_ADIOD-vPE-1 0"),
72 "8d521692-7661-4296-b77e-a2058bb62e87", new Names("201712488AdiodVpe1..ADIOD_vRE_BV..module-1", "201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vRE_BV..module-1"),
73 "79fbee20-7fba-4166-ae4b-b94c869e7d8b", new Names("201712488AdiodVpe1..ADIOD_vPFE_BV..module-2","201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vPFE_BV..module-2"),
74 "806505b8-7a7c-47a2-acef-b4d26fe95a92", new Names("201712488AdiodVpe1..ADIOD_base_vPE_BV..module-0","201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_base_vPE_BV..module-0")
80 public void inflateVlModel_allIdsAreGiven() throws Exception {
81 final String fabricConfigurationUuid = "cb49608f-5a24-4789-b0f7-2595473cb997";
82 final Map<String, Names> inflated = inflateModelByUuid(fabricConfigurationUuid);
85 assertThat(inflated, is(ImmutableMap.of(
86 "af584529-d7f0-420e-a6f3-c38b689c030f", doubleName("ExtVL 0")
91 private Names doubleName(String modelCustomizationName) {
92 return new Names(modelCustomizationName, modelCustomizationName);
96 public void inflateConfigurationByPolicyFalseUuid_allIdsAreGiven() throws Exception {
97 final String configurationByPolicyFalseUuid = "ee6d61be-4841-4f98-8f23-5de9da845544";
98 final Map<String, Names> inflated = inflateModelByUuid(configurationByPolicyFalseUuid);
100 // see policy-configuration-by-policy-false.json
101 // no relevant model here
102 assertThat(inflated, is(emptyMap()));
105 private Map<String, Names> inflateModelByUuid(String fabricConfigurationUuid) throws SdcToscaParserException, AsdcCatalogException {
106 ServiceModel actualServiceModel = serviceModelByUuid(fabricConfigurationUuid);
108 ServiceModelInflator serviceModelInflator = new ServiceModelInflator();
109 return serviceModelInflator.toNamesByVersionId(actualServiceModel);
112 private ServiceModel serviceModelByUuid(String uuid) throws SdcToscaParserException, AsdcCatalogException {
113 final Path modelPath = asdcClient.getServiceToscaModel(UUID.fromString(uuid));
114 final Service modelMetadata = asdcClient.getService(UUID.fromString(uuid));
116 return toscaParserImpl2.makeServiceModel(modelPath, modelMetadata);