X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2Fjersey%2Fproviders%2Fpatch%2FJsonPatchBodyReaderTest.java;h=6f4b1cbc7d0be6fb2df6adf86bb5a3020b7f41aa;hb=b49fc5fd7940c9072cac55c770b3ebe9219ff73e;hp=d9f42d9978f6247a0f53a38c25545f5c8ba58551;hpb=d619eedb10aded59b4196b83e4b6d0841b6364bd;p=netconf.git diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java index d9f42d9978..6f4b1cbc7d 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java @@ -11,7 +11,9 @@ import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 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.BeforeClass; import org.junit.Test; @@ -20,6 +22,9 @@ import org.opendaylight.restconf.common.patch.PatchContext; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest; import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest; import org.opendaylight.yangtools.yang.common.ErrorTag; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.impl.schema.Builders; +import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest { @@ -177,4 +182,39 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest { final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream); checkPatchContext(returnValue); } + + /** + * Test of Yang Patch on the top augmented element. + */ + @Test + public void modulePatchTargetTopLevelAugmentedContainerTest() throws Exception { + mockBodyReader("", jsonToPatchBodyReader, false); + final var inputStream = new ByteArrayInputStream(("{\n" + + " \"ietf-yang-patch:yang-patch\": {\n" + + " \"patch-id\": \"test-patch\",\n" + + " \"comment\": \"comment\",\n" + + " \"edit\": [\n" + + " {\n" + + " \"edit-id\": \"edit1\",\n" + + " \"operation\": \"replace\",\n" + + " \"target\": \"/test-m:container-root/test-m:container-lvl1/test-m-aug:container-aug\",\n" + + " \"value\": {\n" + + " \"container-aug\": {\n" + + " \"leaf-aug\": \"data\"\n" + + " }\n" + + " }\n" + + " }\n" + + " ]\n" + + " }\n" + + "}").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.getIdentifier().getNodeType()); + assertEquals(expectedData, data); + } }