14add9cbae2e13d2f1bb8487c9ad15e8587248dd
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / AbstractMockConfiguration.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 AT&T Intellectual Property
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 package org.oransc.ric.portal.dashboard.config;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.InputStreamReader;
25 import java.lang.invoke.MethodHandles;
26
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 public class AbstractMockConfiguration {
31         private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
32
33         protected static String readDataFromPath(String path) throws IOException {
34                 InputStream is = MethodHandles.lookup().lookupClass().getClassLoader().getResourceAsStream(path);
35                 if (is == null) {
36                         String msg = "readDataFromPath: Failed to find resource on classpath: " + path;
37                         logger.error(msg);
38                         throw new RuntimeException(msg);
39                 }
40                 InputStreamReader reader = new InputStreamReader(is, "UTF-8");
41                 StringBuilder sb = new StringBuilder();
42                 char[] buf = new char[8192];
43                 int i;
44                 while ((i = reader.read(buf)) > 0)
45                         sb.append(buf, 0, i);
46                 reader.close();
47                 is.close();
48                 return sb.toString();
49         }
50
51 }