Search in sources :

Example 41 with NetconfMessage

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

the class NetconfMessageTransformerTest method getWholeListsUsingFieldsTest.

@Test
public void getWholeListsUsingFieldsTest() throws IOException, SAXException {
    // preparation of the fields
    final YangInstanceIdentifier parentYiid = YangInstanceIdentifier.create(toId(NetconfState.QNAME));
    final YangInstanceIdentifier datastoreListField = YangInstanceIdentifier.create(toId(Datastores.QNAME), toId(Datastore.QNAME), NodeIdentifierWithPredicates.of(Datastore.QNAME));
    final YangInstanceIdentifier sessionListField = YangInstanceIdentifier.create(toId(Sessions.QNAME), toId(Session.QNAME), NodeIdentifierWithPredicates.of(Session.QNAME));
    // building filter structure and NETCONF message
    final AnyxmlNode<?> filterStructure = toFilterStructure(List.of(FieldsFilter.of(parentYiid, List.of(datastoreListField, sessionListField))), 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" + "</datastores>\n" + "<sessions>\n" + "<session/>\n" + "</sessions>\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 42 with NetconfMessage

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

the class NetconfMessageTransformerTest method toActionRequestChoiceTest.

@Test
public void toActionRequestChoiceTest() {
    List<PathArgument> nodeIdentifiers = new ArrayList<>();
    nodeIdentifiers.add(NodeIdentifier.create(CONFLICT_CHOICE_QNAME));
    nodeIdentifiers.add(NodeIdentifier.create(CHOICE_CONT_QNAME));
    DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
    NormalizedNode payload = initEmptyInputAction(CHOICE_ACTION_QNAME);
    NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(CHOICE_ACTION_PATH, domDataTreeIdentifier, payload);
    Node childAction = checkBasePartOfActionRequest(actionRequest);
    Node childChoiceCont = childAction.getFirstChild();
    checkNode(childChoiceCont, "choice-cont", "choice-cont", URN_EXAMPLE_CONFLICT);
    Node action = childChoiceCont.getLastChild();
    checkNode(action, CHOICE_ACTION_QNAME.getLocalName(), CHOICE_ACTION_QNAME.getLocalName(), CHOICE_ACTION_QNAME.getNamespace().toString());
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Node(org.w3c.dom.Node) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) AnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.AnyxmlNode) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ArrayList(java.util.ArrayList) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 43 with NetconfMessage

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

the class NetconfMessageTransformerTest method testCreateSubscriberNotificationSchemaNotPresent.

@Test
public void testCreateSubscriberNotificationSchemaNotPresent() throws Exception {
    final NetconfMessageTransformer transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA), true, BASE_SCHEMAS.getBaseSchemaWithNotifications());
    NetconfMessage netconfMessage = transformer.toRpcRequest(CREATE_SUBSCRIPTION_RPC_QNAME, CREATE_SUBSCRIPTION_RPC_CONTENT);
    String documentString = XmlUtil.toString(netconfMessage.getDocument());
    assertThat(documentString, CoreMatchers.containsString("<create-subscription"));
    assertThat(documentString, CoreMatchers.containsString("<rpc"));
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 44 with NetconfMessage

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

the class NetconfMessageTransformerTest method toActionEmptyBodyWithoutOutputDefinedResultTest.

@Test
public void toActionEmptyBodyWithoutOutputDefinedResultTest() throws Exception {
    NetconfMessage message = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">" + "<ok/>" + "</rpc-reply>"));
    DOMActionResult actionResult = actionNetconfMessageTransformer.toActionResult(CHECK_WITHOUT_OUTPUT_INTERFACE_PATH, message);
    assertNotNull(actionResult);
    assertTrue(actionResult.getOutput().isEmpty());
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 45 with NetconfMessage

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

the class BaseRpcSchemalessTransformerTest method toRpcRequest.

@Test
public void toRpcRequest() throws Exception {
    final Document doc = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/schemaless/edit-config/container.xml"));
    final DOMSourceAnyxmlNode xml = Builders.anyXmlBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_CONFIG_QNAME)).withValue(new DOMSource(doc.getDocumentElement())).build();
    final ChoiceNode editContent = Builders.choiceBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(EditContent.QNAME)).withChild(xml).build();
    final ChoiceNode candidate = Builders.choiceBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ConfigTarget.QNAME)).withChild(Builders.leafBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(Candidate.QNAME)).withValue(Empty.value()).build()).build();
    final ContainerNode target = Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_TARGET_QNAME)).withChild(candidate).build();
    final ContainerNode editConfig = Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME)).withChild(editContent).withChild(target).build();
    final NetconfMessage msg = transformer.toRpcRequest(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME, editConfig);
    final Diff diff = XMLUnit.compareXML(EXP_RPC, XmlUtil.toString(msg.getDocument()));
    assertTrue(diff.toString(), diff.similar());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) Diff(org.custommonkey.xmlunit.Diff) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Document(org.w3c.dom.Document) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) 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