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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.sdncsimulator.controller;
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;
32 * @author Waqas Ikram (waqas.ikram@est.tech)
35 public class TestUtils {
36 private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U";
39 private TestUtils() {}
41 public static String getRequestInput() throws IOException {
42 return getFileAsString(getFile("test-data/input.json").toPath());
45 public static String getVnfRequestInput() throws IOException {
46 return getFileAsString(getFile("test-data/vnfInput.json").toPath());
49 public static String getInvalidRequestInput() throws IOException {
50 return getFileAsString(getFile("test-data/InvalidInput.json").toPath());
53 public static String getFileAsString(final Path path) throws IOException {
54 return new String(Files.readAllBytes(path));
57 public static File getFile(final String file) throws IOException {
58 return new ClassPathResource(file).getFile();
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;
68 public static String getBasicAuth(final String username) {
69 return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes()));