package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
abstract class AbstractPatchBodyReaderTest extends AbstractBodyReaderTest {
- static final void checkPatchContext(final PatchContext patchContext) {
+ @NonNull String mountPrefix() {
+ return "";
+ }
+
+ @Nullable DOMMountPoint mountPoint() {
+ return null;
+ }
+
+ final void checkPatchContext(final PatchContext patchContext) {
assertNotNull(patchContext.getData());
final var iid = patchContext.getInstanceIdentifierContext();
assertNotNull(iid.getInstanceIdentifier());
assertNotNull(iid.getSchemaContext());
assertNotNull(iid.getSchemaNode());
+ assertSame(mountPoint(), iid.getMountPoint());
}
- static final void checkPatchContextMountPoint(final PatchContext patchContext) {
- checkPatchContext(patchContext);
- assertNotNull(patchContext.getInstanceIdentifierContext().getMountPoint());
+ static final @NonNull InputStream stringInputStream(final String str) {
+ return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
}
}
*/
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
-
-import java.io.InputStream;
-import javax.ws.rs.core.MediaType;
-import org.junit.Test;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.yangtools.yang.common.ErrorTag;
-
-public class JsonPatchBodyReaderMountPointTest extends AbstractPatchBodyReaderTest {
- private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount/";
-
- private final JsonPatchBodyReader jsonToPatchBodyReader;
-
- public JsonPatchBodyReaderMountPointTest() {
- jsonToPatchBodyReader = new JsonPatchBodyReader(databindProvider, mountPointService);
- }
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+public class JsonPatchBodyReaderMountPointTest extends JsonPatchBodyReaderTest {
@Override
- protected MediaType getMediaType() {
- return new MediaType(APPLICATION_JSON, null);
- }
-
- @Test
- public void modulePatchDataTest() throws Exception {
- final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
-
- checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- JsonPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHdata.json")));
- }
-
- /**
- * 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, jsonToPatchBodyReader, false);
-
- checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- JsonPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json")));
- }
-
- /**
- * 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, jsonToPatchBodyReader, false);
-
- final InputStream inputStream = JsonPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHdataValueMissing.json");
-
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
- () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
- assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
+ String mountPrefix() {
+ return "instance-identifier-module:cont/yang-ext:mount/";
}
- /**
- * 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, jsonToPatchBodyReader, false);
-
- final InputStream inputStream = JsonPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
-
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
- () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
- assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
- }
-
- /**
- * 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, jsonToPatchBodyReader, false);
-
- checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- JsonPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json")));
- }
-
- /**
- * 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, jsonToPatchBodyReader, false);
-
- checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- JsonPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHMergeOperationOnList.json")));
- }
-
- /**
- * 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, jsonToPatchBodyReader, false);
-
- checkPatchContextMountPoint(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- JsonPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json")));
- }
-
- /**
- * Test reading simple leaf value.
- */
- @Test
- public void modulePatchSimpleLeafValueTest() throws Exception {
- final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
-
- checkPatchContext(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- JsonPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHSimpleLeafValue.json")));
+ @Override
+ DOMMountPoint mountPoint() {
+ return mountPoint;
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
import javax.ws.rs.core.MediaType;
import org.junit.Test;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
public class JsonPatchBodyReaderTest extends AbstractPatchBodyReaderTest {
- private final JsonPatchBodyReader jsonToPatchBodyReader;
-
- public JsonPatchBodyReaderTest() {
- jsonToPatchBodyReader = new JsonPatchBodyReader(databindProvider, mountPointService);
- }
+ private final JsonPatchBodyReader jsonToPatchBodyReader =
+ new JsonPatchBodyReader(databindProvider, mountPointService);
@Override
- protected MediaType getMediaType() {
+ protected final MediaType getMediaType() {
return new MediaType(APPLICATION_JSON, null);
}
@Test
- public void modulePatchDataTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
-
- final InputStream inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHdata.json");
+ public final void modulePatchDataTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ jsonToPatchBodyReader, false);
- final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
- checkPatchContext(returnValue);
+ checkPatchContext(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonPatchBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHdata.json")));
}
/**
* Test of successful Patch consisting of create and delete Patch operations.
*/
@Test
- public void modulePatchCreateAndDeleteTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
-
- final InputStream inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json");
+ public final void modulePatchCreateAndDeleteTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ jsonToPatchBodyReader, false);
- final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
- checkPatchContext(returnValue);
+ checkPatchContext(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonPatchBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json")));
}
/**
* {@link RestconfDocumentedException} with error code 400.
*/
@Test
- public void modulePatchValueMissingNegativeTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
+ public final void modulePatchValueMissingNegativeTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
+ final var inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/json/jsonPATCHdataValueMissing.json");
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var ex = assertThrows(RestconfDocumentedException.class,
() -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
}
* {@link RestconfDocumentedException} with error code 400.
*/
@Test
- public void modulePatchValueNotSupportedNegativeTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
+ public final void modulePatchValueNotSupportedNegativeTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
+ final var inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var ex = assertThrows(RestconfDocumentedException.class,
() -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
}
* 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 = "instance-identifier-patch-module:patch-cont";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
-
- final InputStream inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json");
+ public final void modulePatchCompleteTargetInURITest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont", jsonToPatchBodyReader, false);
- final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
- checkPatchContext(returnValue);
+ checkPatchContext(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonPatchBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json")));
}
/**
- * Test of Yang Patch merge operation on list. Test consists of two edit operations - replace and merge.
+ * 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 = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
+ public final void modulePatchMergeOperationOnListTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHMergeOperationOnList.json");
-
- final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
- checkPatchContext(returnValue);
+ checkPatchContext(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonPatchBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHMergeOperationOnList.json")));
}
/**
- * Test of Yang Patch merge operation on container. Test consists of two edit operations - create and merge.
+ * 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 = "instance-identifier-patch-module:patch-cont";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
+ public final void modulePatchMergeOperationOnContainerTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont", jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json");
-
- final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
- checkPatchContext(returnValue);
+ checkPatchContext(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonPatchBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json")));
}
/**
* Test reading simple leaf value.
*/
@Test
- public void modulePatchSimpleLeafValueTest() throws Exception {
- final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
-
- final InputStream inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
+ public final void modulePatchSimpleLeafValueTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ jsonToPatchBodyReader, false);
- final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonPatchBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHSimpleLeafValue.json"));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(LEAF_NAME_QNAME, data.name().getNodeType());
- assertEquals(ImmutableNodes.leafNode(LEAF_NAME_QNAME, "my-leaf20"), data);
+ assertEquals(ImmutableNodes.leafNode(LEAF_NAME_QNAME, "my-leaf20"), returnValue.getData().get(0).getNode());
}
/**
- * Test of Yang Patch on the top-level container with empty URI for data root.
+ * Test of YANG Patch on the top-level container with empty URI for data root.
*/
@Test
- public void modulePatchTargetTopLevelContainerWithEmptyURITest() throws Exception {
- final String uri = "";
- mockBodyReader(uri, jsonToPatchBodyReader, false);
+ public final void modulePatchTargetTopLevelContainerWithEmptyURITest() throws Exception {
+ mockBodyReader(mountPrefix(), jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonPatchBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/json/jsonPATCHTargetTopLevelContainerWithEmptyURI.json");
-
- final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
- checkPatchContext(returnValue);
+ checkPatchContext(jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonPatchBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHTargetTopLevelContainerWithEmptyURI.json")));
}
/**
- * Test of Yang Patch on the top-level container with the full path in the URI and "/" in 'target'.
+ * Test of YANG Patch on the top-level container with the full path in the URI and "/" in 'target'.
*/
@Test
- public void modulePatchTargetTopLevelContainerWithFullPathURITest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont", jsonToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
+ public final void modulePatchTargetTopLevelContainerWithFullPathURITest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont", jsonToPatchBodyReader, false);
+
+ final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, stringInputStream("""
{
"ietf-yang-patch:yang-patch": {
"patch-id": "test-patch",
}
]
}
- }""".getBytes(StandardCharsets.UTF_8));
- final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ }"""));
checkPatchContext(returnValue);
assertEquals(Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(PATCH_CONT_QNAME))
}
/**
- * Test of Yang Patch on the second-level list with the full path in the URI and "/" in 'target'.
+ * Test of YANG Patch on the second-level list with the full path in the URI and "/" in 'target'.
*/
@Test
- public void modulePatchTargetSecondLevelListWithFullPathURITest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=my-leaf-set",
- jsonToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
+ public final void modulePatchTargetSecondLevelListWithFullPathURITest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=my-leaf-set",
+ jsonToPatchBodyReader, false);
+
+ final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, stringInputStream("""
{
"ietf-yang-patch:yang-patch": {
"patch-id": "test-patch",
}
]
}
- }""".getBytes(StandardCharsets.UTF_8));
- final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ }"""));
checkPatchContext(returnValue);
assertEquals(Builders.mapBuilder()
.withNodeIdentifier(new NodeIdentifier(MY_LIST1_QNAME))
* Test of Yang Patch on the top augmented element.
*/
@Test
- public void modulePatchTargetTopLevelAugmentedContainerTest() throws Exception {
- mockBodyReader("", jsonToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
+ public final void modulePatchTargetTopLevelAugmentedContainerTest() throws Exception {
+ mockBodyReader(mountPrefix(), jsonToPatchBodyReader, false);
+
+ final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, stringInputStream("""
{
"ietf-yang-patch:yang-patch": {
"patch-id": "test-patch",
}
]
}
- }
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(CONT_AUG_QNAME))
- .withChild(ImmutableNodes.leafNode(LEAF_AUG_QNAME, "data"))
- .build();
- final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ }"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(CONT_AUG_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(CONT_AUG_QNAME))
+ .withChild(ImmutableNodes.leafNode(LEAF_AUG_QNAME, "data"))
+ .build(), returnValue.getData().get(0).getNode());
}
/**
- * Test of Yang Patch on the system map node element.
+ * Test of YANG Patch on the system map node element.
*/
@Test
- public void modulePatchTargetMapNodeTest() throws Exception {
- mockBodyReader("", jsonToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
+ public final void modulePatchTargetMapNodeTest() throws Exception {
+ mockBodyReader(mountPrefix(), jsonToPatchBodyReader, false);
+
+ final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, stringInputStream("""
{
"ietf-yang-patch:yang-patch": {
"patch-id": "map-patch",
}
]
}
- }
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.mapBuilder()
- .withNodeIdentifier(new NodeIdentifier(MAP_CONT_QNAME))
- .withChild(Builders.mapEntryBuilder()
- .withNodeIdentifier(NodeIdentifierWithPredicates.of(MAP_CONT_QNAME, KEY_LEAF_QNAME, "key"))
- .withChild(ImmutableNodes.leafNode(KEY_LEAF_QNAME, "key"))
- .withChild(ImmutableNodes.leafNode(DATA_LEAF_QNAME, "data"))
- .build())
- .build();
- final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ }"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(MAP_CONT_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MAP_CONT_QNAME))
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(MAP_CONT_QNAME, KEY_LEAF_QNAME, "key"))
+ .withChild(ImmutableNodes.leafNode(KEY_LEAF_QNAME, "key"))
+ .withChild(ImmutableNodes.leafNode(DATA_LEAF_QNAME, "data"))
+ .build())
+ .build(), returnValue.getData().get(0).getNode());
}
/**
* Test of Yang Patch on the leaf set node element.
*/
@Test
- public void modulePatchTargetLeafSetNodeTest() throws Exception {
- mockBodyReader("", jsonToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
+ public final void modulePatchTargetLeafSetNodeTest() throws Exception {
+ mockBodyReader(mountPrefix() + "", jsonToPatchBodyReader, false);
+
+ final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, stringInputStream("""
{
"ietf-yang-patch:yang-patch": {
"patch-id": "set-patch",
}
]
}
- }
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.leafSetBuilder()
- .withNodeIdentifier(new NodeIdentifier(LEAF_SET_QNAME))
- .withChild(Builders.leafSetEntryBuilder()
- .withNodeIdentifier(new NodeWithValue<>(LEAF_SET_QNAME, "data1"))
- .withValue("data1")
- .build())
- .build();
- final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ }"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(LEAF_SET_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(LEAF_SET_QNAME))
+ .withChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(LEAF_SET_QNAME, "data1"))
+ .withValue("data1")
+ .build())
+ .build(), returnValue.getData().get(0).getNode());
}
/**
* Test of Yang Patch on the unkeyed list node element.
*/
@Test
- public void modulePatchTargetUnkeyedListNodeTest() throws Exception {
- mockBodyReader("", jsonToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
+ public final void modulePatchTargetUnkeyedListNodeTest() throws Exception {
+ mockBodyReader(mountPrefix(), jsonToPatchBodyReader, false);
+
+ final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, stringInputStream("""
{
"ietf-yang-patch:yang-patch": {
"patch-id": "list-patch",
}
]
}
- }
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.unkeyedListBuilder()
- .withNodeIdentifier(new NodeIdentifier(LIST_QNAME))
- .withChild(Builders.unkeyedListEntryBuilder()
- .withNodeIdentifier(new NodeIdentifier(LIST_QNAME))
- .withChild(ImmutableNodes.leafNode(LIST_LEAF1_QNAME, "data1"))
- .withChild(ImmutableNodes.leafNode(LIST_LEAF2_QNAME, "data2"))
- .build())
- .build();
- final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ }"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(LIST_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.unkeyedListBuilder()
+ .withNodeIdentifier(new NodeIdentifier(LIST_QNAME))
+ .withChild(Builders.unkeyedListEntryBuilder()
+ .withNodeIdentifier(new NodeIdentifier(LIST_QNAME))
+ .withChild(ImmutableNodes.leafNode(LIST_LEAF1_QNAME, "data1"))
+ .withChild(ImmutableNodes.leafNode(LIST_LEAF2_QNAME, "data2"))
+ .build())
+ .build(), returnValue.getData().get(0).getNode());
}
/**
* Test of Yang Patch on the case node element.
*/
@Test
- public void modulePatchTargetCaseNodeTest() throws Exception {
- mockBodyReader("", jsonToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
+ public final void modulePatchTargetCaseNodeTest() throws Exception {
+ mockBodyReader(mountPrefix(), jsonToPatchBodyReader, false);
+
+ final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, stringInputStream("""
{
"ietf-yang-patch:yang-patch": {
"patch-id": "choice-patch",
}
]
}
- }
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(CHOICE_CONT_QNAME))
- .withChild(ImmutableNodes.leafNode(CASE_LEAF1_QNAME, "data"))
- .build();
- final var returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ }"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(CHOICE_CONT_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(CHOICE_CONT_QNAME))
+ .withChild(ImmutableNodes.leafNode(CASE_LEAF1_QNAME, "data"))
+ .build(), returnValue.getData().get(0).getNode());
}
}
*/
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
-
-import java.io.InputStream;
-import javax.ws.rs.core.MediaType;
-import org.junit.Test;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.yangtools.yang.common.ErrorTag;
-
-public class XmlPatchBodyReaderMountPointTest extends AbstractPatchBodyReaderTest {
- private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount/";
-
- private final XmlPatchBodyReader xmlToPatchBodyReader;
-
- public XmlPatchBodyReaderMountPointTest() {
- xmlToPatchBodyReader = new XmlPatchBodyReader(databindProvider, mountPointService);
- }
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+public class XmlPatchBodyReaderMountPointTest extends XmlPatchBodyReaderTest {
@Override
- protected MediaType getMediaType() {
- return new MediaType(MediaType.APPLICATION_XML, null);
- }
-
- @Test
- public void moduleDataTest() throws Exception {
- mockBodyReader(MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader,
- false);
- checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlPatchBodyReaderMountPointTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml")));
- }
-
- /**
- * 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, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
-
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
- () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
- assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
- }
-
- /**
- * 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, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
-
- RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
- () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
- assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
- }
-
- /**
- * Test of Yang Patch with absolute target path.
- */
- @Test
- public void moduleDataAbsoluteTargetPathTest() throws Exception {
- final String uri = MOUNT_POINT;
- mockBodyReader(uri, xmlToPatchBodyReader, false);
-
- checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml")));
- }
-
- /**
- * 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, xmlToPatchBodyReader, false);
-
- checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml")));
- }
-
- /**
- * 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, xmlToPatchBodyReader, false);
-
- checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml")));
+ String mountPrefix() {
+ return "instance-identifier-module:cont/yang-ext:mount/";
}
- /**
- * 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, xmlToPatchBodyReader, false);
-
- checkPatchContextMountPoint(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
- XmlPatchBodyReaderMountPointTest.class.getResourceAsStream(
- "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml")));
+ @Override
+ DOMMountPoint mountPoint() {
+ return mountPoint;
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
import javax.ws.rs.core.MediaType;
import org.junit.Test;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
public class XmlPatchBodyReaderTest extends AbstractPatchBodyReaderTest {
- private final XmlPatchBodyReader xmlToPatchBodyReader;
-
- public XmlPatchBodyReaderTest() {
- xmlToPatchBodyReader = new XmlPatchBodyReader(databindProvider, mountPointService);
- }
+ private final XmlPatchBodyReader xmlToPatchBodyReader = new XmlPatchBodyReader(databindProvider, mountPointService);
@Override
- protected MediaType getMediaType() {
+ protected final MediaType getMediaType() {
return new MediaType(MediaType.APPLICATION_XML, null);
}
@Test
- public void moduleDataTest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
+ public final void moduleDataTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ xmlToPatchBodyReader, false);
+
checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
XmlPatchBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml")));
}
* Test trying to use Patch create operation which requires value without value. Error code 400 should be returned.
*/
@Test
- public void moduleDataValueMissingNegativeTest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlPatchBodyReaderTest.class.getResourceAsStream(
+ public final void moduleDataValueMissingNegativeTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ xmlToPatchBodyReader, false);
+
+ final var inputStream = XmlPatchBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var ex = assertThrows(RestconfDocumentedException.class,
() -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
}
* returned.
*/
@Test
- public void moduleDataNotValueNotSupportedNegativeTest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlPatchBodyReaderTest.class.getResourceAsStream(
+ public final void moduleDataNotValueNotSupportedNegativeTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ xmlToPatchBodyReader, false);
+
+ final var inputStream = XmlPatchBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
- final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ final var ex = assertThrows(RestconfDocumentedException.class,
() -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
assertEquals(ErrorTag.MALFORMED_MESSAGE, ex.getErrors().get(0).getErrorTag());
}
/**
- * Test of Yang Patch with absolute target path.
+ * Test of YANG Patch with absolute target path.
*/
@Test
- public void moduleDataAbsoluteTargetPathTest() throws Exception {
- mockBodyReader("", xmlToPatchBodyReader, false);
+ public final void moduleDataAbsoluteTargetPathTest() throws Exception {
+ mockBodyReader(mountPrefix(), xmlToPatchBodyReader, false);
+
checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
XmlPatchBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml")));
* Test using Patch when target is completely specified in request URI and thus target leaf contains only '/' sign.
*/
@Test
- public void modulePatchCompleteTargetInURITest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
+ public final void modulePatchCompleteTargetInURITest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
+
checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
XmlPatchBodyReaderTest.class.getResourceAsStream(
"/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml")));
* Test of Yang Patch merge operation on list. Test consists of two edit operations - replace and merge.
*/
@Test
- public void moduleDataMergeOperationOnListTest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlPatchBodyReaderTest.class.getResourceAsStream(
- "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
- checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+ public final void moduleDataMergeOperationOnListTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ xmlToPatchBodyReader, false);
+
+ checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlPatchBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml")));
}
/**
* Test of Yang Patch merge operation on container. Test consists of two edit operations - create and merge.
*/
@Test
- public void moduleDataMergeOperationOnContainerTest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlPatchBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
- checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+ public final void moduleDataMergeOperationOnContainerTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
+
+ checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlPatchBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml")));
}
/**
* Test of Yang Patch on the top-level container with empty URI for data root.
*/
@Test
- public void modulePatchTargetTopLevelContainerWithEmptyURITest() throws Exception {
- mockBodyReader("", xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlPatchBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHTargetTopLevelContainerWithEmptyURI.xml");
- checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+ public final void modulePatchTargetTopLevelContainerWithEmptyURITest() throws Exception {
+ mockBodyReader(mountPrefix(), xmlToPatchBodyReader, false);
+
+ checkPatchContext(xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlPatchBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHTargetTopLevelContainerWithEmptyURI.xml")));
}
/**
- * Test of Yang Patch on the top-level container with the full path in the URI and "/" in 'target'.
+ * Test of YANG Patch on the top-level container with the full path in the URI and "/" in 'target'.
*/
@Test
- public void modulePatchTargetTopLevelContainerWithFullPathURITest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
- <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
- <patch-id>test-patch</patch-id>
- <comment>Test patch applied to the top-level container with '/' in target</comment>
- <edit>
- <edit-id>edit1</edit-id>
- <operation>replace</operation>
- <target>/</target>
- <value>
- <patch-cont xmlns="instance:identifier:patch:module">
- <my-list1>
- <name>my-leaf-set</name>
- <my-leaf11>leaf-a</my-leaf11>
- <my-leaf12>leaf-b</my-leaf12>
- </my-list1>
- </patch-cont>
- </value>
- </edit>
- </yang-patch>
- """.getBytes(StandardCharsets.UTF_8));
- final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ public final void modulePatchTargetTopLevelContainerWithFullPathURITest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont", xmlToPatchBodyReader, false);
+
+ final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ stringInputStream("""
+ <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
+ <patch-id>test-patch</patch-id>
+ <comment>Test patch applied to the top-level container with '/' in target</comment>
+ <edit>
+ <edit-id>edit1</edit-id>
+ <operation>replace</operation>
+ <target>/</target>
+ <value>
+ <patch-cont xmlns="instance:identifier:patch:module">
+ <my-list1>
+ <name>my-leaf-set</name>
+ <my-leaf11>leaf-a</my-leaf11>
+ <my-leaf12>leaf-b</my-leaf12>
+ </my-list1>
+ </patch-cont>
+ </value>
+ </edit>
+ </yang-patch>"""));
checkPatchContext(returnValue);
assertEquals(Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(PATCH_CONT_QNAME))
}
/**
- * Test of Yang Patch on the second-level list with the full path in the URI and "/" in 'target'.
+ * Test of YANG Patch on the second-level list with the full path in the URI and "/" in 'target'.
*/
@Test
- public void modulePatchTargetSecondLevelListWithFullPathURITest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=my-leaf-set",
- xmlToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
- <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
- <patch-id>test-patch</patch-id>
- <comment>Test patch applied to the second-level list with '/' in target</comment>
- <edit>
- <edit-id>edit1</edit-id>
- <operation>replace</operation>
- <target>/</target>
- <value>
- <my-list1 xmlns="instance:identifier:patch:module">
- <name>my-leaf-set</name>
- <my-leaf11>leaf-a</my-leaf11>
- <my-leaf12>leaf-b</my-leaf12>
- </my-list1>
- </value>
- </edit>
- </yang-patch>
- """.getBytes(StandardCharsets.UTF_8));
- final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ public final void modulePatchTargetSecondLevelListWithFullPathURITest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=my-leaf-set",
+ xmlToPatchBodyReader, false);
+
+ final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ stringInputStream("""
+ <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
+ <patch-id>test-patch</patch-id>
+ <comment>Test patch applied to the second-level list with '/' in target</comment>
+ <edit>
+ <edit-id>edit1</edit-id>
+ <operation>replace</operation>
+ <target>/</target>
+ <value>
+ <my-list1 xmlns="instance:identifier:patch:module">
+ <name>my-leaf-set</name>
+ <my-leaf11>leaf-a</my-leaf11>
+ <my-leaf12>leaf-b</my-leaf12>
+ </my-list1>
+ </value>
+ </edit>
+ </yang-patch>
+ """));
checkPatchContext(returnValue);
assertEquals(Builders.mapBuilder()
.withNodeIdentifier(new NodeIdentifier(MY_LIST1_QNAME))
* Test of Yang Patch on the top augmented element.
*/
@Test
- public void moduleTargetTopLevelAugmentedContainerTest() throws Exception {
- mockBodyReader("", xmlToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
- <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
- <patch-id>test-patch</patch-id>
- <comment>This test patch for augmented element</comment>
- <edit>
- <edit-id>edit1</edit-id>
- <operation>replace</operation>
- <target>/test-m:container-root/test-m:container-lvl1/test-m-aug:container-aug</target>
- <value>
- <container-aug xmlns="test-ns-aug">
- <leaf-aug>data</leaf-aug>
- </container-aug>
- </value>
- </edit>
- </yang-patch>
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(CONT_AUG_QNAME))
- .withChild(ImmutableNodes.leafNode(LEAF_AUG_QNAME, "data"))
- .build();
- final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ public final void moduleTargetTopLevelAugmentedContainerTest() throws Exception {
+ mockBodyReader(mountPrefix(), xmlToPatchBodyReader, false);
+
+ final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ stringInputStream("""
+ <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
+ <patch-id>test-patch</patch-id>
+ <comment>This test patch for augmented element</comment>
+ <edit>
+ <edit-id>edit1</edit-id>
+ <operation>replace</operation>
+ <target>/test-m:container-root/test-m:container-lvl1/test-m-aug:container-aug</target>
+ <value>
+ <container-aug xmlns="test-ns-aug">
+ <leaf-aug>data</leaf-aug>
+ </container-aug>
+ </value>
+ </edit>
+ </yang-patch>"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(CONT_AUG_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(CONT_AUG_QNAME))
+ .withChild(ImmutableNodes.leafNode(LEAF_AUG_QNAME, "data"))
+ .build(), returnValue.getData().get(0).getNode());
}
/**
- * Test of Yang Patch on the top system map node element.
+ * Test of YANG Patch on the top system map node element.
*/
@Test
- public void moduleTargetMapNodeTest() throws Exception {
- mockBodyReader("", xmlToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
- <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
- <patch-id>map-patch</patch-id>
- <comment>YANG patch comment</comment>
- <edit>
- <edit-id>edit1</edit-id>
- <operation>replace</operation>
- <target>/map-model:cont-root/map-model:cont1/map-model:my-map=key</target>
- <value>
- <my-map xmlns="map:ns">
- <key-leaf>key</key-leaf>
- <data-leaf>data</data-leaf>
- </my-map>
- </value>
- </edit>
- </yang-patch>
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.mapBuilder()
- .withNodeIdentifier(new NodeIdentifier(MAP_CONT_QNAME))
- .withChild(Builders.mapEntryBuilder()
- .withNodeIdentifier(NodeIdentifierWithPredicates.of(MAP_CONT_QNAME, KEY_LEAF_QNAME, "key"))
- .withChild(ImmutableNodes.leafNode(KEY_LEAF_QNAME, "key"))
- .withChild(ImmutableNodes.leafNode(DATA_LEAF_QNAME, "data"))
- .build())
- .build();
- final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ public final void moduleTargetMapNodeTest() throws Exception {
+ mockBodyReader(mountPrefix(), xmlToPatchBodyReader, false);
+
+ final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ stringInputStream("""
+ <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
+ <patch-id>map-patch</patch-id>
+ <comment>YANG patch comment</comment>
+ <edit>
+ <edit-id>edit1</edit-id>
+ <operation>replace</operation>
+ <target>/map-model:cont-root/map-model:cont1/map-model:my-map=key</target>
+ <value>
+ <my-map xmlns="map:ns">
+ <key-leaf>key</key-leaf>
+ <data-leaf>data</data-leaf>
+ </my-map>
+ </value>
+ </edit>
+ </yang-patch>"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(MAP_CONT_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MAP_CONT_QNAME))
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(MAP_CONT_QNAME, KEY_LEAF_QNAME, "key"))
+ .withChild(ImmutableNodes.leafNode(KEY_LEAF_QNAME, "key"))
+ .withChild(ImmutableNodes.leafNode(DATA_LEAF_QNAME, "data"))
+ .build())
+ .build(), returnValue.getData().get(0).getNode());
}
/**
- * Test of Yang Patch on the leaf set node element.
+ * Test of YANG Patch on the leaf set node element.
*/
@Test
- public void modulePatchTargetLeafSetNodeTest() throws Exception {
- mockBodyReader("", xmlToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
- <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
- <patch-id>set-patch</patch-id>
- <comment>YANG patch comment</comment>
- <edit>
- <edit-id>edit1</edit-id>
- <operation>replace</operation>
- <target>/set-model:cont-root/set-model:cont1/set-model:my-set="data1"</target>
- <value>
- <my-set xmlns="set:ns">data1</my-set>
- </value>
- </edit>
- </yang-patch>
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.leafSetBuilder()
- .withNodeIdentifier(new NodeIdentifier(LEAF_SET_QNAME))
- .withChild(Builders.leafSetEntryBuilder()
- .withNodeIdentifier(new NodeWithValue<>(LEAF_SET_QNAME, "data1"))
- .withValue("data1")
- .build())
- .build();
- final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ public final void modulePatchTargetLeafSetNodeTest() throws Exception {
+ mockBodyReader(mountPrefix(), xmlToPatchBodyReader, false);
+
+ final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ stringInputStream("""
+ <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
+ <patch-id>set-patch</patch-id>
+ <comment>YANG patch comment</comment>
+ <edit>
+ <edit-id>edit1</edit-id>
+ <operation>replace</operation>
+ <target>/set-model:cont-root/set-model:cont1/set-model:my-set="data1"</target>
+ <value>
+ <my-set xmlns="set:ns">data1</my-set>
+ </value>
+ </edit>
+ </yang-patch>"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(LEAF_SET_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(LEAF_SET_QNAME))
+ .withChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(LEAF_SET_QNAME, "data1"))
+ .withValue("data1")
+ .build())
+ .build(), returnValue.getData().get(0).getNode());
}
/**
* Test of Yang Patch on the top unkeyed list element.
*/
@Test
- public void moduleTargetUnkeyedListNodeTest() throws Exception {
- mockBodyReader("", xmlToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
- <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
- <patch-id>list-patch</patch-id>
- <comment>YANG patch comment</comment>
- <edit>
- <edit-id>edit1</edit-id>
- <operation>replace</operation>
- <target>/list-model:cont-root/list-model:cont1/list-model:unkeyed-list</target>
- <value>
- <unkeyed-list xmlns="list:ns">
- <leaf1>data1</leaf1>
- <leaf2>data2</leaf2>
- </unkeyed-list>
- </value>
- </edit>
- </yang-patch>
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.unkeyedListBuilder()
- .withNodeIdentifier(new NodeIdentifier(LIST_QNAME))
- .withChild(Builders.unkeyedListEntryBuilder()
- .withNodeIdentifier(new NodeIdentifier(LIST_QNAME))
- .withChild(ImmutableNodes.leafNode(LIST_LEAF1_QNAME, "data1"))
- .withChild(ImmutableNodes.leafNode(LIST_LEAF2_QNAME, "data2"))
- .build())
- .build();
- final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ public final void moduleTargetUnkeyedListNodeTest() throws Exception {
+ mockBodyReader(mountPrefix(), xmlToPatchBodyReader, false);
+
+ final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ stringInputStream("""
+ <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
+ <patch-id>list-patch</patch-id>
+ <comment>YANG patch comment</comment>
+ <edit>
+ <edit-id>edit1</edit-id>
+ <operation>replace</operation>
+ <target>/list-model:cont-root/list-model:cont1/list-model:unkeyed-list</target>
+ <value>
+ <unkeyed-list xmlns="list:ns">
+ <leaf1>data1</leaf1>
+ <leaf2>data2</leaf2>
+ </unkeyed-list>
+ </value>
+ </edit>
+ </yang-patch>"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(LIST_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.unkeyedListBuilder()
+ .withNodeIdentifier(new NodeIdentifier(LIST_QNAME))
+ .withChild(Builders.unkeyedListEntryBuilder()
+ .withNodeIdentifier(new NodeIdentifier(LIST_QNAME))
+ .withChild(ImmutableNodes.leafNode(LIST_LEAF1_QNAME, "data1"))
+ .withChild(ImmutableNodes.leafNode(LIST_LEAF2_QNAME, "data2"))
+ .build())
+ .build(), returnValue.getData().get(0).getNode());
}
/**
* Test of Yang Patch on the top case node element.
*/
@Test
- public void moduleTargetCaseNodeTest() throws Exception {
- mockBodyReader("", xmlToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
- <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
- <patch-id>choice-patch</patch-id>
- <comment>YANG patch comment</comment>
- <edit>
- <edit-id>edit1</edit-id>
- <operation>replace</operation>
- <target>/choice-model:cont-root/choice-model:cont1/choice-model:case-cont1</target>
- <value>
- <case-cont1 xmlns="choice:ns">
- <case-leaf1>data</case-leaf1>
- </case-cont1>
- </value>
- </edit>
- </yang-patch>
- """.getBytes(StandardCharsets.UTF_8));
- final var expectedData = Builders.containerBuilder()
- .withNodeIdentifier(new NodeIdentifier(CHOICE_CONT_QNAME))
- .withChild(ImmutableNodes.leafNode(CASE_LEAF1_QNAME, "data"))
- .build();
- final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ public final void moduleTargetCaseNodeTest() throws Exception {
+ mockBodyReader(mountPrefix(), xmlToPatchBodyReader, false);
+
+ final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ stringInputStream("""
+ <yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
+ <patch-id>choice-patch</patch-id>
+ <comment>YANG patch comment</comment>
+ <edit>
+ <edit-id>edit1</edit-id>
+ <operation>replace</operation>
+ <target>/choice-model:cont-root/choice-model:cont1/choice-model:case-cont1</target>
+ <value>
+ <case-cont1 xmlns="choice:ns">
+ <case-leaf1>data</case-leaf1>
+ </case-cont1>
+ </value>
+ </edit>
+ </yang-patch>"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(CHOICE_CONT_QNAME, data.name().getNodeType());
- assertEquals(expectedData, data);
+ assertEquals(Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(CHOICE_CONT_QNAME))
+ .withChild(ImmutableNodes.leafNode(CASE_LEAF1_QNAME, "data"))
+ .build(), returnValue.getData().get(0).getNode());
}
/**
* Test reading simple leaf value.
*/
@Test
- public void modulePatchSimpleLeafValueTest() throws Exception {
- mockBodyReader("instance-identifier-patch-module:patch-cont/my-list1=leaf1", xmlToPatchBodyReader, false);
- final var inputStream = new ByteArrayInputStream("""
+ public final void modulePatchSimpleLeafValueTest() throws Exception {
+ mockBodyReader(mountPrefix() + "instance-identifier-patch-module:patch-cont/my-list1=leaf1",
+ xmlToPatchBodyReader, false);
+
+ final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ stringInputStream("""
<yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
<patch-id>test-patch</patch-id>
<comment>this is test patch</comment>
<name xmlns="instance:identifier:patch:module">my-leaf20</name>
</value>
</edit>
- </yang-patch>
- """.getBytes(StandardCharsets.UTF_8));
- final var returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
+ </yang-patch>"""));
checkPatchContext(returnValue);
- final var data = returnValue.getData().get(0).getNode();
- assertEquals(LEAF_NAME_QNAME, data.name().getNodeType());
- assertEquals(ImmutableNodes.leafNode(LEAF_NAME_QNAME, "my-leaf20"), data);
+ assertEquals(ImmutableNodes.leafNode(LEAF_NAME_QNAME, "my-leaf20"), returnValue.getData().get(0).getNode());
}
}
protected final MediaType mediaType;
protected final DatabindProvider databindProvider;
protected final DOMMountPointService mountPointService;
+ protected final DOMMountPoint mountPoint;
protected AbstractBodyReaderTest() {
this(BASELINE_CONTEXT);
databindProvider = () -> databindContext;
mountPointService = mock(DOMMountPointService.class);
- final var mountPoint = mock(DOMMountPoint.class);
+ mountPoint = mock(DOMMountPoint.class);
doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
doReturn(Optional.of(FixedDOMSchemaService.of(schemaContext))).when(mountPoint)
.getService(DOMSchemaService.class);