2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
13 import java.io.InputStream;
14 import javax.ws.rs.core.MediaType;
15 import org.junit.Test;
16 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
17 import org.opendaylight.yangtools.yang.common.ErrorTag;
19 public class XmlPatchBodyReaderMountPointTest extends AbstractPatchBodyReaderTest {
20 private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount/";
22 private final XmlPatchBodyReader xmlToPatchBodyReader;
24 public XmlPatchBodyReaderMountPointTest() {
25 xmlToPatchBodyReader = new XmlPatchBodyReader(databindProvider, mountPointService);
29 protected MediaType getMediaType() {
30 return new MediaType(MediaType.APPLICATION_XML, null);
34 public void moduleDataTest() throws Exception {
35 mockBodyReader(MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader,
37 checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
38 XmlPatchBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml")));
42 * Test trying to use Patch create operation which requires value without value. Error code 400 should be returned.
45 public void moduleDataValueMissingNegativeTest() throws Exception {
46 final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
47 mockBodyReader(uri, xmlToPatchBodyReader, false);
48 final InputStream inputStream = XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
49 "/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
51 final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
52 () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
53 assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
57 * Test trying to use value with Patch delete operation which does not support value. Error code 400 should be
61 public void moduleDataNotValueNotSupportedNegativeTest() throws Exception {
62 final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
63 mockBodyReader(uri, xmlToPatchBodyReader, false);
64 final InputStream inputStream = XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
65 "/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
67 RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
68 () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
69 assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
73 * Test of Yang Patch with absolute target path.
76 public void moduleDataAbsoluteTargetPathTest() throws Exception {
77 final String uri = MOUNT_POINT;
78 mockBodyReader(uri, xmlToPatchBodyReader, false);
80 checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
81 XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
82 "/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml")));
86 * Test using Patch when target is completely specified in request URI and thus target leaf contains only '/' sign.
89 public void modulePatchCompleteTargetInURITest() throws Exception {
90 final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
91 mockBodyReader(uri, xmlToPatchBodyReader, false);
93 checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
94 XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
95 "/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml")));
99 * Test of Yang Patch merge operation on list. Test consists of two edit operations - replace and merge.
102 public void moduleDataMergeOperationOnListTest() throws Exception {
103 final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
104 mockBodyReader(uri, xmlToPatchBodyReader, false);
106 checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
107 XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
108 "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml")));
112 * Test of Yang Patch merge operation on container. Test consists of two edit operations - create and merge.
115 public void moduleDataMergeOperationOnContainerTest() throws Exception {
116 final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
117 mockBodyReader(uri, xmlToPatchBodyReader, false);
119 checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
120 XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
121 "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml")));