X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fsal-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2Fschema%2Fmapping%2FNetconfMessageTransformerTest.java;h=42812abe38440e4d257f6282457b1743d76e0367;hb=b8f5ebd2f817de1d613d84cf41f3516728767eba;hp=a0c90c7293fa5c20c8b136fafa2d03819eaeb20b;hpb=50351b4cb37a1998cfaef53ff584aeb767c25f50;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java index a0c90c7293..42812abe38 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformerTest.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.netconf.sal.connect.netconf.schema.mapping; import static org.junit.Assert.assertEquals; @@ -30,14 +29,19 @@ import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTr import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId; import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toPath; -import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.Set; import javax.xml.transform.dom.DOMSource; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier; @@ -45,34 +49,53 @@ import org.custommonkey.xmlunit.XMLUnit; import org.hamcrest.CoreMatchers; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.config.util.xml.XmlUtil; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; +import org.opendaylight.mdsal.dom.api.DOMActionResult; +import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; +import org.opendaylight.mdsal.dom.api.DOMRpcResult; import org.opendaylight.netconf.api.NetconfMessage; +import org.opendaylight.netconf.api.xml.XmlUtil; import org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider; import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps; import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil; +import org.opendaylight.netconf.util.NetconfUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.$YangModuleInfoImpl; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.ModifyAction; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; +import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; +import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder; +import org.opendaylight.yangtools.yang.model.api.ActionDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.w3c.dom.Element; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; +import org.w3c.dom.Node; import org.xml.sax.SAXException; public class NetconfMessageTransformerTest { + private static final String REVISION_EXAMPLE_SERVER_FARM = "2018-08-07"; + private static final String URN_EXAMPLE_SERVER_FARM = "urn:example:server-farm"; + + private static final String REVISION_EXAMPLE_SERVER_FARM_2 = "2019-05-20"; + private static final String URN_EXAMPLE_SERVER_FARM_2 = "urn:example:server-farm-2"; + + private NetconfMessageTransformer actionNetconfMessageTransformer; private NetconfMessageTransformer netconfMessageTransformer; private SchemaContext schema; @@ -84,7 +107,7 @@ public class NetconfMessageTransformerTest { schema = getSchema(true); netconfMessageTransformer = getTransformer(schema); - + actionNetconfMessageTransformer = getActionMessageTransformer(); } @Test @@ -134,7 +157,7 @@ public class NetconfMessageTransformerTest { } @Test - public void tesGetSchemaRequest() throws Exception { + public void testGetSchemaRequest() throws Exception { final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(GET_SCHEMA_QNAME), NetconfRemoteSchemaYangSourceProvider.createGetSchemaRequest("module", Optional.of("2012-12-12"))); assertSimilarXml(netconfMessage, "\n" @@ -147,8 +170,8 @@ public class NetconfMessageTransformerTest { } @Test - public void tesGetSchemaResponse() throws Exception { - final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true)); + public void testGetSchemaResponse() throws Exception { + final NetconfMessageTransformer transformer = getTransformer(getSchema(true)); final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument( "\n" @@ -160,13 +183,12 @@ public class NetconfMessageTransformerTest { + "\n" + "" )); - final DOMRpcResult compositeNodeRpcResult = - netconfMessageTransformer.toRpcResult(response, toPath(GET_SCHEMA_QNAME)); + final DOMRpcResult compositeNodeRpcResult = transformer.toRpcResult(response, toPath(GET_SCHEMA_QNAME)); assertTrue(compositeNodeRpcResult.getErrors().isEmpty()); assertNotNull(compositeNodeRpcResult.getResult()); final DOMSource schemaContent = ((AnyXmlNode) ((ContainerNode) compositeNodeRpcResult.getResult()).getValue().iterator().next()).getValue(); - assertThat(((Element) schemaContent.getNode()).getTextContent(), + assertThat(schemaContent.getNode().getTextContent(), CoreMatchers.containsString("Random YANG SCHEMA")); } @@ -187,9 +209,9 @@ public class NetconfMessageTransformerTest { + "\n" + "")); - final NetconfMessageTransformer netconfMessageTransformer = getTransformer(getSchema(true)); + final NetconfMessageTransformer transformer = getTransformer(getSchema(true)); final DOMRpcResult compositeNodeRpcResult = - netconfMessageTransformer.toRpcResult(response, toPath(NETCONF_GET_CONFIG_QNAME)); + transformer.toRpcResult(response, toPath(NETCONF_GET_CONFIG_QNAME)); assertTrue(compositeNodeRpcResult.getErrors().isEmpty()); assertNotNull(compositeNodeRpcResult.getResult()); @@ -197,7 +219,7 @@ public class NetconfMessageTransformerTest { NetconfRemoteSchemaYangSourceProvider .createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue()); - final Map keys = Maps.newHashMap(); + final Map keys = new HashMap<>(); for (final DataContainerChild value : values) { keys.put(value.getNodeType(), value.getValue()); } @@ -207,9 +229,13 @@ public class NetconfMessageTransformerTest { final MapEntryNode schemaNode = Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build(); - final ContainerNode data = (ContainerNode) ((ContainerNode) compositeNodeRpcResult + final AnyXmlNode data = (AnyXmlNode) ((ContainerNode) compositeNodeRpcResult .getResult()).getChild(toId(NETCONF_DATA_QNAME)).get(); - final ContainerNode state = (ContainerNode) data.getChild(toId(NetconfState.QNAME)).get(); + + NormalizedNodeResult nodeResult = + NetconfUtil.transformDOMSourceToNormalizedNode(schema, data.getValue()); + ContainerNode result = (ContainerNode) nodeResult.getResult(); + final ContainerNode state = (ContainerNode) result.getChild(toId(NetconfState.QNAME)).get(); final ContainerNode schemas = (ContainerNode) state.getChild(toId(Schemas.QNAME)).get(); final MapNode schemaParent = (MapNode) schemas.getChild(toId(Schema.QNAME)).get(); assertEquals(1, Iterables.size(schemaParent.getValue())); @@ -217,6 +243,36 @@ public class NetconfMessageTransformerTest { assertEquals(schemaNode, schemaParent.getValue().iterator().next()); } + @Test + public void testGetConfigLeafRequest() throws Exception { + final DataContainerChild filter = toFilterStructure( + YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME), toId(Schema.QNAME), + new NodeIdentifierWithPredicates(Schema.QNAME, ImmutableMap.of()), + toId(QName.create(Schemas.QNAME, "version"))), schema); + + final DataContainerChild source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_QNAME); + + final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_GET_CONFIG_QNAME), + NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, source, filter)); + + assertSimilarXml(netconfMessage, "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + ""); + } + @Test public void testGetConfigRequest() throws Exception { final DataContainerChild filter = toFilterStructure( @@ -247,7 +303,7 @@ public class NetconfMessageTransformerTest { NetconfRemoteSchemaYangSourceProvider .createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue()); - final Map keys = Maps.newHashMap(); + final Map keys = new HashMap<>(); for (final DataContainerChild value : values) { keys.put(value.getNodeType(), value.getValue()); } @@ -262,7 +318,7 @@ public class NetconfMessageTransformerTest { .nodeWithKey(Schema.QNAME, keys).build(); final DataContainerChild editConfigStructure = createEditConfigStructure(BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext(), id, - Optional.absent(), Optional.>fromNullable(schemaNode)); + Optional.empty(), Optional.ofNullable(schemaNode)); final DataContainerChild target = NetconfBaseOps.getTargetNode(NETCONF_CANDIDATE_QNAME); @@ -347,4 +403,275 @@ public class NetconfMessageTransformerTest { .netconf.monitoring.rev101004.$YangModuleInfoImpl.getInstance())); return moduleInfoBackedContext.tryToCreateSchemaContext().get(); } + + @Test + public void getActionsTest() { + QName reset = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "reset"); + QName start = QName.create(reset, "start"); + QName open = QName.create(start, "open"); + QName enable = QName.create(open, "enable"); + QName kill = QName.create(URN_EXAMPLE_SERVER_FARM_2, REVISION_EXAMPLE_SERVER_FARM_2, "kill"); + Set qnames = new HashSet<>(Arrays.asList(reset, start, open, enable, kill)); + Set actions = actionNetconfMessageTransformer.getActions(); + assertTrue(!actions.isEmpty()); + for (ActionDefinition actionDefinition : actions) { + QName qname = actionDefinition.getQName(); + assertTrue(qnames.contains(qname)); + qnames.remove(qname); + } + } + + @Test + public void toActionRequestListTopLevelTest() { + QName qname = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "server"); + QName nameQname = QName.create(qname, "name"); + QName actionResetQName = QName.create(qname, "reset"); + List nodeIdentifiers = new ArrayList<>(); + nodeIdentifiers.add(new NodeIdentifier(qname)); + nodeIdentifiers.add(new NodeIdentifierWithPredicates(qname, nameQname, "test")); + DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers); + + ContainerNode data = initInputAction(QName.create(qname, "reset-at"), "now"); + + NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest( + SchemaPath.create(true, actionResetQName), domDataTreeIdentifier, data); + + Node childAction = checkBasePartOfActionRequest(actionRequest); + + Node childServer = childAction.getFirstChild(); + checkNode(childServer, "server", "server", qname.getNamespace().toString()); + + Node childName = childServer.getFirstChild(); + checkNode(childName, "name", "name", qname.getNamespace().toString()); + + Node childTest = childName.getFirstChild(); + assertEquals(childTest.getNodeValue(), "test"); + + checkAction(actionResetQName, childName.getNextSibling(), "reset-at", "reset-at", "now"); + } + + @Test + public void toActionRequestContainerTopLevelTest() { + QName qname = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "device"); + QName actionStartQName = QName.create(qname, "start"); + + List nodeIdentifiers = Collections.singletonList(NodeIdentifier.create(qname)); + DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers); + + NormalizedNode payload = initInputAction(QName.create(qname, "start-at"), "now"); + NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest( + SchemaPath.create(true, actionStartQName), domDataTreeIdentifier, payload); + + Node childAction = checkBasePartOfActionRequest(actionRequest); + + Node childDevice = childAction.getFirstChild(); + checkNode(childDevice, "device", "device", qname.getNamespace().toString()); + + checkAction(actionStartQName, childDevice.getFirstChild(), "start-at", "start-at", "now"); + } + + @Test + public void toActionRequestContainerInContainerTest() { + QName boxOutQName = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "box-out"); + QName boxInQName = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "box-in"); + QName actionOpenQName = QName.create(boxOutQName, "open"); + + List nodeIdentifiers = new ArrayList<>(); + nodeIdentifiers.add(NodeIdentifier.create(boxOutQName)); + nodeIdentifiers.add(NodeIdentifier.create(boxInQName)); + + DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers); + + NormalizedNode payload = initInputAction(QName.create(boxOutQName, "start-at"), "now"); + NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest( + SchemaPath.create(true, actionOpenQName), domDataTreeIdentifier, payload); + + Node childAction = checkBasePartOfActionRequest(actionRequest); + + Node childBoxOut = childAction.getFirstChild(); + checkNode(childBoxOut, "box-out", "box-out", boxOutQName.getNamespace().toString()); + + Node childBoxIn = childBoxOut.getFirstChild(); + checkNode(childBoxIn, "box-in", "box-in", boxOutQName.getNamespace().toString()); + + Node action = childBoxIn.getFirstChild(); + checkNode(action, null, actionOpenQName.getLocalName(), null); + } + + @Test + public void toActionRequestListInContainerTest() { + QName qnameDevice = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "device"); + QName qnameInterface = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "interface"); + QName nameQname = QName.create(qnameInterface, "name"); + QName actionEnableQName = QName.create(qnameInterface, "enable"); + + List nodeIdentifiers = new ArrayList<>(); + nodeIdentifiers.add(NodeIdentifier.create(qnameDevice)); + nodeIdentifiers.add(NodeIdentifier.create(qnameInterface)); + nodeIdentifiers.add(new NodeIdentifierWithPredicates(qnameInterface, nameQname, "test")); + + DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers); + + NormalizedNode payload = initEmptyInputAction(qnameInterface); + NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest( + SchemaPath.create(true, actionEnableQName), domDataTreeIdentifier, payload); + + Node childAction = checkBasePartOfActionRequest(actionRequest); + + Node childDevice = childAction.getFirstChild(); + checkNode(childDevice, "device", "device", qnameDevice.getNamespace().toString()); + + Node childInterface = childDevice.getFirstChild(); + checkNode(childInterface, "interface", "interface", qnameInterface.getNamespace().toString()); + + Node childName = childInterface.getFirstChild(); + checkNode(childName, "name", "name", nameQname.getNamespace().toString()); + + Node childTest = childName.getFirstChild(); + assertEquals(childTest.getNodeValue(), "test"); + + Node action = childInterface.getLastChild(); + checkNode(action, null, actionEnableQName.getLocalName(), null); + } + + @Test + public void toActionRequestListInContainerAugmentedIntoListTest() { + QName qnameServer = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "server"); + QName serverNameQname = QName.create(qnameServer, "name"); + QName qnameAppliactions = QName.create(URN_EXAMPLE_SERVER_FARM_2, + REVISION_EXAMPLE_SERVER_FARM_2, "applications"); + QName qnameAppliaction = QName.create(URN_EXAMPLE_SERVER_FARM_2, + REVISION_EXAMPLE_SERVER_FARM_2, "application"); + QName applicationNameQname = QName.create(qnameAppliaction, "name"); + QName actionKillQName = QName.create(qnameAppliaction, "kill"); + + List nodeIdentifiers = new ArrayList<>(); + nodeIdentifiers.add(NodeIdentifier.create(qnameServer)); + nodeIdentifiers.add(new NodeIdentifierWithPredicates(qnameServer, serverNameQname, "testServer")); + nodeIdentifiers.add(new YangInstanceIdentifier + .AugmentationIdentifier(Collections.singleton(qnameAppliactions))); + nodeIdentifiers.add(NodeIdentifier.create(qnameAppliactions)); + nodeIdentifiers.add(NodeIdentifier.create(qnameAppliaction)); + nodeIdentifiers.add(new NodeIdentifierWithPredicates(qnameAppliaction, + applicationNameQname, "testApplication")); + + DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers); + + NormalizedNode payload = initEmptyInputAction(qnameAppliaction); + NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest( + SchemaPath.create(true, actionKillQName), domDataTreeIdentifier, payload); + + Node childAction = checkBasePartOfActionRequest(actionRequest); + + Node childServer = childAction.getFirstChild(); + checkNode(childServer, "server", "server", qnameServer.getNamespace().toString()); + + Node childServerName = childServer.getFirstChild(); + checkNode(childServerName, "name", "name", serverNameQname.getNamespace().toString()); + + Node childServerNameTest = childServerName.getFirstChild(); + assertEquals(childServerNameTest.getNodeValue(), "testServer"); + + Node childApplications = childServer.getLastChild(); + checkNode(childApplications, "applications", "applications", qnameAppliactions.getNamespace().toString()); + + Node childApplication = childApplications.getFirstChild(); + checkNode(childApplication, "application", "application", qnameAppliaction.getNamespace().toString()); + + Node childApplicationName = childApplication.getFirstChild(); + checkNode(childApplicationName, "name", "name", applicationNameQname.getNamespace().toString()); + + Node childApplicationNameTest = childApplicationName.getFirstChild(); + assertEquals(childApplicationNameTest.getNodeValue(), "testApplication"); + + Node childKillAction = childApplication.getLastChild(); + checkNode(childApplication, "application", "application", qnameAppliaction.getNamespace().toString()); + checkNode(childKillAction, null, actionKillQName.getLocalName(), null); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void toActionResultTest() throws Exception { + QName qname = QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "reset"); + + NetconfMessage message = new NetconfMessage(XmlUtil.readXmlToDocument( + "" + + "" + + "now" + + "" + + "")); + DOMActionResult actionResult = actionNetconfMessageTransformer.toActionResult( + SchemaPath.create(true, qname), message); + assertNotNull(actionResult); + ContainerNode containerNode = actionResult.getOutput().get(); + assertNotNull(containerNode); + LeafNode leaf = (LeafNode) containerNode.getValue().iterator().next(); + assertEquals("now", leaf.getValue()); + } + + private static void checkAction(final QName actionQname, final Node action , final String inputLocalName, + final String inputNodeName, final String inputValue) { + checkNode(action, null, actionQname.getLocalName(), null); + + Node childResetAt = action.getFirstChild(); + checkNode(childResetAt, inputLocalName, inputNodeName, actionQname.getNamespace().toString()); + + Node firstChild = childResetAt.getFirstChild(); + assertEquals(firstChild.getNodeValue(), inputValue); + } + + private static Node checkBasePartOfActionRequest(final NetconfMessage actionRequest) { + Node baseRpc = actionRequest.getDocument().getFirstChild(); + checkNode(baseRpc, "rpc", "rpc", NetconfMessageTransformUtil.NETCONF_QNAME.getNamespace().toString()); + assertTrue(baseRpc.getLocalName().equals("rpc")); + assertTrue(baseRpc.getNodeName().equals("rpc")); + + Node messageId = baseRpc.getAttributes().getNamedItem("message-id"); + assertNotNull(messageId); + assertTrue(messageId.getNodeValue().contains("m-")); + + Node childAction = baseRpc.getFirstChild(); + checkNode(childAction, "action", "action", NetconfMessageTransformUtil.NETCONF_ACTION_NAMESPACE.toString()); + return childAction; + } + + private static DOMDataTreeIdentifier prepareDataTreeId(final List nodeIdentifiers) { + YangInstanceIdentifier yangInstanceIdentifier = + YangInstanceIdentifier.builder().append(nodeIdentifiers).build(); + DOMDataTreeIdentifier domDataTreeIdentifier = + new DOMDataTreeIdentifier(org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION, + yangInstanceIdentifier); + return domDataTreeIdentifier; + } + + private static ContainerNode initInputAction(final QName qname, final String value) { + ImmutableLeafNodeBuilder immutableLeafNodeBuilder = new ImmutableLeafNodeBuilder<>(); + DataContainerChild build = immutableLeafNodeBuilder.withNodeIdentifier( + NodeIdentifier.create(qname)).withValue(value).build(); + ContainerNode data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create( + QName.create(qname, "input"))).withChild(build).build(); + return data; + } + + private static ContainerNode initEmptyInputAction(final QName qname) { + return ImmutableContainerNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create( + QName.create(qname, "input"))).build(); + } + + private static void checkNode(final Node childServer, final String expectedLocalName, final String expectedNodeName, + final String expectedNamespace) { + assertNotNull(childServer); + assertEquals(childServer.getLocalName(), expectedLocalName); + assertEquals(childServer.getNodeName(), expectedNodeName); + assertEquals(childServer.getNamespaceURI(), expectedNamespace); + } + + private static SchemaContext getActionSchema() { + return YangParserTestUtils.parseYangResources(NetconfMessageTransformerTest.class, + "/schemas/example-server-farm.yang","/schemas/example-server-farm-2.yang"); + } + + private static NetconfMessageTransformer getActionMessageTransformer() { + return new NetconfMessageTransformer(getActionSchema(), true); + } }