Search in sources :

Example 36 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfMessageTransformerTest method testGetRequest.

@Test
public void testGetRequest() throws Exception {
    final QName capability = QName.create(Capabilities.QNAME, "capability");
    final DataContainerChild filter = toFilterStructure(YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Capabilities.QNAME), toId(capability), new NodeWithValue<>(capability, "a:b:c")), SCHEMA);
    final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_QNAME, NetconfMessageTransformUtil.wrap(NETCONF_GET_QNAME, filter));
    assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "<get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n" + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" + "<capabilities>\n" + "<capability>a:b:c</capability>\n" + "</capabilities>\n" + "</netconf-state>" + "</filter>\n" + "</get>" + "</rpc>");
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) QName(org.opendaylight.yangtools.yang.common.QName) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 37 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfMessageTransformerTest method testRpcEmptyBodyWithOutputDefinedSchemaResult.

@Test
public void testRpcEmptyBodyWithOutputDefinedSchemaResult() throws Exception {
    final String result = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>";
    DOMRpcResult domRpcResult = actionNetconfMessageTransformer.toRpcResult(new NetconfMessage(XmlUtil.readXmlToDocument(result)), RPC_WITH_OUTPUT_QNAME);
    assertNotNull(domRpcResult);
}
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 38 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfMessageTransformerTest method testGetSchemaResponse.

@Test
public void testGetSchemaResponse() throws Exception {
    final NetconfMessageTransformer transformer = getTransformer(SCHEMA);
    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" + "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" + "Random YANG SCHEMA\n" + "</xs:schema>\n" + "</data>\n" + "</rpc-reply>"));
    final DOMRpcResult compositeNodeRpcResult = transformer.toRpcResult(response, GET_SCHEMA_QNAME);
    assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
    assertNotNull(compositeNodeRpcResult.getResult());
    final DOMSource schemaContent = ((DOMSourceAnyxmlNode) ((ContainerNode) compositeNodeRpcResult.getResult()).body().iterator().next()).body();
    assertThat(schemaContent.getNode().getTextContent(), CoreMatchers.containsString("Random YANG SCHEMA"));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 39 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfMessageTransformerTest method testRpcEmptyBodyWithoutOutputDefinedSchemaResult.

@Test
public void testRpcEmptyBodyWithoutOutputDefinedSchemaResult() throws Exception {
    final String result = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>";
    DOMRpcResult domRpcResult = actionNetconfMessageTransformer.toRpcResult(new NetconfMessage(XmlUtil.readXmlToDocument(result)), RPC_WITHOUT_OUTPUT_QNAME);
    assertNotNull(domRpcResult);
}
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 40 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfMessageTransformerTest method testConfigChangeToNotification.

@Test
public // Proof that YANGTOOLS-1362 works on DOM level
void testConfigChangeToNotification() throws SAXException, IOException {
    final var message = new NetconfMessage(XmlUtil.readXmlToDocument("<notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n" + " <eventTime>2021-11-11T11:26:16Z</eventTime> \n" + "  <netconf-config-change xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-notifications\">\n" + "     <changed-by> \n" + "       <username>root</username> \n" + "       <session-id>3</session-id> \n" + "     </changed-by> \n" + "     <datastore>running</datastore> \n" + "     <edit> \n" + "        <target xmlns:ncm=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">/ncm:netconf-state" + "/ncm:datastores/ncm:datastore[ncm:name='running']</target>\n" + "        <operation>replace</operation> \n" + "     </edit> \n" + "  </netconf-config-change> \n" + "</notification>"));
    final var change = netconfMessageTransformer.toNotification(message).getBody();
    final var editList = change.getChildByArg(new NodeIdentifier(Edit.QNAME));
    assertThat(editList, instanceOf(UnkeyedListNode.class));
    final var edits = ((UnkeyedListNode) editList).body();
    assertEquals(1, edits.size());
    final var edit = edits.iterator().next();
    final var target = edit.getChildByArg(new NodeIdentifier(QName.create(Edit.QNAME, "target"))).body();
    assertThat(target, instanceOf(YangInstanceIdentifier.class));
    final var args = ((YangInstanceIdentifier) target).getPathArguments();
    assertEquals(4, args.size());
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Aggregations

NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)125 Test (org.junit.Test)72 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)40 Document (org.w3c.dom.Document)28 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)23 QName (org.opendaylight.yangtools.yang.common.QName)17 DOMSourceAnyxmlNode (org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode)15 Test (org.junit.jupiter.api.Test)13 SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)13 Node (org.w3c.dom.Node)13 NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)12 ArrayList (java.util.ArrayList)11 Element (org.w3c.dom.Element)11 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)10 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)10 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)9 ChannelFuture (io.netty.channel.ChannelFuture)8 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)8