2 * ============LICENSE_START======================================================================
3 * Copyright (C) 2018-2023 Nordix Foundation. All rights reserved.
4 * Modifications Copyright (C) 2021 Nokia. All rights reserved.
5 * ===============================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. 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 distributed under the License
12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing permissions and limitations under
15 * ============LICENSE_END========================================================================
18 package org.oran.datafile.http;
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
24 import java.net.URISyntaxException;
26 import org.apache.hc.core5.net.URIBuilder;
27 import org.junit.jupiter.api.Test;
28 import org.oran.datafile.model.FileServerData;
32 private static final String XNF_ADDRESS = "127.0.0.1";
33 private static final int PORT = 443;
34 private static final String FRAGMENT = "thisIsTheFragment";
35 private static final String USERNAME = "bob";
36 private static final String PASSWORD = "123";
39 void shouldReturnSuccessfulResponse() {
40 assertTrue(HttpUtils.isSuccessfulResponseCodeWithDataRouter(200));
44 void shouldReturnBadResponse() {
45 assertFalse(HttpUtils.isSuccessfulResponseCodeWithDataRouter(404));
49 void prepareUri_UriWithoutPort() {
50 FileServerData serverData =
51 FileServerData.builder().serverAddress(XNF_ADDRESS).userId(USERNAME).password(PASSWORD).build();
52 String REMOTE_FILE = "any";
54 String retrievedUri = HttpUtils.prepareUri("http", serverData, REMOTE_FILE, 80);
55 assertTrue(retrievedUri.startsWith("http://" + XNF_ADDRESS + ":80"));
59 void prepareUri_verifyUriWithoutTokenAndWithoutFragment() throws URISyntaxException {
60 String file = "/file";
61 String expected = "http://" + XNF_ADDRESS + ":" + PORT + file;
62 assertEquals(expected, HttpUtils.prepareUri("http", fileServerDataNoTokenNoFragment(), file, 443));
65 private FileServerData fileServerDataNoTokenNoFragment() throws URISyntaxException {
66 return FileServerData.builder().serverAddress(XNF_ADDRESS).userId("").password("").port(PORT)
67 .queryParameters(new URIBuilder("").getQueryParams()).uriRawFragment("").build();