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());
}
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();
}
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());
}
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 <ok/> 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);
}
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());
}
Aggregations