use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult 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);
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class PlainPatchDataTransactionUtilTest method testPatchContainerData.
@Test
public void testPatchContainerData() {
final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iidJukebox, schemaNodeForJukebox, null, schema);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, jukeboxContainerWithPlayer);
doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(), any(), any());
PlainPatchDataTransactionUtil.patchData(payload, new MdsalRestconfStrategy(mockDataBroker), schema);
verify(readWrite).merge(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
PlainPatchDataTransactionUtil.patchData(payload, new NetconfRestconfStrategy(netconfService), schema);
verify(netconfService).merge(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData(), Optional.empty());
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class PlainPatchDataTransactionUtilTest method setUp.
@Before
public void setUp() throws Exception {
schema = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
final QName qnJukebox = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
final QName qnPlayer = QName.create(qnJukebox, "player");
final QName qnGap = QName.create(qnJukebox, "gap");
final QName qnPlaylist = QName.create(qnJukebox, "playlist");
final QName qnPlaylistKey = QName.create(qnJukebox, "name");
final NodeIdentifierWithPredicates nidBandA = NodeIdentifierWithPredicates.of(qnPlaylist, qnPlaylistKey, "MyFavoriteBand-A");
final NodeIdentifierWithPredicates nidBandB = NodeIdentifierWithPredicates.of(qnPlaylist, qnPlaylistKey, "MyFavoriteBand-B");
iidGap = YangInstanceIdentifier.builder().node(qnJukebox).node(qnPlayer).node(qnGap).build();
schemaNodeForGap = DataSchemaContextTree.from(schema).findChild(iidGap).orElseThrow().getDataSchemaNode();
iidJukebox = YangInstanceIdentifier.builder().node(qnJukebox).build();
schemaNodeForJukebox = DataSchemaContextTree.from(schema).findChild(iidJukebox).orElseThrow().getDataSchemaNode();
leafGap = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(qnGap)).withValue(0.2).build();
final ContainerNode playerContainer = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(qnPlayer)).withChild(leafGap).build();
jukeboxContainerWithPlayer = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(qnJukebox)).withChild(playerContainer).build();
// ----------
final LeafNode<Object> leafBandA = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(qnJukebox, "name"))).withValue("MyFavoriteBand-A").build();
final LeafNode<Object> leafDescriptionA = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(qnJukebox, "description"))).withValue("band description A").build();
final MapEntryNode entryBandA = Builders.mapEntryBuilder().withNodeIdentifier(nidBandA).withChild(leafBandA).withChild(leafDescriptionA).build();
final LeafNode<Object> leafBandB = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(qnJukebox, "name"))).withValue("MyFavoriteBand-B").build();
final LeafNode<Object> leafDescriptionB = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(qnJukebox, "description"))).withValue("band description B").build();
final MapEntryNode entryBandB = Builders.mapEntryBuilder().withNodeIdentifier(nidBandB).withChild(leafBandB).withChild(leafDescriptionB).build();
final MapNode listBands = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(qnPlaylist)).withChild(entryBandA).withChild(entryBandB).build();
jukeboxContainerWithPlaylist = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(qnJukebox)).withChild(listBands).build();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).lock();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).unlock();
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class PlainPatchDataTransactionUtilTest method testPatchLeafData.
@Test
public void testPatchLeafData() {
final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iidGap, schemaNodeForGap, null, schema);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, leafGap);
doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(), any(), any());
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
PlainPatchDataTransactionUtil.patchData(payload, new MdsalRestconfStrategy(mockDataBroker), schema);
verify(readWrite).merge(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
PlainPatchDataTransactionUtil.patchData(payload, new NetconfRestconfStrategy(netconfService), schema);
verify(netconfService).lock();
verify(netconfService).merge(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData(), Optional.empty());
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class PostDataTransactionUtilTest method testPostListData.
@Test
public void testPostListData() {
final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iidList, null, null, schema);
final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildList);
final MapNode data = (MapNode) payload.getData();
final MapEntryNode entryNode = data.body().iterator().next();
final NodeIdentifierWithPredicates identifier = entryNode.getIdentifier();
final YangInstanceIdentifier node = iidList.node(identifier);
doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, entryNode);
doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).merge(any(), any(), any(), any());
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).create(LogicalDatastoreType.CONFIGURATION, node, entryNode, Optional.empty());
Response response = PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty());
assertEquals(201, response.getStatus());
assertThat(URLDecoder.decode(response.getLocation().toString(), StandardCharsets.UTF_8), containsString(identifier.getValue(identifier.keySet().iterator().next()).toString()));
verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, entryNode);
response = PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty());
assertEquals(201, response.getStatus());
assertThat(URLDecoder.decode(response.getLocation().toString(), StandardCharsets.UTF_8), containsString(identifier.getValue(identifier.keySet().iterator().next()).toString()));
verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, node, entryNode, Optional.empty());
}
Aggregations