import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.Collections;
+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.DOMTransactionChain;
import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
import org.opendaylight.controller.sal.core.api.Provider;
import org.opendaylight.controller.sal.core.api.model.SchemaService;
import org.opendaylight.netconf.sal.rest.api.RestConnector;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.common.handlers.impl.SchemaContextHandlerImpl;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.rest.handlers.impl.DOMMountPointServiceHandlerImpl;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.handlers.TransactionChainHandler;
import org.opendaylight.restconf.rest.services.impl.Draft11ServicesWrapperImpl;
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 draft11.
*/
public class RestConnectorProvider implements Provider, RestConnector, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
+
+ private final TransactionChainListener transactionListener = new TransactionChainListener() {
+ @Override
+ public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+ final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+ LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
+ chain.close();
+ resetTransactionChainForAdapaters(chain);
+ throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
+ }
+
+ @Override
+ public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
+ LOG.trace("TransactionChain({}) {} SUCCESSFUL", chain);
+ }
+ };
+
private ListenerRegistration<SchemaContextListener> listenerRegistration;
+ private DOMDataBroker dataBroker;
+ private DOMTransactionChain transactionChain;
@Override
public void onSessionInitiated(final ProviderSession session) {
final SchemaService schemaService = Preconditions.checkNotNull(session.getService(SchemaService.class));
- final DOMMountPointServiceHandler domMountPointServiceHandler = new DOMMountPointServiceHandlerImpl();
- final SchemaContextHandler schemaCtxHandler = new SchemaContextHandlerImpl();
- domMountPointServiceHandler.setDOMMountPointService(session.getService(DOMMountPointService.class));
+
final Draft11ServicesWrapperImpl wrapperServices = Draft11ServicesWrapperImpl.getInstance();
+
+ final SchemaContextHandler schemaCtxHandler = new SchemaContextHandler();
this.listenerRegistration = schemaService.registerSchemaContextListener(schemaCtxHandler);
+ final DOMMountPointServiceHandler domMountPointServiceHandler = new DOMMountPointServiceHandler(
+ session.getService(DOMMountPointService.class));
+
+ this.dataBroker = session.getService(DOMDataBroker.class);
+ this.transactionChain = this.dataBroker.createTransactionChain(this.transactionListener);
+ final TransactionChainHandler transactionChainHandler = new TransactionChainHandler(this.transactionChain);
+
wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler);
}
+ /**
+ * After {@link TransactionChain} failed, this is creating new transaction
+ * with listener.
+ *
+ * @param chain
+ * - old {@link TransactionChain}
+ */
+ private void resetTransactionChainForAdapaters(final TransactionChain<?, ?> chain) {
+ LOG.trace("Resetting TransactionChain({}) to {}", chain, this.transactionChain);
+ this.transactionChain = Preconditions.checkNotNull(this.dataBroker)
+ .createTransactionChain(this.transactionListener);
+ }
+
@Override
public Collection<ProviderFunctionality> getProviderFunctionality() {
return Collections.emptySet();
if (this.listenerRegistration != null) {
this.listenerRegistration.close();
}
+ if (this.transactionChain != null) {
+ this.transactionChain.close();
+ }
}
}
* 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.rest.handlers.impl;
+package org.opendaylight.restconf.handlers;
+import com.google.common.base.Preconditions;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
/**
* Implementation of {@link DOMMountPointServiceHandler}
*
*/
-public class DOMMountPointServiceHandlerImpl implements DOMMountPointServiceHandler {
+public class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
- private DOMMountPointService domMountPointService;
+ private final DOMMountPointService domMountPointService;
- @Override
- public DOMMountPointService getDOMMountPointService() {
- return this.domMountPointService;
+ /**
+ * Prepare mount point service for Restconf services
+ *
+ * @param domMountPointService
+ * - mount point service
+ */
+ public DOMMountPointServiceHandler(final DOMMountPointService domMountPointService) {
+ Preconditions.checkNotNull(domMountPointService);
+ this.domMountPointService = domMountPointService;
}
@Override
- public void setDOMMountPointService(final DOMMountPointService domMountPointService) {
- this.domMountPointService = domMountPointService;
-
+ public DOMMountPointService get() {
+ return this.domMountPointService;
}
}
--- /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.handlers;
+
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+
+/**
+ * Handler for handling object prepared by provider for Restconf services
+ *
+ * @param <T>
+ * - specific type go object for handling it
+ */
+interface Handler<T> {
+
+ /**
+ * Get prepared object
+ *
+ * @return {@link DOMTransactionChain}
+ */
+ T get();
+}
* 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.common.handlers.impl;
+package org.opendaylight.restconf.handlers;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
+import com.google.common.base.Preconditions;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
* Implementation of {@link SchemaContextHandler}
*
*/
-public class SchemaContextHandlerImpl implements SchemaContextHandler {
+public class SchemaContextHandler implements SchemaContextListenerHandler {
private SchemaContext context;
@Override
public void onGlobalContextUpdated(final SchemaContext context) {
+ Preconditions.checkNotNull(context);
this.context = null;
this.context = context;
}
@Override
- public SchemaContext getSchemaContext() {
+ public SchemaContext get() {
return this.context;
}
}
* 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.common.handlers.api;
+package org.opendaylight.restconf.handlers;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-/**
- * Handling schema context:
- * <ul>
- * <li>Retention
- * <li>Update
- * </ul>
- */
-public interface SchemaContextHandler extends SchemaContextListener {
+interface SchemaContextListenerHandler extends Handler<SchemaContext>, SchemaContextListener {
- /**
- * Get the {@link SchemaContext}.
- *
- * @return {@link SchemaContext}
- */
- SchemaContext getSchemaContext();
}
--- /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.handlers;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+
+
+/**
+ * Implementation of {@link TransactionChainHandler}
+ *
+ */
+public class TransactionChainHandler implements Handler<DOMTransactionChain> {
+
+ private final DOMTransactionChain transactionChain;
+
+ /**
+ * Prepare transaction chain service for Restconf services
+ *
+ * @param transactionChain
+ */
+ public TransactionChainHandler(final DOMTransactionChain transactionChain) {
+ Preconditions.checkNotNull(transactionChain);
+ this.transactionChain = transactionChain;
+ }
+
+ @Override
+ public DOMTransactionChain get() {
+ return this.transactionChain;
+ }
+}
+++ /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.rest.handlers.api;
-
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-
-/**
- * Handling dom mount point service:
- * <ul>
- * <li>Retention
- * <li>Set
- * </ul>
- */
-public interface DOMMountPointServiceHandler {
-
- /**
- * Get the {@link DOMMountPointService}
- *
- * @return {@link DOMMountPointService}
- */
- DOMMountPointService getDOMMountPointService();
-
- /**
- * Set {@link DOMMountPointService}
- *
- * @param domMountPointService
- * - {@link DOMMountPointService}
- */
- void setDOMMountPointService(DOMMountPointService domMountPointService);
-}
import javax.ws.rs.core.UriInfo;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.Draft11ServicesWrapper;
import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
import org.opendaylight.restconf.rest.services.api.RestconfOperationsService;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
import org.opendaylight.restconf.Draft11;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
import org.opendaylight.restconf.common.references.SchemaContextRef;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeUtil;
@Override
public NormalizedNodeContext getModules(final UriInfo uriInfo) {
- final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+ final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
return getModules(schemaContextRef.getModules(), schemaContextRef, null);
}
LOG.debug(errMsg + " for " + identifier);
throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
- final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+ final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
final InstanceIdentifierContext<?> mountPointIdentifier = ParserIdentifier.toInstanceIdentifier(identifier,
schemaContextRef.get());
- final DOMMountPointService domMointPointService = this.domMountPointServiceHandler.getDOMMountPointService();
+ final DOMMountPointService domMointPointService = this.domMountPointServiceHandler.get();
final DOMMountPoint mountPoint = domMointPointService
.getMountPoint(mountPointIdentifier.getInstanceIdentifier()).get();
return getModules(mountPoint.getSchemaContext().getModules(), schemaContextRef, mountPoint);
@Override
public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
Preconditions.checkNotNull(identifier);
- final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+ final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
final QName moduleQname = ParserIdentifier.makeQNameFromIdentifier(identifier);
Module module = null;
DOMMountPoint mountPoint = null;
if (identifier.contains(RestconfConstants.MOUNT)) {
final InstanceIdentifierContext<?> point = ParserIdentifier.toInstanceIdentifier(identifier,
schemaContextRef.get());
- final DOMMountPointService domMointPointService = this.domMountPointServiceHandler
- .getDOMMountPointService();
+ final DOMMountPointService domMointPointService = this.domMountPointServiceHandler.get();
mountPoint = domMointPointService.getMountPoint(point.getInstanceIdentifier()).get();
module = schemaContextRef.findModuleInMountPointByQName(mountPoint, moduleQname);
} else {
import javax.ws.rs.core.UriInfo;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.RestconfOperationsService;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
package org.opendaylight.restconf.rest.services.impl;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
import org.opendaylight.restconf.common.references.SchemaContextRef;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.RestconfSchemaService;
import org.opendaylight.restconf.utils.parser.ParserIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@Override
public SchemaExportContext getSchema(final String identifier) {
- final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+ final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContextRef.get(), identifier,
- this.domMountPointServiceHandler.getDOMMountPointService());
+ this.domMountPointServiceHandler.get());
}
}
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.streams.listeners.Notificator;
import org.opendaylight.restconf.Draft11;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
import org.opendaylight.restconf.common.references.SchemaContextRef;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.RestconfStreamsService;
import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeUtil;
import org.opendaylight.restconf.utils.schema.context.RestconfSchemaUtil;
@Override
public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
- final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+ final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
final Set<String> availableStreams = Notificator.getStreamNames();
final DataSchemaNode streamListSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
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.DOMTransactionChain;
import org.opendaylight.controller.sal.core.api.Broker;
import org.opendaylight.controller.sal.core.api.model.SchemaService;
import org.opendaylight.restconf.RestConnectorProvider;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
// prepare conditions
when(this.mockSession.getService(SchemaService.class)).thenReturn(this.mockSchemaService);
when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(this.mockMountPointService);
+ final DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+ when(this.mockSession.getService(DOMDataBroker.class)).thenReturn(mockDataBroker);
+ final DOMTransactionChain mockTransactionChain = Mockito.mock(DOMTransactionChain.class);
+ when(mockDataBroker.createTransactionChain(Mockito.any())).thenReturn(mockTransactionChain);
// test
this.connectorProvider.onSessionInitiated(this.mockSession);
// prepare conditions
when(this.mockSession.getService(SchemaService.class)).thenReturn(this.mockSchemaService);
when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(null);
+ final DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+ when(this.mockSession.getService(DOMDataBroker.class)).thenReturn(mockDataBroker);
+ final DOMTransactionChain mockTransactionChain = Mockito.mock(DOMTransactionChain.class);
+ when(mockDataBroker.createTransactionChain(Mockito.any())).thenReturn(mockTransactionChain);
+ final DOMMountPointService mockDomMountPoint = Mockito.mock(DOMMountPointService.class);
+ when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(mockDomMountPoint);
// test
this.connectorProvider.onSessionInitiated(this.mockSession);
when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(this.mockMountPointService);
when(this.mockSchemaService.registerSchemaContextListener(Mockito.any(SchemaContextHandler.class)))
.thenReturn(this.mockRegistration);
+ final DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+ when(this.mockSession.getService(DOMDataBroker.class)).thenReturn(mockDataBroker);
+ final DOMTransactionChain mockTransactionChain = Mockito.mock(DOMTransactionChain.class);
+ when(mockDataBroker.createTransactionChain(Mockito.any())).thenReturn(mockTransactionChain);
// register
this.connectorProvider.onSessionInitiated(this.mockSession);
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.common.handlers.impl.SchemaContextHandlerImpl;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
@Before
public void setup() throws Exception {
- this.schemaContextHandler = new SchemaContextHandlerImpl();
+ this.schemaContextHandler = new SchemaContextHandler();
this.schemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_ACTUAL_SCHEMA_CONTEXT);
this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
}
/**
- * Testing init of {@link SchemaContextHandlerImpl}
+ * Testing init of {@link SchemaContextHandler}
*/
@Test
public void schemaContextHandlerImplInitTest() {
@Test
public void getSchemaContextTest() {
assertEquals("SchemaContextHandler should has reference to actual SchemaContext",
- this.schemaContext, this.schemaContextHandler.getSchemaContext());
+ this.schemaContext, this.schemaContextHandler.get());
}
/**
this.schemaContextHandler.onGlobalContextUpdated(newSchemaContext);
assertNotEquals("SchemaContextHandler should not has reference to old SchemaContext",
- this.schemaContext, this.schemaContextHandler.getSchemaContext());
+ this.schemaContext, this.schemaContextHandler.get());
assertEquals("SchemaContextHandler should has reference to new SchemaContext",
- newSchemaContext, this.schemaContextHandler.getSchemaContext());
+ newSchemaContext, this.schemaContextHandler.get());
}
}
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.RestconfSchemaService;
import org.opendaylight.restconf.rest.services.impl.RestconfSchemaServiceImpl;
import org.opendaylight.restconf.utils.RestconfConstants;
this.mountPointService = new DOMMountPointServiceImpl();
((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPointWithNullSchemaContext);
- when(this.mockMountPointHandler.getDOMMountPointService()).thenReturn(this.mountPointService);
+ when(this.mockMountPointHandler.get()).thenReturn(this.mountPointService);
this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler);
}
@Test
public void getSchemaTest() {
// prepare conditions - return not-mount point schema context
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
// make test
final SchemaExportContext exportContext = this.schemaService.getSchema(TEST_MODULE);
@Test
public void getSchemaForNotExistingModuleTest() {
// prepare conditions - return not-mount point schema context
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
// make test
final SchemaExportContext exportContext = this.schemaService.getSchema(NOT_EXISTING_MODULE);
@Test
public void getSchemaMountPointTest() {
// prepare conditions - return schema context with mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
// make test
final SchemaExportContext exportContext = this.schemaService.getSchema(MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT);
@Test
public void getSchemaForNotExistingModuleMountPointTest() {
// prepare conditions - return schema context with mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
// make test
final SchemaExportContext exportContext = this.schemaService.getSchema(MOUNT_POINT + NOT_EXISTING_MODULE);
@Test
public void getSchemaWithNullSchemaContextTest() {
// prepare conditions - returned schema context is null
- when(this.mockContextHandler.getSchemaContext()).thenReturn(null);
+ when(this.mockContextHandler.get()).thenReturn(null);
// make test
this.thrown.expect(NullPointerException.class);
@Test
public void getSchemaWithNullSchemaContextMountPointTest() {
// prepare conditions - returned schema context for mount points is null
- when(this.mockContextHandler.getSchemaContext()).thenReturn(null);
+ when(this.mockContextHandler.get()).thenReturn(null);
// make test
this.thrown.expect(NullPointerException.class);
@Test
public void getSchemaNullSchemaContextBehindMountPointTest() {
// prepare conditions - return correct schema context for mount points (this is not null)
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
// make test - call service on mount point with null schema context
this.thrown.expect(NullPointerException.class);
@Test
public void getSchemaWithNullIdentifierTest() {
// prepare conditions - return correct schema context
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
// make test
this.thrown.expect(NullPointerException.class);
@Test
public void getSchemaWithEmptyIdentifierTest() {
// prepare conditions - return correct schema context
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
// make test and verify
try {
@Test
public void getSchemaWithEmptyIdentifierMountPointTest() {
// prepare conditions - return correct schema context with mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
// make test and verify
try {
@Test
public void getSchemaWithNotParsableIdentifierTest() {
// prepare conditions - return correct schema context without mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
// make test and verify
try {
@Test
public void getSchemaWithNotParsableIdentifierMountPointTest() {
// prepare conditions - return correct schema context with mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
// make test and verify
try {
@Test
public void getSchemaWrongIdentifierTest() {
// prepare conditions - return correct schema context without mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
// make test and verify
try {
@Test
public void getSchemaWrongIdentifierMountPointTest() {
// prepare conditions - return correct schema context with mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
// make test and verify
try {
@Test
public void getSchemaWithoutRevisionTest() {
// prepare conditions - return correct schema context without mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
// make test and verify
try {
@Test
public void getSchemaWithoutRevisionMountPointTest() {
// prepare conditions - return correct schema context with mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
// make test and verify
try {
@Test
public void getSchemaContextWithNotExistingMountPointTest() {
// prepare conditions - return schema context with mount points
- when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+ when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
// make test
this.thrown.expect(IllegalArgumentException.class);
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
import org.opendaylight.netconf.sal.streams.listeners.Notificator;
import org.opendaylight.restconf.Draft11;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.RestconfStreamsService;
import org.opendaylight.restconf.rest.services.impl.RestconfStreamsServiceImpl;
import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeConstants;
@Test
public void getAvailableStreamsTest() throws Exception {
// prepare conditions - get correct Restconf module
- when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+ when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
.getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("ietf-restconf"));
@Test
public void getAvailableStreamsNullSchemaContextNegativeTest() {
// prepare conditions - returned SchemaContext is null
- when(this.contextHandler.getSchemaContext()).thenReturn(null);
+ when(this.contextHandler.get()).thenReturn(null);
// make test
this.thrown.expect(NullPointerException.class);
@Test
public void getAvailableStreamsMissingRestconfModuleNegativeTest() {
// prepare conditions - get null Restconf module
- when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+ when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
.getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision())).thenReturn(null);
@Test
public void getAvailableStreamsMissingListStreamNegativeTest() {
// prepare conditions - get Restconf module with missing list stream
- when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+ when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
.getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-missing-list-stream"));
@Test
public void getAvailableStreamsMissingContainerStreamsNegativeTest() {
// prepare conditions - get Restconf module with missing container streams
- when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+ when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
.getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-missing-container-streams"));
@Test
public void getAvailableStreamsIllegalListStreamNegativeTest() {
// prepare conditions - get Restconf module with illegal list stream
- when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+ when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
.getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-illegal-list-stream"));
@Test
public void getAvailableStreamsIllegalContainerStreamsNegativeTest() {
// prepare conditions - get Restconf module with illegal container streams
- when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+ when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
.getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-illegal-container-streams"));
@Test
public void getAvailableStreamsIllegalLeafDescriptionNegativeTest() {
// prepare conditions - get Restconf module with illegal leaf description in list stream
- when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+ when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
.getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-illegal-leaf-description"));
import org.junit.Test;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
+import org.opendaylight.restconf.utils.validation.RestconfValidation;
/**
* Unit test for {@link RestconfValidation}