blob: 77675745574fd1b71a955575d0c7bb7d8df0f03c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.aaisimulator.utils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Base64;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.util.UriComponentsBuilder;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
/**
* @author waqas.ikram@ericsson.com
*
*/
public class TestUtils {
private static final String PASSWORD = "aai.onap.org:demo123456!";
public static HttpHeaders getHttpHeaders(final String username) {
final HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Authorization", getBasicAuth(username));
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
return requestHeaders;
}
public static File getFile(final String file) throws IOException {
return new ClassPathResource(file).getFile();
}
public static String getJsonString(final String file) throws IOException {
return new String(Files.readAllBytes(getFile(file).toPath()));
}
public static <T> T getObjectFromFile(final File file, final Class<T> clazz) throws Exception {
final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JaxbAnnotationModule());
return mapper.readValue(file, clazz);
}
public static String getBasicAuth(final String username) {
return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes()));
}
public static String getBaseUrl(final int port) {
return "https://localhost:" + port;
}
public static String getCustomer() throws Exception, IOException {
return getJsonString("test-data/business-customer.json");
}
public static String getServiceSubscription() throws IOException {
return getJsonString("test-data/service-subscription.json");
}
public static String getServiceInstance() throws IOException {
return getJsonString("test-data/service-instance.json");
}
public static String getSvcInstance() throws IOException {
return getJsonString("test-data/service-instance-aai.json");
}
public static String getGenericVnf() throws IOException {
return getJsonString("test-data/generic-vnf.json");
}
public static String getPnf() throws IOException {
return getJsonString("test-data/pnf.json");
}
public static String getRelationShip() throws IOException {
return getJsonString("test-data/relation-ship.json");
}
public static String getPlatformRelatedLink() throws IOException {
return getJsonString("test-data/platform-related-link.json");
}
public static String getLineOfBusinessRelatedLink() throws IOException {
return getJsonString("test-data/line-of-business-related-link.json");
}
public static String getPlatform() throws IOException {
return getJsonString("test-data/platform.json");
}
public static String getGenericVnfRelationShip() throws IOException {
return getJsonString("test-data/generic-vnf-relationship.json");
}
public static String getLineOfBusiness() throws IOException {
return getJsonString("test-data/line-of-business.json");
}
public static String getBusinessProject() throws IOException {
return getJsonString("test-data/business-project.json");
}
public static String getBusinessProjectRelationship() throws IOException {
return getJsonString("test-data/business-project-relation-ship.json");
}
public static String getOwningEntityRelationship() throws IOException {
return getJsonString("test-data/owning-entity-relation-ship.json");
}
public static String getOwningEntity() throws IOException {
return getJsonString("test-data/owning-entity.json");
}
public static String getOrchStatuUpdateServiceInstance() throws IOException {
return getJsonString("test-data/service-instance-orch-status-update.json");
}
public static String getRelationShipJsonObject() throws IOException {
return getJsonString("test-data/service-Instance-relationShip.json");
}
public static String getCloudRegion() throws IOException {
return getJsonString("test-data/cloud-region.json");
}
public static String getTenant() throws IOException {
return getJsonString("test-data/tenant.json");
}
public static String getCloudRegionRelatedLink() throws IOException {
return getJsonString("test-data/cloud-region-related-link.json");
}
public static String getGenericVnfRelatedLink() throws IOException {
return getJsonString("test-data/generic-vnf-related-link.json");
}
public static String getTenantRelationShip() throws IOException {
return getJsonString("test-data/tenant-relationship.json");
}
public static String getGenericVnfOrchStatuUpdate() throws IOException {
return getJsonString("test-data/generic-vnf-orch-status-update.json");
}
public static String getEsrVnfm() throws IOException {
return getJsonString("test-data/esr-vnfm.json");
}
public static String getEsrSystemInfo() throws IOException {
return getJsonString("test-data/esr-system-info.json");
}
public static String getVserver() throws IOException {
return getJsonString("test-data/vServer.json");
}
public static String getUrl(final int port, final String... urls) {
final UriComponentsBuilder baseUri = UriComponentsBuilder.fromUriString("https://localhost:" + port);
for (final String url : urls) {
baseUri.path(url);
}
return baseUri.toUriString();
}
private TestUtils() {}
}
|