Search in sources :

Example 21 with DOMSourceAnyxmlNode

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());
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) Diff(org.custommonkey.xmlunit.Diff) InputStream(java.io.InputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Element(org.w3c.dom.Element) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Document(org.w3c.dom.Document) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 22 with DOMSourceAnyxmlNode

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());
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) 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) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NormalizedNodeResult(org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 23 with DOMSourceAnyxmlNode

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());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) Diff(org.custommonkey.xmlunit.Diff) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) Node(org.w3c.dom.Node) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Test(org.junit.Test)

Example 24 with DOMSourceAnyxmlNode

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());
}
Also used : DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) Diff(org.custommonkey.xmlunit.Diff) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) QName(org.opendaylight.yangtools.yang.common.QName) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 25 with DOMSourceAnyxmlNode

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());
}
Also used : DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) Diff(org.custommonkey.xmlunit.Diff) Test(org.junit.Test)

Aggregations

DOMSourceAnyxmlNode (org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode)30 Test (org.junit.Test)16 DOMSource (javax.xml.transform.dom.DOMSource)15 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)15 Diff (org.custommonkey.xmlunit.Diff)10 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)10 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)10 Document (org.w3c.dom.Document)10 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)9 QName (org.opendaylight.yangtools.yang.common.QName)8 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)6 Element (org.w3c.dom.Element)6 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)5 IOException (java.io.IOException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)4 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)4 URISyntaxException (java.net.URISyntaxException)3