Implant vid-app-common org.onap.vid.job (main and test)
[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 java.io.IOException;
26 import java.io.InputStream;
27 import java.nio.charset.StandardCharsets;
28 import org.apache.commons.io.IOUtils;
29 import org.apache.log4j.LogManager;
30 import org.apache.log4j.Logger;
31 import org.onap.vid.model.ServiceModel;
32
33 public class ToscaParserMockHelper {
34     private static final Logger logger = LogManager.getLogger(ToscaParserMockHelper.class);
35
36     private static final ObjectMapper om = new ObjectMapper();
37     private final String uuid;
38     private final String filePath;
39     private final ServiceModel serviceModel;
40
41     public ToscaParserMockHelper(String uuid, String filePath) throws IOException {
42         this.uuid = uuid;
43         this.filePath = filePath;
44
45         InputStream jsonFile = this.getClass().getClassLoader().getResourceAsStream(getFilePath());
46         logger.info(jsonFile);
47         String expectedJsonAsString = IOUtils.toString(jsonFile, StandardCharsets.UTF_8.name());
48         om.registerModule(new KotlinModule());
49         this.serviceModel = om.readValue(expectedJsonAsString, ServiceModel.class);
50     }
51
52     public String getUuid() {
53         return uuid;
54     }
55
56     public String getFilePath() {
57         return filePath;
58     }
59
60     public ServiceModel getServiceModel() {
61         return serviceModel;
62     }
63 }