252b392668fb6d6e422f14cacae43efc817c5506
[externalapi/nbi.git] / src / test / java / org / onap / nbi / apis / servicecatalog / ToscaInfosProcessorTest.java
1 /**
2  *     Copyright (c) 2018 Orange
3  *
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
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.nbi.apis.servicecatalog;
17
18 import static org.junit.Assert.assertNull;
19
20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
22 import java.io.File;
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;
29
30
31
32 public class ToscaInfosProcessorTest {
33
34     final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson databind
35
36     ToscaInfosProcessor toscaInfosProcessor = new ToscaInfosProcessor();
37
38
39
40     private LinkedHashMap parseToscaFile(String fileName) {
41
42         File toscaFile = new File(fileName);
43         if (!toscaFile.exists()) {
44             throw new TechnicalException("unable to find  file : " + fileName);
45         }
46         try {
47             return (LinkedHashMap) mapper.readValue(toscaFile, Object.class);
48         } catch (IOException e) {
49             throw new TechnicalException("Unable to parse tosca file : " + fileName);
50
51         } catch (NullPointerException e) {
52             throw new TechnicalException("unable to find tosca file : " + fileName);
53         }
54     }
55
56
57     @Test
58     public void buildResponseWithToscaInfos() {
59
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);
70
71         resources = (List<LinkedHashMap>)response.get("resourceSpecification");
72         assertNull(resources.get(0).get("modelCustomizationId"));
73         assertNull(resources.get(0).get("modelCustomizationName"));
74
75     }
76
77
78
79 }