Add simplified local setup
[aai/test-config.git] / local-setup / src / main / java / onap / aai / util / AaiRequest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2018-2019 Nokia 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 package onap.aai.util;
21
22 import com.github.kevinsawicki.http.HttpRequest;
23
24 public class AaiRequest {
25
26     private static final String AAI_BASE_URL = "https://localhost:8443/aai";
27     private static final String AAI_AUTH = "Basic QUFJOkFBSQ==";
28     private static final String SCHEMA_VERSION = "/v14";
29
30     public static HttpRequest get(String endpoint) {
31         return aaiRequest(HttpRequest.get(aaiEndpoint(endpoint)));
32     }
33
34     public static HttpRequest post(String endpoint) {
35         return aaiRequest(HttpRequest.post(aaiEndpoint(endpoint)));
36     }
37
38     public static HttpRequest put(String endpoint) {
39         return aaiRequest(HttpRequest.put(aaiEndpoint(endpoint)));
40     }
41
42     public static HttpRequest delete(String endpoint) {
43         return aaiRequest(HttpRequest.delete(aaiEndpoint(endpoint)));
44     }
45
46     public static String v14(String endpoint) {
47         return SCHEMA_VERSION + endpoint;
48     }
49
50     private static HttpRequest aaiRequest(HttpRequest httpRequest) {
51         return httpRequest
52             .header("X-FromAppId", "dummy id")
53             .header("X-TransactionId", "1234")
54             .authorization(AAI_AUTH)
55             .trustAllCerts()
56             .trustAllHosts();
57     }
58
59     private static String aaiEndpoint(String endpoint) {
60         return AAI_BASE_URL + endpoint;
61     }
62 }