+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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 com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.util.Set;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-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.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;
-
-/**
- * Provider for restconf draft18.
- *
- */
-public class RestConnectorProvider<T extends ServiceWrapper> implements RestconfConnector, AutoCloseable {
-
- private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
-
- public static final TransactionChainListener TRANSACTION_CHAIN_LISTENER = new TransactionChainListener() {
- @Override
- public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
- final AsyncTransaction<?, ?> transaction, final Throwable cause) {
- LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
- resetTransactionChainForAdapaters(chain);
- throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
- }
-
- @Override
- public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
- LOG.trace("TransactionChain({}) {} SUCCESSFUL", chain);
- }
- };
-
- @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
- private static volatile TransactionChainHandler transactionChainHandler;
- @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
- private static volatile DOMDataBroker dataBroker;
- @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
- private static volatile DOMMountPointServiceHandler mountPointServiceHandler;
-
- private final DOMRpcService rpcService;
- private final DOMNotificationService notificationService;
- private final DOMMountPointService mountPointService;
- private final DOMSchemaService domSchemaService;
- private final Builder<Object> servicesProperties;
-
- private ListenerRegistration<SchemaContextListener> listenerRegistration;
- private SchemaContextHandler schemaCtxHandler;
- private T wrapperServices;
-
- // FIXME: refactor this class and its users to interact via builder pattern, where individual
- // services are injected and then the provider is created
- public RestConnectorProvider(final DOMDataBroker domDataBroker,
- final DOMSchemaService domSchemaService, final DOMRpcService rpcService,
- final DOMNotificationService notificationService, final DOMMountPointService mountPointService) {
- this(domDataBroker, domSchemaService, rpcService, notificationService, mountPointService, null);
- }
-
- public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
- final DOMRpcService rpcService, final DOMNotificationService notificationService,
- final DOMMountPointService mountPointService, final T wrapperServices) {
- this.servicesProperties = ImmutableSet.<Object>builder();
- this.wrapperServices = wrapperServices;
- this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
- this.rpcService = Preconditions.checkNotNull(rpcService);
- this.notificationService = Preconditions.checkNotNull(notificationService);
- this.mountPointService = Preconditions.checkNotNull(mountPointService);
-
- RestConnectorProvider.dataBroker = Preconditions.checkNotNull(domDataBroker);
- }
-
- public synchronized void start() {
- mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
- servicesProperties.add(mountPointServiceHandler);
-
- final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
- servicesProperties.add(brokerHandler);
-
- RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(dataBroker
- .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER));
- servicesProperties.add(transactionChainHandler);
-
- this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
- servicesProperties.add(schemaCtxHandler);
- this.listenerRegistration = domSchemaService.registerSchemaContextListener(this.schemaCtxHandler);
-
- final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
- servicesProperties.add(rpcServiceHandler);
-
- final NotificationServiceHandler notificationServiceHandler =
- new NotificationServiceHandler(notificationService);
- servicesProperties.add(notificationServiceHandler);
-
- if (wrapperServices != null) {
- wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
- RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler,
- notificationServiceHandler, domSchemaService);
- }
- }
-
- public DOMMountPointServiceHandler getMountPointServiceHandler() {
- return mountPointServiceHandler;
- }
-
- /**
- * After {@link TransactionChain} failed, this updates {@link TransactionChainHandler} with new transaction chain.
- *
- * @param chain
- * old {@link TransactionChain}
- */
- public static void resetTransactionChainForAdapaters(final TransactionChain<?, ?> chain) {
- LOG.trace("Resetting TransactionChain({})", chain);
- chain.close();
- RestConnectorProvider.transactionChainHandler.update(
- Preconditions.checkNotNull(dataBroker).createTransactionChain(
- RestConnectorProvider.TRANSACTION_CHAIN_LISTENER)
- );
- }
-
- /**
- * Get current {@link DOMMountPointService} from {@link DOMMountPointServiceHandler}.
- * @return {@link DOMMountPointService}
- */
- public static DOMMountPointService getMountPointService() {
- return mountPointServiceHandler.get();
- }
-
- @Override
- public void close() throws Exception {
- // close registration
- if (this.listenerRegistration != null) {
- this.listenerRegistration.close();
- }
-
- // close transaction chain
- if (transactionChainHandler != null && transactionChainHandler.get() != null) {
- transactionChainHandler.get().close();
- }
-
- transactionChainHandler = null;
- mountPointServiceHandler = null;
- dataBroker = null;
- }
-
- public final synchronized Set<Object> getServicesProperties() {
- return servicesProperties.build();
- }
-}
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+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;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlToPatchBodyReader;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYangBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYinBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
public class RestconfApplication extends Application {
+ private final SchemaContextHandler schemaContextHandler = SchemaContextHandler.instance();
+ private final DOMMountPointServiceHandler mountPointServiceHandler = DOMMountPointServiceHandler.instance();
@Override
public Set<Class<?>> getClasses() {
return ImmutableSet.<Class<?>>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();
}
@Override
public Set<Object> getSingletons() {
final Set<Object> singletons = new HashSet<>();
- singletons.add(ServicesWrapperImpl.getInstance());
+ singletons.add(ServicesWrapper.getInstance());
+ singletons.add(new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
+ singletons.add(new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
+ singletons.add(new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
+ singletons.add(new XmlToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
return singletons;
}
}
+++ /dev/null
-/*
- * Copyright (c) 2014, 2015 Cisco Systems, 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;
-
-/*
- * This is a simple dummy interface to allow us to create instances of RestconfProvider
- * via the config subsystem.
- */
-public interface RestconfConnector {
-
-}
* Implementation of {@link DOMMountPointServiceHandler}.
*
*/
-public class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
- private final DOMMountPointService domMountPointService;
+public final class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
+ private static final DOMMountPointServiceHandler INSTANCE = new DOMMountPointServiceHandler();
+
+ private DOMMountPointService domMountPointService;
/**
* Prepare mount point service for Restconf services.
* @param domMountPointService
* mount point service
*/
- public DOMMountPointServiceHandler(final DOMMountPointService domMountPointService) {
+ private DOMMountPointServiceHandler(final DOMMountPointService domMountPointService) {
this.domMountPointService = Objects.requireNonNull(domMountPointService);
}
+ @Deprecated
+ private DOMMountPointServiceHandler() {
+ }
+
+ @Deprecated
+ public static DOMMountPointServiceHandler instance() {
+ return INSTANCE;
+ }
+
+ public static DOMMountPointServiceHandler newInstance(DOMMountPointService domMountPointService) {
+ INSTANCE.domMountPointService = domMountPointService;
+ return INSTANCE;
+ }
+
@Override
public DOMMountPointService get() {
return this.domMountPointService;
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.RestConnectorProvider;
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;
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;
* 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<SchemaContextListener> 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
final Module ietfYangLibraryModule =
context.findModule(IetfYangLibrary.MODULE_QNAME).orElse(null);
- NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode =
- RestconfMappingNodeUtil.mapModulesByIetfYangLibraryYang(context.getModules(), ietfYangLibraryModule,
- context, String.valueOf(this.moduleSetId.incrementAndGet()));
- putData(normNode);
+ if (ietfYangLibraryModule != null) {
+ NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> 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<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode =
+ RestconfMappingNodeUtil.mapCapabilites(monitoringModule);
+ putData(normNode);
+ }
}
@Override
return schemaContext;
}
- public static SchemaContext getSchemaContext() {
- return schemaContext;
- }
-
- public static void setSchemaContext(final SchemaContext context) {
- schemaContext = context;
- }
-
private void putData(
final NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode) {
final DOMDataWriteTransaction wTx = this.transactionChainHandler.get().newWriteOnlyTransaction();
https://bugs.opendaylight.org/show_bug.cgi?id=7728
*/
LOG.warn("Ignoring that another cluster node is already putting the same data to DS.", e);
- RestConnectorProvider.resetTransactionChainForAdapaters(this.transactionChainHandler.get());
+ this.transactionChainHandler.reset();
}
}
}
package org.opendaylight.restconf.nb.rfc8040.handlers;
-import com.google.common.base.Preconditions;
+import java.util.Objects;
+import javax.annotation.Nullable;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Implementation of {@link TransactionChainHandler}.
*
*/
-public class TransactionChainHandler implements Handler<DOMTransactionChain> {
+public class TransactionChainHandler implements Handler<DOMTransactionChain>, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(TransactionChainHandler.class);
- private DOMTransactionChain transactionChain;
+ private final TransactionChainListener transactionChainListener = new TransactionChainListener() {
+ @Override
+ public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+ final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+ LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
+ reset();
+ throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
+ }
+
+ @Override
+ public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
+ LOG.trace("TransactionChain({}) {} SUCCESSFUL", chain);
+ }
+ };
+
+ @Nullable
+ private final DOMDataBroker dataBroker;
+ private volatile DOMTransactionChain transactionChain;
/**
* Prepare transaction chain service for Restconf services.
- *
- * @param transactionChain Transaction chain
*/
- public TransactionChainHandler(final DOMTransactionChain transactionChain) {
- Preconditions.checkNotNull(transactionChain);
- this.transactionChain = transactionChain;
+ public TransactionChainHandler(final DOMDataBroker dataBroker) {
+ this.dataBroker = Objects.requireNonNull(dataBroker);
+ transactionChain = Objects.requireNonNull(dataBroker.createTransactionChain(transactionChainListener));
}
@Override
- @SuppressWarnings("checkstyle:hiddenField")
- public void update(final DOMTransactionChain transactionChain) {
- Preconditions.checkNotNull(transactionChain);
- this.transactionChain = transactionChain;
+ public DOMTransactionChain get() {
+ return this.transactionChain;
+ }
+
+ public synchronized void reset() {
+ LOG.trace("Resetting TransactionChain({})", transactionChain);
+ transactionChain.close();
+ transactionChain = dataBroker.createTransactionChain(transactionChainListener);
}
@Override
- public DOMTransactionChain get() {
- return this.transactionChain;
+ public synchronized void close() {
+ transactionChain.close();
}
}
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.DOMMountPointServiceHandler;
+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;
@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,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
+ }
+
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected NormalizedNodeContext readBody(final InstanceIdentifierContext<?> path, final InputStream entityStream)
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.DOMMountPointServiceHandler;
+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;
public class XmlNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader {
private static final Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class);
+ public XmlNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
+ }
+
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected NormalizedNodeContext readBody(final InstanceIdentifierContext<?> path, final InputStream entityStream)
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.patch.PatchContext;
+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;
/**
* @author Robert Varga
*/
abstract class AbstractToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider<PatchContext> {
+ protected AbstractToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
+ }
@Override
protected final PatchContext emptyBody(final InstanceIdentifierContext<?> path) {
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;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchEditOperation;
import org.opendaylight.restconf.common.patch.PatchEntity;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
import org.opendaylight.restconf.nb.rfc8040.codecs.StringModuleInstanceIdentifierCodec;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
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;
public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
private static final Logger LOG = LoggerFactory.getLogger(JsonToPatchBodyReader.class);
- private String patchId;
+ public JsonToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
+ }
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
private PatchContext readFrom(final InstanceIdentifierContext<?> path, final InputStream entityStream)
throws IOException {
final JsonReader jsonReader = new JsonReader(new InputStreamReader(entityStream, StandardCharsets.UTF_8));
- final List<PatchEntity> resultList = read(jsonReader, path);
+ AtomicReference<String> patchId = new AtomicReference<>();
+ final List<PatchEntity> resultList = read(jsonReader, path, patchId);
jsonReader.close();
- return new PatchContext(path, resultList, patchId);
+ return new PatchContext(path, resultList, patchId.get());
}
@SuppressWarnings("checkstyle:IllegalCatch")
RestconfDocumentedException {
try {
return readFrom(
- ParserIdentifier.toInstanceIdentifier(uriPath, SchemaContextHandler.getSchemaContext(),
- Optional.of(RestConnectorProvider.getMountPointService())), entityStream);
+ ParserIdentifier.toInstanceIdentifier(uriPath, getSchemaContext(),
+ Optional.fromNullable(getMountPointService())), entityStream);
} catch (final Exception e) {
propagateExceptionAs(e);
return null; // no-op
ErrorTag.MALFORMED_MESSAGE, exception);
}
- private List<PatchEntity> read(final JsonReader in, final InstanceIdentifierContext<?> path) throws IOException {
+ private List<PatchEntity> read(final JsonReader in, final InstanceIdentifierContext<?> path,
+ final AtomicReference<String> patchId) throws IOException {
final List<PatchEntity> resultCollection = new ArrayList<>();
final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec(
path.getSchemaContext());
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();
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<PatchEntity> resultCollection) throws IOException {
+ @Nonnull final List<PatchEntity> resultCollection,
+ @Nonnull final AtomicReference<String> patchId) throws IOException {
switch (name) {
case "edit":
if (in.peek() == JsonToken.BEGIN_ARRAY) {
break;
case "patch-id":
- this.patchId = in.nextString();
+ patchId.set(in.nextString());
break;
default:
break;
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.DOMMountPointServiceHandler;
+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;
private static final Logger LOG = LoggerFactory.getLogger(XmlToPatchBodyReader.class);
private static final Splitter SLASH_SPLITTER = Splitter.on('/');
+ public XmlToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
+ }
+
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected PatchContext readBody(final InstanceIdentifierContext<?> path, final InputStream entityStream)
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.MessageBodyReader;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
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<T> implements MessageBodyReader<T> {
@Context
private Request request;
+ private final SchemaContextHandler schemaContextHandler;
+ private final DOMMountPointServiceHandler mountPointServiceHandler;
+
+ protected AbstractIdentifierAwareJaxRsProvider(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ this.schemaContextHandler = schemaContextHandler;
+ this.mountPointServiceHandler = mountPointServiceHandler;
+ }
+
@Override
public final boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
final MediaType mediaType) {
}
private InstanceIdentifierContext<?> getInstanceIdentifierContext() {
- return ParserIdentifier.toInstanceIdentifier(
- getIdentifier(),
- SchemaContextHandler.getSchemaContext(),
- Optional.of(RestConnectorProvider.getMountPointService()));
+ return ParserIdentifier.toInstanceIdentifier(getIdentifier(), getSchemaContext(),
+ Optional.fromNullable(getMountPointService()));
}
protected UriInfo getUriInfo() {
return this.uriInfo;
}
+ protected SchemaContext getSchemaContext() {
+ return schemaContextHandler.get();
+ }
+
+ protected DOMMountPointService getMountPointService() {
+ return mountPointServiceHandler.get();
+ }
+
protected boolean isPost() {
return HttpMethod.POST.equals(this.request.getMethod());
}
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.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
/**
* Common superclass for readers producing {@link NormalizedNodeContext}.
@Beta
public abstract class AbstractNormalizedNodeBodyReader
extends AbstractIdentifierAwareJaxRsProvider<NormalizedNodeContext> {
+ protected AbstractNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler,
+ DOMMountPointServiceHandler mountPointServiceHandler) {
+ super(schemaContextHandler, mountPointServiceHandler);
+ }
public final void injectParams(final UriInfo uriInfo, final Request request) {
setUriInfo(uriInfo);
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")
final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
- JsonToPatchBodyReader jsonToPatchBodyReader = new JsonToPatchBodyReader();
+ JsonToPatchBodyReader jsonToPatchBodyReader =
+ new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
final PatchContext context = jsonToPatchBodyReader.readFrom(uriPath, entityStream);
LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
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);
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map.Entry;
+import java.util.Objects;
import javax.annotation.Nonnull;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.context.WriterParameters;
import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
final TransactionChainHandler transactionChainHandler,
final DOMMountPointServiceHandler mountPointServiceHandler,
final RestconfStreamsSubscriptionService delegRestconfSubscrService) {
- this.schemaContextHandler = schemaContextHandler;
- this.transactionChainHandler = transactionChainHandler;
- this.mountPointServiceHandler = mountPointServiceHandler;
- this.delegRestconfSubscrService = delegRestconfSubscrService;
+ this.schemaContextHandler = Objects.requireNonNull(schemaContextHandler);
+ this.transactionChainHandler = Objects.requireNonNull(transactionChainHandler);
+ this.mountPointServiceHandler = Objects.requireNonNull(mountPointServiceHandler);
+ this.delegRestconfSubscrService = Objects.requireNonNull(delegRestconfSubscrService);
}
@Override
instanceIdentifier, uriInfo, tagged);
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- instanceIdentifier, mountPoint, transactionChain);
+ instanceIdentifier, mountPoint, localTransactionChainHandler);
final NormalizedNode<?, ?> node =
ReadDataTransactionUtil.readData(identifier, parameters.getContent(), transactionNode, withDefa,
schemaContextRef, uriInfo);
PutDataTransactionUtil.validateListKeysEqualityInPayloadAndUri(payload);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
final SchemaContextRef ref;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
ref = new SchemaContextRef(mountPoint.getSchemaContext());
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
+ payload.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
return PutDataTransactionUtil.putData(payload, ref, transactionNode, insert, point);
}
checkQueryParams(insertUsed, pointUsed, insert);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
final SchemaContextRef ref;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
ref = new SchemaContextRef(mountPoint.getSchemaContext());
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
+ payload.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
return PostDataTransactionUtil.postData(uriInfo, payload, transactionNode, ref, insert, point);
}
identifier, schemaContextRef.get(), Optional.of(this.mountPointServiceHandler.get()));
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(instanceIdentifier, mountPoint,
- transactionChain);
+ localTransactionChainHandler);
return DeleteDataTransactionUtil.deleteData(transactionNode);
}
Preconditions.checkNotNull(context);
final DOMMountPoint mountPoint = context.getInstanceIdentifierContext().getMountPoint();
- final DOMTransactionChain transactionChain;
+ final TransactionChainHandler localTransactionChainHandler;
final SchemaContextRef ref;
if (mountPoint == null) {
- transactionChain = this.transactionChainHandler.get();
+ localTransactionChainHandler = this.transactionChainHandler;
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
- transactionChain = transactionChainOfMountPoint(mountPoint);
+ localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
ref = new SchemaContextRef(mountPoint.getSchemaContext());
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
- context.getInstanceIdentifierContext(), mountPoint, transactionChain);
+ context.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
return PatchDataTransactionUtil.patchData(context, transactionNode, ref);
}
* Prepare transaction chain to access data of mount point.
* @param mountPoint
* mount point reference
- * @return {@link DOMTransactionChain}
+ * @return {@link TransactionChainHandler}
*/
- private static DOMTransactionChain transactionChainOfMountPoint(@Nonnull final DOMMountPoint mountPoint) {
+ private static TransactionChainHandler transactionChainOfMountPoint(@Nonnull final DOMMountPoint mountPoint) {
final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
if (domDataBrokerService.isPresent()) {
- return domDataBrokerService.get().createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
+ return new TransactionChainHandler(domDataBrokerService.get());
}
final String errMsg = "DOM data broker service isn't available for mount point " + mountPoint.getIdentifier();
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
/**
* This class represent delegation wrapper for transaction variables.
private final DOMMountPoint mountPoint;
private LogicalDatastoreType configuration = null;
private final DOMTransactionChain transactionChain;
+ private final TransactionChainHandler transactionChainHandler;
/**
* Set base type of variables, which ones we need for transaction.
* {@link InstanceIdentifierContext} of data for transaction
* @param mountPoint
* mount point if is present
- * @param transactionChain
- * transaction chain for creating specific type of transaction
- * in specific operation
+ * @param transactionChainHandler
+ * used to obtain the transaction chain for creating specific type of transaction
+ * in specific operation
*/
public TransactionVarsWrapper(final InstanceIdentifierContext<?> instanceIdentifier, final DOMMountPoint mountPoint,
- final DOMTransactionChain transactionChain) {
+ final TransactionChainHandler transactionChainHandler) {
this.instanceIdentifier = instanceIdentifier;
this.mountPoint = mountPoint;
- this.transactionChain = transactionChain;
+ this.transactionChainHandler = transactionChainHandler;
+ transactionChain = transactionChainHandler.get();
}
/**
public DOMTransactionChain getTransactionChain() {
return this.transactionChain;
}
+
+ public TransactionChainHandler getTransactionChainHandler() {
+ return transactionChainHandler;
+ }
}
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.DOMDataReadWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
*/
public static Response deleteData(final TransactionVarsWrapper transactionNode) {
final CheckedFuture<Void, TransactionCommitFailedException> future = submitData(
- transactionNode.getTransactionChain(), transactionNode.getTransactionChain().newReadWriteTransaction(),
+ transactionNode.getTransactionChainHandler(),
transactionNode.getInstanceIdentifier().getInstanceIdentifier());
final ResponseFactory response = new ResponseFactory(Status.NO_CONTENT);
FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE, response);
/**
* Delete data via transaction. Return error if data to delete does not exist.
*
- * @param transactionChain
- * transaction chain
+ * @param transactionChainHandler
+ * transaction chain handler
* @param readWriteTx
* read and write transaction
* @param path
* @return {@link CheckedFuture}
*/
private static CheckedFuture<Void, TransactionCommitFailedException> submitData(
- final DOMTransactionChain transactionChain, final DOMDataReadWriteTransaction readWriteTx,
- final YangInstanceIdentifier path) {
- TransactionUtil.checkItemExists(transactionChain, readWriteTx, LogicalDatastoreType.CONFIGURATION, path,
+ final TransactionChainHandler transactionChainHandler, final YangInstanceIdentifier path) {
+ final DOMDataReadWriteTransaction readWriteTx = transactionChainHandler.get().newReadWriteTransaction();
+ TransactionUtil.checkItemExists(transactionChainHandler, readWriteTx, LogicalDatastoreType.CONFIGURATION, path,
RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE);
readWriteTx.delete(LogicalDatastoreType.CONFIGURATION, path);
return readWriteTx.submit();
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.PatchData;
return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), true, null);
} else {
tx.cancel();
- RestConnectorProvider.resetTransactionChainForAdapaters(transactionNode.getTransactionChain());
+ transactionNode.getTransactionChainHandler().reset();
return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection),
false, null);
}
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
final DOMTransactionChain domTransactionChain = transactionNode.getTransactionChain();
final DOMDataReadWriteTransaction newReadWriteTransaction = domTransactionChain.newReadWriteTransaction();
if (insert == null) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(), newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
final DataSchemaNode schemaNode = PutDataTransactionUtil.checkListAndOrderedType(schemaContext, path);
switch (insert) {
case "first":
if (schemaNode instanceof ListSchemaNode) {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
path.getParent().getParent());
simplePost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
- schemaContext, domTransactionChain);
- makePost(path, readData, schemaContext, domTransactionChain,
+ schemaContext, transactionNode.getTransactionChainHandler());
+ makePost(path, readData, schemaContext, transactionNode.getTransactionChainHandler(),
newReadWriteTransaction);
return newReadWriteTransaction.submit();
}
} else {
- final NormalizedNode<?, ?> readData = PutDataTransactionUtil
- .readList(path.getParent(), schemaContext, domTransactionChain, schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
path.getParent().getParent());
simplePost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
- schemaContext, domTransactionChain);
- makePost(path, readData, schemaContext, domTransactionChain, newReadWriteTransaction);
+ schemaContext, transactionNode.getTransactionChainHandler());
+ makePost(path, readData, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
}
}
case "last":
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
case "before":
if (schemaNode instanceof ListSchemaNode) {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
insertWithPointListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path,
- data, schemaContext, point, readList, true, domTransactionChain);
+ data, schemaContext, point, readList, true,
+ transactionNode.getTransactionChainHandler());
return newReadWriteTransaction.submit();
}
} else {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
insertWithPointLeafListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION,
- path, data, schemaContext, point, readLeafList, true, domTransactionChain);
+ path, data, schemaContext, point, readLeafList, true,
+ transactionNode.getTransactionChainHandler());
return newReadWriteTransaction.submit();
}
}
case "after":
if (schemaNode instanceof ListSchemaNode) {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
insertWithPointListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path,
- data, schemaContext, point, readList, false, domTransactionChain);
+ data, schemaContext, point, readList, false,
+ transactionNode.getTransactionChainHandler());
return newReadWriteTransaction.submit();
}
} else {
- final NormalizedNode<?, ?> readData =
- PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
- schemaNode);
+ final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+ schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
- makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+ newReadWriteTransaction);
return newReadWriteTransaction.submit();
} else {
insertWithPointLeafListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION,
- path, data, schemaContext, point, readLeafList, true, domTransactionChain);
+ path, data, schemaContext, point, readLeafList, true,
+ transactionNode.getTransactionChainHandler());
return newReadWriteTransaction.submit();
}
}
private static void insertWithPointLeafListPost(final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
- final boolean before, final DOMTransactionChain domTransactionChain) {
+ final boolean before, final TransactionChainHandler transactionChainHandler) {
rwTransaction.delete(datastore, path.getParent().getParent());
final InstanceIdentifierContext<?> instanceIdentifier =
ParserIdentifier.toInstanceIdentifier(point, schemaContext, Optional.absent());
rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
if (lastInsertedPosition == lastItemPosition) {
- TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, path,
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, path,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
rwTransaction.put(datastore, path, payload);
}
final YangInstanceIdentifier childPath = path.getParent().getParent().node(nodeChild.getIdentifier());
- TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, childPath,
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, childPath,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
rwTransaction.put(datastore, childPath, nodeChild);
lastInsertedPosition++;
private static void insertWithPointListPost(final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
final SchemaContext schemaContext, final String point, final MapNode readList, final boolean before,
- final DOMTransactionChain domTransactionChain) {
+ final TransactionChainHandler transactionChainHandler) {
rwTransaction.delete(datastore, path.getParent().getParent());
final InstanceIdentifierContext<?> instanceIdentifier =
ParserIdentifier.toInstanceIdentifier(point, schemaContext, Optional.absent());
rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
for (final MapEntryNode mapEntryNode : readList.getValue()) {
if (lastInsertedPosition == lastItemPosition) {
- TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, path,
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, path,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
rwTransaction.put(datastore, path, payload);
}
final YangInstanceIdentifier childPath = path.getParent().getParent().node(mapEntryNode.getIdentifier());
- TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, childPath,
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, childPath,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
rwTransaction.put(datastore, childPath, mapEntryNode);
lastInsertedPosition++;
}
private static void makePost(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
- final SchemaContext schemaContext, final DOMTransactionChain transactionChain,
+ final SchemaContext schemaContext, final TransactionChainHandler transactionChainHandler,
final DOMDataReadWriteTransaction transaction) {
if (data instanceof MapNode) {
boolean merge = false;
for (final MapEntryNode child : ((MapNode) data).getValue()) {
final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
TransactionUtil.checkItemDoesNotExists(
- transactionChain, transaction, LogicalDatastoreType.CONFIGURATION, childPath,
+ transactionChainHandler, transaction, LogicalDatastoreType.CONFIGURATION, childPath,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
if (!merge) {
merge = true;
}
} else {
TransactionUtil.checkItemDoesNotExists(
- transactionChain, transaction, LogicalDatastoreType.CONFIGURATION, path,
+ transactionChainHandler, transaction, LogicalDatastoreType.CONFIGURATION, path,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
private static void simplePost(final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
- final SchemaContext schemaContext, final DOMTransactionChain transactionChain) {
- TransactionUtil.checkItemDoesNotExists(transactionChain, rwTransaction, datastore, path,
+ final SchemaContext schemaContext, final TransactionChainHandler transactionChainHandler) {
+ TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, path,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
TransactionUtil.ensureParentsByMerge(path, schemaContext, rwTransaction);
rwTransaction.put(datastore, path, payload);
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
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.common.validation.RestconfValidationUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
final ResponseFactory responseFactory =
new ResponseFactory(existsResponse.result ? Status.NO_CONTENT : Status.CREATED);
final CheckedFuture<Void, TransactionCommitFailedException> submitData = submitData(path, schemaContext,
- transactionNode.getTransactionChain(), readWriteTransaction, payload.getData(), insert, point);
+ transactionNode.getTransactionChainHandler(), readWriteTransaction, payload.getData(), insert, point);
FutureCallbackTx.addCallback(submitData, RestconfDataServiceConstant.PutData.PUT_TX_TYPE, responseFactory);
return responseFactory.build();
}
* path of data
* @param schemaContext
* {@link SchemaContext}
- * @param domTransactionChain
+ * @param transactionChainHandler
* write transaction
* @param data
* data
* @return {@link CheckedFuture}
*/
private static CheckedFuture<Void, TransactionCommitFailedException> submitData(final YangInstanceIdentifier path,
- final SchemaContext schemaContext, final DOMTransactionChain domTransactionChain,
+ final SchemaContext schemaContext, final TransactionChainHandler transactionChainHandler,
final DOMDataReadWriteTransaction readWriteTransaction,
final NormalizedNode<?, ?> data, final String insert, final String point) {
if (insert == null) {
case "first":
if (schemaNode instanceof ListSchemaNode) {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
return makePut(path, schemaContext, readWriteTransaction, data);
}
} else {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
case "before":
if (schemaNode instanceof ListSchemaNode) {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
return makePut(path, schemaContext, readWriteTransaction, data);
}
} else {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
case "after":
if (schemaNode instanceof ListSchemaNode) {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedMapNode readList = (OrderedMapNode) readData;
if (readList == null || readList.getValue().isEmpty()) {
return makePut(path, schemaContext, readWriteTransaction, data);
}
} else {
final NormalizedNode<?, ?> readData =
- readList(path, schemaContext, domTransactionChain, schemaNode);
+ readList(path, schemaContext, transactionChainHandler, schemaNode);
final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
if (readLeafList == null || readLeafList.getValue().isEmpty()) {
}
public static NormalizedNode<?, ?> readList(final YangInstanceIdentifier path, final SchemaContext schemaContext,
- final DOMTransactionChain domTransactionChain, final DataSchemaNode schemaNode) {
+ final TransactionChainHandler transactionChainHandler, final DataSchemaNode schemaNode) {
final InstanceIdentifierContext<?> iid = new InstanceIdentifierContext<SchemaNode>(
path.getParent(), schemaNode, null, schemaContext);
- final TransactionVarsWrapper transactionNode =
- new TransactionVarsWrapper(iid, null, domTransactionChain);
+ final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(iid, null, transactionChainHandler);
final NormalizedNode<?, ?> readData = ReadDataTransactionUtil
.readData(RestconfDataServiceConstant.ReadData.CONFIG, transactionNode, schemaContext);
return readData;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
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.RestConnectorProvider;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
/**
* Check if items already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
* data does NOT already exists.
- * @param transactionChain Transaction chain
+ * @param transactionChainHandler Transaction chain handler
* @param rwTransaction Transaction
* @param store Datastore
* @param path Path to be checked
* @param operationType Type of operation (READ, POST, PUT, DELETE...)
*/
- public static void checkItemExists(final DOMTransactionChain transactionChain,
+ public static void checkItemExists(final TransactionChainHandler transactionChainHandler,
final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType store, final YangInstanceIdentifier path,
final String operationType) {
if (!response.result) {
// close transaction and reset transaction chain
rwTransaction.cancel();
- RestConnectorProvider.resetTransactionChainForAdapaters(transactionChain);
+ transactionChainHandler.reset();
// throw error
final String errMsg = "Operation via Restconf was not executed because data does not exist";
/**
* Check if items do NOT already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
* data already exists.
- * @param transactionChain Transaction chain
+ * @param transactionChainHandler Transaction chain handler
* @param rwTransaction Transaction
* @param store Datastore
* @param path Path to be checked
* @param operationType Type of operation (READ, POST, PUT, DELETE...)
*/
- public static void checkItemDoesNotExists(final DOMTransactionChain transactionChain,
+ public static void checkItemDoesNotExists(final TransactionChainHandler transactionChainHandler,
final DOMDataReadWriteTransaction rwTransaction,
final LogicalDatastoreType store, final YangInstanceIdentifier path,
final String operationType) {
if (response.result) {
// close transaction and reset transaction chain
rwTransaction.cancel();
- RestConnectorProvider.resetTransactionChainForAdapaters(transactionChain);
+ transactionChainHandler.reset();
// throw error
final String errMsg = "Operation via Restconf was not executed because data already exists";
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.services.wrapper;
-
-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;
-
-public interface ServiceWrapper {
-
- void setHandlers(SchemaContextHandler schemaCtxHandler, DOMMountPointServiceHandler domMountPointServiceHandler,
- TransactionChainHandler transactionChainHandler, DOMDataBrokerHandler domDataBrokerHandler,
- RpcServiceHandler rpcServiceHandler, NotificationServiceHandler notificationServiceHandler,
- DOMSchemaService domSchemaService);
-}
*
*/
@Path("/")
-public final class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServicesWrapper, ServiceWrapper {
+public final class ServicesWrapper implements BaseServicesWrapper, TransactionServicesWrapper {
private RestconfDataService delegRestconfDataService;
private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
private RestconfSchemaService delegRestSchService;
private RestconfService delegRestService;
- private ServicesWrapperImpl() {
+ @Deprecated
+ private ServicesWrapper() {
}
private static class InstanceHolder {
- public static final ServicesWrapperImpl INSTANCE = new ServicesWrapperImpl();
+ public static final ServicesWrapper INSTANCE = new ServicesWrapper();
}
- public static ServicesWrapperImpl getInstance() {
+ @Deprecated
+ public static ServicesWrapper getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ public static ServicesWrapper newInstance(final SchemaContextHandler schemaCtxHandler,
+ final DOMMountPointServiceHandler domMountPointServiceHandler,
+ final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
+ final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
+ final DOMSchemaService domSchemaService) {
+ InstanceHolder.INSTANCE.delegRestOpsService =
+ new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+ final DOMYangTextSourceProvider yangTextSourceProvider =
+ (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
+ .get(DOMYangTextSourceProvider.class);
+ InstanceHolder.INSTANCE.delegRestSchService =
+ new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
+ yangTextSourceProvider);
+ InstanceHolder.INSTANCE.delegRestconfSubscrService =
+ new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
+ notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
+ InstanceHolder.INSTANCE.delegRestconfDataService =
+ new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler, domMountPointServiceHandler,
+ InstanceHolder.INSTANCE.delegRestconfSubscrService);
+ InstanceHolder.INSTANCE.delegRestconfInvokeOpsService =
+ new RestconfInvokeOperationsServiceImpl(rpcServiceHandler, schemaCtxHandler);
+ InstanceHolder.INSTANCE.delegRestService = new RestconfImpl(schemaCtxHandler);
return InstanceHolder.INSTANCE;
}
public NormalizedNodeContext getLibraryVersion() {
return this.delegRestService.getLibraryVersion();
}
-
- @Override
- public void setHandlers(final SchemaContextHandler schemaCtxHandler,
- final DOMMountPointServiceHandler domMountPointServiceHandler,
- final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
- final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
- final DOMSchemaService domSchemaService) {
- this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
- final DOMYangTextSourceProvider yangTextSourceProvider =
- (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
- .get(DOMYangTextSourceProvider.class);
- this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
- yangTextSourceProvider);
- this.delegRestconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
- notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
- this.delegRestconfDataService =
- new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler, domMountPointServiceHandler,
- this.delegRestconfSubscrService);
- this.delegRestconfInvokeOpsService =
- new RestconfInvokeOperationsServiceImpl(rpcServiceHandler, schemaCtxHandler);
- this.delegRestService = new RestconfImpl(schemaCtxHandler);
- }
}
ext:filter="(type=@{databroker-service-type})"/>
<reference id="domSchemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
- <bean id="wrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl"
- factory-method="getInstance" />
-
- <bean id="restconfProvider" class="org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider"
- init-method="start" destroy-method="close">
+ <bean id="transactionChainHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler"
+ destroy-method="close">
<argument ref="domDataBroker"/>
+ </bean>
+
+ <bean id="schemaContextHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler"
+ factory-method="newInstance" init-method="init" destroy-method="close">
+ <argument ref="transactionChainHandler"/>
<argument ref="domSchemaService"/>
+ </bean>
+
+ <bean id="mountPointServiceHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler"
+ factory-method="newInstance">
+ <argument ref="domMountPointService"/>
+ </bean>
+
+ <bean id="dataBrokerHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler">
+ <argument ref="domDataBroker"/>
+ </bean>
+
+ <bean id="rpcServiceHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler">
<argument ref="domRpcService"/>
+ </bean>
+
+ <bean id="notificationServiceHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler">
<argument ref="domNotificationService"/>
- <argument ref="domMountPointService"/>
- <argument ref="wrapper"/>
</bean>
- <service ref="restconfProvider"
- interface="org.opendaylight.restconf.nb.rfc8040.RestconfConnector" />
+ <bean id="servicesWrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper"
+ factory-method="newInstance">
+ <argument ref="schemaContextHandler"/>
+ <argument ref="mountPointServiceHandler"/>
+ <argument ref="transactionChainHandler"/>
+ <argument ref="dataBrokerHandler"/>
+ <argument ref="rpcServiceHandler"/>
+ <argument ref="notificationServiceHandler"/>
+ <argument ref="domSchemaService"/>
+ </bean>
<!-- JSONRestconfService -->
- <bean id="jsonRestconfService" depends-on="restconfProvider"
+ <bean id="jsonRestconfService"
class="org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl"
destroy-method="close">
- <argument ref="wrapper"/>
- <argument>
- <bean factory-ref="restconfProvider" factory-method="getMountPointServiceHandler" />
- </argument>
+ <argument ref="servicesWrapper"/>
+ <argument ref="mountPointServiceHandler"/>
+ <argument ref="schemaContextHandler"/>
</bean>
<service ref="jsonRestconfService" odl:type="rfc8040"
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, 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 static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
-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.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-
-/**
- * Unit tests for {@link RestConnectorProvider}.
- */
-public class RestConnectorProviderTest {
- // service under test
- private RestConnectorProvider connectorProvider;
-
- @Mock private DOMMountPointService mockMountPointService;
- @Mock private DOMDataBroker mockDataBroker;
- @Mock private DOMRpcService mockRpcService;
- @Mock private DOMNotificationService mockNotificationService;
- @Mock DOMTransactionChain mockTransactionChain;
- @Mock private ListenerRegistration<SchemaContextListener> mockRegistration;
- @Mock
- private DOMSchemaService domSchemaService;
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Before
- public void init() {
- MockitoAnnotations.initMocks(this);
-
- doReturn(mockTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
- doReturn(mockRegistration).when(domSchemaService).registerSchemaContextListener(
- Mockito.any(SchemaContextHandler.class));
-
- this.connectorProvider = new RestConnectorProvider(mockDataBroker, domSchemaService, mockRpcService,
- mockNotificationService, mockMountPointService, ServicesWrapperImpl.getInstance());
- }
-
- /**
- * Test for successful start when all conditions are satisfied.
- */
- @Test
- public void successfulStartTest() {
- // test
- this.connectorProvider.start();
-
- // verify interactions
- verify(mockDataBroker).createTransactionChain(Mockito.any());
- verify(domSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
- }
-
- /**
- * Test of closing <code>null</code> registration.
- */
- @Test
- public void closeNotOpenTest() throws Exception {
- this.connectorProvider.close();
- }
-
- /**
- * Test of creating and closing not <code>null</code> registration.
- */
- @Test
- public void closeOpenTest() throws Exception {
- // start
- this.connectorProvider.start();
-
- // close
- this.connectorProvider.close();
-
- // verify interaction
- verify(this.mockRegistration).close();
- verify(mockTransactionChain).close();
- }
-}
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;
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;
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;
+ }
}
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;
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;
private SchemaContextHandler schemaContextHandler;
private SchemaContext schemaContext;
+ private final DOMSchemaService mockDOMSchemaService = Mockito.mock(DOMSchemaService.class);
@Before
public void setup() throws Exception {
final CheckedFuture<Void,TransactionCommitFailedException> 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));
}
/**
- * 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();
}
/**
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import java.io.File;
import java.io.InputStream;
import java.net.URI;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
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;
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, mountPointServiceHandler);
}
@Override
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-
- final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
- final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-
- 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
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
-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;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
private final JsonToPatchBodyReader jsonToPatchBodyReader;
public JsonPatchBodyReaderMountPointTest() throws Exception {
- jsonToPatchBodyReader = new JsonToPatchBodyReader();
+ super(schemaContext);
+ jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
@BeforeClass
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-
- final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
- final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-
- 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
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
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;
private static SchemaContext schemaContext;
public JsonPatchBodyReaderTest() throws Exception {
- jsonToPatchBodyReader = new JsonToPatchBodyReader();
+ super(schemaContext);
+ jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
@BeforeClass
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
- SchemaContextHandler.setSchemaContext(schemaContext);
}
@Test
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
-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;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
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, mountPointServiceHandler);
}
@Override
@BeforeClass
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-
- final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
- final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-
- 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
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
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;
private static SchemaContext schemaContext;
public XmlPatchBodyReaderTest() throws Exception {
- xmlToPatchBodyReader = new XmlToPatchBodyReader();
+ super(schemaContext);
+ xmlToPatchBodyReader = new XmlToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
}
@Override
@BeforeClass
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
- SchemaContextHandler.setSchemaContext(schemaContext);
}
@Test
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.test;
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 static org.mockito.Mockito.when;
-import java.lang.reflect.Field;
+import com.google.common.base.Optional;
import java.util.Collections;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
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.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public abstract class AbstractBodyReaderTest {
- protected static final DOMMountPointServiceHandler MOUNT_POINT_SERVICE_HANDLER =
- mock(DOMMountPointServiceHandler.class);
-
protected final MediaType mediaType;
+ protected final SchemaContextHandler schemaContextHandler;
+ protected final DOMMountPointServiceHandler mountPointServiceHandler;
- 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);
+
+ final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
+ final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
+ doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
+ doReturn(schemaContext).when(mountPoint).getSchemaContext();
+
+ mountPointServiceHandler = DOMMountPointServiceHandler.newInstance(mountPointService);
}
protected abstract MediaType getMediaType();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import com.google.common.collect.Sets;
import java.io.File;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
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;
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, mountPointServiceHandler);
}
@Override
final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
- when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
- SchemaContextHandler.setSchemaContext(schemaContext);
}
@Test
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import com.google.common.collect.Sets;
import java.io.File;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
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;
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, mountPointServiceHandler);
}
@Override
testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
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
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.TestUtils;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
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.ServicesWrapperImpl;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@Mock
private DOMMountPointService mockMountPointService;
- @Mock
- private SchemaContextHandler mockSchemaContextHandler;
-
@Mock
private DOMDataBroker mockDOMDataBroker;
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")
doReturn(mockTxChain).when(mockDOMDataBroker).createTransactionChain(any());
- doReturn(schemaContext).when(mockSchemaContextHandler).get();
-
- final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockTxChain);
+ final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockDOMDataBroker);
final DOMMountPointServiceHandler mountPointServiceHandler =
- new DOMMountPointServiceHandler(mockMountPointService);
+ DOMMountPointServiceHandler.newInstance(mockMountPointService);
final DOMNotificationService mockNotificationService = mock(DOMNotificationService.class);
- ServicesWrapperImpl.getInstance().setHandlers(mockSchemaContextHandler, mountPointServiceHandler,
- txChainHandler, new DOMDataBrokerHandler(mockDOMDataBroker),
- new RpcServiceHandler(mockRpcService),
- new NotificationServiceHandler(mockNotificationService), domSchemaService);
-
- service = new JSONRestconfServiceRfc8040Impl(ServicesWrapperImpl.getInstance(), mountPointServiceHandler);
-
- new RestConnectorProvider<>(mockDOMDataBroker, domSchemaService, mockRpcService, mockNotificationService,
- mockMountPointService).start();
+ final ServicesWrapper servicesWrapper = ServicesWrapper.newInstance(schemaContextHandler,
+ mountPointServiceHandler, txChainHandler, new DOMDataBrokerHandler(mockDOMDataBroker),
+ new RpcServiceHandler(mockRpcService), new NotificationServiceHandler(mockNotificationService),
+ domSchemaService);
- SchemaContextHandler.setSchemaContext(schemaContext);
+ service = new JSONRestconfServiceRfc8040Impl(servicesWrapper, mountPointServiceHandler,
+ schemaContextHandler);
}
private static String loadData(final String path) throws IOException {
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.CREATE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.DELETE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.REMOVE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.REPLACE;
import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
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;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
private ContainerNode buildPlayerCont;
private ContainerNode buildLibraryCont;
private MapNode buildPlaylistList;
-
- @Mock
private TransactionChainHandler transactionChainHandler;
+
@Mock
private DOMTransactionChain domTransactionChain;
@Mock
@Mock
private DOMDataWriteTransaction write;
@Mock
- private DOMMountPointServiceHandler mountPointServiceHandler;
- @Mock
private DOMMountPointService mountPointService;
@Mock
private DOMMountPoint mountPoint;
@Mock
private DOMDataBroker mountDataBroker;
@Mock
- private DOMTransactionChain transactionChain;
+ private DOMTransactionChain mountTransactionChain;
@Mock
private RestconfStreamsSubscriptionService delegRestconfSubscrService;
YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
this.schemaNode = DataSchemaContextTree.from(this.contextRef.get()).getChild(this.iidBase).getDataSchemaNode();
- 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<Void, TransactionCommitFailedException> checked = Mockito.mock(CheckedFuture.class);
- Mockito.when(wTx.submit()).thenReturn(checked);
- Mockito.when(checked.checkedGet()).thenReturn(null);
- final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+
+ doReturn(this.read).when(domTransactionChain).newReadOnlyTransaction();
+ doReturn(this.readWrite).when(domTransactionChain).newReadWriteTransaction();
+ doReturn(this.write).when(domTransactionChain).newWriteOnlyTransaction();
+
+ DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+ Mockito.doReturn(domTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
+
+ final SchemaContextHandler schemaContextHandler = SchemaContextHandler.newInstance(transactionChainHandler,
+ Mockito.mock(DOMSchemaService.class));
schemaContextHandler.onGlobalContextUpdated(this.contextRef.get());
this.dataService = new RestconfDataServiceImpl(schemaContextHandler, this.transactionChainHandler,
- this.mountPointServiceHandler, this.delegRestconfSubscrService);
- doReturn(this.domTransactionChain).when(this.transactionChainHandler).get();
- doReturn(this.read).when(this.domTransactionChain).newReadOnlyTransaction();
- doReturn(this.readWrite).when(this.domTransactionChain).newReadWriteTransaction();
- doReturn(this.write).when(this.domTransactionChain).newWriteOnlyTransaction();
- doReturn(this.mountPointService).when(this.mountPointServiceHandler).get();
+ DOMMountPointServiceHandler.newInstance(mountPointService), this.delegRestconfSubscrService);
doReturn(Optional.of(this.mountPoint)).when(this.mountPointService)
.getMountPoint(any(YangInstanceIdentifier.class));
doReturn(this.contextRef.get()).when(this.mountPoint).getSchemaContext();
doReturn(Optional.of(this.mountDataBroker)).when(this.mountPoint).getService(DOMDataBroker.class);
- doReturn(this.transactionChain).when(this.mountDataBroker)
+ doReturn(this.mountTransactionChain).when(this.mountDataBroker)
.createTransactionChain(any(TransactionChainListener.class));
- doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
- doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
+ doReturn(this.read).when(this.mountTransactionChain).newReadOnlyTransaction();
+ doReturn(this.readWrite).when(this.mountTransactionChain).newReadWriteTransaction();
}
@Test
doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(this.readWrite)
.exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final Response response = this.dataService.putData(null, payload, this.uriInfo);
assertNotNull(response);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
@Test
public void testPutDataWithMountPoint() {
- final DOMDataBroker dataBroker = Mockito.mock(DOMDataBroker.class);
- doReturn(Optional.of(dataBroker)).when(mountPoint).getService(DOMDataBroker.class);
- doReturn(this.transactionChainHandler.get()).when(dataBroker)
- .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
+// final DOMDataBroker dataBroker = Mockito.mock(DOMDataBroker.class);
+// doReturn(Optional.of(dataBroker)).when(mountPoint).getService(DOMDataBroker.class);
+// doReturn(this.transactionChainHandler.get()).when(dataBroker)
+// .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
final InstanceIdentifierContext<DataSchemaNode> iidContext =
new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, mountPoint, this.contextRef.get());
final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildBaseCont);
doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(this.readWrite)
.exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final Response response = this.dataService.putData(null, payload, this.uriInfo);
assertNotNull(response);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
doReturn(Futures.immediateCheckedFuture(false))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/15/")).when(this.uriInfo).getBaseUriBuilder();
final Response response = this.dataService.postData(null, payload, this.uriInfo);
@Test
public void testDeleteData() {
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(true))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
final Response response = this.dataService.deleteData("example-jukebox:jukebox");
@Test
public void testDeleteDataMountPoint() {
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(true))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
final Response response =
doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
.read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(false))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doReturn(Futures.immediateCheckedFuture(true))
doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
.read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(false))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doReturn(Futures.immediateCheckedFuture(true))
@Test
public void testPatchDataDeleteNotExist() throws Exception {
- final Field handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
- final Field broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
-
- handler.setAccessible(true);
- handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
-
- broker.setAccessible(true);
- broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef.get());
final List<PatchEntity> entity = new ArrayList<>();
doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
.read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
doReturn(Futures.immediateCheckedFuture(false))
.when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
doReturn(Futures.immediateCheckedFuture(false))
doReturn(true).when(this.readWrite).cancel();
final PatchStatusContext status = this.dataService.patchData(patch, this.uriInfo);
- handler.set(RestConnectorProvider.class, null);
- handler.setAccessible(false);
-
- broker.set(RestConnectorProvider.class, null);
- broker.setAccessible(false);
-
assertFalse(status.isOk());
assertEquals(3, status.getEditCollection().size());
assertTrue(status.getEditCollection().get(0).isOk());
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;
final CheckedFuture<Void, TransactionCommitFailedException> 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);
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;
private UriInfo uriInfo;
@Mock
private NotificationServiceHandler notificationServiceHandler;
- @Mock
- private TransactionChainHandler transactionHandler;
+ private TransactionChainHandler transactionHandler;
private SchemaContextHandler schemaHandler;
@SuppressWarnings("unchecked")
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);
final CheckedFuture<Void, TransactionCommitFailedException> 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)
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-import org.junit.AfterClass;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
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.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
private InstanceIdentifierContext<?> context;
@Mock
private DOMDataReadWriteTransaction readWrite;
+ @Mock
+ private DOMDataBroker mockDataBroker;
- // Fields used when delete operation fails to reset transaction chain
- private static Field handler;
- private static Field broker;
-
- @BeforeClass
- public static void setup() throws Exception {
- DeleteDataTransactionUtilTest.handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
- DeleteDataTransactionUtilTest.broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
-
- DeleteDataTransactionUtilTest.handler.setAccessible(true);
- DeleteDataTransactionUtilTest.handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
-
- DeleteDataTransactionUtilTest.broker.setAccessible(true);
- DeleteDataTransactionUtilTest.broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
- }
-
- @AfterClass
- public static void clean() throws Exception {
- DeleteDataTransactionUtilTest.handler.set(RestConnectorProvider.class, null);
- DeleteDataTransactionUtilTest.handler.setAccessible(false);
-
- DeleteDataTransactionUtilTest.broker.set(RestConnectorProvider.class, null);
- DeleteDataTransactionUtilTest.broker.setAccessible(false);
- }
+ private TransactionChainHandler transactionChainHandler;
@Before
public void init() throws Exception {
Mockito.when(this.transactionChain.newReadWriteTransaction()).thenReturn(this.readWrite);
Mockito.when(this.readWrite.submit()).thenReturn(Futures.immediateCheckedFuture(null));
Mockito.when(this.context.getInstanceIdentifier()).thenReturn(YangInstanceIdentifier.EMPTY);
+
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
}
/**
// test
final Response response = DeleteDataTransactionUtil.deleteData(
- new TransactionVarsWrapper(this.context, null, this.transactionChain));
+ new TransactionVarsWrapper(this.context, null, transactionChainHandler));
// assert success
assertEquals("Not expected response received", Status.NO_CONTENT.getStatusCode(), response.getStatus());
// test and assert error
try {
- DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null, this.transactionChain));
+ DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null,
+ transactionChainHandler));
fail("Delete operation should fail due to missing data");
} catch (final RestconfDocumentedException e) {
assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.CREATE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.DELETE;
import static org.opendaylight.restconf.common.patch.PatchEditOperation.REPLACE;
import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
+import org.mockito.Mockito;
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.DOMDataReadWriteTransaction;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
@Mock
private DOMDataReadWriteTransaction rwTransaction;
+ @Mock
+ private DOMDataBroker mockDataBroker;
+
+ private TransactionChainHandler transactionChainHandler;
private SchemaContextRef refSchemaCtx;
private YangInstanceIdentifier instanceIdContainer;
private YangInstanceIdentifier instanceIdCreateAndDelete;
private YangInstanceIdentifier targetNodeMerge;
private MapNode buildArtistList;
- // Fields used when delete operation fails to reset transaction chain
- private static Field handler;
- private static Field broker;
-
@Before
public void setUp() throws Exception {
initMocks(this);
- PatchDataTransactionUtilTest.handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
- PatchDataTransactionUtilTest.broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
-
- PatchDataTransactionUtilTest.handler.setAccessible(true);
- PatchDataTransactionUtilTest.handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
-
- PatchDataTransactionUtilTest.broker.setAccessible(true);
- PatchDataTransactionUtilTest.broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
this.refSchemaCtx = new SchemaContextRef(
YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.instanceIdMerge, null, null, this.refSchemaCtx.get());
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchRMRm");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
final PatchStatusContext patchStatusContext =
PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx.get());
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchCD");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
final PatchStatusContext patchStatusContext =
PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx.get());
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchD");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
final PatchStatusContext patchStatusContext =
PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
final InstanceIdentifierContext<? extends SchemaNode> iidContext =
new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx.get());
final PatchContext patchContext = new PatchContext(iidContext, entities, "patchM");
- final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+ final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
final PatchStatusContext patchStatusContext =
PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
}
assertTrue(patchStatusContext.isOk());
}
-}
\ No newline at end of file
+}
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.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.util.SingletonSet;
private UriInfo uriInfo;
@Mock
private UriBuilder uriBuilder;
+ @Mock
+ private DOMDataBroker mockDataBroker;
+ private TransactionChainHandler transactionChainHandler;
private SchemaContextRef refSchemaCtx;
private ContainerNode buildBaseCont;
private SchemaContext schema;
doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/16/")).when(this.uriInfo).getBaseUriBuilder();
doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
+
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
}
@Test
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final TransactionVarsWrapper wrapper =
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler);
final Response response =
PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
assertEquals(201, response.getStatus());
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final TransactionVarsWrapper wrapper =
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler);
final Response response =
PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
assertEquals(201, response.getStatus());
final DOMException domException = new DOMException((short) 414, "Post request failed");
doReturn(Futures.immediateFailedCheckedFuture(domException)).when(this.readWrite).submit();
final TransactionVarsWrapper wrapper =
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler);
try {
PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
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.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.common.QName;
private DOMDataReadOnlyTransaction read;
@Mock
private DOMDataWriteTransaction write;
+ @Mock
+ private DOMDataBroker mockDataBroker;
-
+ private TransactionChainHandler transactionChainHandler;
private SchemaContextRef refSchemaCtx;
private LeafNode buildLeaf;
private ContainerNode buildBaseCont;
.withChild(buildList)
.build();
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ transactionChainHandler = new TransactionChainHandler(mockDataBroker);
}
@Test
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
null);
verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION,
payload.getInstanceIdentifierContext().getInstanceIdentifier());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
null);
verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION,
payload.getInstanceIdentifierContext().getInstanceIdentifier());
payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
null);
verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2);
verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iid2, payload.getData());
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
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.DOMDataReadOnlyTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
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.handlers.TransactionChainHandler;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
when(containerChildNode.getQName()).thenReturn(containerChildQName);
when(containerSchemaNode.getDataChildByName(containerChildQName)).thenReturn(containerChildNode);
- wrapper = new TransactionVarsWrapper(this.context, null, this.transactionChain);
+ DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+ Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ wrapper = new TransactionVarsWrapper(this.context, null, new TransactionChainHandler(mockDataBroker));
}
@Test
*/
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;
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<Void, TransactionCommitFailedException> 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();
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;
public void init() throws Exception {
MockitoAnnotations.initMocks(this);
this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules"));
+ this.schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
- 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.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService);
+ this.domMountPointServiceHandler = DOMMountPointServiceHandler.newInstance(this.domMountPointService);
final QNameModule module1 = QNameModule.create(URI.create("module:1"));
final QNameModule module2 = QNameModule.create(URI.create("module:2"));
@Mock
private SchemaContextHandler mockContextHandler;
@Mock
- private DOMMountPointServiceHandler mockMountPointHandler;
- @Mock
private DOMYangTextSourceProvider sourceProvider;
// schema context with modules
this.mountPointService = new DOMMountPointServiceImpl();
((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPointWithNullSchemaContext);
- when(this.mockMountPointHandler.get()).thenReturn(this.mountPointService);
- this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler,
- sourceProvider);
+ this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler,
+ DOMMountPointServiceHandler.newInstance(mountPointService), sourceProvider);
}
/**
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
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;
SchemaContext sc = YangParserTestUtils.parseYangResource(
"/instanceidentifier/yang/instance-identifier-patch-module.yang");
- transactionChainHandler = new TransactionChainHandler(domDataBroker.createTransactionChain(
- Mockito.mock(TransactionChainListener.class)));
- schemaContextHandler = new SchemaContextHandler(transactionChainHandler);
- SchemaContextHandler.setSchemaContext(sc);
+ transactionChainHandler = new TransactionChainHandler(domDataBroker);
+ schemaContextHandler = SchemaContextHandler.newInstance(transactionChainHandler,
+ Mockito.mock(DOMSchemaService.class));
+ schemaContextHandler.onGlobalContextUpdated(sc);
}
class ListenerAdapterTester extends ListenerAdapter {