Refactor root resource discovery 02/109102/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Nov 2023 16:16:56 +0000 (17:16 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 28 Nov 2023 16:17:20 +0000 (17:17 +0100)
RootResourceDiscoveryServiceImpl is a mouthful and it is in a legacy
package.

Rename it to JaxRsWebHostMetadata, which is really what we are doing
here. Also eliminate RootFoundApplication by making it an anonymous
class in its sole user.

JIRA: NETCONF-773
Change-Id: I2dcaf136f5e8a324b5f31b72ad9bf5bcd7edbcd4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsWebHostMetadata.java [moved from restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RootResourceDiscoveryServiceImpl.java with 88% similarity]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/JaxRsNorthbound.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RootFoundApplication.java [deleted file]
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/jaxrs/JaxRsWebHostMetadataTest.java [moved from restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RootResourceDiscoveryServiceImplTest.java with 73% similarity]

@@ -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.nb.rfc8040.rests.services.impl;
+package org.opendaylight.restconf.nb.jaxrs;
 
 import static java.util.Objects.requireNonNull;
 
@@ -20,15 +20,15 @@ import org.opendaylight.restconf.api.MediaTypes;
 /**
  * Controller for determining the {@code Root Resource} of the RESTCONF API. This interface serves up a
  * {@code host-meta} document as defined in
- * <a href="https://tools.ietf.org/html/rfc8040#section-3">RFC6415 section 3</a>.
+ * <a href="https://tools.ietf.org/html/rfc6415#section-3">RFC6415 The host-meta Document</a>.
  */
 // FIXME: this really should be the endpoint's job to aggregate these. Once JAX-RS (or any other wiring) can provide it,
 //        integrate with that framework, so we co-exist with others.
 @Path("/")
-public final class RootResourceDiscoveryServiceImpl {
+public final class JaxRsWebHostMetadata {
     private final String restconfRoot;
 
-    public RootResourceDiscoveryServiceImpl(final String restconfRoot) {
+    public JaxRsWebHostMetadata(final String restconfRoot) {
         this.restconfRoot = requireNonNull(restconfRoot);
     }
 
index f2c9edd0efe2bf74fca648b636d935b9d8d123d9..8722d6b66d62e58576e5fdbf309b1c5d91d8f108 100644 (file)
@@ -8,7 +8,9 @@
 package org.opendaylight.restconf.nb.rfc8040;
 
 import com.google.common.annotations.Beta;
+import java.util.Set;
 import javax.servlet.ServletException;
+import javax.ws.rs.core.Application;
 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
 import org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter;
 import org.opendaylight.aaa.web.FilterDetails;
@@ -19,6 +21,7 @@ import org.opendaylight.aaa.web.WebServer;
 import org.opendaylight.aaa.web.servlet.ServletSupport;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.restconf.nb.jaxrs.JaxRsWebHostMetadata;
 import org.opendaylight.restconf.nb.rfc8040.streams.RestconfStreamServletFactory;
 import org.opendaylight.restconf.server.api.RestconfServer;
 import org.opendaylight.restconf.server.spi.DatabindProvider;
@@ -79,8 +82,13 @@ public final class JaxRsNorthbound implements AutoCloseable {
             .supportsSessions(false)
             .addServlet(ServletDetails.builder()
                 .addUrlPattern("/*")
-                .servlet(servletSupport.createHttpServletBuilder(new RootFoundApplication(URLConstants.BASE_PATH))
-                    .build())
+                .servlet(servletSupport.createHttpServletBuilder(
+                    new Application() {
+                        @Override
+                        public Set<Object> getSingletons() {
+                            return Set.of(new JaxRsWebHostMetadata(URLConstants.BASE_PATH));
+                        }
+                    }).build())
                 .name("Rootfound")
                 .build());
 
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RootFoundApplication.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RootFoundApplication.java
deleted file mode 100644 (file)
index 0b9eb60..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2020 ZTE Corp. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.nb.rfc8040;
-
-import java.util.Set;
-import javax.ws.rs.core.Application;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors.RestconfDocumentedExceptionMapper;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RootResourceDiscoveryServiceImpl;
-
-public class RootFoundApplication extends Application {
-    private final RootResourceDiscoveryServiceImpl rrds;
-
-    public RootFoundApplication(final String restconfRoot) {
-        rrds = new RootResourceDiscoveryServiceImpl(restconfRoot);
-    }
-
-    @Override
-    public Set<Class<?>> getClasses() {
-        return Set.of(RestconfDocumentedExceptionMapper.class);
-    }
-
-    @Override
-    public Set<Object> getSingletons() {
-        return Set.of(rrds);
-    }
-}
@@ -5,17 +5,17 @@
  * 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.nb.rfc8040.rests.services.impl;
+package org.opendaylight.restconf.nb.jaxrs;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
-public class RootResourceDiscoveryServiceImplTest {
-    private final RootResourceDiscoveryServiceImpl svc = new RootResourceDiscoveryServiceImpl("fooBarBaz");
+class JaxRsWebHostMetadataTest {
+    private final JaxRsWebHostMetadata svc = new JaxRsWebHostMetadata("fooBarBaz");
 
     @Test
-    public void testJsonData() {
+    void testJsonData() {
         final var response = svc.readJsonData();
         assertEquals(200, response.getStatus());
         assertEquals("""
@@ -28,7 +28,7 @@ public class RootResourceDiscoveryServiceImplTest {
     }
 
     @Test
-    public void testXrdData() {
+    void testXrdData() {
         final var response = svc.readXrdData();
         assertEquals(200, response.getStatus());
         assertEquals("""