Search in sources :

Example 26 with DefaultDOMRpcResult

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

the class PutDataTransactionUtilTest method testPutCreateLeafData.

@Test
public void testPutCreateLeafData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildLeaf);
    doReturn(immediateFluentFuture(Optional.empty())).when(netconfService).getConfig(iid);
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, payload.getData(), Optional.empty());
    PutDataTransactionUtil.putData(payload, schema, new NetconfRestconfStrategy(netconfService), WriteDataParams.empty());
    verify(netconfService).getConfig(iid);
    verify(netconfService).replace(LogicalDatastoreType.CONFIGURATION, iid, 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) Test(org.junit.Test)

Example 27 with DefaultDOMRpcResult

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

the class PutDataTransactionUtilTest 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");
    final NodeIdentifierWithPredicates nodeWithKey2 = NodeIdentifierWithPredicates.of(listQname, listKeyQname, "name of band 2");
    final DataSchemaContextTree tree = DataSchemaContextTree.from(schema);
    iid = YangInstanceIdentifier.builder().node(baseQName).node(containerQname).node(leafQname).build();
    schemaNode = tree.findChild(iid).orElseThrow().getDataSchemaNode();
    iid2 = YangInstanceIdentifier.builder().node(baseQName).build();
    schemaNode2 = tree.findChild(iid2).orElseThrow().getDataSchemaNode();
    iid3 = YangInstanceIdentifier.builder().node(baseQName).node(listQname).node(nodeWithKey).build();
    schemaNode3 = tree.findChild(iid3).orElseThrow().getDataSchemaNode();
    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();
    buildListEntry = Builders.mapEntryBuilder().withNodeIdentifier(nodeWithKey).withChild(content).withChild(content2).build();
    final LeafNode<Object> content3 = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "name"))).withValue("name of band 2").build();
    final LeafNode<Object> content4 = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(QName.create(baseQName, "description"))).withValue("band description 2").build();
    final MapEntryNode buildListEntry2 = Builders.mapEntryBuilder().withNodeIdentifier(nodeWithKey2).withChild(content3).withChild(content4).build();
    final MapNode buildList = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(listQname)).withChild(buildListEntry).withChild(buildListEntry2).build();
    buildBaseContWithList = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildList).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) DataSchemaContextTree(org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree) Before(org.junit.Before)

Example 28 with DefaultDOMRpcResult

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

the class PutDataTransactionUtilTest method testPutReplaceListData.

@Test
public void testPutReplaceListData() {
    final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
    final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, buildBaseContWithList);
    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)

Example 29 with DefaultDOMRpcResult

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

the class SchemalessMessageTransformer method toRpcResult.

/**
 * Transforms reply message to anyXml node.
 * In case, that rpc-reply doesn't contain data and contains only &lt;ok/&gt; element, returns null.
 * @param rpcReply reply message
 * @return anyxml
 */
@Override
public DOMRpcResult toRpcResult(final NetconfMessage rpcReply, final QName rpc) {
    final Document document = rpcReply.getDocument();
    final DOMSourceAnyxmlNode result;
    if (BaseRpcSchemalessTransformer.isOkPresent(document)) {
        result = null;
    } else {
        result = Builders.anyXmlBuilder().withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_NODEID).withValue(new DOMSource(rpcReply.getDocument())).build();
    }
    return new DefaultDOMRpcResult(result);
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMSource(javax.xml.transform.dom.DOMSource) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) Document(org.w3c.dom.Document)

Example 30 with DefaultDOMRpcResult

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

the class NetconfStateSchemasTest method testCreateRpcError.

@Test
public void testCreateRpcError() throws Exception {
    final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "fail", "fail");
    doReturn(immediateFluentFuture(new DefaultDOMRpcResult(rpcError))).when(rpc).invokeRpc(eq(NETCONF_GET_QNAME), any());
    final NetconfStateSchemas stateSchemas = NetconfStateSchemas.create(rpc, CAPS, deviceId, schemaContext);
    final Set<QName> availableYangSchemasQNames = stateSchemas.getAvailableYangSchemasQNames();
    assertTrue(availableYangSchemasQNames.isEmpty());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) RpcError(org.opendaylight.yangtools.yang.common.RpcError) 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