2eedee9d7fbccb74ed562949ec7f15e348f80a94
[vid.git] / vid-app-common / src / test / java / org / onap / vid / controller / ToscaParserMockHelper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.vid.controller;
22
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import com.fasterxml.jackson.module.kotlin.KotlinModule;
25 import org.apache.commons.io.IOUtils;
26 import org.apache.log4j.LogManager;
27 import org.apache.log4j.Logger;
28 import org.onap.vid.model.NewServiceModel;
29
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.nio.charset.StandardCharsets;
33
34 /**
35  * Created by moriya1 on 04/07/2017.
36  */
37 public class ToscaParserMockHelper {
38     private static final Logger logger = LogManager.getLogger(ToscaParserMockHelper.class);
39
40     private static final ObjectMapper om = new ObjectMapper();
41     private final String uuid;
42     private final String filePath;
43     private final NewServiceModel newServiceModel;
44
45     public ToscaParserMockHelper(String uuid, String filePath) throws IOException {
46         this.uuid = uuid;
47         this.filePath = filePath;
48
49         InputStream jsonFile = this.getClass().getClassLoader().getResourceAsStream(getFilePath());
50         logger.info(jsonFile);
51         String expectedJsonAsString = IOUtils.toString(jsonFile, StandardCharsets.UTF_8.name());
52         om.registerModule(new KotlinModule());
53         this.newServiceModel = om.readValue(expectedJsonAsString, NewServiceModel.class);
54     }
55
56     public String getUuid() {
57         return uuid;
58     }
59
60     public String getFilePath() {
61         return filePath;
62     }
63
64     public NewServiceModel getNewServiceModel() {
65         return newServiceModel;
66     }
67 }