diff --git a/src/main/java/org/opendaylight/restconf/simple/RestConfConfig.java b/src/main/java/org/opendaylight/restconf/simple/RestConfConfig.java index f28ad56..2d6df65 100644 --- a/src/main/java/org/opendaylight/restconf/simple/RestConfConfig.java +++ b/src/main/java/org/opendaylight/restconf/simple/RestConfConfig.java @@ -41,4 +41,14 @@ static RestConfConfigBuilder builder() { 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 + } } diff --git a/src/main/java/org/opendaylight/restconf/simple/RestConfWiring.java b/src/main/java/org/opendaylight/restconf/simple/RestConfWiring.java index 80fbcc9..881b03d 100644 --- a/src/main/java/org/opendaylight/restconf/simple/RestConfWiring.java +++ b/src/main/java/org/opendaylight/restconf/simple/RestConfWiring.java @@ -29,7 +29,6 @@ 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 RestConfWiring(RestConfConfig config, WebServer webServer, ServletSupport // 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()) diff --git a/src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java b/src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java index 3f5031b..a590b33 100644 --- a/src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java +++ b/src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java @@ -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 }