Update vnfm simulator - subscribe and notify
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / vnfm-simulator / vnfm-service / src / test / java / org / onap / so / svnfm / simulator / utils / TestUtils.java
1 /*-
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
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.svnfm.simulator.utils;
21
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;
26 import java.io.File;
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;
31
32 /**
33  * @author Andrew Lamb (andrew.a.lamb@est.tech)
34  *
35  */
36 public class TestUtils {
37
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)));
41     }
42
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);
48         return headers;
49     }
50
51     public static File getFile(final String file) throws IOException {
52         return new ClassPathResource(file).getFile();
53     }
54
55     public static String getJsonString(final String file) throws IOException {
56         return new String(Files.readAllBytes(getFile(file).toPath()));
57     }
58
59     public static String getBaseUrl(final int port) {
60         return "http://localhost:" + port;
61     }
62
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");
69             default:
70                 return null;
71         }
72     }
73
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");
80             default:
81                 return null;
82         }
83     }
84
85     private TestUtils() {}
86
87 }