Merge from ECOMP's repository
[vid.git] / vid-app-common / src / test / java / org / onap / vid / controller / ToscaParserMockHelper.java
1 package org.onap.vid.controller;
2
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.fasterxml.jackson.module.kotlin.KotlinModule;
5 import org.apache.commons.io.IOUtils;
6 import org.apache.log4j.LogManager;
7 import org.apache.log4j.Logger;
8 import org.onap.vid.model.NewServiceModel;
9
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.nio.charset.StandardCharsets;
13
14 /**
15  * Created by moriya1 on 04/07/2017.
16  */
17 public class ToscaParserMockHelper {
18     private static final Logger logger = LogManager.getLogger(ToscaParserMockHelper.class);
19
20     private static final ObjectMapper om = new ObjectMapper();
21     private final String uuid;
22     private final String filePath;
23     private final NewServiceModel newServiceModel;
24
25     public ToscaParserMockHelper(String uuid, String filePath) throws IOException {
26         this.uuid = uuid;
27         this.filePath = filePath;
28
29         InputStream jsonFile = this.getClass().getClassLoader().getResourceAsStream(getFilePath());
30         logger.info(jsonFile);
31         String expectedJsonAsString = IOUtils.toString(jsonFile, StandardCharsets.UTF_8.name());
32         om.registerModule(new KotlinModule());
33         this.newServiceModel = om.readValue(expectedJsonAsString, NewServiceModel.class);
34     }
35
36     public String getUuid() {
37         return uuid;
38     }
39
40     public String getFilePath() {
41         return filePath;
42     }
43
44     public NewServiceModel getNewServiceModel() {
45         return newServiceModel;
46     }
47 }