use of org.opendaylight.netconf.api.NetconfMessage 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.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageTransformerTest method getTwoNonOverlappingFieldsTest.
@Test
public void getTwoNonOverlappingFieldsTest() throws IOException, SAXException {
// preparation of the fields
final YangInstanceIdentifier parentYiid = YangInstanceIdentifier.create(toId(NetconfState.QNAME));
final YangInstanceIdentifier netconfStartTimeField = YangInstanceIdentifier.create(toId(Statistics.QNAME), toId(QName.create(Statistics.QNAME, "netconf-start-time")));
final YangInstanceIdentifier datastoresField = YangInstanceIdentifier.create(toId(Datastores.QNAME));
// building filter structure and NETCONF message
final AnyxmlNode<?> filterStructure = toFilterStructure(List.of(FieldsFilter.of(parentYiid, List.of(netconfStartTimeField, datastoresField))), SCHEMA);
final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_QNAME, NetconfMessageTransformUtil.wrap(toId(NETCONF_GET_QNAME), filterStructure));
// testing
assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<get>\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" + "<statistics>\n" + "<netconf-start-time/>\n" + "</statistics>\n" + "<datastores/>\n" + "</netconf-state>\n" + "</filter>\n" + "</get>\n" + "</rpc>");
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageTransformerTest method getOverlappingFieldsTest.
@Test
public void getOverlappingFieldsTest() throws IOException, SAXException {
// preparation of the fields
final YangInstanceIdentifier parentYiid = YangInstanceIdentifier.create(toId(NetconfState.QNAME));
final YangInstanceIdentifier capabilitiesField = YangInstanceIdentifier.create(toId(Capabilities.QNAME));
final YangInstanceIdentifier capabilityField = YangInstanceIdentifier.create(toId(Capabilities.QNAME), toId(QName.create(Capabilities.QNAME, "capability").intern()));
final YangInstanceIdentifier datastoreField = YangInstanceIdentifier.create(toId(Datastores.QNAME));
final YangInstanceIdentifier locksFields = YangInstanceIdentifier.create(toId(Datastores.QNAME), toId(Datastore.QNAME), NodeIdentifierWithPredicates.of(Datastore.QNAME), toId(Locks.QNAME));
// building filter structure and NETCONF message
final AnyxmlNode<?> filterStructure = toFilterStructure(List.of(FieldsFilter.of(parentYiid, List.of(capabilitiesField, capabilityField, datastoreField, locksFields))), SCHEMA);
final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_QNAME, NetconfMessageTransformUtil.wrap(toId(NETCONF_GET_QNAME), filterStructure));
// testing
assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<get>\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" + "<datastores/>\n" + "</netconf-state>\n" + "</filter>\n" + "</get>\n" + "</rpc>");
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageTransformerTest method getSpecificFieldsUnderMultipleLists.
@Test
public void getSpecificFieldsUnderMultipleLists() throws IOException, SAXException {
// preparation of the fields
final YangInstanceIdentifier parentYiid = YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Datastores.QNAME));
final YangInstanceIdentifier partialLockYiid = YangInstanceIdentifier.create(toId(Datastore.QNAME), NodeIdentifierWithPredicates.of(Datastore.QNAME), toId(Locks.QNAME), toId(QName.create(Locks.QNAME, "lock-type").intern()), toId(PartialLock.QNAME), NodeIdentifierWithPredicates.of(PartialLock.QNAME));
final YangInstanceIdentifier lockedTimeField = partialLockYiid.node(QName.create(Locks.QNAME, "locked-time").intern());
final YangInstanceIdentifier lockedBySessionField = partialLockYiid.node(QName.create(Locks.QNAME, "locked-by-session").intern());
// building filter structure and NETCONF message
final AnyxmlNode<?> filterStructure = toFilterStructure(List.of(FieldsFilter.of(parentYiid, List.of(lockedTimeField, lockedBySessionField))), SCHEMA);
final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_QNAME, NetconfMessageTransformUtil.wrap(toId(NETCONF_GET_QNAME), filterStructure));
// testing
assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<get>\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" + "<datastores>\n" + "<datastore>\n" + "<locks>\n" + "<partial-lock>\n" + "<locked-time/>\n" + "<locked-by-session/>\n" + "<lock-id/>\n" + "</partial-lock>\n" + "</locks>\n" + "<name/>\n" + "</datastore>\n" + "</datastores>\n" + "</netconf-state>\n" + "</filter>\n" + "</get>\n" + "</rpc>");
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageTransformerTest method testLockRequestBaseSchemaNotPresent.
@Test
public void testLockRequestBaseSchemaNotPresent() throws Exception {
final NetconfMessageTransformer transformer = getTransformer(PARTIAL_SCHEMA);
final NetconfMessage netconfMessage = transformer.toRpcRequest(NETCONF_LOCK_QNAME, NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_QNAME));
assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<lock"));
assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<rpc"));
}
Aggregations