private ListenerRegistration<SchemaContextListener> listenerRegistration;
private static TransactionChainHandler transactionChainHandler;
private static DOMDataBroker dataBroker;
+ private static DOMMountPointServiceHandler mountPointServiceHandler;
@Override
public void onSessionInitiated(final ProviderSession session) {
final SchemaContextHandler schemaCtxHandler = new SchemaContextHandler();
this.listenerRegistration = schemaService.registerSchemaContextListener(schemaCtxHandler);
- final DOMMountPointServiceHandler domMountPointServiceHandler = new DOMMountPointServiceHandler(
+ RestConnectorProvider.mountPointServiceHandler = new DOMMountPointServiceHandler(
session.getService(DOMMountPointService.class));
RestConnectorProvider.dataBroker = session.getService(DOMDataBroker.class);
final DOMRpcService rpcService = session.getService(DOMRpcService.class);
final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
- wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler,
+ wrapperServices.setHandlers(schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler);
}
);
}
+ /**
+ * Get current {@link DOMMountPointService} from {@link DOMMountPointServiceHandler}.
+ * @return {@link DOMMountPointService}
+ */
+ public static DOMMountPointService getMountPointService() {
+ return RestConnectorProvider.mountPointServiceHandler.get();
+ }
+
@Override
public Collection<ProviderFunctionality> getProviderFunctionality() {
return Collections.emptySet();
import org.opendaylight.netconf.sal.rest.api.RestconfConstants;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
+import org.opendaylight.restconf.RestConnectorProvider;
import org.opendaylight.restconf.utils.parser.ParserIdentifier;
public class AbstractIdentifierAwareJaxRsProvider {
}
protected InstanceIdentifierContext<?> getInstanceIdentifierContext() {
- return ParserIdentifier.toInstanceIdentifier(getIdentifier(),
- ControllerContext.getInstance().getGlobalSchema(), Optional.absent());
+ return ParserIdentifier.toInstanceIdentifier(
+ getIdentifier(),
+ ControllerContext.getInstance().getGlobalSchema(),
+ Optional.of(RestConnectorProvider.getMountPointService()));
}
protected UriInfo getUriInfo() {
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.controller.sal.rest.impl.test.providers;
+package org.opendaylight.restconf.jersey.providers;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
-import org.opendaylight.restconf.jersey.providers.AbstractIdentifierAwareJaxRsProvider;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public abstract class Draft17AbstractBodyReaderTest {
+abstract class AbstractBodyReaderTest {
protected final static ControllerContext controllerContext = ControllerContext.getInstance();
protected final MediaType mediaType;
private static Field uriField;
private static Field requestField;
+ protected final static DOMMountPointServiceHandler mountPointServiceHandler = mock(
+ DOMMountPointServiceHandler.class);
- public Draft17AbstractBodyReaderTest() throws NoSuchFieldException,
- SecurityException {
+ AbstractBodyReaderTest() throws NoSuchFieldException, IllegalAccessException {
uriField = AbstractIdentifierAwareJaxRsProvider.class
.getDeclaredField("uriInfo");
uriField.setAccessible(true);
+
requestField = AbstractIdentifierAwareJaxRsProvider.class
.getDeclaredField("request");
requestField.setAccessible(true);
+
mediaType = getMediaType();
+
+ final Field mountPointServiceHandlerField = RestConnectorProvider.class.
+ getDeclaredField("mountPointServiceHandler");
+ mountPointServiceHandlerField.setAccessible(true);
+ mountPointServiceHandlerField.set(RestConnectorProvider.class, mountPointServiceHandler);
}
protected abstract MediaType getMediaType();
requestField.set(normalizedNodeProvider, request);
}
- protected static void checkMountPointNormalizedNodeContext(
- final NormalizedNodeContext nnContext) {
- checkNormalizedNodeContext(nnContext);
- assertNotNull(nnContext.getInstanceIdentifierContext().getMountPoint());
- }
-
protected static void checkNormalizedNodeContext(
final NormalizedNodeContext nnContext) {
assertNotNull(nnContext.getData());
assertNotNull(patchContext.getInstanceIdentifierContext().getSchemaContext());
assertNotNull(patchContext.getInstanceIdentifierContext().getSchemaNode());
}
+
+ protected static void checkPATCHContextMountPoint(final PATCHContext patchContext) {
+ checkPATCHContext(patchContext);
+ assertNotNull(patchContext.getInstanceIdentifierContext().getMountPoint());
+ assertNotNull(patchContext.getInstanceIdentifierContext().getMountPoint().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.jersey.providers;
+
+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 java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URI;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+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.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.controller.sal.rest.impl.test.providers.TestXmlBodyReader;
+import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+public class JsonBodyReaderTest extends AbstractBodyReaderTest {
+
+ private final JsonNormalizedNodeBodyReader jsonBodyReader;
+ private static SchemaContext schemaContext;
+
+ private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = initializeInstanceIdentifierModule();
+
+ private static QNameModule initializeInstanceIdentifierModule() {
+ try {
+ return QNameModule.create(URI.create("instance:identifier:module"),
+ new SimpleDateFormat("yyyy-MM-dd").parse("2014-01-17"));
+ } catch (final ParseException e) {
+ throw new Error(e);
+ }
+ }
+
+ public JsonBodyReaderTest() throws Exception {
+ super();
+ this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
+ }
+
+ @Override
+ protected MediaType getMediaType() {
+ return new MediaType(MediaType.APPLICATION_XML, null);
+ }
+
+ @BeforeClass
+ public static void initialization()
+ throws NoSuchFieldException, SecurityException, FileNotFoundException, SourceException, ReactorException {
+ final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
+ testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
+ schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ controllerContext.setSchemas(schemaContext);
+ when(mountPointServiceHandler.get()).thenReturn(mock(DOMMountPointService.class));
+ }
+
+ @Test
+ public void moduleDataTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, this.jsonBodyReader, false);
+ final InputStream inputStream = JsonBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/json/jsondata.json");
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerDataPutTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
+ final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
+ final String uri = "instance-identifier-module:cont/cont1";
+ mockBodyReader(uri, this.jsonBodyReader, false);
+ final InputStream inputStream = JsonBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, this.jsonBodyReader, true);
+ final InputStream inputStream = JsonBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerAugmentDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
+ final QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
+ final YangInstanceIdentifier.AugmentationIdentifier augII = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(contAugmentQName));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(augII)
+ .node(contAugmentQName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, this.jsonBodyReader, true);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/json_augment_container.json");
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerChoiceAugmentDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
+ final QName augmentChoice1QName = QName.create(augmentModule.getQNameModule(), "augment-choice1");
+ final QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
+ final QName containerQName = QName.create(augmentChoice1QName, "case-choice-case-container1");
+ final YangInstanceIdentifier.AugmentationIdentifier augChoice1II = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(augmentChoice1QName));
+ final YangInstanceIdentifier.AugmentationIdentifier augChoice2II = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(augmentChoice2QName));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(augChoice1II)
+ .node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName).node(containerQName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, this.jsonBodyReader, true);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/json_augment_choice_container.json");
+ final NormalizedNodeContext returnValue = this.jsonBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ final NormalizedNodeContext nnContext, final YangInstanceIdentifier dataNodeIdent) {
+ assertEquals(dataSchemaNode, nnContext.getInstanceIdentifierContext().getSchemaNode());
+ assertEquals(dataNodeIdent, nnContext.getInstanceIdentifierContext().getInstanceIdentifier());
+ assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
+ }
+}
\ No newline at end of file
--- /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.jersey.providers;
+
+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.controller.sal.rest.impl.test.providers.TestJsonBodyReader;
+import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public class JsonPATCHBodyReaderMountPointTest extends AbstractBodyReaderTest {
+
+ private final JsonToPATCHBodyReader jsonPATCHBodyReader;
+ private static SchemaContext schemaContext;
+ private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount/";
+
+ public JsonPATCHBodyReaderMountPointTest() throws Exception {
+ super();
+ jsonPATCHBodyReader = new JsonToPATCHBodyReader();
+ }
+
+ @Override
+ protected MediaType getMediaType() {
+ return new MediaType(APPLICATION_JSON, null);
+ }
+
+ @BeforeClass
+ public static void initialization() {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+
+ final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
+ final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
+
+ when(mountPointServiceHandler.get()).thenReturn(mountPointService);
+ when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
+ when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
+
+ controllerContext.setSchemas(schemaContext);
+ }
+
+ @Test
+ public void modulePATCHDataTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+ mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+ final InputStream inputStream = TestJsonBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/jsonPATCHdata.json");
+
+ final PATCHContext returnValue = jsonPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+
+ /**
+ * Test of successful PATCH consisting of create and delete PATCH operations.
+ */
+ @Test
+ public void modulePATCHCreateAndDeleteTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+ mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+ final InputStream inputStream = TestJsonBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json");
+
+ final PATCHContext returnValue = jsonPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+
+ /**
+ * Test trying to use PATCH create operation which requires value without value. Test should fail with
+ * {@link RestconfDocumentedException} with error code 400.
+ */
+ @Test
+ public void modulePATCHValueMissingNegativeTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+ mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+ final InputStream inputStream = TestJsonBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueMissing.json");
+
+ try {
+ jsonPATCHBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ fail("Test should return error 400 due to missing value node when attempt to invoke create operation");
+ } catch (final RestconfDocumentedException e) {
+ assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
+ }
+ }
+
+ /**
+ * Test trying to use value with PATCH delete operation which does not support value. Test should fail with
+ * {@link RestconfDocumentedException} with error code 400.
+ */
+ @Test
+ public void modulePATCHValueNotSupportedNegativeTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+ mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+ final InputStream inputStream = TestJsonBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
+
+ try {
+ jsonPATCHBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ fail("Test should return error 400 due to present value node when attempt to invoke delete operation");
+ } catch (final RestconfDocumentedException e) {
+ assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
+ }
+ }
+
+ /**
+ * Test using PATCH when target is completely specified in request URI and thus target leaf contains only '/' sign.
+ */
+ @Test
+ public void modulePATCHCompleteTargetInURITest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
+ mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+ final InputStream inputStream = TestJsonBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json");
+
+ final PATCHContext returnValue = jsonPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+
+ /**
+ * Test of Yang PATCH merge operation on list. Test consists of two edit operations - replace and merge.
+ */
+ @Test
+ public void modulePATCHMergeOperationOnListTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+ mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+ final InputStream inputStream = TestJsonBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnList.json");
+
+ final PATCHContext returnValue = jsonPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+
+ /**
+ * Test of Yang PATCH merge operation on container. Test consists of two edit operations - create and merge.
+ */
+ @Test
+ public void modulePATCHMergeOperationOnContainerTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
+ mockBodyReader(uri, jsonPATCHBodyReader, false);
+
+ final InputStream inputStream = TestJsonBodyReader.class
+ .getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json");
+
+ final PATCHContext returnValue = jsonPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.controller.sal.rest.impl.test.providers;
+package org.opendaylight.restconf.jersey.providers;
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.controller.sal.rest.impl.test.providers.TestJsonBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.restconf.jersey.providers.JsonToPATCHBodyReader;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class TestDraft17JsonPATCHBodyReader extends Draft17AbstractBodyReaderTest {
+public class JsonPATCHBodyReaderTest extends AbstractBodyReaderTest {
private final JsonToPATCHBodyReader jsonPATCHBodyReader;
private static SchemaContext schemaContext;
- public TestDraft17JsonPATCHBodyReader() throws NoSuchFieldException, SecurityException {
+ public JsonPATCHBodyReaderTest() throws Exception {
super();
jsonPATCHBodyReader = new JsonToPATCHBodyReader();
}
@BeforeClass
public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+ when(mountPointServiceHandler.get()).thenReturn(mock(DOMMountPointService.class));
controllerContext.setSchemas(schemaContext);
}
--- /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.jersey.providers;
+
+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 java.io.InputStream;
+import java.net.URI;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+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.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public class XmlBodyReaderTest extends AbstractBodyReaderTest {
+
+ private final XmlNormalizedNodeBodyReader xmlBodyReader;
+ private static SchemaContext schemaContext;
+ private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = initializeInstanceIdentifierModule();
+
+ private static QNameModule initializeInstanceIdentifierModule() {
+ try {
+ return QNameModule.create(URI.create("instance:identifier:module"),
+ new SimpleDateFormat("yyyy-MM-dd").parse("2014-01-17"));
+ } catch (final ParseException e) {
+ throw new Error(e);
+ }
+ }
+
+ public XmlBodyReaderTest() throws Exception {
+ super();
+ this.xmlBodyReader = new XmlNormalizedNodeBodyReader();
+ }
+
+ @Override
+ protected MediaType getMediaType() {
+ return new MediaType(MediaType.APPLICATION_XML, null);
+ }
+
+ @BeforeClass
+ public static void initialization() throws Exception {
+ final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
+ testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
+ testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
+ schemaContext = TestRestconfUtils.parseYangSources(testFiles);
+ controllerContext.setSchemas(schemaContext);
+ when(mountPointServiceHandler.get()).thenReturn(mock(DOMMountPointService.class));
+ }
+
+ @Test
+ public void moduleDataTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName());
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, this.xmlBodyReader, false);
+ final InputStream inputStream = XmlBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerDataPutTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
+ final DataSchemaNode dataSchemaNodeOnPath = ((DataNodeContainer) dataSchemaNode).getDataChildByName(cont1QName);
+ final String uri = "instance-identifier-module:cont/cont1";
+ mockBodyReader(uri, this.xmlBodyReader, false);
+ final InputStream inputStream = XmlBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNodeOnPath, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final QName cont1QName = QName.create(dataSchemaNode.getQName(), "cont1");
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(cont1QName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, this.xmlBodyReader, true);
+ final InputStream inputStream = XmlBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerAugmentDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
+ final QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
+ final YangInstanceIdentifier.AugmentationIdentifier augII = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(contAugmentQName));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(augII)
+ .node(contAugmentQName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, this.xmlBodyReader, true);
+ final InputStream inputStream = XmlBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/xml/xml_augment_container.xml");
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ @Test
+ public void moduleSubContainerChoiceAugmentDataPostTest() throws Exception {
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
+ final Module augmentModule = schemaContext.findModuleByNamespace(new URI("augment:module")).iterator().next();
+ final QName augmentChoice1QName = QName.create(augmentModule.getQNameModule(), "augment-choice1");
+ final QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
+ final QName containerQName = QName.create(augmentChoice1QName, "case-choice-case-container1");
+ final YangInstanceIdentifier.AugmentationIdentifier augChoice1II = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(augmentChoice1QName));
+ final YangInstanceIdentifier.AugmentationIdentifier augChoice2II = new YangInstanceIdentifier.AugmentationIdentifier(
+ Sets.newHashSet(augmentChoice2QName));
+ final YangInstanceIdentifier dataII = YangInstanceIdentifier.of(dataSchemaNode.getQName()).node(augChoice1II)
+ .node(augmentChoice1QName).node(augChoice2II).node(augmentChoice2QName).node(containerQName);
+ final String uri = "instance-identifier-module:cont";
+ mockBodyReader(uri, this.xmlBodyReader, true);
+ final InputStream inputStream = XmlBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/xml/xml_augment_choice_container.xml");
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+ checkNormalizedNodeContext(returnValue);
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
+ }
+
+ private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ final NormalizedNodeContext nnContext, final YangInstanceIdentifier dataNodeIdent) {
+ assertEquals(dataSchemaNode, nnContext.getInstanceIdentifierContext().getSchemaNode());
+ assertEquals(dataNodeIdent, nnContext.getInstanceIdentifierContext().getInstanceIdentifier());
+ assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
+ }
+
+ /**
+ * Test when container with the same name is placed in two modules
+ * (foo-module and bar-module). Namespace must be used to distinguish
+ * between them to find correct one. Check if container was found not only
+ * according to its name but also by correct namespace used in payload.
+ */
+ @Test
+ public void findFooContainerUsingNamespaceTest() throws Exception {
+ mockBodyReader("", this.xmlBodyReader, true);
+ final InputStream inputStream = XmlBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlDataFindFooContainer.xml");
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+
+ // check return value
+ checkNormalizedNodeContext(returnValue);
+ // check if container was found both according to its name and namespace
+ assertEquals("Not correct container found, name was ignored", "foo-bar-container",
+ returnValue.getData().getNodeType().getLocalName());
+ assertEquals("Not correct container found, namespace was ignored", "foo:module",
+ returnValue.getData().getNodeType().getNamespace().toString());
+ }
+
+ /**
+ * Test when container with the same name is placed in two modules
+ * (foo-module and bar-module). Namespace must be used to distinguish
+ * between them to find correct one. Check if container was found not only
+ * according to its name but also by correct namespace used in payload.
+ */
+ @Test
+ public void findBarContainerUsingNamespaceTest() throws Exception {
+ mockBodyReader("", this.xmlBodyReader, true);
+ final InputStream inputStream = XmlBodyReaderTest.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlDataFindBarContainer.xml");
+ final NormalizedNodeContext returnValue = this.xmlBodyReader.readFrom(null, null, null, this.mediaType, null,
+ inputStream);
+
+ // check return value
+ checkNormalizedNodeContext(returnValue);
+ // check if container was found both according to its name and namespace
+ assertEquals("Not correct container found, name was ignored", "foo-bar-container",
+ returnValue.getData().getNodeType().getLocalName());
+ assertEquals("Not correct container found, namespace was ignored", "bar:module",
+ returnValue.getData().getNodeType().getNamespace().toString());
+ }
+}
--- /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.jersey.providers;
+
+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.controller.sal.rest.impl.test.providers.TestXmlBodyReader;
+import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public class XmlPATCHBodyReaderMountPointTest extends AbstractBodyReaderTest {
+
+ private final XmlToPATCHBodyReader xmlPATCHBodyReader;
+ private static SchemaContext schemaContext;
+ private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount/";
+
+ public XmlPATCHBodyReaderMountPointTest() throws Exception {
+ super();
+ xmlPATCHBodyReader = new XmlToPATCHBodyReader();
+ }
+
+ @Override
+ protected MediaType getMediaType() {
+ return new MediaType(MediaType.APPLICATION_XML, null);
+ }
+
+ @BeforeClass
+ public static void initialization() {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+
+ final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
+ final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
+
+ when(mountPointServiceHandler.get()).thenReturn(mountPointService);
+ when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
+ when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
+
+ controllerContext.setSchemas(schemaContext);
+ }
+
+ @Test
+ public void moduleDataTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+ mockBodyReader(uri, xmlPATCHBodyReader, false);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml");
+ final PATCHContext returnValue = xmlPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+
+ /**
+ * Test trying to use PATCH create operation which requires value without value. Error code 400 should be returned.
+ */
+ @Test
+ public void moduleDataValueMissingNegativeTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+ mockBodyReader(uri, xmlPATCHBodyReader, false);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
+ try {
+ xmlPATCHBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ fail("Test should return error 400 due to missing value node when attempt to invoke create operation");
+ } catch (final RestconfDocumentedException e) {
+ assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
+ }
+ }
+
+ /**
+ * Test trying to use value with PATCH delete operation which does not support value. Error code 400 should be
+ * returned.
+ */
+ @Test
+ public void moduleDataNotValueNotSupportedNegativeTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+ mockBodyReader(uri, xmlPATCHBodyReader, false);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
+ try {
+ xmlPATCHBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ fail("Test should return error 400 due to present value node when attempt to invoke delete operation");
+ } catch (final RestconfDocumentedException e) {
+ assertEquals("Error code 400 expected", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
+ }
+ }
+
+
+ /**
+ * Test of Yang PATCH with absolute target path.
+ */
+ @Test
+ public void moduleDataAbsoluteTargetPathTest() throws Exception {
+ final String uri = MOUNT_POINT;
+ mockBodyReader(uri, xmlPATCHBodyReader, false);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml");
+ final PATCHContext returnValue = xmlPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+
+ /**
+ * Test using PATCH when target is completely specified in request URI and thus target leaf contains only '/' sign.
+ */
+ @Test
+ public void modulePATCHCompleteTargetInURITest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
+ mockBodyReader(uri, xmlPATCHBodyReader, false);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml");
+ final PATCHContext returnValue = xmlPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+
+ /**
+ * Test of Yang PATCH merge operation on list. Test consists of two edit operations - replace and merge.
+ */
+ @Test
+ public void moduleDataMergeOperationOnListTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
+ mockBodyReader(uri, xmlPATCHBodyReader, false);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
+ final PATCHContext returnValue = xmlPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+
+ /**
+ * Test of Yang PATCH merge operation on container. Test consists of two edit operations - create and merge.
+ */
+ @Test
+ public void moduleDataMergeOperationOnContainerTest() throws Exception {
+ final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
+ mockBodyReader(uri, xmlPATCHBodyReader, false);
+ final InputStream inputStream = TestXmlBodyReader.class
+ .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
+ final PATCHContext returnValue = xmlPATCHBodyReader
+ .readFrom(null, null, null, mediaType, null, inputStream);
+ checkPATCHContextMountPoint(returnValue);
+ }
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.controller.sal.rest.impl.test.providers;
+package org.opendaylight.restconf.jersey.providers;
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.controller.sal.rest.impl.test.providers.TestXmlBodyReader;
import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.restconf.jersey.providers.XmlToPATCHBodyReader;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public class TestDraft17XmlPATCHBodyReader extends Draft17AbstractBodyReaderTest {
+public class XmlPATCHBodyReaderTest extends AbstractBodyReaderTest {
private final XmlToPATCHBodyReader xmlPATCHBodyReader;
private static SchemaContext schemaContext;
- public TestDraft17XmlPATCHBodyReader() throws NoSuchFieldException, SecurityException {
+ public XmlPATCHBodyReaderTest() throws Exception {
super();
xmlPATCHBodyReader = new XmlToPATCHBodyReader();
}
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException, SecurityException {
+ public static void initialization() {
schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+ when(mountPointServiceHandler.get()).thenReturn(mock(DOMMountPointService.class));
controllerContext.setSchemas(schemaContext);
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
assertEquals("replace data", status.getEditCollection().get(1).getEditId());
}
+ @Test
+ public void testPatchDataMountPoint() throws Exception {
+ final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(
+ iidBase, schemaNode, mountPoint, contextRef.get());
+ final List<PATCHEntity> entity = new ArrayList<>();
+ final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(iidBase)
+ .node(containerPlayerQname)
+ .node(leafQname)
+ .build();
+ entity.add(new PATCHEntity("create data", "CREATE", iidBase, buildBaseCont));
+ entity.add(new PATCHEntity("replace data", "REPLACE", iidBase, buildBaseCont));
+ entity.add(new PATCHEntity("delete data", "DELETE", iidleaf));
+ final PATCHContext patch = new PATCHContext(iidContext, entity, "test patch id");
+
+ doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseCont))).when(read)
+ .read(LogicalDatastoreType.CONFIGURATION, iidBase);
+ doNothing().when(write).put(LogicalDatastoreType.CONFIGURATION, iidBase, buildBaseCont);
+ doReturn(Futures.immediateCheckedFuture(null)).when(write).submit();
+ doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
+ doReturn(Futures.immediateCheckedFuture(null)).when(readWrite).submit();
+ doReturn(Futures.immediateCheckedFuture(false)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
+ doReturn(Futures.immediateCheckedFuture(true)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
+
+ final PATCHStatusContext status = dataService.patchData(patch, uriInfo);
+ assertTrue(status.isOk());
+ assertEquals(3, status.getEditCollection().size());
+ assertNull(status.getGlobalErrors());
+ }
+
@Test
public void testPatchDataDeleteNotExist() throws Exception {
final Field handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");