Search in sources :

Example 26 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class RestconfDataServiceImplTest method testPatchData.

@Test
public void testPatchData() {
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, schemaNode, null, contextRef);
    final List<PatchEntity> entity = new ArrayList<>();
    final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(iidBase).node(containerPlayerQname).node(leafQname).build();
    entity.add(new PatchEntity("create data", CREATE, iidBase, buildBaseCont));
    entity.add(new PatchEntity("replace data", REPLACE, iidBase, buildBaseCont));
    entity.add(new PatchEntity("delete data", DELETE, iidleaf));
    final PatchContext patch = new PatchContext(iidContext, entity, "test patch id");
    doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
    doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
    doReturn(immediateTrueFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
    final PatchStatusContext status = dataService.patchData(patch, uriInfo);
    assertTrue(status.isOk());
    assertEquals(3, status.getEditCollection().size());
    assertEquals("replace data", status.getEditCollection().get(1).getEditId());
}
Also used : PatchStatusContext(org.opendaylight.restconf.common.patch.PatchStatusContext) PatchContext(org.opendaylight.restconf.common.patch.PatchContext) PatchEntity(org.opendaylight.restconf.common.patch.PatchEntity) ArrayList(java.util.ArrayList) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 27 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class PatchDataTransactionUtilTest method testPatchDataReplaceMergeAndRemove.

@Test
public void testPatchDataReplaceMergeAndRemove() {
    final PatchEntity entityReplace = new PatchEntity("edit1", REPLACE, this.targetNodeMerge, this.buildArtistList);
    final PatchEntity entityMerge = new PatchEntity("edit2", MERGE, this.targetNodeMerge, this.buildArtistList);
    final PatchEntity entityRemove = new PatchEntity("edit3", REMOVE, this.targetNodeMerge);
    final List<PatchEntity> entities = new ArrayList<>();
    entities.add(entityReplace);
    entities.add(entityMerge);
    entities.add(entityRemove);
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(this.instanceIdMerge, null, null, this.refSchemaCtx);
    final PatchContext patchContext = new PatchContext(iidContext, entities, "patchRMRm");
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(this.netconfService).remove(LogicalDatastoreType.CONFIGURATION, targetNodeMerge);
    patch(patchContext, new MdsalRestconfStrategy(mockDataBroker), false);
    patch(patchContext, new NetconfRestconfStrategy(netconfService), false);
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) PatchContext(org.opendaylight.restconf.common.patch.PatchContext) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) PatchEntity(org.opendaylight.restconf.common.patch.PatchEntity) ArrayList(java.util.ArrayList) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) Test(org.junit.Test)

Example 28 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class JsonPatchBodyReaderTest method modulePatchMergeOperationOnListTest.

/**
 * 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);
    final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnList.json");
    final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
    checkPatchContext(returnValue);
}
Also used : PatchContext(org.opendaylight.restconf.common.patch.PatchContext) InputStream(java.io.InputStream) Test(org.junit.Test) JsonBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest) AbstractBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest)

Example 29 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class JsonPatchBodyReaderTest method modulePatchMergeOperationOnContainerTest.

/**
 * 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);
    final InputStream inputStream = JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnContainer.json");
    final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
    checkPatchContext(returnValue);
}
Also used : PatchContext(org.opendaylight.restconf.common.patch.PatchContext) InputStream(java.io.InputStream) Test(org.junit.Test) JsonBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest) AbstractBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest)

Example 30 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class JsonPatchBodyReaderTest method modulePatchSimpleLeafValueTest.

/**
 * 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 = JsonBodyReaderTest.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
    final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
    checkPatchContext(returnValue);
}
Also used : PatchContext(org.opendaylight.restconf.common.patch.PatchContext) InputStream(java.io.InputStream) Test(org.junit.Test) JsonBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest) AbstractBodyReaderTest(org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest)

Aggregations

PatchContext (org.opendaylight.restconf.common.patch.PatchContext)42 Test (org.junit.Test)36 InputStream (java.io.InputStream)31 PatchEntity (org.opendaylight.restconf.common.patch.PatchEntity)11 ArrayList (java.util.ArrayList)9 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)9 PatchStatusContext (org.opendaylight.restconf.common.patch.PatchStatusContext)7 AbstractBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest)7 JsonBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 IOException (java.io.IOException)4 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)4 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)4 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)4 URISyntaxException (java.net.URISyntaxException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)3 Verify.verify (com.google.common.base.Verify.verify)2