From 99ac1b634b84653ff04f349b405e8c9250635947 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 12 Apr 2022 13:56:04 +0200 Subject: [PATCH] Move SimpleUriInfo This class is used only in tests, move it and hide it. Also rename it to LocalUriInfo and mark its sole user for future evolution, e.g. use mocks. JIRA: NETCONF-837 Change-Id: If3ecdbf332cd3c18bdb8822d2f5396c3d59df3b4 Signed-off-by: Robert Varga --- .../rests/services/impl/LocalUriInfo.java} | 31 ++++++++----------- ...onfStreamsSubscriptionServiceImplTest.java | 14 +-------- 2 files changed, 14 insertions(+), 31 deletions(-) rename restconf/{restconf-common/src/main/java/org/opendaylight/restconf/common/util/SimpleUriInfo.java => restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/LocalUriInfo.java} (73%) diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/SimpleUriInfo.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/LocalUriInfo.java similarity index 73% rename from restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/SimpleUriInfo.java rename to restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/LocalUriInfo.java index b964b4ce65..ade99f2672 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/SimpleUriInfo.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/LocalUriInfo.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.restconf.common.util; +package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import java.net.URI; import java.util.List; @@ -20,17 +20,12 @@ import javax.ws.rs.core.UriInfo; * * @author Thomas Pantelis */ -public class SimpleUriInfo implements UriInfo { +final class LocalUriInfo implements UriInfo { + private final MultivaluedMap queryParams = new MultivaluedHashMap<>(); private final String path; - private final MultivaluedMap queryParams; - public SimpleUriInfo(String path) { - this(path, new MultivaluedHashMap<>()); - } - - public SimpleUriInfo(String path, MultivaluedMap queryParams) { - this.path = path; - this.queryParams = queryParams; + LocalUriInfo() { + path = "/"; } @Override @@ -39,7 +34,7 @@ public class SimpleUriInfo implements UriInfo { } @Override - public String getPath(boolean decode) { + public String getPath(final boolean decode) { return path; } @@ -49,7 +44,7 @@ public class SimpleUriInfo implements UriInfo { } @Override - public List getPathSegments(boolean decode) { + public List getPathSegments(final boolean decode) { throw new UnsupportedOperationException(); } @@ -75,7 +70,7 @@ public class SimpleUriInfo implements UriInfo { @Override public URI getBaseUri() { - return URI.create(""); + return UriBuilder.fromUri("http://localhost:8181").build(); } @Override @@ -89,7 +84,7 @@ public class SimpleUriInfo implements UriInfo { } @Override - public MultivaluedMap getPathParameters(boolean decode) { + public MultivaluedMap getPathParameters(final boolean decode) { return getPathParameters(); } @@ -99,7 +94,7 @@ public class SimpleUriInfo implements UriInfo { } @Override - public MultivaluedMap getQueryParameters(boolean decode) { + public MultivaluedMap getQueryParameters(final boolean decode) { return getQueryParameters(); } @@ -109,7 +104,7 @@ public class SimpleUriInfo implements UriInfo { } @Override - public List getMatchedURIs(boolean decode) { + public List getMatchedURIs(final boolean decode) { return getMatchedURIs(); } @@ -119,12 +114,12 @@ public class SimpleUriInfo implements UriInfo { } @Override - public URI resolve(URI uri) { + public URI resolve(final URI uri) { return uri; } @Override - public URI relativize(URI uri) { + public URI relativize(final URI uri) { return uri; } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java index 8accfc7922..2d4809c4e6 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.java @@ -19,7 +19,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Map; import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; import org.junit.AfterClass; import org.junit.Before; @@ -35,7 +34,6 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; import org.opendaylight.mdsal.dom.api.DOMNotificationService; import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; -import org.opendaylight.restconf.common.util.SimpleUriInfo; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload; @@ -87,6 +85,7 @@ public class RestconfStreamsSubscriptionServiceImplTest { .when(dataBroker).getExtensions(); doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters(); + // FIXME: just mock UriInfo here doReturn(new LocalUriInfo().getBaseUriBuilder()).when(uriInfo).getBaseUriBuilder(); doReturn(new URI("http://127.0.0.1/" + URI)).when(uriInfo).getAbsolutePath(); schemaHandler.onModelContextUpdated( @@ -95,17 +94,6 @@ public class RestconfStreamsSubscriptionServiceImplTest { configurationSse = new Configuration(0, 100, 10, true); } - private static class LocalUriInfo extends SimpleUriInfo { - LocalUriInfo() { - super("/"); - } - - @Override - public URI getBaseUri() { - return UriBuilder.fromUri("http://localhost:8181").build(); - } - } - @BeforeClass public static void setUpBeforeTest() { final String name = -- 2.36.6