Search in sources :

Example 36 with DOMRpcResult

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());
}
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 37 with DOMRpcResult

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());
}
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 38 with DOMRpcResult

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());
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 39 with DOMRpcResult

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());
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 40 with DOMRpcResult

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());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) Diff(org.custommonkey.xmlunit.Diff) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)61 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)39 Test (org.junit.Test)38 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 QName (org.opendaylight.yangtools.yang.common.QName)18 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)16 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)10 RpcError (org.opendaylight.yangtools.yang.common.RpcError)8 ExecutionException (java.util.concurrent.ExecutionException)7 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)7 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)7 ClusteringRpcException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException)6 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)5 InvokeRpcMessageReply (org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)5 DOMRpcImplementationNotAvailableException (org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException)4 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3