2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.nbi.apis.servicecatalog;
18 import static org.junit.Assert.assertNull;
20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.LinkedHashMap;
26 import java.util.List;
27 import org.junit.Test;
28 import org.onap.nbi.exceptions.TechnicalException;
32 public class ToscaInfosProcessorTest {
34 final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson databind
36 ToscaInfosProcessor toscaInfosProcessor = new ToscaInfosProcessor();
40 private LinkedHashMap parseToscaFile(String fileName) {
42 File toscaFile = new File(fileName);
43 if (!toscaFile.exists()) {
44 throw new TechnicalException("unable to find file : " + fileName);
47 return (LinkedHashMap) mapper.readValue(toscaFile, Object.class);
48 } catch (IOException e) {
49 throw new TechnicalException("Unable to parse tosca file : " + fileName);
51 } catch (NullPointerException e) {
52 throw new TechnicalException("unable to find tosca file : " + fileName);
58 public void buildResponseWithToscaInfos() {
60 ClassLoader classLoader = getClass().getClassLoader();
61 File file = new File(classLoader.getResource("toscafile/service-TestNetwork-template.yml").getFile());
62 List<LinkedHashMap> resources= new ArrayList<>();
63 LinkedHashMap resource1= new LinkedHashMap();
64 resource1.put("id","e2b12ac6-cbb6-4517-9c58-b846d1f68caf");
65 resources.add(resource1);
66 LinkedHashMap toscaFile = parseToscaFile(file.getPath());
67 LinkedHashMap response = new LinkedHashMap();
68 response.put("resourceSpecification",resources);
69 toscaInfosProcessor.buildResponseWithToscaInfos((LinkedHashMap)toscaFile.get("topology_template"),response);
71 resources = (List<LinkedHashMap>)response.get("resourceSpecification");
72 assertNull(resources.get(0).get("modelCustomizationId"));
73 assertNull(resources.get(0).get("modelCustomizationName"));