populating esr data in a&ai simulator
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / sdnc-simulator / src / test / java / org / onap / so / sdncsimulator / controller / TestUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.sdncsimulator.controller;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.util.Base64;
27 import org.springframework.core.io.ClassPathResource;
28 import org.springframework.http.HttpHeaders;
29 import org.springframework.http.MediaType;
30
31 /**
32  * @author Waqas Ikram (waqas.ikram@est.tech)
33  *
34  */
35 public class TestUtils {
36     private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U";
37
38
39     private TestUtils() {}
40
41     public static String getRequestInput() throws IOException {
42         return getFileAsString(getFile("test-data/input.json").toPath());
43     }
44
45     public static String getVnfRequestInput() throws IOException {
46         return getFileAsString(getFile("test-data/vnfInput.json").toPath());
47     }
48
49     public static String getInvalidRequestInput() throws IOException {
50         return getFileAsString(getFile("test-data/InvalidInput.json").toPath());
51     }
52
53     public static String getFileAsString(final Path path) throws IOException {
54         return new String(Files.readAllBytes(path));
55     }
56
57     public static File getFile(final String file) throws IOException {
58         return new ClassPathResource(file).getFile();
59     }
60
61     public static HttpHeaders getHttpHeaders(final String username) {
62         final HttpHeaders requestHeaders = new HttpHeaders();
63         requestHeaders.add("Authorization", getBasicAuth(username));
64         requestHeaders.setContentType(MediaType.APPLICATION_JSON);
65         return requestHeaders;
66     }
67
68     public static String getBasicAuth(final String username) {
69         return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes()));
70     }
71
72 }