From: Tom Pantelis Date: Thu, 19 Apr 2018 22:16:03 +0000 (-0400) Subject: Use SchemaContextHandler non-statically X-Git-Tag: release/fluorine~89^2~2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=b121b01510163f7182432c2de8341702ec960b8b;p=netconf.git Use SchemaContextHandler non-statically Removed the static SchemaContext field and made the SchemaContextHandler instance static temporarily for the RestconfApplication but converts the rest of the code to reference it non-statically. The static SchemaContextHandler will be removed in a subsequent patch. Change-Id: I9763ad472acdefbade511c47ee7e2f140f9d6ca1 Signed-off-by: Tom Pantelis --- diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java index 4cf3aa1636..e13a2f691e 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java @@ -22,8 +22,6 @@ 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.services.wrapper.ServiceWrapper; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,15 +42,13 @@ public class RestConnectorProvider implements Restconf private final DOMSchemaService domSchemaService; private final TransactionChainHandler transactionChainHandler; private final DOMDataBroker dataBroker; - - private ListenerRegistration listenerRegistration; - private SchemaContextHandler schemaCtxHandler; + private final SchemaContextHandler schemaCtxHandler; private final T wrapperServices; public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService, final DOMRpcService rpcService, final DOMNotificationService notificationService, final DOMMountPointService mountPointService, final TransactionChainHandler transactionChainHandler, - final T wrapperServices) { + final SchemaContextHandler schemaCtxHandler, final T wrapperServices) { this.wrapperServices = wrapperServices; this.domSchemaService = Preconditions.checkNotNull(domSchemaService); this.rpcService = Preconditions.checkNotNull(rpcService); @@ -60,6 +56,7 @@ public class RestConnectorProvider implements Restconf this.mountPointService = Preconditions.checkNotNull(mountPointService); this.transactionChainHandler = Preconditions.checkNotNull(transactionChainHandler); this.dataBroker = Preconditions.checkNotNull(domDataBroker); + this.schemaCtxHandler = Preconditions.checkNotNull(schemaCtxHandler); } public synchronized void start() { @@ -67,9 +64,6 @@ public class RestConnectorProvider implements Restconf final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker); - this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler); - this.listenerRegistration = domSchemaService.registerSchemaContextListener(this.schemaCtxHandler); - final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService); final NotificationServiceHandler notificationServiceHandler = @@ -95,12 +89,7 @@ public class RestConnectorProvider implements Restconf } @Override - public void close() throws Exception { - // close registration - if (this.listenerRegistration != null) { - this.listenerRegistration.close(); - } - + public void close() { mountPointServiceHandler = null; } } 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 e779281483..3c386490a4 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 @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableSet; import java.util.HashSet; import java.util.Set; import javax.ws.rs.core.Application; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.NormalizedNodeJsonBodyWriter; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.NormalizedNodeXmlBodyWriter; @@ -24,14 +25,13 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExport import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl; public class RestconfApplication extends Application { + private final SchemaContextHandler schemaContextHandler = SchemaContextHandler.instance(); @Override public Set> getClasses() { return ImmutableSet.>builder() .add(NormalizedNodeJsonBodyWriter.class).add(NormalizedNodeXmlBodyWriter.class) - .add(JsonNormalizedNodeBodyReader.class).add(XmlNormalizedNodeBodyReader.class) .add(SchemaExportContentYinBodyWriter.class).add(SchemaExportContentYangBodyWriter.class) - .add(JsonToPatchBodyReader.class).add(XmlToPatchBodyReader.class) .add(PatchJsonBodyWriter.class).add(PatchXmlBodyWriter.class) .build(); } @@ -40,6 +40,10 @@ public class RestconfApplication extends Application { public Set getSingletons() { final Set singletons = new HashSet<>(); singletons.add(ServicesWrapperImpl.getInstance()); + singletons.add(new JsonNormalizedNodeBodyReader(schemaContextHandler)); + singletons.add(new JsonToPatchBodyReader(schemaContextHandler)); + singletons.add(new XmlNormalizedNodeBodyReader(schemaContextHandler)); + singletons.add(new XmlToPatchBodyReader(schemaContextHandler)); return singletons; } } 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 65534bf16f..aecbf8d6ae 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 @@ -8,16 +8,17 @@ package org.opendaylight.restconf.nb.rfc8040.handlers; import com.google.common.base.Preconditions; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Collection; import java.util.concurrent.atomic.AtomicInteger; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary; import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule; import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil; +import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; @@ -26,6 +27,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,25 +35,57 @@ import org.slf4j.LoggerFactory; * Implementation of {@link SchemaContextHandler}. * */ -public class SchemaContextHandler implements SchemaContextListenerHandler { +@SuppressWarnings("checkstyle:FinalClass") +public class SchemaContextHandler implements SchemaContextListenerHandler, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(SchemaContextHandler.class); - @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") - private static volatile SchemaContext schemaContext; - - private final TransactionChainHandler transactionChainHandler; + private static final SchemaContextHandler INSTANCE = new SchemaContextHandler(); private final AtomicInteger moduleSetId = new AtomicInteger(0); + private TransactionChainHandler transactionChainHandler; + private DOMSchemaService domSchemaService; + private ListenerRegistration listenerRegistration; + + private volatile SchemaContext schemaContext; + /** * Constructor. * * @param transactionChainHandler Transaction chain handler */ - public SchemaContextHandler(final TransactionChainHandler transactionChainHandler) { + private SchemaContextHandler(final TransactionChainHandler transactionChainHandler, + final DOMSchemaService domSchemaService) { this.transactionChainHandler = transactionChainHandler; - schemaContext = null; + this.domSchemaService = domSchemaService; + } + + @Deprecated + private SchemaContextHandler() { + } + + @Deprecated + public static SchemaContextHandler instance() { + return INSTANCE; + } + + public static SchemaContextHandler newInstance(TransactionChainHandler transactionChainHandler, + DOMSchemaService domSchemaService) { + INSTANCE.transactionChainHandler = transactionChainHandler; + INSTANCE.domSchemaService = domSchemaService; + return INSTANCE; + } + + public void init() { + listenerRegistration = domSchemaService.registerSchemaContextListener(this); + } + + @Override + public void close() { + if (listenerRegistration != null) { + listenerRegistration.close(); + } } @Override @@ -62,15 +96,20 @@ public class SchemaContextHandler implements SchemaContextListenerHandler { final Module ietfYangLibraryModule = context.findModule(IetfYangLibrary.MODULE_QNAME).orElse(null); - NormalizedNode>> normNode = - RestconfMappingNodeUtil.mapModulesByIetfYangLibraryYang(context.getModules(), ietfYangLibraryModule, - context, String.valueOf(this.moduleSetId.incrementAndGet())); - putData(normNode); + if (ietfYangLibraryModule != null) { + NormalizedNode>> normNode = + RestconfMappingNodeUtil.mapModulesByIetfYangLibraryYang(context.getModules(), ietfYangLibraryModule, + context, String.valueOf(this.moduleSetId.incrementAndGet())); + putData(normNode); + } final Module monitoringModule = schemaContext.findModule(MonitoringModule.MODULE_QNAME).orElse(null); - normNode = RestconfMappingNodeUtil.mapCapabilites(monitoringModule); - putData(normNode); + if (monitoringModule != null) { + NormalizedNode>> normNode = + RestconfMappingNodeUtil.mapCapabilites(monitoringModule); + putData(normNode); + } } @Override @@ -78,14 +117,6 @@ public class SchemaContextHandler implements SchemaContextListenerHandler { return schemaContext; } - public static SchemaContext getSchemaContext() { - return schemaContext; - } - - public static void setSchemaContext(final SchemaContext context) { - schemaContext = context; - } - private void putData( final NormalizedNode>> normNode) { final DOMDataWriteTransaction wTx = this.transactionChainHandler.get().newWriteOnlyTransaction(); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java index 83b927a7bb..e03f60c805 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java @@ -25,6 +25,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; import org.opendaylight.restconf.nb.rfc8040.Rfc8040; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractNormalizedNodeBodyReader; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -50,9 +51,12 @@ import org.slf4j.LoggerFactory; @Provider @Consumes({ Rfc8040.MediaTypes.DATA + RestconfConstants.JSON, MediaType.APPLICATION_JSON }) public class JsonNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader { - private static final Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class); + public JsonNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler) { + super(schemaContextHandler); + } + @SuppressWarnings("checkstyle:IllegalCatch") @Override protected NormalizedNodeContext readBody(final InstanceIdentifierContext path, final InputStream entityStream) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java index 54ea4fe368..a2e873a067 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java @@ -30,6 +30,7 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; import org.opendaylight.restconf.nb.rfc8040.Rfc8040; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractNormalizedNodeBodyReader; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; import org.opendaylight.yangtools.util.xml.UntrustedXML; @@ -63,6 +64,10 @@ import org.xml.sax.SAXException; public class XmlNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader { private static final Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class); + public XmlNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler) { + super(schemaContextHandler); + } + @SuppressWarnings("checkstyle:IllegalCatch") @Override protected NormalizedNodeContext readBody(final InstanceIdentifierContext path, final InputStream entityStream) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractToPatchBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractToPatchBodyReader.java index e2e7fdc21d..963194001e 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractToPatchBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractToPatchBodyReader.java @@ -9,6 +9,7 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.patch.PatchContext; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider; /** @@ -17,6 +18,9 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentif * @author Robert Varga */ abstract class AbstractToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider { + protected AbstractToPatchBodyReader(SchemaContextHandler schemaContextHandler) { + super(schemaContextHandler); + } @Override protected final PatchContext emptyBody(final InstanceIdentifierContext path) { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java index 9985f76861..489f8e0e32 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.ws.rs.Consumes; import javax.ws.rs.WebApplicationException; @@ -57,7 +58,9 @@ import org.slf4j.LoggerFactory; public class JsonToPatchBodyReader extends AbstractToPatchBodyReader { private static final Logger LOG = LoggerFactory.getLogger(JsonToPatchBodyReader.class); - private String patchId; + public JsonToPatchBodyReader(SchemaContextHandler schemaContextHandler) { + super(schemaContextHandler); + } @SuppressWarnings("checkstyle:IllegalCatch") @Override @@ -73,10 +76,11 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader { private PatchContext readFrom(final InstanceIdentifierContext path, final InputStream entityStream) throws IOException { final JsonReader jsonReader = new JsonReader(new InputStreamReader(entityStream, StandardCharsets.UTF_8)); - final List resultList = read(jsonReader, path); + AtomicReference patchId = new AtomicReference<>(); + final List resultList = read(jsonReader, path, patchId); jsonReader.close(); - return new PatchContext(path, resultList, patchId); + return new PatchContext(path, resultList, patchId.get()); } @SuppressWarnings("checkstyle:IllegalCatch") @@ -84,7 +88,7 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader { RestconfDocumentedException { try { return readFrom( - ParserIdentifier.toInstanceIdentifier(uriPath, SchemaContextHandler.getSchemaContext(), + ParserIdentifier.toInstanceIdentifier(uriPath, getSchemaContext(), Optional.of(RestConnectorProvider.getMountPointService())), entityStream); } catch (final Exception e) { propagateExceptionAs(e); @@ -106,7 +110,8 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader { ErrorTag.MALFORMED_MESSAGE, exception); } - private List read(final JsonReader in, final InstanceIdentifierContext path) throws IOException { + private List read(final JsonReader in, final InstanceIdentifierContext path, + final AtomicReference patchId) throws IOException { final List resultCollection = new ArrayList<>(); final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec( path.getSchemaContext()); @@ -133,7 +138,7 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader { case END_DOCUMENT: break; case NAME: - parseByName(in.nextName(), edit, in, path, codec, resultCollection); + parseByName(in.nextName(), edit, in, path, codec, resultCollection, patchId); break; case END_OBJECT: in.endObject(); @@ -164,7 +169,8 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader { private void parseByName(@Nonnull final String name, @Nonnull final PatchEdit edit, @Nonnull final JsonReader in, @Nonnull final InstanceIdentifierContext path, @Nonnull final StringModuleInstanceIdentifierCodec codec, - @Nonnull final List resultCollection) throws IOException { + @Nonnull final List resultCollection, + @Nonnull final AtomicReference patchId) throws IOException { switch (name) { case "edit": if (in.peek() == JsonToken.BEGIN_ARRAY) { @@ -185,7 +191,7 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader { break; case "patch-id": - this.patchId = in.nextString(); + patchId.set(in.nextString()); break; default: break; diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java index 7af6e56b32..338c605867 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java @@ -34,6 +34,7 @@ import org.opendaylight.restconf.common.patch.PatchEditOperation; import org.opendaylight.restconf.common.patch.PatchEntity; import org.opendaylight.restconf.nb.rfc8040.Rfc8040; import org.opendaylight.restconf.nb.rfc8040.codecs.StringModuleInstanceIdentifierCodec; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.common.QName; @@ -66,6 +67,10 @@ public class XmlToPatchBodyReader extends AbstractToPatchBodyReader { private static final Logger LOG = LoggerFactory.getLogger(XmlToPatchBodyReader.class); private static final Splitter SLASH_SPLITTER = Splitter.on('/'); + public XmlToPatchBodyReader(SchemaContextHandler schemaContextHandler) { + super(schemaContextHandler); + } + @SuppressWarnings("checkstyle:IllegalCatch") @Override protected PatchContext readBody(final InstanceIdentifierContext path, final InputStream entityStream) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java index 8028ee94d8..a3398aa7b2 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java @@ -27,6 +27,7 @@ import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; public abstract class AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader { @@ -36,6 +37,12 @@ public abstract class AbstractIdentifierAwareJaxRsProvider implements Message @Context private Request request; + private final SchemaContextHandler schemaContextHandler; + + protected AbstractIdentifierAwareJaxRsProvider(SchemaContextHandler schemaContextHandler) { + this.schemaContextHandler = schemaContextHandler; + } + @Override public final boolean isReadable(final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) { @@ -78,9 +85,7 @@ public abstract class AbstractIdentifierAwareJaxRsProvider implements Message } private InstanceIdentifierContext getInstanceIdentifierContext() { - return ParserIdentifier.toInstanceIdentifier( - getIdentifier(), - SchemaContextHandler.getSchemaContext(), + return ParserIdentifier.toInstanceIdentifier(getIdentifier(), getSchemaContext(), Optional.of(RestConnectorProvider.getMountPointService())); } @@ -88,6 +93,10 @@ public abstract class AbstractIdentifierAwareJaxRsProvider implements Message return this.uriInfo; } + protected SchemaContext getSchemaContext() { + return schemaContextHandler.get(); + } + protected boolean isPost() { return HttpMethod.POST.equals(this.request.getMethod()); } diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractNormalizedNodeBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractNormalizedNodeBodyReader.java index 61147543e2..3e2862ee71 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractNormalizedNodeBodyReader.java @@ -12,6 +12,7 @@ import javax.ws.rs.core.Request; import javax.ws.rs.core.UriInfo; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.context.NormalizedNodeContext; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; /** * Common superclass for readers producing {@link NormalizedNodeContext}. @@ -21,6 +22,9 @@ import org.opendaylight.restconf.common.context.NormalizedNodeContext; @Beta public abstract class AbstractNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider { + protected AbstractNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler) { + super(schemaContextHandler); + } public final void injectParams(final UriInfo uriInfo, final Request request) { setUriInfo(uriInfo); 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 8ec497f31e..52664062ec 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 @@ -60,11 +60,14 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto private final TransactionServicesWrapper services; private final DOMMountPointServiceHandler mountPointServiceHandler; + private final SchemaContextHandler schemaContextHandler; public JSONRestconfServiceRfc8040Impl(final TransactionServicesWrapper services, - final DOMMountPointServiceHandler mountPointServiceHandler) { + final DOMMountPointServiceHandler mountPointServiceHandler, + final SchemaContextHandler schemaContextHandler) { this.services = services; this.mountPointServiceHandler = mountPointServiceHandler; + this.schemaContextHandler = schemaContextHandler; } @SuppressWarnings("checkstyle:IllegalCatch") @@ -192,7 +195,7 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); - JsonToPatchBodyReader jsonToPatchBodyReader = new JsonToPatchBodyReader(); + JsonToPatchBodyReader jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler); final PatchContext context = jsonToPatchBodyReader.readFrom(uriPath, entityStream); LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier()); @@ -214,8 +217,7 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto private NormalizedNodeContext toNormalizedNodeContext(final String uriPath, @Nullable final String payload, final boolean isPost) throws OperationFailedException { final InstanceIdentifierContext instanceIdentifierContext = ParserIdentifier.toInstanceIdentifier( - uriPath, SchemaContextHandler.getSchemaContext(), - Optional.of(mountPointServiceHandler.get())); + uriPath, schemaContextHandler.get(), Optional.of(mountPointServiceHandler.get())); if (payload == null) { return new NormalizedNodeContext(instanceIdentifierContext, null); diff --git a/restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml b/restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml index acf12a8119..943639892e 100644 --- a/restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml +++ b/restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml @@ -44,6 +44,12 @@ + + + + + @@ -52,6 +58,7 @@ + @@ -66,6 +73,7 @@ + (mockDataBroker, domSchemaService, mockRpcService, - mockNotificationService, mockMountPointService, - new TransactionChainHandler(mockDataBroker), ServicesWrapperImpl.getInstance()); + mockNotificationService, mockMountPointService, transactionChainHandler, + SchemaContextHandler.newInstance(transactionChainHandler, domSchemaService), + ServicesWrapperImpl.getInstance()); } /** @@ -72,7 +74,6 @@ public class RestConnectorProviderTest { // verify interactions verify(mockDataBroker).createTransactionChain(Mockito.any()); - verify(domSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class)); } /** @@ -93,8 +94,5 @@ public class RestConnectorProviderTest { // close this.connectorProvider.close(); - - // verify interaction - verify(this.mockRegistration).close(); } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java index ab7ad9bf87..be8b993ae3 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java @@ -8,8 +8,12 @@ package org.opendaylight.restconf.nb.rfc8040; import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.Futures; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; @@ -35,6 +39,13 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.mockito.Mockito; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; +import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.Revision; @@ -263,4 +274,18 @@ public final class TestUtils { return mapEntryNode.build(); } + + public static SchemaContextHandler newSchemaContextHandler(SchemaContext schemaContext) { + DOMDataBroker mockDataBroker = mock(DOMDataBroker.class); + DOMTransactionChain mockChain = mock(DOMTransactionChain.class); + DOMDataWriteTransaction mockTx = mock(DOMDataWriteTransaction.class); + doReturn(Futures.immediateCheckedFuture(null)).when(mockTx).submit(); + doReturn(mockTx).when(mockChain).newWriteOnlyTransaction(); + + doReturn(mockChain).when(mockDataBroker).createTransactionChain(any()); + SchemaContextHandler schemaContextHandler = SchemaContextHandler.newInstance( + new TransactionChainHandler(mockDataBroker), Mockito.mock(DOMSchemaService.class)); + schemaContextHandler.onGlobalContextUpdated(schemaContext); + return schemaContextHandler; + } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandlerTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandlerTest.java index ef4c63b985..8ea9b45275 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandlerTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandlerTest.java @@ -10,7 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040.handlers; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; import com.google.common.util.concurrent.CheckedFuture; import org.junit.Before; @@ -19,7 +18,9 @@ import org.mockito.Mockito; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; +import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -33,6 +34,7 @@ public class SchemaContextHandlerTest { private SchemaContextHandler schemaContextHandler; private SchemaContext schemaContext; + private final DOMSchemaService mockDOMSchemaService = Mockito.mock(DOMSchemaService.class); @Before public void setup() throws Exception { @@ -44,7 +46,9 @@ public class SchemaContextHandlerTest { final CheckedFuture checked = Mockito.mock(CheckedFuture.class); Mockito.when(wTx.submit()).thenReturn(checked); Mockito.when(checked.checkedGet()).thenReturn(null); - this.schemaContextHandler = new SchemaContextHandler(txHandler); + + + this.schemaContextHandler = SchemaContextHandler.newInstance(txHandler, mockDOMSchemaService); this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_ACTUAL_SCHEMA_CONTEXT)); @@ -52,11 +56,21 @@ public class SchemaContextHandlerTest { } /** - * Testing init of {@link SchemaContextHandler}. + * Testing init and close. */ @Test - public void schemaContextHandlerImplInitTest() { - assertNotNull("Handler should be created and not null", this.schemaContextHandler); + public void testInitAndClose() { + ListenerRegistration mockListenerReg = Mockito.mock(ListenerRegistration.class); + Mockito.doReturn(mockListenerReg).when(mockDOMSchemaService) + .registerSchemaContextListener(schemaContextHandler); + + schemaContextHandler.init(); + + Mockito.verify(mockDOMSchemaService).registerSchemaContextListener(schemaContextHandler); + + schemaContextHandler.close(); + + Mockito.verify(mockListenerReg).close(); } /** diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java index 6290961e1d..aa33375b57 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java @@ -30,7 +30,6 @@ import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest; import org.opendaylight.yangtools.yang.common.QName; @@ -54,7 +53,8 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest { URI.create("instance:identifier:module"), Revision.of("2014-01-17")); public XmlBodyReaderMountPointTest() throws Exception { - this.xmlBodyReader = new XmlNormalizedNodeBodyReader(); + super(schemaContext); + this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler); } @Override @@ -74,7 +74,6 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest { when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mountPointService); when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint)); when(mountPoint.getSchemaContext()).thenReturn(schemaContext); - SchemaContextHandler.setSchemaContext(schemaContext); } @Test diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java index fa0d482fde..1453027ed5 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java @@ -24,7 +24,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.patch.PatchContext; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -37,7 +36,8 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest { private final JsonToPatchBodyReader jsonToPatchBodyReader; public JsonPatchBodyReaderMountPointTest() throws Exception { - jsonToPatchBodyReader = new JsonToPatchBodyReader(); + super(schemaContext); + jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler); } @Override @@ -55,7 +55,6 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest { when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mountPointService); when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint)); when(mountPoint.getSchemaContext()).thenReturn(schemaContext); - SchemaContextHandler.setSchemaContext(schemaContext); } @Test diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java index e5824c9217..770746ce81 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java @@ -21,7 +21,6 @@ import org.junit.Test; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.patch.PatchContext; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -32,7 +31,8 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest { private static SchemaContext schemaContext; public JsonPatchBodyReaderTest() throws Exception { - jsonToPatchBodyReader = new JsonToPatchBodyReader(); + super(schemaContext); + jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler); } @Override @@ -44,7 +44,6 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest { public static void initialization() { schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext); when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class)); - SchemaContextHandler.setSchemaContext(schemaContext); } @Test diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java index 00c200ea27..c638331097 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java @@ -23,7 +23,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.patch.PatchContext; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -36,7 +35,8 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest { private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount/"; public XmlPatchBodyReaderMountPointTest() throws Exception { - xmlToPatchBodyReader = new XmlToPatchBodyReader(); + super(schemaContext); + xmlToPatchBodyReader = new XmlToPatchBodyReader(schemaContextHandler); } @Override @@ -54,7 +54,6 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest { when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mountPointService); when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint)); when(mountPoint.getSchemaContext()).thenReturn(schemaContext); - SchemaContextHandler.setSchemaContext(schemaContext); } @Test diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java index aee4a97663..f98f576a95 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java @@ -20,7 +20,6 @@ import org.junit.Test; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.patch.PatchContext; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -31,7 +30,8 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest { private static SchemaContext schemaContext; public XmlPatchBodyReaderTest() throws Exception { - xmlToPatchBodyReader = new XmlToPatchBodyReader(); + super(schemaContext); + xmlToPatchBodyReader = new XmlToPatchBodyReader(schemaContextHandler); } @Override @@ -43,7 +43,6 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest { public static void initialization() { schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext); when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class)); - SchemaContextHandler.setSchemaContext(schemaContext); } @Test diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java index 990340edae..a112fd0015 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java @@ -23,7 +23,9 @@ import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.patch.PatchContext; import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; +import org.opendaylight.restconf.nb.rfc8040.TestUtils; import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler; +import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider; import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -34,14 +36,17 @@ public abstract class AbstractBodyReaderTest { mock(DOMMountPointServiceHandler.class); protected final MediaType mediaType; + protected final SchemaContextHandler schemaContextHandler; - protected AbstractBodyReaderTest() throws NoSuchFieldException, IllegalAccessException { + protected AbstractBodyReaderTest(SchemaContext schemaContext) throws NoSuchFieldException, IllegalAccessException { mediaType = getMediaType(); final Field mountPointServiceHandlerField = RestConnectorProvider.class.getDeclaredField("mountPointServiceHandler"); mountPointServiceHandlerField.setAccessible(true); mountPointServiceHandlerField.set(RestConnectorProvider.class, MOUNT_POINT_SERVICE_HANDLER); + + schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext); } protected abstract MediaType getMediaType(); diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java index 41283b63f8..b372915132 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java @@ -25,7 +25,6 @@ import org.junit.Test; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; @@ -49,7 +48,8 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest { URI.create("instance:identifier:module"), Revision.of("2014-01-17")); public JsonBodyReaderTest() throws Exception { - this.jsonBodyReader = new JsonNormalizedNodeBodyReader(); + super(schemaContext); + this.jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler); } @Override @@ -64,7 +64,6 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest { testFiles.addAll(TestRestconfUtils.loadFiles("/modules")); schemaContext = YangParserTestUtils.parseYangFiles(testFiles); when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class)); - SchemaContextHandler.setSchemaContext(schemaContext); } @Test diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java index d3529d0ab0..ead68d4848 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.java @@ -29,7 +29,6 @@ import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; -import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyReader; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; @@ -53,7 +52,8 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest { URI.create("instance:identifier:module"), Revision.of("2014-01-17")); public XmlBodyReaderTest() throws Exception { - this.xmlBodyReader = new XmlNormalizedNodeBodyReader(); + super(schemaContext); + this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler); } @Override @@ -68,7 +68,6 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest { testFiles.addAll(TestRestconfUtils.loadFiles("/foo-xml-test/yang")); schemaContext = YangParserTestUtils.parseYangFiles(testFiles); when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class)); - SchemaContextHandler.setSchemaContext(schemaContext); } @Test diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040ImplTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040ImplTest.java index c8821e8e7b..681dd4db76 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040ImplTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040ImplTest.java @@ -128,9 +128,6 @@ public class JSONRestconfServiceRfc8040ImplTest { @Mock private DOMMountPointService mockMountPointService; - @Mock - private SchemaContextHandler mockSchemaContextHandler; - @Mock private DOMDataBroker mockDOMDataBroker; @@ -142,10 +139,11 @@ public class JSONRestconfServiceRfc8040ImplTest { private JSONRestconfServiceRfc8040Impl service; + private final SchemaContextHandler schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext); + @BeforeClass public static void init() throws IOException, ReactorException { schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs"); - SchemaContextHandler.setSchemaContext(schemaContext); } @SuppressWarnings("resource") @@ -177,25 +175,22 @@ public class JSONRestconfServiceRfc8040ImplTest { doReturn(mockTxChain).when(mockDOMDataBroker).createTransactionChain(any()); - doReturn(schemaContext).when(mockSchemaContextHandler).get(); - final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockDOMDataBroker); final DOMMountPointServiceHandler mountPointServiceHandler = new DOMMountPointServiceHandler(mockMountPointService); final DOMNotificationService mockNotificationService = mock(DOMNotificationService.class); - ServicesWrapperImpl.getInstance().setHandlers(mockSchemaContextHandler, mountPointServiceHandler, + ServicesWrapperImpl.getInstance().setHandlers(schemaContextHandler, mountPointServiceHandler, txChainHandler, new DOMDataBrokerHandler(mockDOMDataBroker), new RpcServiceHandler(mockRpcService), new NotificationServiceHandler(mockNotificationService), domSchemaService); - service = new JSONRestconfServiceRfc8040Impl(ServicesWrapperImpl.getInstance(), mountPointServiceHandler); + service = new JSONRestconfServiceRfc8040Impl(ServicesWrapperImpl.getInstance(), mountPointServiceHandler, + schemaContextHandler); new RestConnectorProvider<>(mockDOMDataBroker, domSchemaService, mockRpcService, mockNotificationService, - mockMountPointService, txChainHandler, null).start(); - - SchemaContextHandler.setSchemaContext(schemaContext); + mockMountPointService, txChainHandler, schemaContextHandler, null).start(); } private static String loadData(final String path) throws IOException { diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java index de78c34c9d..37e62b0bbc 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java @@ -45,6 +45,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; @@ -184,7 +185,8 @@ public class RestconfDataServiceImplTest { transactionChainHandler = new TransactionChainHandler(mockDataBroker); - final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(transactionChainHandler); + final SchemaContextHandler schemaContextHandler = SchemaContextHandler.newInstance(transactionChainHandler, + Mockito.mock(DOMSchemaService.class)); schemaContextHandler.onGlobalContextUpdated(this.contextRef.get()); this.dataService = new RestconfDataServiceImpl(schemaContextHandler, this.transactionChainHandler, diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java index 87998c82aa..f8ab905c79 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java @@ -23,6 +23,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcException; import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; @@ -61,7 +62,8 @@ public class RestconfInvokeOperationsServiceImplTest { final CheckedFuture checked = Mockito.mock(CheckedFuture.class); Mockito.when(wTx.submit()).thenReturn(checked); Mockito.when(checked.checkedGet()).thenReturn(null); - final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler); + final SchemaContextHandler schemaContextHandler = + SchemaContextHandler.newInstance(txHandler, Mockito.mock(DOMSchemaService.class)); schemaContextHandler.onGlobalContextUpdated(contextRef.get()); this.invokeOperationsService = new RestconfInvokeOperationsServiceImpl(this.rpcServiceHandler, schemaContextHandler); 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 bda60dd71d..b7d476fa07 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 @@ -42,6 +42,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService; import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.util.SimpleUriInfo; @@ -70,9 +71,8 @@ public class RestconfStreamsSubscriptionServiceImplTest { private UriInfo uriInfo; @Mock private NotificationServiceHandler notificationServiceHandler; - @Mock - private TransactionChainHandler transactionHandler; + private TransactionChainHandler transactionHandler; private SchemaContextHandler schemaHandler; @SuppressWarnings("unchecked") @@ -80,10 +80,7 @@ public class RestconfStreamsSubscriptionServiceImplTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - final TransactionChainHandler txHandler = mock(TransactionChainHandler.class); final DOMTransactionChain domTx = mock(DOMTransactionChain.class); - Mockito.when(this.transactionHandler.get()).thenReturn(domTx); - Mockito.when(txHandler.get()).thenReturn(domTx); final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class); Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx); final DOMDataReadWriteTransaction rwTx = Mockito.mock(DOMDataReadWriteTransaction.class); @@ -96,9 +93,12 @@ public class RestconfStreamsSubscriptionServiceImplTest { final CheckedFuture checked = mock(CheckedFuture.class); Mockito.when(wTx.submit()).thenReturn(checked); Mockito.when(checked.checkedGet()).thenReturn(null); - this.schemaHandler = new SchemaContextHandler(txHandler); final DOMDataBroker dataBroker = mock(DOMDataBroker.class); + doReturn(domTx).when(dataBroker).createTransactionChain(any()); + + transactionHandler = new TransactionChainHandler(dataBroker); + schemaHandler = SchemaContextHandler.newInstance(transactionHandler, Mockito.mock(DOMSchemaService.class)); DOMDataTreeChangeService dataTreeChangeService = mock(DOMDataTreeChangeService.class); doReturn(mock(ListenerRegistration.class)).when(dataTreeChangeService) diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfImplTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfImplTest.java index dcfa41a805..bec5c7be12 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfImplTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfImplTest.java @@ -7,18 +7,13 @@ */ package org.opendaylight.restconf.nb.rfc8040.services.simple.impl; -import com.google.common.util.concurrent.CheckedFuture; import org.junit.Assert; import org.junit.Test; -import org.mockito.Mockito; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; +import org.opendaylight.restconf.nb.rfc8040.TestUtils; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; -import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -29,18 +24,7 @@ public class RestconfImplTest { public void restImplTest() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/impl")); - - final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class); - final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class); - Mockito.when(txHandler.get()).thenReturn(domTx); - final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class); - Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx); - final CheckedFuture checked = Mockito.mock(CheckedFuture.class); - Mockito.when(wTx.submit()).thenReturn(checked); - Mockito.when(checked.checkedGet()).thenReturn(null); - final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler); - schemaContextHandler.onGlobalContextUpdated(schemaContext); - + final SchemaContextHandler schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext); final RestconfImpl restconfImpl = new RestconfImpl(schemaContextHandler); final NormalizedNodeContext libraryVersion = restconfImpl.getLibraryVersion(); final LeafNode value = (LeafNode) libraryVersion.getData(); diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfOperationsServiceTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfOperationsServiceTest.java index 562a1f2bbe..078f27534b 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfOperationsServiceTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfOperationsServiceTest.java @@ -11,23 +11,19 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableSet; -import com.google.common.util.concurrent.Futures; import java.net.URI; import java.util.Set; import javax.ws.rs.core.UriInfo; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; -import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; +import org.opendaylight.restconf.nb.rfc8040.TestUtils; import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; -import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler; import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; @@ -55,15 +51,7 @@ public class RestconfOperationsServiceTest { public void init() throws Exception { MockitoAnnotations.initMocks(this); this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules")); - - final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class); - final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class); - Mockito.when(txHandler.get()).thenReturn(domTx); - final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class); - Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx); - Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null)); - this.schemaContextHandler = new SchemaContextHandler(txHandler); - this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext); + this.schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext); this.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService); diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java index d80a86f004..5d1d335380 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java @@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit; import org.json.JSONObject; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; @@ -31,6 +32,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler; import org.opendaylight.yang.gen.v1.instance.identifier.patch.module.rev151121.PatchCont; @@ -72,8 +74,9 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest { "/instanceidentifier/yang/instance-identifier-patch-module.yang"); transactionChainHandler = new TransactionChainHandler(domDataBroker); - schemaContextHandler = new SchemaContextHandler(transactionChainHandler); - SchemaContextHandler.setSchemaContext(sc); + schemaContextHandler = SchemaContextHandler.newInstance(transactionChainHandler, + Mockito.mock(DOMSchemaService.class)); + schemaContextHandler.onGlobalContextUpdated(sc); } class ListenerAdapterTester extends ListenerAdapter {