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>");
}
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);
}
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"));
}
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);
}
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());
}
Aggregations