From: Jakub Morvay Date: Fri, 8 Feb 2019 18:41:41 +0000 (+0000) Subject: Merge "introduce Rfc8040RestConfWiring for standalone (simple) environments" X-Git-Tag: release/sodium~96 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=741f648fbad43e1197253097806f1df360664589;hp=fabd70b6060cb56557018fe880f5fd7502a0f9ae;p=netconf.git Merge "introduce Rfc8040RestConfWiring for standalone (simple) environments" --- diff --git a/restconf/restconf-nb-bierman02/pom.xml b/restconf/restconf-nb-bierman02/pom.xml index 5a456adfb6..1f997ef1ee 100644 --- a/restconf/restconf-nb-bierman02/pom.xml +++ b/restconf/restconf-nb-bierman02/pom.xml @@ -204,13 +204,11 @@ org.opendaylight.infrautils inject.guice.testutils - 1.6.0-SNAPSHOT test org.opendaylight.infrautils infrautils-testutils - 1.6.0-SNAPSHOT test diff --git a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/incubate/InMemoryMdsalModule.java b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/incubate/InMemoryMdsalModule.java index fba66a0339..18f1287a79 100644 --- a/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/incubate/InMemoryMdsalModule.java +++ b/restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/incubate/InMemoryMdsalModule.java @@ -33,7 +33,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider; * *

This class is here only temporarily and it can and should be removed and * replaced when the equivalent will be offered by the mdsal project itself; see - * MDSAL-418. + * MDSAL-418. It is + * also copy/pasted to org.opendaylight.restconf.nb.rfc8040.test.incubate.InMemoryMdsalModule. * *

BEWARE: Do *NOT* use this module in component tests or applications mixing * code requiring the old controller and the new mdsal {@link DataBroker} & Co. diff --git a/restconf/restconf-nb-rfc8040/pom.xml b/restconf/restconf-nb-rfc8040/pom.xml index babb39d16c..4ace689413 100644 --- a/restconf/restconf-nb-rfc8040/pom.xml +++ b/restconf/restconf-nb-rfc8040/pom.xml @@ -23,6 +23,20 @@ bundle + + javax.annotation + javax.annotation-api + true + + + javax.inject + javax.inject + + + org.apache.aries.blueprint + blueprint-maven-plugin-annotation + true + org.opendaylight.netconf restconf-common-models @@ -153,10 +167,34 @@ jsonassert test + + org.opendaylight.aaa.web + testutils + test + + + org.opendaylight.infrautils + inject.guice.testutils + test + + + org.opendaylight.infrautils + infrautils-testutils + test + + + org.opendaylight.netconf + ietf-restconf + test + + + org.apache.aries.blueprint + blueprint-maven-plugin + org.apache.felix maven-bundle-plugin diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java index 89c8587880..d5acb74925 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java @@ -10,6 +10,8 @@ package org.opendaylight.restconf.nb.rfc8040; import com.google.common.collect.ImmutableSet; import java.util.HashSet; import java.util.Set; +import javax.inject.Inject; +import javax.inject.Singleton; import javax.ws.rs.core.Application; import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; @@ -25,11 +27,14 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExport import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYinBodyWriter; import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper; +@Singleton public class RestconfApplication extends Application { + private final SchemaContextHandler schemaContextHandler; private final DOMMountPointServiceHandler mountPointServiceHandler; private final ServicesWrapper servicesWrapper; + @Inject public RestconfApplication(SchemaContextHandler schemaContextHandler, DOMMountPointServiceHandler mountPointServiceHandler, ServicesWrapper servicesWrapper) { this.schemaContextHandler = schemaContextHandler; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040RestConfWiring.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040RestConfWiring.java new file mode 100644 index 0000000000..d3fe40686a --- /dev/null +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040RestConfWiring.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 Red Hat, Inc. 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 javax.inject.Inject; +import javax.inject.Singleton; +import org.apache.aries.blueprint.annotation.service.Reference; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; +import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler; +import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler; +import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler; +import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler; +import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl; +import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper; +import org.opendaylight.restconf.nb.rfc8040.web.WebInitializer; + +/** + * Standalone wiring for RESTCONF. + * + *

This wiring alone is not sufficient; there are a few other singletons which + * need to be bound as well, incl. {@link RestconfApplication}, + * {@link JSONRestconfServiceRfc8040Impl} & {@link WebInitializer}; see the + * Rfc8040RestConfWiringTest for how to do this e.g. for Guice (this class can + * be used with another DI framework but needs the equivalent). + * + * @author Michael Vorburger.ch + */ +@Singleton +public class Rfc8040RestConfWiring { + + private final ServicesWrapper servicesWrapper; + + @Inject + public Rfc8040RestConfWiring( + SchemaContextHandler schemaCtxHandler, + DOMMountPointServiceHandler domMountPointServiceHandler, TransactionChainHandler transactionChainHandler, + DOMDataBrokerHandler domDataBrokerHandler, RpcServiceHandler rpcServiceHandler, + NotificationServiceHandler notificationServiceHandler, @Reference DOMSchemaService domSchemaService) { + servicesWrapper = ServicesWrapper.newInstance(schemaCtxHandler, domMountPointServiceHandler, + transactionChainHandler, domDataBrokerHandler, rpcServiceHandler, notificationServiceHandler, + domSchemaService); + } + + public ServicesWrapper getServicesWrapper() { + return servicesWrapper; + } +} diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMDataBrokerHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMDataBrokerHandler.java index f53bb40513..8702c4ab3f 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMDataBrokerHandler.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMDataBrokerHandler.java @@ -7,15 +7,19 @@ */ package org.opendaylight.restconf.nb.rfc8040.handlers; +import javax.inject.Inject; +import javax.inject.Singleton; import org.opendaylight.mdsal.dom.api.DOMDataBroker; /** * Implementation of {@link DOMDataBrokerHandler}. */ +@Singleton public class DOMDataBrokerHandler implements Handler { private final DOMDataBroker broker; + @Inject public DOMDataBrokerHandler(final DOMDataBroker broker) { this.broker = broker; } @@ -24,5 +28,4 @@ public class DOMDataBrokerHandler implements Handler { public DOMDataBroker get() { return this.broker; } - } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMMountPointServiceHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMMountPointServiceHandler.java index fcec775ce9..501aeafa73 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMMountPointServiceHandler.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMMountPointServiceHandler.java @@ -9,12 +9,16 @@ package org.opendaylight.restconf.nb.rfc8040.handlers; import static java.util.Objects.requireNonNull; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.apache.aries.blueprint.annotation.service.Reference; import org.opendaylight.mdsal.dom.api.DOMMountPointService; /** * Implementation of {@link DOMMountPointServiceHandler}. * */ +@Singleton public final class DOMMountPointServiceHandler implements Handler { private final DOMMountPointService domMountPointService; @@ -24,10 +28,12 @@ public final class DOMMountPointServiceHandler implements Handler { private final DOMNotificationService notificationService; @@ -19,7 +23,8 @@ public class NotificationServiceHandler implements Handler { private final DOMRpcService rpcService; - public RpcServiceHandler(final DOMRpcService rpcService) { + @Inject + public RpcServiceHandler(final @Reference DOMRpcService rpcService) { this.rpcService = rpcService; } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java index 86396c100d..6e12200660 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java @@ -12,6 +12,11 @@ import com.google.common.base.Throwables; import java.util.Collection; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.apache.aries.blueprint.annotation.service.Reference; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.common.api.TransactionCommitFailedException; import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction; @@ -35,8 +40,8 @@ import org.slf4j.LoggerFactory; /** * Implementation of {@link SchemaContextHandler}. - * */ +@Singleton @SuppressWarnings("checkstyle:FinalClass") public class SchemaContextHandler implements SchemaContextListenerHandler, AutoCloseable { @@ -55,22 +60,26 @@ public class SchemaContextHandler implements SchemaContextListenerHandler, AutoC * * @param transactionChainHandler Transaction chain handler */ - private SchemaContextHandler(final TransactionChainHandler transactionChainHandler, - final DOMSchemaService domSchemaService) { + @Inject + public SchemaContextHandler(final TransactionChainHandler transactionChainHandler, + final @Reference DOMSchemaService domSchemaService) { this.transactionChainHandler = transactionChainHandler; this.domSchemaService = domSchemaService; } + @Deprecated public static SchemaContextHandler newInstance(final TransactionChainHandler transactionChainHandler, final DOMSchemaService domSchemaService) { return new SchemaContextHandler(transactionChainHandler, domSchemaService); } + @PostConstruct public void init() { listenerRegistration = domSchemaService.registerSchemaContextListener(this); } @Override + @PreDestroy public void close() { if (listenerRegistration != null) { listenerRegistration.close(); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandler.java index 7c2440bc3f..0e2df38e5f 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandler.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandler.java @@ -8,6 +8,9 @@ package org.opendaylight.restconf.nb.rfc8040.handlers; import java.util.Objects; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction; import org.opendaylight.mdsal.dom.api.DOMTransactionChain; @@ -18,8 +21,8 @@ import org.slf4j.LoggerFactory; /** * Implementation of {@link TransactionChainHandler}. - * */ +@Singleton public class TransactionChainHandler implements Handler, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(TransactionChainHandler.class); @@ -45,6 +48,7 @@ public class TransactionChainHandler implements Handler, Au /** * Prepare transaction chain service for Restconf services. */ + @Inject public TransactionChainHandler(final DOMDataBroker dataBroker) { this.dataBroker = Objects.requireNonNull(dataBroker); transactionChain = Objects.requireNonNull(dataBroker.createTransactionChain(transactionChainListener)); @@ -62,6 +66,7 @@ public class TransactionChainHandler implements Handler, Au } @Override + @PreDestroy public synchronized void close() { transactionChain.close(); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040Impl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040Impl.java index 642ecabec8..b33d21971a 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040Impl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040Impl.java @@ -18,6 +18,9 @@ import java.lang.annotation.Annotation; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Optional; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; @@ -41,6 +44,7 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.PatchJsonBody import org.opendaylight.restconf.nb.rfc8040.rests.services.api.JSONRestconfService; import org.opendaylight.restconf.nb.rfc8040.rests.services.api.TransactionServicesWrapper; import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant; +import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper; import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; import org.opendaylight.yangtools.yang.common.OperationFailedException; import org.opendaylight.yangtools.yang.common.RpcError; @@ -54,6 +58,7 @@ import org.slf4j.LoggerFactory; * * @author Thomas Pantelis */ +@Singleton public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(JSONRestconfServiceRfc8040Impl.class); @@ -63,7 +68,8 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto private final DOMMountPointServiceHandler mountPointServiceHandler; private final SchemaContextHandler schemaContextHandler; - public JSONRestconfServiceRfc8040Impl(final TransactionServicesWrapper services, + @Inject + public JSONRestconfServiceRfc8040Impl(final ServicesWrapper services, final DOMMountPointServiceHandler mountPointServiceHandler, final SchemaContextHandler schemaContextHandler) { this.services = services; @@ -212,6 +218,7 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto } @Override + @PreDestroy public void close() { } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java index 02e69b589f..aabce8a544 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java @@ -43,7 +43,6 @@ import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfSchemaS *

  • {@link BaseServicesWrapper} *
  • {@link TransactionServicesWrapper} * - * */ @Path("/") public final class ServicesWrapper implements BaseServicesWrapper, TransactionServicesWrapper { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java index d971aa0391..e7f80a7388 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java @@ -7,8 +7,11 @@ */ package org.opendaylight.restconf.nb.rfc8040.web; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; import javax.servlet.ServletException; -import javax.ws.rs.core.Application; +import org.apache.aries.blueprint.annotation.service.Reference; import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration; import org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter; import org.opendaylight.aaa.web.FilterDetails; @@ -19,17 +22,22 @@ import org.opendaylight.aaa.web.WebContextRegistration; import org.opendaylight.aaa.web.WebContextSecurer; import org.opendaylight.aaa.web.WebServer; import org.opendaylight.aaa.web.servlet.ServletSupport; +import org.opendaylight.restconf.nb.rfc8040.RestconfApplication; /** * Initializes the rfc8040 web app endpoint. * * @author Thomas Pantelis */ +@Singleton public class WebInitializer { + private final WebContextRegistration registration; - public WebInitializer(WebServer webServer, WebContextSecurer webContextSecurer, ServletSupport servletSupport, - Application webApp, CustomFilterAdapterConfiguration customFilterAdapterConfig) throws ServletException { + @Inject + public WebInitializer(@Reference WebServer webServer, @Reference WebContextSecurer webContextSecurer, + @Reference ServletSupport servletSupport, RestconfApplication webApp, + @Reference CustomFilterAdapterConfiguration customFilterAdapterConfig) throws ServletException { WebContextBuilder webContextBuilder = WebContext.builder().contextPath("rests").supportsSessions(false) .addServlet(ServletDetails.builder().servlet(servletSupport.createHttpServletBuilder(webApp).build()) .addUrlPattern("/*").build()) @@ -48,6 +56,7 @@ public class WebInitializer { registration = webServer.registerWebContext(webContextBuilder.build()); } + @PreDestroy public void close() { if (registration != null) { registration.close(); diff --git a/restconf/restconf-nb-rfc8040/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml b/restconf/restconf-nb-rfc8040/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml index 758a0ed8e2..b009a9ae64 100644 --- a/restconf/restconf-nb-rfc8040/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml +++ b/restconf/restconf-nb-rfc8040/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml @@ -26,88 +26,12 @@ - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/Rfc8040RestConfWiringTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/Rfc8040RestConfWiringTest.java new file mode 100644 index 0000000000..7b9a9a694c --- /dev/null +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/Rfc8040RestConfWiringTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2019 Red Hat, Inc. 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.test; + +import static com.google.common.truth.Truth.assertThat; +import static org.opendaylight.infrautils.testutils.web.TestWebClient.Method.GET; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import java.io.IOException; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.junit.Rule; +import org.junit.Test; +import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration; +import org.opendaylight.aaa.web.WebServer; +import org.opendaylight.aaa.web.testutils.TestWebClient; +import org.opendaylight.aaa.web.testutils.WebTestModule; +import org.opendaylight.infrautils.inject.guice.testutils.AnnotationsModule; +import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule; +import org.opendaylight.infrautils.testutils.LogRule; +import org.opendaylight.restconf.nb.rfc8040.RestconfApplication; +import org.opendaylight.restconf.nb.rfc8040.Rfc8040RestConfWiring; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl; +import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper; +import org.opendaylight.restconf.nb.rfc8040.test.incubate.InMemoryMdsalModule; +import org.opendaylight.restconf.nb.rfc8040.web.WebInitializer; +import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider; + +/** + * Tests if the {@link Rfc8040RestConfWiring} works. + * + * @author Michael Vorburger.ch + */ +public class Rfc8040RestConfWiringTest { + + public static class TestModule extends AbstractModule { + @Override + protected void configure() { + bind(Rfc8040RestConfWiring.class).asEagerSingleton(); + bind(RestconfApplication.class).asEagerSingleton(); + bind(JSONRestconfServiceRfc8040Impl.class).asEagerSingleton(); + bind(WebInitializer.class).asEagerSingleton(); + bind(CustomFilterAdapterConfiguration.class).toInstance(listener -> { }); + } + + @Provides + @Singleton ServicesWrapper getServicesWrapper(Rfc8040RestConfWiring wiring) { + return wiring.getServicesWrapper(); + } + } + + public @Rule LogRule logRule = new LogRule(); + + public @Rule GuiceRule guice = new GuiceRule(TestModule.class, + InMemoryMdsalModule.class, WebTestModule.class, AnnotationsModule.class); + + @Inject WebServer webServer; + @Inject TestWebClient webClient; + + @Inject SchemaContextProvider schemaContextProvider; + @Inject SchemaContextHandler schemaContextHandler; + + @Test + public void testWiring() throws IOException { + schemaContextHandler.onGlobalContextUpdated(schemaContextProvider.getSchemaContext()); + assertThat(webClient.request(GET, "/rests/yang-library-version").getStatus()).isEqualTo(200); + } +} diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/incubate/InMemoryMdsalModule.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/incubate/InMemoryMdsalModule.java new file mode 100644 index 0000000000..986575cc48 --- /dev/null +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/incubate/InMemoryMdsalModule.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2019 Red Hat, Inc. 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.test.incubate; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import javax.annotation.PreDestroy; +import javax.inject.Singleton; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractBaseDataBrokerTest; +import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; +import org.opendaylight.mdsal.dom.api.DOMMountPointService; +import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService; +import org.opendaylight.mdsal.dom.api.DOMNotificationService; +import org.opendaylight.mdsal.dom.api.DOMRpcService; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; +import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl; +import org.opendaylight.mdsal.dom.broker.DOMNotificationRouter; +import org.opendaylight.mdsal.dom.broker.DOMRpcRouter; +import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry; +import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider; + +/** + * Copy paste from org.opendaylight.controller.sal.restconf.impl.test.incubate.InMemoryMdsalModule. + * + * @author Michael Vorburger.ch + */ +public class InMemoryMdsalModule extends AbstractModule { + + private static final int NOTIFICATION_SERVICE_QUEUE_DEPTH = 128; + + private final AbstractBaseDataBrokerTest dataBrokerTest; + private final DOMNotificationRouter domNotificationRouter; + + public InMemoryMdsalModule() throws Exception { + dataBrokerTest = new AbstractConcurrentDataBrokerTest(true) { // NOT AbstractDataBrokerTest + }; + dataBrokerTest.setup(); + + domNotificationRouter = DOMNotificationRouter.create(NOTIFICATION_SERVICE_QUEUE_DEPTH); + } + + @Override + protected void configure() { + } + + @Provides + @Singleton + DataBroker getDataBroker() { + return dataBrokerTest.getDataBroker(); + } + + @Provides + @Singleton DOMDataBroker getDOMDataBroker() { + return dataBrokerTest.getDomBroker(); + } + + @Provides + @Singleton DOMNotificationRouter getDOMNotificationRouter() { + return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter(); + } + + @Provides + @Singleton DOMSchemaService getSchemaService() { + return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService(); + } + + @Provides + @Singleton SchemaContextProvider getSchemaContextProvider() { + DOMSchemaService schemaService = dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService(); + if (schemaService instanceof SchemaContextProvider) { + return (SchemaContextProvider) schemaService; + } + throw new IllegalStateException( + "The schema service isn't a SchemaContextProvider, it's a " + schemaService.getClass()); + } + + @Provides + @Singleton DOMMountPointService getDOMMountPoint() { + return new DOMMountPointServiceImpl(); + } + + @Provides + @Singleton DOMNotificationService getDOMNotificationService() { + return domNotificationRouter; + } + + @Provides + @Singleton DOMNotificationPublishService getDOMNotificationPublishService() { + return domNotificationRouter; + } + + @Provides + @Singleton DOMNotificationSubscriptionListenerRegistry getDOMNotificationSubscriptionListenerRegistry() { + return domNotificationRouter; + } + + @Provides + @Singleton DOMRpcService getDOMRpcService(DOMSchemaService schemaService) { + return DOMRpcRouter.newInstance(schemaService).getRpcService(); + } + + @PreDestroy + public void close() { + } +} diff --git a/restconf/restconf-parent/pom.xml b/restconf/restconf-parent/pom.xml index a1f4b84341..26ac2eaa00 100644 --- a/restconf/restconf-parent/pom.xml +++ b/restconf/restconf-parent/pom.xml @@ -22,6 +22,13 @@ + + org.opendaylight.infrautils + infrautils-artifacts + 1.6.0-SNAPSHOT + pom + import + org.opendaylight.aaa aaa-artifacts