Bump yangtools to 4.0.1
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / schema / mapping / NetconfMessageTransformerTest.java
index a2050628aec2ec4562da1a887a07e080ade29a82..dddd363003b5aa78608c08559fc7864c8afa6020 100644 (file)
@@ -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;
@@ -18,7 +17,6 @@ import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTr
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.GET_SCHEMA_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME;
-import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DATA_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
@@ -29,52 +27,146 @@ import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTr
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toPath;
+import static org.opendaylight.netconf.util.NetconfUtil.NETCONF_DATA_QNAME;
 
-import com.google.common.base.Optional;
 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.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;
 import org.custommonkey.xmlunit.XMLUnit;
 import org.hamcrest.CoreMatchers;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 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.rcf8528.data.util.EmptyMountPointContext;
 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.schema.AnyXmlNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
+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.NodeWithValue;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
 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 static final String URN_EXAMPLE_CONFLICT = "urn:example:conflict";
+
+    private static final QName SERVER_QNAME =
+            QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "server");
+    private static final QName RESET_QNAME = QName.create(SERVER_QNAME, "reset");
+    private static final SchemaPath RESET_SERVER_PATH = SchemaPath.create(true, SERVER_QNAME, RESET_QNAME);
+    private static final QName APPLICATIONS_QNAME = QName.create(URN_EXAMPLE_SERVER_FARM_2,
+            REVISION_EXAMPLE_SERVER_FARM_2, "applications");
+    private static final QName APPLICATION_QNAME = QName.create(APPLICATIONS_QNAME, "application");
+    private static final QName KILL_QNAME = QName.create(APPLICATION_QNAME, "kill");
+    private static final SchemaPath KILL_SERVER_APP_PATH =
+            SchemaPath.create(true, SERVER_QNAME, APPLICATIONS_QNAME, APPLICATION_QNAME, KILL_QNAME);
+
+    private static final QName DEVICE_QNAME =
+            QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "device");
+    private static final QName START_QNAME = QName.create(DEVICE_QNAME, "start");
+    private static final SchemaPath START_DEVICE_PATH = SchemaPath.create(true, DEVICE_QNAME, START_QNAME);
+    private static final QName INTERFACE_QNAME = QName.create(DEVICE_QNAME, "interface");
+    private static final QName ENABLE_QNAME = QName.create(INTERFACE_QNAME, "enable");
+    private static final SchemaPath ENABLE_INTERFACE_PATH =
+            SchemaPath.create(true, DEVICE_QNAME, INTERFACE_QNAME, ENABLE_QNAME);
+
+    private static final QName BOX_OUT_QNAME =
+            QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "box-out");
+    private static final QName BOX_IN_QNAME = QName.create(BOX_OUT_QNAME, "box-in");
+    private static final QName OPEN_QNAME = QName.create(BOX_IN_QNAME, "open");
+    private static final SchemaPath OPEN_BOXES_PATH =
+            SchemaPath.create(true, BOX_OUT_QNAME, BOX_IN_QNAME, OPEN_QNAME);
+
+    private static final QName FOO_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "foo");
+    private static final QName BAR_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "bar");
+    private static final QName XYZZY_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "xyzzy");
+    private static final SchemaPath XYZZY_FOO_PATH = SchemaPath.create(true, FOO_QNAME, XYZZY_QNAME);
+    private static final SchemaPath XYZZY_BAR_PATH = SchemaPath.create(true, BAR_QNAME, XYZZY_QNAME);
+
+    private static final QName CONFLICT_CHOICE_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "conflict-choice");
+    private static final QName CHOICE_CONT_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "choice-cont");
+    private static final QName CHOICE_ACTION_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "choice-action");
+    private static final SchemaPath CHOICE_ACTION_PATH =
+            SchemaPath.create(true, CONFLICT_CHOICE_QNAME, CHOICE_CONT_QNAME, CHOICE_CONT_QNAME, CHOICE_ACTION_QNAME);
+
+    private static SchemaContext PARTIAL_SCHEMA;
+    private static SchemaContext SCHEMA;
+    private static SchemaContext ACTION_SCHEMA;
+
+    private NetconfMessageTransformer actionNetconfMessageTransformer;
     private NetconfMessageTransformer netconfMessageTransformer;
-    private SchemaContext schema;
+
+    @BeforeClass
+    public static void beforeClass() {
+        final ModuleInfoBackedContext context = ModuleInfoBackedContext.create();
+        context.addModuleInfos(Collections.singleton(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
+            .netconf.monitoring.rev101004.$YangModuleInfoImpl.getInstance()));
+        PARTIAL_SCHEMA = context.tryToCreateSchemaContext().get();
+
+        context.addModuleInfos(Collections.singleton($YangModuleInfoImpl.getInstance()));
+        SCHEMA = context.tryToCreateSchemaContext().get();
+
+        ACTION_SCHEMA = YangParserTestUtils.parseYangResources(NetconfMessageTransformerTest.class,
+            "/schemas/example-server-farm.yang","/schemas/example-server-farm-2.yang",
+            "/schemas/conflicting-actions.yang");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        PARTIAL_SCHEMA = null;
+        SCHEMA = null;
+        ACTION_SCHEMA = null;
+    }
 
     @Before
     public void setUp() throws Exception {
@@ -82,15 +174,14 @@ public class NetconfMessageTransformerTest {
         XMLUnit.setIgnoreAttributeOrder(true);
         XMLUnit.setIgnoreComments(true);
 
-        schema = getSchema(true);
-        netconfMessageTransformer = getTransformer(schema);
-
+        netconfMessageTransformer = getTransformer(SCHEMA);
+        actionNetconfMessageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(ACTION_SCHEMA),
+            true);
     }
 
     @Test
     public void testLockRequestBaseSchemaNotPresent() throws Exception {
-        final SchemaContext partialSchema = getSchema(false);
-        final NetconfMessageTransformer transformer = getTransformer(partialSchema);
+        final NetconfMessageTransformer transformer = getTransformer(PARTIAL_SCHEMA);
         final NetconfMessage netconfMessage = transformer.toRpcRequest(toPath(NETCONF_LOCK_QNAME),
                 NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_QNAME));
 
@@ -100,12 +191,8 @@ public class NetconfMessageTransformerTest {
 
     @Test
     public void testCreateSubscriberNotificationSchemaNotPresent() throws Exception {
-        final SchemaContext partialSchema = getSchema(true);
-        final NetconfMessageTransformer transformer = new NetconfMessageTransformer(
-                partialSchema,
-                true,
-                BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS
-        );
+        final NetconfMessageTransformer transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA),
+            true, BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS);
         NetconfMessage netconfMessage = transformer.toRpcRequest(
                 toPath(CREATE_SUBSCRIPTION_RPC_QNAME),
                 CREATE_SUBSCRIPTION_RPC_CONTENT
@@ -117,8 +204,7 @@ public class NetconfMessageTransformerTest {
 
     @Test
     public void tesLockSchemaRequest() throws Exception {
-        final SchemaContext partialSchema = getSchema(false);
-        final NetconfMessageTransformer transformer = getTransformer(partialSchema);
+        final NetconfMessageTransformer transformer = getTransformer(PARTIAL_SCHEMA);
         final String result = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>";
 
         transformer.toRpcResult(new NetconfMessage(XmlUtil.readXmlToDocument(result)), toPath(NETCONF_LOCK_QNAME));
@@ -134,7 +220,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, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
@@ -147,8 +233,8 @@ public class NetconfMessageTransformerTest {
     }
 
     @Test
-    public void tesGetSchemaResponse() throws Exception {
-        final NetconfMessageTransformer transformer = getTransformer(getSchema(true));
+    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"
@@ -163,9 +249,9 @@ public class NetconfMessageTransformerTest {
         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(),
+        final DOMSource schemaContent = ((DOMSourceAnyxmlNode) ((ContainerNode) compositeNodeRpcResult.getResult())
+                .getValue().iterator().next()).getValue();
+        assertThat(schemaContent.getNode().getTextContent(),
                 CoreMatchers.containsString("Random YANG SCHEMA"));
     }
 
@@ -186,29 +272,33 @@ public class NetconfMessageTransformerTest {
                 + "</data>\n"
                 + "</rpc-reply>"));
 
-        final NetconfMessageTransformer transformer = getTransformer(getSchema(true));
+        final NetconfMessageTransformer transformer = getTransformer(SCHEMA);
         final DOMRpcResult compositeNodeRpcResult =
                 transformer.toRpcResult(response, toPath(NETCONF_GET_CONFIG_QNAME));
         assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
         assertNotNull(compositeNodeRpcResult.getResult());
 
-        final List<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> values = Lists.newArrayList(
+        final List<DataContainerChild<?, ?>> values = Lists.newArrayList(
                 NetconfRemoteSchemaYangSourceProvider
                         .createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue());
 
-        final Map<QName, Object> keys = Maps.newHashMap();
-        for (final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> value : values) {
+        final Map<QName, Object> keys = new HashMap<>();
+        for (final DataContainerChild<?, ?> value : values) {
             keys.put(value.getNodeType(), value.getValue());
         }
 
-        final YangInstanceIdentifier.NodeIdentifierWithPredicates identifierWithPredicates =
-                new YangInstanceIdentifier.NodeIdentifierWithPredicates(Schema.QNAME, keys);
+        final NodeIdentifierWithPredicates identifierWithPredicates =
+                NodeIdentifierWithPredicates.of(Schema.QNAME, keys);
         final MapEntryNode schemaNode =
                 Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build();
 
-        final ContainerNode data = (ContainerNode) ((ContainerNode) compositeNodeRpcResult
-                .getResult()).getChild(toId(NETCONF_DATA_QNAME)).get();
-        final ContainerNode state = (ContainerNode) data.getChild(toId(NetconfState.QNAME)).get();
+        final DOMSourceAnyxmlNode data = (DOMSourceAnyxmlNode) ((ContainerNode) compositeNodeRpcResult.getResult())
+                .getChild(toId(NETCONF_DATA_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()));
@@ -216,10 +306,40 @@ 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),
+                    NodeIdentifierWithPredicates.of(Schema.QNAME),
+                    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, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
+                + "<get-config 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"
+                + "<schemas>\n"
+                + "<schema>\n"
+                + "<version/>\n"
+                + "</schema>\n"
+                + "</schemas>\n"
+                + "</netconf-state>\n"
+                + "</filter>\n"
+                + "<source>\n"
+                + "<running/>\n"
+                + "</source>\n"
+                + "</get-config>\n"
+                + "</rpc>");
+    }
+
     @Test
     public void testGetConfigRequest() throws Exception {
         final DataContainerChild<?, ?> filter = toFilterStructure(
-                YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME)), schema);
+                YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME)), SCHEMA);
 
         final DataContainerChild<?, ?> source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_QNAME);
 
@@ -242,17 +362,17 @@ public class NetconfMessageTransformerTest {
 
     @Test
     public void testEditConfigRequest() throws Exception {
-        final List<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> values = Lists.newArrayList(
+        final List<DataContainerChild<?, ?>> values = Lists.newArrayList(
                 NetconfRemoteSchemaYangSourceProvider
                         .createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue());
 
-        final Map<QName, Object> keys = Maps.newHashMap();
-        for (final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> value : values) {
+        final Map<QName, Object> keys = new HashMap<>();
+        for (final DataContainerChild<?, ?> value : values) {
             keys.put(value.getNodeType(), value.getValue());
         }
 
-        final YangInstanceIdentifier.NodeIdentifierWithPredicates identifierWithPredicates =
-                new YangInstanceIdentifier.NodeIdentifierWithPredicates(Schema.QNAME, keys);
+        final NodeIdentifierWithPredicates identifierWithPredicates =
+                NodeIdentifierWithPredicates.of(Schema.QNAME, keys);
         final MapEntryNode schemaNode =
                 Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build();
 
@@ -261,7 +381,7 @@ public class NetconfMessageTransformerTest {
                 .nodeWithKey(Schema.QNAME, keys).build();
         final DataContainerChild<?, ?> editConfigStructure =
                 createEditConfigStructure(BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext(), id,
-                        Optional.<ModifyAction>absent(), Optional.<NormalizedNode<?, ?>>fromNullable(schemaNode));
+                    Optional.empty(), Optional.ofNullable(schemaNode));
 
         final DataContainerChild<?, ?> target = NetconfBaseOps.getTargetNode(NETCONF_CANDIDATE_QNAME);
 
@@ -303,7 +423,7 @@ public class NetconfMessageTransformerTest {
         final QName capability = QName.create(Capabilities.QNAME, "capability");
         final DataContainerChild<?, ?> filter = toFilterStructure(
                 YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Capabilities.QNAME), toId(capability),
-                    new YangInstanceIdentifier.NodeWithValue<>(capability, "a:b:c")), schema);
+                    new NodeWithValue<>(capability, "a:b:c")), SCHEMA);
 
         final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_GET_QNAME),
                 NetconfMessageTransformUtil.wrap(NETCONF_GET_QNAME, filter));
@@ -322,7 +442,7 @@ public class NetconfMessageTransformerTest {
     }
 
     private static NetconfMessageTransformer getTransformer(final SchemaContext schema) {
-        return new NetconfMessageTransformer(schema, true);
+        return new NetconfMessageTransformer(new EmptyMountPointContext(schema), true);
     }
 
     @Test
@@ -336,14 +456,323 @@ public class NetconfMessageTransformerTest {
         assertNull(compositeNodeRpcResult.getResult());
     }
 
-    public SchemaContext getSchema(final boolean addBase) {
-        final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
-        if (addBase) {
-            moduleInfoBackedContext.addModuleInfos(Collections.singleton($YangModuleInfoImpl.getInstance()));
+    @Test
+    public void getActionsTest() {
+        Set<SchemaPath> schemaPaths = new HashSet<>();
+        schemaPaths.add(RESET_SERVER_PATH);
+        schemaPaths.add(START_DEVICE_PATH);
+        schemaPaths.add(ENABLE_INTERFACE_PATH);
+        schemaPaths.add(OPEN_BOXES_PATH);
+        schemaPaths.add(KILL_SERVER_APP_PATH);
+        schemaPaths.add(XYZZY_FOO_PATH);
+        schemaPaths.add(XYZZY_BAR_PATH);
+        schemaPaths.add(CHOICE_ACTION_PATH);
+
+        List<ActionDefinition> actions = NetconfMessageTransformer.getActions(ACTION_SCHEMA);
+        assertEquals(schemaPaths.size(), actions.size());
+        for (ActionDefinition actionDefinition : actions) {
+            SchemaPath path = actionDefinition.getPath();
+            assertTrue(schemaPaths.remove(path));
         }
-        moduleInfoBackedContext
-                .addModuleInfos(Collections.singleton(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf
-                        .netconf.monitoring.rev101004.$YangModuleInfoImpl.getInstance()));
-        return moduleInfoBackedContext.tryToCreateSchemaContext().get();
+    }
+
+    @Test
+    public void toActionRequestListTopLevelTest() {
+        QName nameQname = QName.create(SERVER_QNAME, "name");
+        List<PathArgument> nodeIdentifiers = new ArrayList<>();
+        nodeIdentifiers.add(new NodeIdentifier(SERVER_QNAME));
+        nodeIdentifiers.add(NodeIdentifierWithPredicates.of(SERVER_QNAME, nameQname, "test"));
+        DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
+
+        ContainerNode data = initInputAction(QName.create(SERVER_QNAME, "reset-at"), "now");
+
+        NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
+                RESET_SERVER_PATH, domDataTreeIdentifier, data);
+
+        Node childAction = checkBasePartOfActionRequest(actionRequest);
+
+        Node childServer = childAction.getFirstChild();
+        checkNode(childServer, "server", "server", URN_EXAMPLE_SERVER_FARM);
+
+        Node childName = childServer.getFirstChild();
+        checkNode(childName, "name", "name", URN_EXAMPLE_SERVER_FARM);
+
+        Node childTest = childName.getFirstChild();
+        assertEquals(childTest.getNodeValue(), "test");
+
+        checkAction(RESET_QNAME, childName.getNextSibling(), "reset-at", "reset-at", "now");
+    }
+
+    @Test
+    public void toActionRequestContainerTopLevelTest() {
+        List<PathArgument> nodeIdentifiers = Collections.singletonList(NodeIdentifier.create(DEVICE_QNAME));
+        DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
+
+        NormalizedNode<?, ?> payload = initInputAction(QName.create(DEVICE_QNAME, "start-at"), "now");
+        NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
+                START_DEVICE_PATH, domDataTreeIdentifier, payload);
+
+        Node childAction = checkBasePartOfActionRequest(actionRequest);
+
+        Node childDevice = childAction.getFirstChild();
+        checkNode(childDevice, "device", "device", URN_EXAMPLE_SERVER_FARM);
+
+        checkAction(START_QNAME, childDevice.getFirstChild(), "start-at", "start-at", "now");
+    }
+
+    @Test
+    public void toActionRequestContainerInContainerTest() {
+        List<PathArgument> nodeIdentifiers = new ArrayList<>();
+        nodeIdentifiers.add(NodeIdentifier.create(BOX_OUT_QNAME));
+        nodeIdentifiers.add(NodeIdentifier.create(BOX_IN_QNAME));
+
+        DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
+
+        NormalizedNode<?, ?> payload = initInputAction(QName.create(BOX_OUT_QNAME, "start-at"), "now");
+        NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
+                OPEN_BOXES_PATH, domDataTreeIdentifier, payload);
+
+        Node childAction = checkBasePartOfActionRequest(actionRequest);
+
+        Node childBoxOut = childAction.getFirstChild();
+        checkNode(childBoxOut, "box-out", "box-out", URN_EXAMPLE_SERVER_FARM);
+
+        Node childBoxIn = childBoxOut.getFirstChild();
+        checkNode(childBoxIn, "box-in", "box-in", URN_EXAMPLE_SERVER_FARM);
+
+        Node action = childBoxIn.getFirstChild();
+        checkNode(action, null, OPEN_QNAME.getLocalName(), null);
+    }
+
+    @Test
+    public void toActionRequestListInContainerTest() {
+        QName nameQname = QName.create(INTERFACE_QNAME, "name");
+
+        List<PathArgument> nodeIdentifiers = new ArrayList<>();
+        nodeIdentifiers.add(NodeIdentifier.create(DEVICE_QNAME));
+        nodeIdentifiers.add(NodeIdentifier.create(INTERFACE_QNAME));
+        nodeIdentifiers.add(NodeIdentifierWithPredicates.of(INTERFACE_QNAME, nameQname, "test"));
+
+        DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
+
+        NormalizedNode<?, ?> payload = initEmptyInputAction(INTERFACE_QNAME);
+        NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
+                ENABLE_INTERFACE_PATH, domDataTreeIdentifier, payload);
+
+        Node childAction = checkBasePartOfActionRequest(actionRequest);
+
+        Node childDevice = childAction.getFirstChild();
+        checkNode(childDevice, "device", "device", URN_EXAMPLE_SERVER_FARM);
+
+        Node childInterface = childDevice.getFirstChild();
+        checkNode(childInterface, "interface", "interface", URN_EXAMPLE_SERVER_FARM);
+
+        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, ENABLE_QNAME.getLocalName(), null);
+    }
+
+    @Test
+    public void toActionRequestListInContainerAugmentedIntoListTest() {
+        QName serverNameQname = QName.create(SERVER_QNAME, "name");
+        QName applicationNameQname = QName.create(APPLICATION_QNAME, "name");
+
+        List<PathArgument> nodeIdentifiers = new ArrayList<>();
+        nodeIdentifiers.add(NodeIdentifier.create(SERVER_QNAME));
+        nodeIdentifiers.add(NodeIdentifierWithPredicates.of(SERVER_QNAME, serverNameQname, "testServer"));
+        nodeIdentifiers.add(new AugmentationIdentifier(Collections.singleton(APPLICATIONS_QNAME)));
+        nodeIdentifiers.add(NodeIdentifier.create(APPLICATIONS_QNAME));
+        nodeIdentifiers.add(NodeIdentifier.create(APPLICATION_QNAME));
+        nodeIdentifiers.add(NodeIdentifierWithPredicates.of(APPLICATION_QNAME,
+                applicationNameQname, "testApplication"));
+
+        DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
+
+        NormalizedNode<?, ?> payload = initEmptyInputAction(APPLICATION_QNAME);
+        NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
+                KILL_SERVER_APP_PATH, domDataTreeIdentifier, payload);
+
+        Node childAction = checkBasePartOfActionRequest(actionRequest);
+
+        Node childServer = childAction.getFirstChild();
+        checkNode(childServer, "server", "server", URN_EXAMPLE_SERVER_FARM);
+
+        Node childServerName = childServer.getFirstChild();
+        checkNode(childServerName, "name", "name", URN_EXAMPLE_SERVER_FARM);
+
+        Node childServerNameTest = childServerName.getFirstChild();
+        assertEquals(childServerNameTest.getNodeValue(), "testServer");
+
+        Node childApplications = childServer.getLastChild();
+        checkNode(childApplications, "applications", "applications", URN_EXAMPLE_SERVER_FARM_2);
+
+        Node childApplication = childApplications.getFirstChild();
+        checkNode(childApplication, "application", "application", URN_EXAMPLE_SERVER_FARM_2);
+
+        Node childApplicationName = childApplication.getFirstChild();
+        checkNode(childApplicationName, "name", "name", URN_EXAMPLE_SERVER_FARM_2);
+
+        Node childApplicationNameTest = childApplicationName.getFirstChild();
+        assertEquals(childApplicationNameTest.getNodeValue(), "testApplication");
+
+        Node childKillAction = childApplication.getLastChild();
+        checkNode(childApplication, "application", "application", URN_EXAMPLE_SERVER_FARM_2);
+        checkNode(childKillAction, null, KILL_QNAME.getLocalName(), null);
+    }
+
+    @Test
+    public void toActionRequestConflictingInListTest() {
+        QName barInputQname = QName.create(BAR_QNAME, "bar");
+        QName barIdQname = QName.create(BAR_QNAME, "bar-id");
+        Byte barInput = new Byte("1");
+
+        List<PathArgument> nodeIdentifiers = new ArrayList<>();
+        nodeIdentifiers.add(NodeIdentifier.create(BAR_QNAME));
+        nodeIdentifiers.add(NodeIdentifierWithPredicates.of(BAR_QNAME, barIdQname, "test"));
+
+        DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
+
+        ImmutableLeafNodeBuilder<Byte> immutableLeafNodeBuilder = new ImmutableLeafNodeBuilder<>();
+        DataContainerChild<NodeIdentifier, Byte> build = immutableLeafNodeBuilder.withNodeIdentifier(
+                NodeIdentifier.create(barInputQname)).withValue(barInput).build();
+        NormalizedNode<?, ?> payload = ImmutableContainerNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create(
+                QName.create(barInputQname, "input"))).withChild(build).build();
+
+        NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
+                XYZZY_BAR_PATH, domDataTreeIdentifier, payload);
+
+        Node childAction = checkBasePartOfActionRequest(actionRequest);
+
+        Node childBar = childAction.getFirstChild();
+        checkNode(childBar, "bar", "bar", URN_EXAMPLE_CONFLICT);
+
+        Node childBarId = childBar.getFirstChild();
+        checkNode(childBarId, "bar-id", "bar-id", URN_EXAMPLE_CONFLICT);
+
+        Node childTest = childBarId.getFirstChild();
+        assertEquals(childTest.getNodeValue(), "test");
+
+        Node action = childBar.getLastChild();
+        checkNode(action, null, XYZZY_QNAME.getLocalName(), null);
+    }
+
+    @Test
+    public void toActionRequestConflictingInContainerTest() {
+        QName fooInputQname = QName.create(FOO_QNAME, "foo");
+
+        List<PathArgument> nodeIdentifiers = new ArrayList<>();
+        nodeIdentifiers.add(NodeIdentifier.create(FOO_QNAME));
+        DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
+        NormalizedNode<?, ?> payload = initInputAction(fooInputQname, "test");
+
+        NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
+                XYZZY_FOO_PATH, domDataTreeIdentifier, payload);
+
+        Node childAction = checkBasePartOfActionRequest(actionRequest);
+
+        Node childBar = childAction.getFirstChild();
+        checkNode(childBar, "foo", "foo", URN_EXAMPLE_CONFLICT);
+
+        Node action = childBar.getLastChild();
+        checkNode(action, null, XYZZY_QNAME.getLocalName(), null);
+    }
+
+    @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, null, CHOICE_ACTION_QNAME.getLocalName(), null);
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void toActionResultTest() throws Exception {
+        NetconfMessage message = new NetconfMessage(XmlUtil.readXmlToDocument(
+                "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
+                + "<reset-finished-at xmlns=\"urn:example:server-farm\">"
+                + "now"
+                + "</reset-finished-at>"
+                + "</rpc-reply>"));
+        DOMActionResult actionResult = actionNetconfMessageTransformer.toActionResult(RESET_SERVER_PATH, message);
+        assertNotNull(actionResult);
+        ContainerNode containerNode = actionResult.getOutput().get();
+        assertNotNull(containerNode);
+        LeafNode<String> 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", NetconfUtil.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<PathArgument> 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<String> immutableLeafNodeBuilder = new ImmutableLeafNodeBuilder<>();
+        DataContainerChild<NodeIdentifier, String> 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);
     }
 }