2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 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.svnfm.simulator.utils;
22 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter;
23 import org.springframework.core.io.ClassPathResource;
24 import org.springframework.http.HttpHeaders;
25 import javax.ws.rs.core.MediaType;
27 import java.io.IOException;
28 import java.nio.charset.StandardCharsets;
29 import java.nio.file.Files;
30 import org.apache.commons.codec.binary.Base64;
33 * @author Andrew Lamb (andrew.a.lamb@est.tech)
36 public class TestUtils {
38 public static String getBasicAuth(final String username, final String password) {
39 final String auth = username + ":" + password;
40 return "Basic " + new String(Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)));
43 public static HttpHeaders getHttpHeaders(final String authHeader) {
44 final HttpHeaders headers = new HttpHeaders();
45 headers.add(HttpHeaders.AUTHORIZATION, authHeader);
46 headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
47 headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
51 public static File getFile(final String file) throws IOException {
52 return new ClassPathResource(file).getFile();
55 public static String getJsonString(final String file) throws IOException {
56 return new String(Files.readAllBytes(getFile(file).toPath()));
59 public static String getBaseUrl(final int port) {
60 return "http://localhost:" + port;
63 public static String getSubscriptionRequest(final SubscriptionsFilter.NotificationTypesEnum notificationType) throws Exception {
64 switch (notificationType) {
65 case VNFPACKAGECHANGENOTIFICATION:
66 return getJsonString("test-data/pkg-subscription-request-change.json");
67 case VNFPACKAGEONBOARDINGNOTIFICATION:
68 return getJsonString("test-data/pkg-subscription-request-onboarding.json");
74 public static String getNotification(final SubscriptionsFilter.NotificationTypesEnum notificationType) throws Exception {
75 switch (notificationType) {
76 case VNFPACKAGECHANGENOTIFICATION:
77 return getJsonString("test-data/vnf-package-change-notification.json");
78 case VNFPACKAGEONBOARDINGNOTIFICATION:
79 return getJsonString("test-data/vnf-package-onboarding-notification.json");
85 private TestUtils() {}