Search in sources :

Example 96 with NetconfMessage

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());
}
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 97 with NetconfMessage

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>");
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 98 with NetconfMessage

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>");
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 99 with NetconfMessage

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>");
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 100 with NetconfMessage

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"));
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) 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