Search in sources :

Example 56 with DefaultDOMRpcResult

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);
}
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 57 with DefaultDOMRpcResult

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());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) Test(org.junit.Test)

Example 58 with DefaultDOMRpcResult

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();
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Before(org.junit.Before)

Example 59 with DefaultDOMRpcResult

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());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) Test(org.junit.Test)

Example 60 with DefaultDOMRpcResult

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());
}
Also used : Response(javax.ws.rs.core.Response) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)72 Test (org.junit.Test)51 QName (org.opendaylight.yangtools.yang.common.QName)27 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)25 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)25 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)16 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)15 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)15 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)12 Before (org.junit.Before)10 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)10 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)10 NetconfBaseOps (org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps)9 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)9 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)5 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)5 RpcError (org.opendaylight.yangtools.yang.common.RpcError)5 ArrayList (java.util.ArrayList)4 NormalizedNodeMessage (org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage)4