use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class BaseRpcSchemalessTransformerTest method toRpcResult.
@Test
public void toRpcResult() throws Exception {
final Document doc = XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>");
final InputStream stream = getClass().getResourceAsStream("/schemaless/get-config/container.xml");
final Element dataElement = XmlUtil.readXmlToElement(stream);
final Element element = (Element) doc.importNode(dataElement, true);
doc.getDocumentElement().appendChild(element);
final NetconfMessage msg = new NetconfMessage(doc);
final DOMRpcResult result = transformer.toRpcResult(msg, NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME);
assertNotNull(result.getResult());
final ContainerNode rpcReply = (ContainerNode) result.getResult();
assertEquals(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_QNAME, rpcReply.getIdentifier().getNodeType());
final Optional<?> dataOpt = rpcReply.findChildByArg(NetconfMessageTransformUtil.NETCONF_DATA_NODEID);
assertTrue(dataOpt.isPresent());
final DOMSourceAnyxmlNode data = (DOMSourceAnyxmlNode) dataOpt.get();
final Diff diff = XMLUnit.compareXML(dataElement.getOwnerDocument(), (Document) data.body().getNode());
assertTrue(diff.toString(), diff.similar());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class NetconfMessageTransformerTest method testGetConfigResponse.
@Test
public void testGetConfigResponse() throws Exception {
final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n" + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<data>\n" + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" + "<schemas>\n" + "<schema>\n" + "<identifier>module</identifier>\n" + "<version>2012-12-12</version>\n" + "<format xmlns:x=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">x:yang</format>\n" + "</schema>\n" + "</schemas>\n" + "</netconf-state>\n" + "</data>\n" + "</rpc-reply>"));
final NetconfMessageTransformer transformer = getTransformer(SCHEMA);
final DOMRpcResult compositeNodeRpcResult = transformer.toRpcResult(response, NETCONF_GET_CONFIG_QNAME);
assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
assertNotNull(compositeNodeRpcResult.getResult());
final List<DataContainerChild> values = Lists.newArrayList(NetconfRemoteSchemaYangSourceProvider.createGetSchemaRequest("module", Optional.of("2012-12-12")).body());
final Map<QName, Object> keys = new HashMap<>();
for (final DataContainerChild value : values) {
keys.put(value.getIdentifier().getNodeType(), value.body());
}
final NodeIdentifierWithPredicates identifierWithPredicates = NodeIdentifierWithPredicates.of(Schema.QNAME, keys);
final MapEntryNode schemaNode = Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build();
final DOMSourceAnyxmlNode data = (DOMSourceAnyxmlNode) ((ContainerNode) compositeNodeRpcResult.getResult()).findChildByArg(toId(NETCONF_DATA_QNAME)).get();
NormalizedNodeResult nodeResult = NetconfUtil.transformDOMSourceToNormalizedNode(SCHEMA, data.body());
ContainerNode result = (ContainerNode) nodeResult.getResult();
final ContainerNode state = (ContainerNode) result.findChildByArg(toId(NetconfState.QNAME)).get();
final ContainerNode schemas = (ContainerNode) state.findChildByArg(toId(Schemas.QNAME)).get();
final MapNode schemaParent = (MapNode) schemas.findChildByArg(toId(Schema.QNAME)).get();
assertEquals(1, Iterables.size(schemaParent.body()));
assertEquals(schemaNode, schemaParent.body().iterator().next());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class NetconfMessageTransformerTest method testCommitResponse.
@Test
public void testCommitResponse() throws Exception {
final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>"));
final DOMRpcResult compositeNodeRpcResult = netconfMessageTransformer.toRpcResult(response, NETCONF_COMMIT_QNAME);
assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
assertNull(compositeNodeRpcResult.getResult());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class SchemalessMessageTransformerTest method toEmptyRpcResult.
@Test
public void toEmptyRpcResult() throws Exception {
final Document doc = XmlUtil.readXmlToDocument(OK_REPLY);
final DOMRpcResult result = transformer.toRpcResult(new NetconfMessage(doc), NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME);
assertNull(result.getResult());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class SchemalessMessageTransformerTest method toRpcResult.
@Test
public void toRpcResult() throws Exception {
final Document doc = XmlUtil.readXmlToDocument(EXP_REPLY);
final NetconfMessage netconfMessage = new NetconfMessage(doc);
final DOMRpcResult result = transformer.toRpcResult(netconfMessage, TEST_RPC);
final DOMSource value = (DOMSource) result.getResult().body();
assertNotNull(result.getResult());
final Document domSourceDoc = (Document) value.getNode();
final Diff diff = XMLUnit.compareXML(XmlUtil.readXmlToDocument(EXP_REPLY), domSourceDoc);
assertTrue(diff.toString(), diff.similar());
}
Aggregations