2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.asdc.parser;
23 import com.google.common.collect.ImmutableMap;
24 import org.apache.commons.io.IOUtils;
25 import org.apache.log4j.LogManager;
26 import org.apache.log4j.Logger;
27 import org.jetbrains.annotations.NotNull;
28 import org.json.JSONObject;
29 import org.json.JSONTokener;
30 import org.mockito.InjectMocks;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
34 import org.onap.vid.asdc.AsdcCatalogException;
35 import org.onap.vid.asdc.AsdcClient;
36 import org.onap.vid.asdc.beans.Service;
37 import org.onap.vid.asdc.local.LocalAsdcClient;
38 import org.onap.vid.asdc.parser.ServiceModelInflator.Names;
39 import org.onap.vid.model.ServiceModel;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.BeforeMethod;
42 import org.testng.annotations.Test;
44 import java.io.IOException;
45 import java.io.InputStream;
46 import java.nio.file.Path;
48 import java.util.UUID;
50 import static java.util.Collections.emptyMap;
51 import static org.hamcrest.Matchers.is;
52 import static org.junit.Assert.assertThat;
54 public class ToscaParserInflatorTest {
56 private static final Logger log = LogManager.getLogger(ToscaParserInflatorTest.class);
59 private ToscaParserImpl2 toscaParserImpl2;
62 private VidNotionsBuilder vidNotionsBuilder;
64 private AsdcClient asdcClient;
67 void init() throws IOException {
69 final InputStream asdcServicesFile = this.getClass().getClassLoader().getResourceAsStream("sdcservices.json");
71 final JSONTokener jsonTokener = new JSONTokener(IOUtils.toString(asdcServicesFile));
72 final JSONObject sdcServicesCatalog = new JSONObject(jsonTokener);
74 asdcClient = new LocalAsdcClient.Builder().catalog(sdcServicesCatalog).build();
79 public void initMocks() {
80 MockitoAnnotations.initMocks(this);
85 public void inflateFabricConfigurationModel_allIdsAreGiven() throws Exception {
86 final String fabricConfigurationUuid = "90fe6842-aa76-4b68-8329-5c86ff564407";
87 final Map<String, Names> inflated = inflateModelByUuid(fabricConfigurationUuid);
89 // see vf-with-annotation-csar.json
90 assertThat(inflated, is(ImmutableMap.of(
91 "8df1892c-377d-460b-8a8d-fc8a116e9d92", doubleName("201712-488_ADIOD-vPE-1 0"),
92 "8d521692-7661-4296-b77e-a2058bb62e87", new Names("201712488AdiodVpe1..ADIOD_vRE_BV..module-1", "201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vRE_BV..module-1"),
93 "79fbee20-7fba-4166-ae4b-b94c869e7d8b", new Names("201712488AdiodVpe1..ADIOD_vPFE_BV..module-2","201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vPFE_BV..module-2"),
94 "806505b8-7a7c-47a2-acef-b4d26fe95a92", new Names("201712488AdiodVpe1..ADIOD_base_vPE_BV..module-0","201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_base_vPE_BV..module-0")
100 public void inflateVlModel_allIdsAreGiven() throws Exception {
101 final String fabricConfigurationUuid = "cb49608f-5a24-4789-b0f7-2595473cb997";
102 final Map<String, Names> inflated = inflateModelByUuid(fabricConfigurationUuid);
105 assertThat(inflated, is(ImmutableMap.of(
106 "af584529-d7f0-420e-a6f3-c38b689c030f", doubleName("ExtVL 0")
111 private Names doubleName(String modelCustomizationName) {
112 return new Names(modelCustomizationName, modelCustomizationName);
116 public void inflateConfigurationByPolicyFalseUuid_allIdsAreGiven() throws Exception {
117 final String configurationByPolicyFalseUuid = "ee6d61be-4841-4f98-8f23-5de9da845544";
118 final Map<String, Names> inflated = inflateModelByUuid(configurationByPolicyFalseUuid);
120 // see policy-configuration-by-policy-false.json
121 // no relevant model here
122 assertThat(inflated, is(emptyMap()));
125 private Map<String, Names> inflateModelByUuid(String fabricConfigurationUuid) throws SdcToscaParserException, AsdcCatalogException {
126 ServiceModel actualServiceModel = serviceModelByUuid(fabricConfigurationUuid);
128 ServiceModelInflator serviceModelInflator = new ServiceModelInflator();
129 return serviceModelInflator.toNamesByVersionId(actualServiceModel);
132 private ServiceModel serviceModelByUuid(String uuid) throws SdcToscaParserException, AsdcCatalogException {
133 final Path modelPath = asdcClient.getServiceToscaModel(UUID.fromString(uuid));
134 final Service modelMetadata = asdcClient.getService(UUID.fromString(uuid));
136 return toscaParserImpl2.makeServiceModel(modelPath, modelMetadata);