use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode 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.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode 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.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class SchemalessMessageTransformerTest method toRpcRequest.
@Test
public void toRpcRequest() throws Exception {
final Node src = XmlUtil.readXmlToDocument("<test-rpc xmlns=\"test-ns\"><input>aaa</input></test-rpc>");
final DOMSourceAnyxmlNode input = Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(TEST_RPC)).withValue(new DOMSource(src)).build();
final NetconfMessage netconfMessage = transformer.toRpcRequest(TEST_RPC, input);
final Diff diff = XMLUnit.compareXML(XmlUtil.readXmlToDocument(EXP_REQUEST), netconfMessage.getDocument());
assertTrue(diff.toString(), diff.similar());
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class SchemalessMessageTransformerTest method toNotification.
@Test
public void toNotification() throws Exception {
final Document payload = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/notification-payload.xml"));
final NetconfMessage netconfMessage = new NetconfMessage(payload);
final DOMNotification domNotification = transformer.toNotification(netconfMessage);
assertEquals(domNotification.getType().lastNodeIdentifier(), SchemalessMessageTransformer.SCHEMALESS_NOTIFICATION_PAYLOAD.getNodeType());
final QName qName = QName.create("org:opendaylight:notification:test:ns:yang:user-notification", "user-visited-page");
final DOMSourceAnyxmlNode dataContainerChild = (DOMSourceAnyxmlNode) domNotification.getBody().findChildByArg(new NodeIdentifier(qName)).get();
final Diff diff = XMLUnit.compareXML(payload, dataContainerChild.body().getNode().getOwnerDocument());
assertTrue(diff.toString(), diff.similar());
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class SchemalessRpcStructureTransformerTest method testToFilterStructure.
@Test
public void testToFilterStructure() throws Exception {
final DOMSourceAnyxmlNode anyXmlNode = (DOMSourceAnyxmlNode) adapter.toFilterStructure(path);
final String s = XmlUtil.toString((Element) anyXmlNode.body().getNode());
Diff diff = new Diff(expectedFilter, s);
assertTrue(String.format("Input %s: %s", testDataset, diff.toString()), diff.similar());
}
Aggregations