Added oparent to sdc main
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / impl / orchestration / csar / validation / ValidatorUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 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.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
22
23 import org.apache.commons.io.IOUtils;
24
25 import java.io.IOException;
26 import java.io.InputStream;
27
28 /**
29  * Provides util methods for Validation Test classes.
30  */
31
32 class ValidatorUtil {
33
34     private ValidatorUtil() {
35
36     }
37
38     /**
39      * Reads a file and coverts it to a byte array.
40      *
41      * @param filePath      The file path
42      * @return
43      *  The file byte array
44      * @throws IOException
45      *  When the file was not found or the input stream could not be opened
46      */
47     public static byte[] getFileResource(final String filePath) throws IOException {
48         try(final InputStream inputStream = ClassLoader.class.getResourceAsStream(filePath)) {
49             if (inputStream == null) {
50                 throw new IOException(String.format("Could not find the resource on path \"%s\"", filePath));
51             }
52             return IOUtils.toByteArray(inputStream);
53         } catch (final IOException ex) {
54             throw new IOException(String.format("Could not open the input stream for resource on path \"%s\"", filePath), ex);
55         }
56     }
57 }