edit.setTarget(path.getInstanceIdentifier());
edit.setTargetSchemaNode(path.getSchemaContext());
} else {
- edit.setTarget(codec.deserialize(codec.serialize(path.getInstanceIdentifier()).concat(target)));
+ edit.setTarget(ParserIdentifier.parserPatchTarget(path, target));
edit.setTargetSchemaNode(SchemaContextUtil.findDataSchemaNode(path.getSchemaContext(),
codec.getDataContextTree().findChild(edit.getTarget()).orElseThrow().getDataSchemaNode()
.getPath().getParent()));
*/
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
+import static com.google.common.base.Verify.verifyNotNull;
+
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import javax.ws.rs.Consumes;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.dom.DOMSource;
import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.patch.PatchEditOperation;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
-import org.opendaylight.restconf.nb.rfc8040.codecs.StringModuleInstanceIdentifierCodec;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
+import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
+import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.slf4j.Logger;
targetII = pathContext.getInstanceIdentifier();
targetNode = pathContext.getSchemaContext();
} else {
- // get namespace according to schema node from path context or value
- final URI namespace = firstValueElement == null ? schemaNode.getQName().getNamespace()
- : URI.create(firstValueElement.getNamespaceURI());
-
- // find module according to namespace
- final Module module = pathContext.getSchemaContext().findModules(namespace).iterator().next();
-
- // initialize codec + set default prefix derived from module name
- final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec(
- pathContext.getSchemaContext(), module.getName());
+ // interpret as simple context
+ targetII = ParserIdentifier.parserPatchTarget(pathContext, target);
- targetII = codec.deserialize(codec.serialize(pathContext.getInstanceIdentifier())
- .concat(prepareNonCondXpath(schemaNode, target.replaceFirst("/", ""), firstValueElement,
- namespace, module.getQNameModule().getRevision().orElse(null))));
+ // move schema node
+ final DataSchemaContextTree tree = DataSchemaContextTree.from(pathContext.getSchemaContext());
+ schemaNode = verifyNotNull(tree.findChild(targetII).orElseThrow().getDataSchemaNode());
targetNode = SchemaContextUtil.findDataSchemaNode(pathContext.getSchemaContext(),
- codec.getDataContextTree().findChild(targetII).orElseThrow().getDataSchemaNode()
- .getPath().getParent());
-
- // move schema node
- schemaNode = (DataSchemaNode) SchemaContextUtil.findDataSchemaNode(pathContext.getSchemaContext(),
- codec.getDataContextTree().findChild(targetII).orElseThrow().getDataSchemaNode().getPath());
+ schemaNode.getPath().getParent());
}
if (targetNode == null) {
return result;
}
-
- /**
- * Prepare non-conditional XPath suitable for deserialization with {@link StringModuleInstanceIdentifierCodec}.
- *
- * @param schemaNode Top schema node
- * @param target Edit operation target
- * @param value Element with value
- * @param namespace Module namespace
- * @param revision Module revision
- * @return Non-conditional XPath
- */
- private static String prepareNonCondXpath(final @NonNull DataSchemaNode schemaNode, final @NonNull String target,
- final @NonNull Element value, final @NonNull URI namespace, final @Nullable Revision revision) {
- final Iterator<String> args = SLASH_SPLITTER.split(target.substring(target.indexOf(':') + 1)).iterator();
-
- final StringBuilder nonCondXpath = new StringBuilder();
- SchemaNode childNode = schemaNode;
-
- while (args.hasNext()) {
- final String s = args.next();
- nonCondXpath.append("/");
- nonCondXpath.append(s);
- childNode = ((DataNodeContainer) childNode).getDataChildByName(QName.create(namespace, revision, s));
-
- if (childNode instanceof ListSchemaNode && args.hasNext()) {
- appendKeys(nonCondXpath, ((ListSchemaNode) childNode).getKeyDefinition().iterator(), args);
- }
- }
-
- if (childNode instanceof ListSchemaNode && value != null) {
- final Iterator<String> keyValues = readKeyValues(value,
- ((ListSchemaNode) childNode).getKeyDefinition().iterator());
- appendKeys(nonCondXpath, ((ListSchemaNode) childNode).getKeyDefinition().iterator(), keyValues);
- }
-
- return nonCondXpath.toString();
- }
-
- /**
- * Read value for every list key.
- *
- * @param value Value element
- * @param keys Iterator of list keys names
- * @return Iterator of list keys values
- */
- private static Iterator<String> readKeyValues(final @NonNull Element value, final @NonNull Iterator<QName> keys) {
- final List<String> result = new ArrayList<>();
-
- while (keys.hasNext()) {
- result.add(value.getElementsByTagName(keys.next().getLocalName()).item(0).getFirstChild().getNodeValue());
- }
-
- return result.iterator();
- }
-
- /**
- * Append key name - key value pairs for every list key to {@code nonCondXpath}.
- *
- * @param nonCondXpath Builder for creating non-conditional XPath
- * @param keyNames Iterator of list keys names
- * @param keyValues Iterator of list keys values
- */
- private static void appendKeys(final @NonNull StringBuilder nonCondXpath, final @NonNull Iterator<QName> keyNames,
- final @NonNull Iterator<String> keyValues) {
- while (keyNames.hasNext()) {
- nonCondXpath.append('[').append(keyNames.next().getLocalName()).append("='").append(keyValues.next())
- .append("']");
- }
- }
}
}
}
+ public static YangInstanceIdentifier parserPatchTarget(final InstanceIdentifierContext<?> context,
+ final String target) {
+ final var schemaContext = context.getSchemaContext();
+ final var urlPath = context.getInstanceIdentifier();
+ final String targetUrl;
+ if (urlPath.isEmpty()) {
+ targetUrl = target.startsWith("/") ? target.substring(1) : target;
+ } else {
+ targetUrl = stringFromYangInstanceIdentifier(urlPath, schemaContext) + target;
+ }
+
+ return toInstanceIdentifier(targetUrl, schemaContext, Optional.empty()).getInstanceIdentifier();
+ }
+
/**
* Validation and parsing of revision.
*
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/json/jsonPATCHdata.json");
-
- final PatchContext returnValue = jsonToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHdata.json"));
checkPatchContextMountPoint(returnValue);
}
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json");
-
- final PatchContext returnValue = jsonToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCreateAndDelete.json"));
checkPatchContextMountPoint(returnValue);
}
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueMissing.json");
-
- try {
- jsonToPatchBodyReader.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());
- }
+ final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHdataValueMissing.json");
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+ assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
}
/**
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
-
- try {
- jsonToPatchBodyReader.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());
- }
+ final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHdataValueNotSupported.json");
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+ assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
}
/**
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
mockBodyReader(uri, jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json");
-
- final PatchContext returnValue = jsonToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json"));
checkPatchContextMountPoint(returnValue);
}
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnList.json");
-
- final PatchContext returnValue = jsonToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHMergeOperationOnList.json"));
checkPatchContextMountPoint(returnValue);
}
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
mockBodyReader(uri, jsonToPatchBodyReader, false);
- final InputStream inputStream = JsonBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json");
-
- final PatchContext returnValue = jsonToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json"));
checkPatchContextMountPoint(returnValue);
}
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, jsonToPatchBodyReader, false);
- final InputStream inputStream =
- JsonBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
-
- final PatchContext returnValue = jsonToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json"));
checkPatchContext(returnValue);
}
}
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
public void moduleDataTest() throws Exception {
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml"));
checkPatchContextMountPoint(returnValue);
}
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 = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
- try {
- xmlToPatchBodyReader.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());
- }
+ final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
+
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+ assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
}
/**
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 = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
- try {
- xmlToPatchBodyReader.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());
- }
+ final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
+
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+ assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
}
public void moduleDataAbsoluteTargetPathTest() throws Exception {
final String uri = MOUNT_POINT;
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml"));
checkPatchContextMountPoint(returnValue);
}
public void modulePatchCompleteTargetInURITest() throws Exception {
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml"));
checkPatchContextMountPoint(returnValue);
}
public void moduleDataMergeOperationOnListTest() throws Exception {
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml"));
checkPatchContextMountPoint(returnValue);
}
public void moduleDataMergeOperationOnContainerTest() throws Exception {
final String uri = MOUNT_POINT + "instance-identifier-patch-module:patch-cont";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml"));
checkPatchContextMountPoint(returnValue);
}
}
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
public void moduleDataTest() throws Exception {
final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdata.xml"));
checkPatchContext(returnValue);
}
public void moduleDataValueMissingNegativeTest() throws Exception {
final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
- try {
- xmlToPatchBodyReader.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());
- }
+ final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataValueMissing.xml");
+
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+ assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
}
/**
public void moduleDataNotValueNotSupportedNegativeTest() throws Exception {
final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
- try {
- xmlToPatchBodyReader.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());
- }
+ final InputStream inputStream = XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataValueNotSupported.xml");
+
+ final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class,
+ () -> xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream));
+ assertEquals("Error code 400 expected", 400, ex.getErrors().get(0).getErrorTag().getStatusCode());
}
public void moduleDataAbsoluteTargetPathTest() throws Exception {
final String uri = "";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataAbsoluteTargetPath.xml"));
checkPatchContext(returnValue);
}
public void modulePatchCompleteTargetInURITest() throws Exception {
final String uri = "instance-identifier-patch-module:patch-cont";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataCompleteTargetInURI.xml"));
checkPatchContext(returnValue);
}
public void moduleDataMergeOperationOnListTest() throws Exception {
final String uri = "instance-identifier-patch-module:patch-cont/my-list1=leaf1";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnList.xml"));
checkPatchContext(returnValue);
}
public void moduleDataMergeOperationOnContainerTest() throws Exception {
final String uri = "instance-identifier-patch-module:patch-cont";
mockBodyReader(uri, xmlToPatchBodyReader, false);
- final InputStream inputStream = XmlBodyReaderTest.class
- .getResourceAsStream("/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml");
- final PatchContext returnValue = xmlToPatchBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final PatchContext returnValue = xmlToPatchBodyReader.readFrom(null, null, null, mediaType, null,
+ XmlBodyReaderTest.class.getResourceAsStream(
+ "/instanceidentifier/xml/xmlPATCHdataMergeOperationOnContainer.xml"));
checkPatchContext(returnValue);
}
}
{
"edit-id": "edit1",
"operation": "replace",
- "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name='my-leaf20']",
+ "target": "/my-list2=my-leaf20",
"value": {
"my-list2": {
"name": "my-leaf20",
{
"edit-id": "edit2",
"operation": "merge",
- "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name='my-leaf21']",
+ "target": "/my-list2=my-leaf21",
"value": {
"my-list2": {
"name": "my-leaf21",
}
]
}
-}
\ No newline at end of file
+}
{
"edit-id": "edit1",
"operation": "replace",
- "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name='my-leaf20']/instance-identifier-patch-module:name",
+ "target": "/my-list2=my-leaf20/name",
"value": {
"name": "my-leaf20"
}
}
]
}
-}
\ No newline at end of file
+}
{
"edit-id": "edit1",
"operation": "replace",
- "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name='my-leaf20']",
+ "target": "/my-list2=my-leaf20",
"value": {
"my-list2": {
"name": "my-leaf20",
{
"edit-id": "edit2",
"operation": "replace",
- "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name='my-leaf20']",
+ "target": "/my-list2=my-leaf20",
"value": {
"my-list2": {
"name": "my-leaf20",
}
]
},
- "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name='my-leaf20']",
+ "target": "/my-list2=my-leaf20",
"operation": "create"
},
{
"edit-id": "edit2",
"operation": "delete",
- "target": "/instance-identifier-patch-module:my-list2[instance-identifier-patch-module:name='my-leaf20']"
+ "target": "/my-list2=my-leaf20"
}
]
}
-}
\ No newline at end of file
+}
<edit>
<edit-id>edit1</edit-id>
<operation>create</operation>
- <target>/my-list2</target>
+ <target>/my-list2=my-leaf20</target>
<value>
<my-list2 xmlns="instance:identifier:patch:module">
<name>my-leaf20</name>
<edit>
<edit-id>edit2</edit-id>
<operation>create</operation>
- <target>/my-list2</target>
+ <target>/my-list2=my-leaf21</target>
<value>
<my-list2 xmlns="instance:identifier:patch:module">
<name>my-leaf21</name>
</my-list2>
</value>
</edit>
-</yang-patch>
\ No newline at end of file
+</yang-patch>
<edit>
<edit-id>edit1</edit-id>
<operation>create</operation>
- <target>/instance-identifier-patch-module:patch-cont/my-list1/leaf1/my-list2</target>
+ <target>/instance-identifier-patch-module:patch-cont/my-list1=leaf1/my-list2=my-leaf20</target>
<value>
<my-list2 xmlns="instance:identifier:patch:module">
<name>my-leaf20</name>
<edit>
<edit-id>edit2</edit-id>
<operation>create</operation>
- <target>/instance-identifier-patch-module:patch-cont/my-list1/leaf1/my-list2</target>
+ <target>/instance-identifier-patch-module:patch-cont/my-list1=leaf1/my-list2=my-leaf21</target>
<value>
<my-list2 xmlns="instance:identifier:patch:module">
<name>my-leaf21</name>
</my-list2>
</value>
</edit>
-</yang-patch>
\ No newline at end of file
+</yang-patch>
<edit>
<edit-id>edit1</edit-id>
<operation>replace</operation>
- <target>/my-list2</target>
+ <target>/my-list2=my-leaf20</target>
<value>
<my-list2 xmlns="instance:identifier:patch:module">
<name>my-leaf20</name>
<edit>
<edit-id>edit2</edit-id>
<operation>merge</operation>
- <target>/my-list2</target>
+ <target>/my-list2=my-leaf21</target>
<value>
<my-list2 xmlns="instance:identifier:patch:module">
<name>my-leaf21</name>
</my-list2>
</value>
</edit>
-</yang-patch>
\ No newline at end of file
+</yang-patch>