Search in sources :

Example 61 with DefaultDOMRpcResult

use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.

the class PostDataTransactionUtilTest method testPostContainerData.

@Test
public void testPostContainerData() {
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, null, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
    doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    final NodeIdentifier identifier = ((ContainerNode) ((Collection<?>) payload.getData().body()).iterator().next()).getIdentifier();
    final YangInstanceIdentifier node = iid2.node(identifier);
    doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node.getParent(), payload.getData());
    doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
    Response response = PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty());
    assertEquals(201, response.getStatus());
    verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
    response = PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty());
    assertEquals(201, response.getStatus());
    verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), 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) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 62 with DefaultDOMRpcResult

use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.

the class PostDataTransactionUtilTest method setUp.

@Before
public void setUp() throws Exception {
    schema = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
    final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
    final QName containerQname = QName.create(baseQName, "player");
    final QName leafQname = QName.create(baseQName, "gap");
    final QName listQname = QName.create(baseQName, "playlist");
    final QName listKeyQname = QName.create(baseQName, "name");
    final NodeIdentifierWithPredicates nodeWithKey = NodeIdentifierWithPredicates.of(listQname, listKeyQname, "name of band");
    iid2 = YangInstanceIdentifier.builder().node(baseQName).build();
    iidList = YangInstanceIdentifier.builder().node(baseQName).node(listQname).build();
    final LeafNode<?> buildLeaf = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(leafQname)).withValue(0.2).build();
    final ContainerNode buildPlayerCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(containerQname)).withChild(buildLeaf).build();
    buildBaseCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildPlayerCont).build();
    final LeafNode<Object> content = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "name"))).withValue("name of band").build();
    final LeafNode<Object> content2 = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "description"))).withValue("band description").build();
    final MapEntryNode mapEntryNode = Builders.mapEntryBuilder().withNodeIdentifier(nodeWithKey).withChild(content).withChild(content2).build();
    buildList = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(listQname)).withChild(mapEntryNode).build();
    doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/16/")).when(uriInfo).getBaseUriBuilder();
    doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
    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) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Before(org.junit.Before)

Example 63 with DefaultDOMRpcResult

use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.

the class PostDataTransactionUtilTest method testPostDataFail.

@Test
public void testPostDataFail() {
    final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, null, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
    doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    final NodeIdentifier identifier = ((ContainerNode) ((Collection<?>) payload.getData().body()).iterator().next()).getIdentifier();
    final YangInstanceIdentifier node = iid2.node(identifier);
    doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node.getParent(), payload.getData());
    final DOMException domException = new DOMException((short) 414, "Post request failed");
    doReturn(immediateFailedFluentFuture(domException)).when(readWrite).commit();
    doReturn(immediateFailedFluentFuture(domException)).when(netconfService).create(any(), any(), any(), any());
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).discardChanges();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).unlock();
    RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> PostDataTransactionUtil.postData(uriInfo, payload, new MdsalRestconfStrategy(mockDataBroker), schema, WriteDataParams.empty()));
    assertEquals(1, ex.getErrors().size());
    assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
    verify(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
    verify(readWrite).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
    ex = assertThrows(RestconfDocumentedException.class, () -> PostDataTransactionUtil.postData(uriInfo, payload, new NetconfRestconfStrategy(netconfService), schema, WriteDataParams.empty()));
    assertEquals(1, ex.getErrors().size());
    assertThat(ex.getErrors().get(0).getErrorInfo(), containsString(domException.getMessage()));
    verify(netconfService).create(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
}
Also used : DOMException(org.w3c.dom.DOMException) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Collection(java.util.Collection) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 64 with DefaultDOMRpcResult

use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.

the class PatchDataTransactionUtilTest method setUp.

@Before
public void setUp() throws Exception {
    this.refSchemaCtx = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
    final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
    final QName containerPlayerQName = QName.create(baseQName, "player");
    final QName leafGapQName = QName.create(baseQName, "gap");
    final QName containerLibraryQName = QName.create(baseQName, "library");
    final QName listArtistQName = QName.create(baseQName, "artist");
    final QName leafNameQName = QName.create(baseQName, "name");
    final NodeIdentifierWithPredicates nodeWithKey = NodeIdentifierWithPredicates.of(listArtistQName, leafNameQName, "name of artist");
    /* instance identifier for accessing container node "player" */
    this.instanceIdContainer = YangInstanceIdentifier.builder().node(baseQName).node(containerPlayerQName).build();
    /* instance identifier for accessing leaf node "gap" */
    this.instanceIdCreateAndDelete = instanceIdContainer.node(leafGapQName);
    /* values that are used for creating leaf for testPatchDataCreateAndDelete test */
    final LeafNode<?> buildGapLeaf = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(leafGapQName)).withValue(0.2).build();
    final ContainerNode buildPlayerContainer = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(containerPlayerQName)).withChild(buildGapLeaf).build();
    this.buildBaseContainerForTests = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildPlayerContainer).build();
    this.targetNodeForCreateAndDelete = YangInstanceIdentifier.builder(this.instanceIdCreateAndDelete).node(containerPlayerQName).node(leafGapQName).build();
    /* instance identifier for accessing leaf node "name" in list "artist" */
    this.instanceIdMerge = YangInstanceIdentifier.builder().node(baseQName).node(containerLibraryQName).node(listArtistQName).nodeWithKey(listArtistQName, QName.create(listArtistQName, "name"), "name of artist").node(leafNameQName).build();
    /* values that are used for creating leaf for testPatchDataReplaceMergeAndRemove test */
    final LeafNode<Object> contentName = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "name"))).withValue("name of artist").build();
    final LeafNode<Object> contentDescription = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "description"))).withValue("description of artist").build();
    final MapEntryNode mapEntryNode = Builders.mapEntryBuilder().withNodeIdentifier(nodeWithKey).withChild(contentName).withChild(contentDescription).build();
    this.buildArtistList = Builders.mapBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listArtistQName)).withChild(mapEntryNode).build();
    this.targetNodeMerge = YangInstanceIdentifier.builder().node(baseQName).node(containerLibraryQName).node(listArtistQName).nodeWithKey(listArtistQName, leafNameQName, "name of artist").build();
    /* Mocks */
    doReturn(this.rwTransaction).when(this.mockDataBroker).newReadWriteTransaction();
    doReturn(CommitInfo.emptyFluentFuture()).when(this.rwTransaction).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(this.netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(this.netconfService).discardChanges();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(this.netconfService).unlock();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(this.netconfService).lock();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(this.netconfService).merge(any(), any(), any(), any());
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(this.netconfService).replace(any(), any(), any(), any());
}
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) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Before(org.junit.Before)

Example 65 with DefaultDOMRpcResult

use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.

the class PutDataTransactionUtilTest method testPutReplaceContainerData.

@Test
public void testPutReplaceContainerData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseCont);
    doReturn(immediateFluentFuture(Optional.of(mock(NormalizedNode.class)))).when(netconfService).getConfig(iid2);
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
    PutDataTransactionUtil.putData(payload, schema, new NetconfRestconfStrategy(netconfService), WriteDataParams.empty());
    verify(netconfService).getConfig(iid2);
    verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData(), Optional.empty());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) NetconfRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) 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