intro RESTCONF Version DRAFT_02 vs DRAFT_18
authorMichael Vorburger <mike@vorburger.ch>
Sat, 20 Oct 2018 17:34:29 +0000 (19:34 +0200)
committerMichael Vorburger <mike@vorburger.ch>
Wed, 1 Jul 2020 23:37:35 +0000 (01:37 +0200)
use DRAFT_02 by default (instead of previous DRAFT_18)

un-comment the test which now passes!

Signed-off-by: Michael Vorburger <mike@vorburger.ch>
src/main/java/org/opendaylight/restconf/simple/RestConfConfig.java
src/main/java/org/opendaylight/restconf/simple/RestConfWiring.java
src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java

index f28ad564137d9fd725bac7662dae7078e32f90ad..2d6df657858ccf5f376ee464f81e5ea951a7fc0b 100644 (file)
@@ -41,4 +41,14 @@ public interface RestConfConfig {
     default String contextPath() {
         return "/restconf";
     }
+
+    default Version version() {
+        return Version.DRAFT_02;
+    }
+
+    enum Version {
+        // TODO Confirm what are appropriate names for these versions?
+        DRAFT_18, // RFC_8040 ?
+        DRAFT_02
+    }
 }
index 80fbcc9137f487bd296f47f30bbb519386e27e19..881b03d944dd2737d21699e474e9b15094f1ade7 100644 (file)
@@ -29,7 +29,6 @@ import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl;
 import org.opendaylight.netconf.sal.restconf.impl.StatisticsRestconfServiceWrapper;
-import org.opendaylight.restconf.nb.rfc8040.RestconfApplication;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
@@ -99,8 +98,22 @@ public class RestConfWiring {
 
         // This is currently hard-coded to DRAFT_18; if we ever actually need to support the
         // older DRAFT_02 for anything, then (only) add it to the RestConfConfig and switch here
-        Application application = new RestconfApplication(schemaCtxHandler,
-                domMountPointServiceHandler, servicesWrapper);
+        Application application;
+        switch (config.version()) {
+            case DRAFT_02:
+                application = new org.opendaylight.netconf.sal.rest.impl.RestconfApplication(
+                        controllerContext, stats);
+                break;
+
+            case DRAFT_18:
+                application = new org.opendaylight.restconf.nb.rfc8040.RestconfApplication(
+                        schemaCtxHandler, domMountPointServiceHandler, servicesWrapper);
+                break;
+
+            default:
+                throw new UnsupportedOperationException(config.version().name());
+        }
+
         HttpServlet servlet = jaxRS.createHttpServletBuilder(application).build();
         this.webContext = WebContext.builder().contextPath(config.contextPath())
                 .addServlet(ServletDetails.builder().addUrlPattern("/*").servlet(servlet).build())
index 3f5031b35e4feece81fc6000557c17fc80a5c8e2..a590b33eb67f4c066b827a7a7c846d25f58a38e8 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.restconf.simple.test;
 
+import static com.google.common.truth.Truth.assertThat;
+import static org.opendaylight.infrautils.testutils.TestHttpClient.Method.GET;
+
 import java.io.IOException;
 import javax.inject.Inject;
 import org.junit.Rule;
@@ -35,7 +38,7 @@ public class RestConfModuleTest extends AbstractSimpleDistributionTest {
     @Inject TestHttpClient http;
 
     @Test public void testRestConf() throws IOException {
-        // TODO assertThat(http.responseCode(GET, "/restconf/modules/")).isEqualTo(200);
+        assertThat(http.responseCode(GET, "/restconf/modules/")).isEqualTo(200);
 
         // TODO test security; add auth support to TestHttpClient, check that w.o. auth it's 401
     }