* ============LICENSE_START=======================================================
* DCAEGEN2-SERVICES-SDK
* ================================================================================
- * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 NOKIA Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
-package org.onap.dcaegen2.services.sdk.rest.services.uri;
+package org.onap.dcaegen2.services.sdk.rest.services.adapters.http;
public final class URI {
private String scheme;
private void defineString() {
if (string != null) return;
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
if (scheme != null) {
sb.append(scheme);
sb.append(':');
private boolean isOpaque() {
return path == null;
}
-}
\ No newline at end of file
+}
* ============LICENSE_START=======================================================
* DCAEGEN2-SERVICES-SDK
* ================================================================================
- * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 NOKIA Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
*/
-package org.onap.dcaegen2.services.sdk.rest.services.uri;
+package org.onap.dcaegen2.services.sdk.rest.services.adapters.http;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Test
void buildProperUri() {
- String expectedValue = "http://user@localhost:8080path?query#fragment";
+ String expectedValue = "http://user@localhost:8080/path?query#fragment";
URI uri = new URI.URIBuilder().scheme("http")
.host("localhost")
.port(8080)
- .path("path")
+ .path("/path")
.fragment("fragment")
.authority("authority")
.userInfo("user")
assertEquals(expectedValue, uri.toString());
}
-}
\ No newline at end of file
+
+ @Test
+ void buildProperUriWithoutUser() {
+ String expectedValue = "http://localhost:8080/path?query#fragment";
+ URI uri = new URI.URIBuilder().scheme("http")
+ .host("localhost")
+ .port(8080)
+ .path("/path")
+ .fragment("fragment")
+ .authority("authority")
+ .query("query")
+ .build();
+
+ assertEquals(expectedValue, uri.toString());
+ }
+
+ @Test
+ void buildProperUriForMissingQuery() {
+ String expectedValue = "http://localhost:8080/path#fragment";
+ URI uri = new URI.URIBuilder().scheme("http")
+ .host("localhost")
+ .port(8080)
+ .path("/path")
+ .fragment("fragment")
+ .authority("authority")
+ .build();
+
+ assertEquals(expectedValue, uri.toString());
+ }
+
+ @Test
+ void buildProperUriForMissingFragment() {
+ String expectedValue = "http://localhost:8080/path?query";
+ URI uri = new URI.URIBuilder().scheme("http")
+ .host("localhost")
+ .port(8080)
+ .path("/path")
+ .authority("authority")
+ .query("query")
+ .build();
+
+ assertEquals(expectedValue, uri.toString());
+ }
+}