Update MRI projects for Aluminium
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / schema / mapping / NetconfMessageTransformerTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.sal.connect.netconf.schema.mapping;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertThat;
14 import static org.junit.Assert.assertTrue;
15 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_CONTENT;
16 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_QNAME;
17 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.GET_SCHEMA_QNAME;
18 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME;
19 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME;
20 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME;
21 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME;
22 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME;
23 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_GET_QNAME;
24 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_LOCK_QNAME;
25 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
26 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.createEditConfigStructure;
27 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure;
28 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
29 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toPath;
30 import static org.opendaylight.netconf.util.NetconfUtil.NETCONF_DATA_QNAME;
31
32 import com.google.common.collect.Iterables;
33 import com.google.common.collect.Lists;
34 import java.io.IOException;
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.HashMap;
38 import java.util.HashSet;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Optional;
42 import java.util.Set;
43 import javax.xml.transform.dom.DOMSource;
44 import org.custommonkey.xmlunit.Diff;
45 import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier;
46 import org.custommonkey.xmlunit.XMLUnit;
47 import org.hamcrest.CoreMatchers;
48 import org.junit.AfterClass;
49 import org.junit.Before;
50 import org.junit.BeforeClass;
51 import org.junit.Test;
52 import org.opendaylight.binding.runtime.spi.BindingRuntimeHelpers;
53 import org.opendaylight.mdsal.dom.api.DOMActionResult;
54 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
55 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
56 import org.opendaylight.netconf.api.NetconfMessage;
57 import org.opendaylight.netconf.api.xml.XmlUtil;
58 import org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider;
59 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
60 import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
61 import org.opendaylight.netconf.util.NetconfUtil;
62 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.IetfNetconfService;
63 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState;
64 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas;
66 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema;
67 import org.opendaylight.yangtools.rcf8528.data.util.EmptyMountPointContext;
68 import org.opendaylight.yangtools.yang.common.QName;
69 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
70 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
71 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
72 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
73 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
74 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
75 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
76 import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
77 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
78 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
79 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
80 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
81 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
82 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
83 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
84 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
85 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
86 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
87 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
88 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
89 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
90 import org.w3c.dom.Node;
91 import org.xml.sax.SAXException;
92
93 public class NetconfMessageTransformerTest {
94
95     private static final String REVISION_EXAMPLE_SERVER_FARM = "2018-08-07";
96     private static final String URN_EXAMPLE_SERVER_FARM = "urn:example:server-farm";
97
98     private static final String REVISION_EXAMPLE_SERVER_FARM_2 = "2019-05-20";
99     private static final String URN_EXAMPLE_SERVER_FARM_2 = "urn:example:server-farm-2";
100
101     private static final String URN_EXAMPLE_CONFLICT = "urn:example:conflict";
102
103     private static final String URN_EXAMPLE_AUGMENTED_ACTION = "urn:example:augmented-action";
104
105     private static final String URN_EXAMPLE_RPCS_ACTIONS_OUTPUTS = "urn:example:rpcs-actions-outputs";
106
107     private static final QName SERVER_QNAME =
108             QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "server");
109     private static final QName RESET_QNAME = QName.create(SERVER_QNAME, "reset");
110     private static final SchemaPath RESET_SERVER_PATH = SchemaPath.create(true, SERVER_QNAME, RESET_QNAME);
111     private static final QName APPLICATIONS_QNAME = QName.create(URN_EXAMPLE_SERVER_FARM_2,
112             REVISION_EXAMPLE_SERVER_FARM_2, "applications");
113     private static final QName APPLICATION_QNAME = QName.create(APPLICATIONS_QNAME, "application");
114     private static final QName KILL_QNAME = QName.create(APPLICATION_QNAME, "kill");
115     private static final SchemaPath KILL_SERVER_APP_PATH =
116             SchemaPath.create(true, SERVER_QNAME, APPLICATIONS_QNAME, APPLICATION_QNAME, KILL_QNAME);
117
118     private static final QName DEVICE_QNAME =
119             QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "device");
120     private static final QName START_QNAME = QName.create(DEVICE_QNAME, "start");
121     private static final SchemaPath START_DEVICE_PATH = SchemaPath.create(true, DEVICE_QNAME, START_QNAME);
122     private static final QName INTERFACE_QNAME = QName.create(DEVICE_QNAME, "interface");
123     private static final QName ENABLE_QNAME = QName.create(INTERFACE_QNAME, "enable");
124     private static final SchemaPath ENABLE_INTERFACE_PATH =
125             SchemaPath.create(true, DEVICE_QNAME, INTERFACE_QNAME, ENABLE_QNAME);
126
127     private static final QName DISABLE_QNAME = QName.create(URN_EXAMPLE_AUGMENTED_ACTION, "disable");
128     private static final SchemaPath DISABLE_INTERFACE_PATH =
129             SchemaPath.create(true, DEVICE_QNAME, INTERFACE_QNAME, DISABLE_QNAME);
130
131     private static final QName CHECK_WITH_OUTPUT_QNAME =
132             QName.create(URN_EXAMPLE_RPCS_ACTIONS_OUTPUTS, "check-with-output");
133     private static final SchemaPath CHECK_WITH_OUTPUT_INTERFACE_PATH =
134             SchemaPath.create(true, DEVICE_QNAME, INTERFACE_QNAME, CHECK_WITH_OUTPUT_QNAME);
135     private static final QName CHECK_WITHOUT_OUTPUT_QNAME =
136             QName.create(URN_EXAMPLE_RPCS_ACTIONS_OUTPUTS, "check-without-output");
137     private static final SchemaPath CHECK_WITHOUT_OUTPUT_INTERFACE_PATH =
138             SchemaPath.create(true, DEVICE_QNAME, INTERFACE_QNAME, CHECK_WITHOUT_OUTPUT_QNAME);
139     private static final QName RPC_WITH_OUTPUT_QNAME =
140             QName.create(URN_EXAMPLE_RPCS_ACTIONS_OUTPUTS, "rpc-with-output");
141     private static final QName RPC_WITHOUT_OUTPUT_QNAME =
142             QName.create(URN_EXAMPLE_RPCS_ACTIONS_OUTPUTS, "rpc-without-output");
143
144     private static final QName BOX_OUT_QNAME =
145             QName.create(URN_EXAMPLE_SERVER_FARM, REVISION_EXAMPLE_SERVER_FARM, "box-out");
146     private static final QName BOX_IN_QNAME = QName.create(BOX_OUT_QNAME, "box-in");
147     private static final QName OPEN_QNAME = QName.create(BOX_IN_QNAME, "open");
148     private static final SchemaPath OPEN_BOXES_PATH =
149             SchemaPath.create(true, BOX_OUT_QNAME, BOX_IN_QNAME, OPEN_QNAME);
150
151     private static final QName FOO_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "foo");
152     private static final QName BAR_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "bar");
153     private static final QName XYZZY_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "xyzzy");
154     private static final SchemaPath XYZZY_FOO_PATH = SchemaPath.create(true, FOO_QNAME, XYZZY_QNAME);
155     private static final SchemaPath XYZZY_BAR_PATH = SchemaPath.create(true, BAR_QNAME, XYZZY_QNAME);
156
157     private static final QName CONFLICT_CHOICE_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "conflict-choice");
158     private static final QName CHOICE_CONT_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "choice-cont");
159     private static final QName CHOICE_ACTION_QNAME = QName.create(URN_EXAMPLE_CONFLICT, "choice-action");
160     private static final SchemaPath CHOICE_ACTION_PATH =
161             SchemaPath.create(true, CONFLICT_CHOICE_QNAME, CHOICE_CONT_QNAME, CHOICE_CONT_QNAME, CHOICE_ACTION_QNAME);
162
163     private static EffectiveModelContext PARTIAL_SCHEMA;
164     private static EffectiveModelContext SCHEMA;
165     private static EffectiveModelContext ACTION_SCHEMA;
166
167     private NetconfMessageTransformer actionNetconfMessageTransformer;
168     private NetconfMessageTransformer netconfMessageTransformer;
169
170     @BeforeClass
171     public static void beforeClass() {
172         PARTIAL_SCHEMA = BindingRuntimeHelpers.createEffectiveModel(NetconfState.class);
173         SCHEMA = BindingRuntimeHelpers.createEffectiveModel(IetfNetconfService.class, NetconfState.class);
174         ACTION_SCHEMA = YangParserTestUtils.parseYangResources(NetconfMessageTransformerTest.class,
175             "/schemas/example-server-farm.yang","/schemas/example-server-farm-2.yang",
176             "/schemas/conflicting-actions.yang", "/schemas/augmented-action.yang",
177             "/schemas/rpcs-actions-outputs.yang");
178     }
179
180     @AfterClass
181     public static void afterClass() {
182         PARTIAL_SCHEMA = null;
183         SCHEMA = null;
184         ACTION_SCHEMA = null;
185     }
186
187     @Before
188     public void setUp() throws Exception {
189         XMLUnit.setIgnoreWhitespace(true);
190         XMLUnit.setIgnoreAttributeOrder(true);
191         XMLUnit.setIgnoreComments(true);
192
193         netconfMessageTransformer = getTransformer(SCHEMA);
194         actionNetconfMessageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(ACTION_SCHEMA),
195             true);
196     }
197
198     @Test
199     public void testLockRequestBaseSchemaNotPresent() throws Exception {
200         final NetconfMessageTransformer transformer = getTransformer(PARTIAL_SCHEMA);
201         final NetconfMessage netconfMessage = transformer.toRpcRequest(toPath(NETCONF_LOCK_QNAME),
202                 NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_QNAME));
203
204         assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<lock"));
205         assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<rpc"));
206     }
207
208     @Test
209     public void testCreateSubscriberNotificationSchemaNotPresent() throws Exception {
210         final NetconfMessageTransformer transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA),
211             true, BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS);
212         NetconfMessage netconfMessage = transformer.toRpcRequest(
213                 toPath(CREATE_SUBSCRIPTION_RPC_QNAME),
214                 CREATE_SUBSCRIPTION_RPC_CONTENT
215         );
216         String documentString = XmlUtil.toString(netconfMessage.getDocument());
217         assertThat(documentString, CoreMatchers.containsString("<create-subscription"));
218         assertThat(documentString, CoreMatchers.containsString("<rpc"));
219     }
220
221     @Test
222     public void tesLockSchemaRequest() throws Exception {
223         final NetconfMessageTransformer transformer = getTransformer(PARTIAL_SCHEMA);
224         final String result = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>";
225
226         transformer.toRpcResult(new NetconfMessage(XmlUtil.readXmlToDocument(result)), toPath(NETCONF_LOCK_QNAME));
227     }
228
229     @Test
230     public void testRpcEmptyBodyWithOutputDefinedSchemaResult() throws Exception {
231         final String result = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>";
232
233         DOMRpcResult domRpcResult = actionNetconfMessageTransformer
234                 .toRpcResult(new NetconfMessage(XmlUtil.readXmlToDocument(result)),
235                         toPath(RPC_WITH_OUTPUT_QNAME));
236         assertNotNull(domRpcResult);
237     }
238
239     @Test
240     public void testRpcEmptyBodyWithoutOutputDefinedSchemaResult() throws Exception {
241         final String result = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>";
242
243         DOMRpcResult domRpcResult = actionNetconfMessageTransformer
244                 .toRpcResult(new NetconfMessage(XmlUtil.readXmlToDocument(result)),
245                         toPath(RPC_WITHOUT_OUTPUT_QNAME));
246         assertNotNull(domRpcResult);
247     }
248
249     @Test
250     public void testDiscardChangesRequest() throws Exception {
251         final NetconfMessage netconfMessage =
252                 netconfMessageTransformer.toRpcRequest(toPath(NETCONF_DISCARD_CHANGES_QNAME), null);
253         assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<discard"));
254         assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<rpc"));
255         assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("message-id"));
256     }
257
258     @Test
259     public void testGetSchemaRequest() throws Exception {
260         final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(GET_SCHEMA_QNAME),
261                 NetconfRemoteSchemaYangSourceProvider.createGetSchemaRequest("module", Optional.of("2012-12-12")));
262         assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
263                 + "<get-schema xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
264                 + "<format>yang</format>\n"
265                 + "<identifier>module</identifier>\n"
266                 + "<version>2012-12-12</version>\n"
267                 + "</get-schema>\n"
268                 + "</rpc>");
269     }
270
271     @Test
272     public void testGetSchemaResponse() throws Exception {
273         final NetconfMessageTransformer transformer = getTransformer(SCHEMA);
274         final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument(
275                 "<rpc-reply message-id=\"101\"\n"
276                         + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
277                         + "<data\n"
278                         + "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
279                         + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n"
280                         + "Random YANG SCHEMA\n"
281                         + "</xs:schema>\n"
282                         + "</data>\n"
283                         + "</rpc-reply>"
284         ));
285         final DOMRpcResult compositeNodeRpcResult = transformer.toRpcResult(response, toPath(GET_SCHEMA_QNAME));
286         assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
287         assertNotNull(compositeNodeRpcResult.getResult());
288         final DOMSource schemaContent = ((DOMSourceAnyxmlNode) ((ContainerNode) compositeNodeRpcResult.getResult())
289                 .getValue().iterator().next()).getValue();
290         assertThat(schemaContent.getNode().getTextContent(),
291                 CoreMatchers.containsString("Random YANG SCHEMA"));
292     }
293
294     @Test
295     public void testGetConfigResponse() throws Exception {
296         final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n"
297                 + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
298                 + "<data>\n"
299                 + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
300                 + "<schemas>\n"
301                 + "<schema>\n"
302                 + "<identifier>module</identifier>\n"
303                 + "<version>2012-12-12</version>\n"
304                 + "<format xmlns:x=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">x:yang</format>\n"
305                 + "</schema>\n"
306                 + "</schemas>\n"
307                 + "</netconf-state>\n"
308                 + "</data>\n"
309                 + "</rpc-reply>"));
310
311         final NetconfMessageTransformer transformer = getTransformer(SCHEMA);
312         final DOMRpcResult compositeNodeRpcResult =
313                 transformer.toRpcResult(response, toPath(NETCONF_GET_CONFIG_QNAME));
314         assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
315         assertNotNull(compositeNodeRpcResult.getResult());
316
317         final List<DataContainerChild<?, ?>> values = Lists.newArrayList(
318                 NetconfRemoteSchemaYangSourceProvider
319                         .createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue());
320
321         final Map<QName, Object> keys = new HashMap<>();
322         for (final DataContainerChild<?, ?> value : values) {
323             keys.put(value.getNodeType(), value.getValue());
324         }
325
326         final NodeIdentifierWithPredicates identifierWithPredicates =
327                 NodeIdentifierWithPredicates.of(Schema.QNAME, keys);
328         final MapEntryNode schemaNode =
329                 Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build();
330
331         final DOMSourceAnyxmlNode data = (DOMSourceAnyxmlNode) ((ContainerNode) compositeNodeRpcResult.getResult())
332                 .getChild(toId(NETCONF_DATA_QNAME)).get();
333
334         NormalizedNodeResult nodeResult =
335                 NetconfUtil.transformDOMSourceToNormalizedNode(SCHEMA, data.getValue());
336         ContainerNode result = (ContainerNode) nodeResult.getResult();
337         final ContainerNode state = (ContainerNode) result.getChild(toId(NetconfState.QNAME)).get();
338         final ContainerNode schemas = (ContainerNode) state.getChild(toId(Schemas.QNAME)).get();
339         final MapNode schemaParent = (MapNode) schemas.getChild(toId(Schema.QNAME)).get();
340         assertEquals(1, Iterables.size(schemaParent.getValue()));
341
342         assertEquals(schemaNode, schemaParent.getValue().iterator().next());
343     }
344
345     @Test
346     public void testGetConfigLeafRequest() throws Exception {
347         final DataContainerChild<?, ?> filter = toFilterStructure(
348                 YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME), toId(Schema.QNAME),
349                     NodeIdentifierWithPredicates.of(Schema.QNAME),
350                     toId(QName.create(Schemas.QNAME, "version"))), SCHEMA);
351
352         final DataContainerChild<?, ?> source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_QNAME);
353
354         final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_GET_CONFIG_QNAME),
355                 NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, source, filter));
356
357         assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
358                 + "<get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
359                 + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n"
360                 + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
361                 + "<schemas>\n"
362                 + "<schema>\n"
363                 + "<version/>\n"
364                 + "</schema>\n"
365                 + "</schemas>\n"
366                 + "</netconf-state>\n"
367                 + "</filter>\n"
368                 + "<source>\n"
369                 + "<running/>\n"
370                 + "</source>\n"
371                 + "</get-config>\n"
372                 + "</rpc>");
373     }
374
375     @Test
376     public void testGetConfigRequest() throws Exception {
377         final DataContainerChild<?, ?> filter = toFilterStructure(
378                 YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME)), SCHEMA);
379
380         final DataContainerChild<?, ?> source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_QNAME);
381
382         final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_GET_CONFIG_QNAME),
383                 NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, source, filter));
384
385         assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
386                 + "<get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
387                 + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n"
388                 + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
389                 + "<schemas/>\n"
390                 + "</netconf-state>"
391                 + "</filter>\n"
392                 + "<source>\n"
393                 + "<running/>\n"
394                 + "</source>\n"
395                 + "</get-config>"
396                 + "</rpc>");
397     }
398
399     @Test
400     public void testEditConfigRequest() throws Exception {
401         final List<DataContainerChild<?, ?>> values = Lists.newArrayList(
402                 NetconfRemoteSchemaYangSourceProvider
403                         .createGetSchemaRequest("module", Optional.of("2012-12-12")).getValue());
404
405         final Map<QName, Object> keys = new HashMap<>();
406         for (final DataContainerChild<?, ?> value : values) {
407             keys.put(value.getNodeType(), value.getValue());
408         }
409
410         final NodeIdentifierWithPredicates identifierWithPredicates =
411                 NodeIdentifierWithPredicates.of(Schema.QNAME, keys);
412         final MapEntryNode schemaNode =
413                 Builders.mapEntryBuilder().withNodeIdentifier(identifierWithPredicates).withValue(values).build();
414
415         final YangInstanceIdentifier id = YangInstanceIdentifier.builder()
416                 .node(NetconfState.QNAME).node(Schemas.QNAME).node(Schema.QNAME)
417                 .nodeWithKey(Schema.QNAME, keys).build();
418         final DataContainerChild<?, ?> editConfigStructure =
419                 createEditConfigStructure(BaseSchema.BASE_NETCONF_CTX_WITH_NOTIFICATIONS.getSchemaContext(), id,
420                     Optional.empty(), Optional.ofNullable(schemaNode));
421
422         final DataContainerChild<?, ?> target = NetconfBaseOps.getTargetNode(NETCONF_CANDIDATE_QNAME);
423
424         final ContainerNode wrap =
425                 NetconfMessageTransformUtil.wrap(NETCONF_EDIT_CONFIG_QNAME, editConfigStructure, target);
426         final NetconfMessage netconfMessage =
427                 netconfMessageTransformer.toRpcRequest(toPath(NETCONF_EDIT_CONFIG_QNAME), wrap);
428
429         assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
430                 + "<edit-config>\n"
431                 + "<target>\n"
432                 + "<candidate/>\n"
433                 + "</target>\n"
434                 + "<config>\n"
435                 + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
436                 + "<schemas>\n"
437                 + "<schema>\n"
438                 + "<identifier>module</identifier>\n"
439                 + "<version>2012-12-12</version>\n"
440                 + "<format>yang</format>\n"
441                 + "</schema>\n"
442                 + "</schemas>\n"
443                 + "</netconf-state>\n"
444                 + "</config>\n"
445                 + "</edit-config>\n"
446                 + "</rpc>");
447     }
448
449     private static void assertSimilarXml(final NetconfMessage netconfMessage, final String xmlContent)
450             throws SAXException, IOException {
451         final Diff diff = XMLUnit.compareXML(netconfMessage.getDocument(), XmlUtil.readXmlToDocument(xmlContent));
452         diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
453         assertTrue(diff.toString(), diff.similar());
454     }
455
456     @Test
457     public void testGetRequest() throws Exception {
458
459         final QName capability = QName.create(Capabilities.QNAME, "capability");
460         final DataContainerChild<?, ?> filter = toFilterStructure(
461                 YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Capabilities.QNAME), toId(capability),
462                     new NodeWithValue<>(capability, "a:b:c")), SCHEMA);
463
464         final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(toPath(NETCONF_GET_QNAME),
465                 NetconfMessageTransformUtil.wrap(NETCONF_GET_QNAME, filter));
466
467         assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
468                 + "<get xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
469                 + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n"
470                 + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n"
471                 + "<capabilities>\n"
472                 + "<capability>a:b:c</capability>\n"
473                 + "</capabilities>\n"
474                 + "</netconf-state>"
475                 + "</filter>\n"
476                 + "</get>"
477                 + "</rpc>");
478     }
479
480     private static NetconfMessageTransformer getTransformer(final EffectiveModelContext schema) {
481         return new NetconfMessageTransformer(new EmptyMountPointContext(schema), true);
482     }
483
484     @Test
485     public void testCommitResponse() throws Exception {
486         final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument(
487                 "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>"
488         ));
489         final DOMRpcResult compositeNodeRpcResult =
490                 netconfMessageTransformer.toRpcResult(response, toPath(NETCONF_COMMIT_QNAME));
491         assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
492         assertNull(compositeNodeRpcResult.getResult());
493     }
494
495     @Test
496     public void getActionsTest() {
497         Set<SchemaPath> schemaPaths = new HashSet<>();
498         schemaPaths.add(RESET_SERVER_PATH);
499         schemaPaths.add(START_DEVICE_PATH);
500         schemaPaths.add(ENABLE_INTERFACE_PATH);
501         schemaPaths.add(OPEN_BOXES_PATH);
502         schemaPaths.add(KILL_SERVER_APP_PATH);
503         schemaPaths.add(XYZZY_FOO_PATH);
504         schemaPaths.add(XYZZY_BAR_PATH);
505         schemaPaths.add(CHOICE_ACTION_PATH);
506         schemaPaths.add(DISABLE_INTERFACE_PATH);
507         schemaPaths.add(CHECK_WITH_OUTPUT_INTERFACE_PATH);
508         schemaPaths.add(CHECK_WITHOUT_OUTPUT_INTERFACE_PATH);
509
510         List<ActionDefinition> actions = NetconfMessageTransformer.getActions(ACTION_SCHEMA);
511         assertEquals(schemaPaths.size(), actions.size());
512         for (ActionDefinition actionDefinition : actions) {
513             SchemaPath path = actionDefinition.getPath();
514             assertTrue(schemaPaths.remove(path));
515         }
516     }
517
518     @Test
519     public void toActionRequestListTopLevelTest() {
520         QName nameQname = QName.create(SERVER_QNAME, "name");
521         List<PathArgument> nodeIdentifiers = new ArrayList<>();
522         nodeIdentifiers.add(new NodeIdentifier(SERVER_QNAME));
523         nodeIdentifiers.add(NodeIdentifierWithPredicates.of(SERVER_QNAME, nameQname, "test"));
524         DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
525
526         ContainerNode data = initInputAction(QName.create(SERVER_QNAME, "reset-at"), "now");
527
528         NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
529                 RESET_SERVER_PATH, domDataTreeIdentifier, data);
530
531         Node childAction = checkBasePartOfActionRequest(actionRequest);
532
533         Node childServer = childAction.getFirstChild();
534         checkNode(childServer, "server", "server", URN_EXAMPLE_SERVER_FARM);
535
536         Node childName = childServer.getFirstChild();
537         checkNode(childName, "name", "name", URN_EXAMPLE_SERVER_FARM);
538
539         Node childTest = childName.getFirstChild();
540         assertEquals(childTest.getNodeValue(), "test");
541
542         checkAction(RESET_QNAME, childName.getNextSibling(), "reset-at", "reset-at", "now");
543     }
544
545     @Test
546     public void toActionRequestContainerTopLevelTest() {
547         List<PathArgument> nodeIdentifiers = Collections.singletonList(NodeIdentifier.create(DEVICE_QNAME));
548         DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
549
550         NormalizedNode<?, ?> payload = initInputAction(QName.create(DEVICE_QNAME, "start-at"), "now");
551         NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
552                 START_DEVICE_PATH, domDataTreeIdentifier, payload);
553
554         Node childAction = checkBasePartOfActionRequest(actionRequest);
555
556         Node childDevice = childAction.getFirstChild();
557         checkNode(childDevice, "device", "device", URN_EXAMPLE_SERVER_FARM);
558
559         checkAction(START_QNAME, childDevice.getFirstChild(), "start-at", "start-at", "now");
560     }
561
562     @Test
563     public void toActionRequestContainerInContainerTest() {
564         List<PathArgument> nodeIdentifiers = new ArrayList<>();
565         nodeIdentifiers.add(NodeIdentifier.create(BOX_OUT_QNAME));
566         nodeIdentifiers.add(NodeIdentifier.create(BOX_IN_QNAME));
567
568         DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
569
570         NormalizedNode<?, ?> payload = initInputAction(QName.create(BOX_OUT_QNAME, "start-at"), "now");
571         NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
572                 OPEN_BOXES_PATH, domDataTreeIdentifier, payload);
573
574         Node childAction = checkBasePartOfActionRequest(actionRequest);
575
576         Node childBoxOut = childAction.getFirstChild();
577         checkNode(childBoxOut, "box-out", "box-out", URN_EXAMPLE_SERVER_FARM);
578
579         Node childBoxIn = childBoxOut.getFirstChild();
580         checkNode(childBoxIn, "box-in", "box-in", URN_EXAMPLE_SERVER_FARM);
581
582         Node action = childBoxIn.getFirstChild();
583         checkNode(action, OPEN_QNAME.getLocalName(), OPEN_QNAME.getLocalName(), OPEN_QNAME.getNamespace().toString());
584     }
585
586     @Test
587     public void toActionRequestListInContainerTest() {
588         QName nameQname = QName.create(INTERFACE_QNAME, "name");
589
590         List<PathArgument> nodeIdentifiers = new ArrayList<>();
591         nodeIdentifiers.add(NodeIdentifier.create(DEVICE_QNAME));
592         nodeIdentifiers.add(NodeIdentifier.create(INTERFACE_QNAME));
593         nodeIdentifiers.add(NodeIdentifierWithPredicates.of(INTERFACE_QNAME, nameQname, "test"));
594
595         DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
596
597         NormalizedNode<?, ?> payload = initEmptyInputAction(INTERFACE_QNAME);
598         NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
599                 ENABLE_INTERFACE_PATH, domDataTreeIdentifier, payload);
600
601         Node childAction = checkBasePartOfActionRequest(actionRequest);
602
603         Node childDevice = childAction.getFirstChild();
604         checkNode(childDevice, "device", "device", URN_EXAMPLE_SERVER_FARM);
605
606         Node childInterface = childDevice.getFirstChild();
607         checkNode(childInterface, "interface", "interface", URN_EXAMPLE_SERVER_FARM);
608
609         Node childName = childInterface.getFirstChild();
610         checkNode(childName, "name", "name", nameQname.getNamespace().toString());
611
612         Node childTest = childName.getFirstChild();
613         assertEquals(childTest.getNodeValue(), "test");
614
615         Node action = childInterface.getLastChild();
616         checkNode(action, ENABLE_QNAME.getLocalName(), ENABLE_QNAME.getLocalName(),
617                 ENABLE_QNAME.getNamespace().toString());
618     }
619
620     @Test
621     public void toActionRequestListInContainerAugmentedIntoListTest() {
622         QName serverNameQname = QName.create(SERVER_QNAME, "name");
623         QName applicationNameQname = QName.create(APPLICATION_QNAME, "name");
624
625         List<PathArgument> nodeIdentifiers = new ArrayList<>();
626         nodeIdentifiers.add(NodeIdentifier.create(SERVER_QNAME));
627         nodeIdentifiers.add(NodeIdentifierWithPredicates.of(SERVER_QNAME, serverNameQname, "testServer"));
628         nodeIdentifiers.add(new AugmentationIdentifier(Collections.singleton(APPLICATIONS_QNAME)));
629         nodeIdentifiers.add(NodeIdentifier.create(APPLICATIONS_QNAME));
630         nodeIdentifiers.add(NodeIdentifier.create(APPLICATION_QNAME));
631         nodeIdentifiers.add(NodeIdentifierWithPredicates.of(APPLICATION_QNAME,
632                 applicationNameQname, "testApplication"));
633
634         DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
635
636         NormalizedNode<?, ?> payload = initEmptyInputAction(APPLICATION_QNAME);
637         NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
638                 KILL_SERVER_APP_PATH, domDataTreeIdentifier, payload);
639
640         Node childAction = checkBasePartOfActionRequest(actionRequest);
641
642         Node childServer = childAction.getFirstChild();
643         checkNode(childServer, "server", "server", URN_EXAMPLE_SERVER_FARM);
644
645         Node childServerName = childServer.getFirstChild();
646         checkNode(childServerName, "name", "name", URN_EXAMPLE_SERVER_FARM);
647
648         Node childServerNameTest = childServerName.getFirstChild();
649         assertEquals(childServerNameTest.getNodeValue(), "testServer");
650
651         Node childApplications = childServer.getLastChild();
652         checkNode(childApplications, "applications", "applications", URN_EXAMPLE_SERVER_FARM_2);
653
654         Node childApplication = childApplications.getFirstChild();
655         checkNode(childApplication, "application", "application", URN_EXAMPLE_SERVER_FARM_2);
656
657         Node childApplicationName = childApplication.getFirstChild();
658         checkNode(childApplicationName, "name", "name", URN_EXAMPLE_SERVER_FARM_2);
659
660         Node childApplicationNameTest = childApplicationName.getFirstChild();
661         assertEquals(childApplicationNameTest.getNodeValue(), "testApplication");
662
663         Node childKillAction = childApplication.getLastChild();
664         checkNode(childApplication, "application", "application", URN_EXAMPLE_SERVER_FARM_2);
665         checkNode(childKillAction, KILL_QNAME.getLocalName(), KILL_QNAME.getLocalName(),
666                 KILL_QNAME.getNamespace().toString());
667     }
668
669     @Test
670     public void toActionRequestConflictingInListTest() {
671         QName barInputQname = QName.create(BAR_QNAME, "bar");
672         QName barIdQname = QName.create(BAR_QNAME, "bar-id");
673         Byte barInput = new Byte("1");
674
675         List<PathArgument> nodeIdentifiers = new ArrayList<>();
676         nodeIdentifiers.add(NodeIdentifier.create(BAR_QNAME));
677         nodeIdentifiers.add(NodeIdentifierWithPredicates.of(BAR_QNAME, barIdQname, "test"));
678
679         DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
680
681         ImmutableLeafNodeBuilder<Byte> immutableLeafNodeBuilder = new ImmutableLeafNodeBuilder<>();
682         DataContainerChild<NodeIdentifier, Byte> build = immutableLeafNodeBuilder.withNodeIdentifier(
683                 NodeIdentifier.create(barInputQname)).withValue(barInput).build();
684         NormalizedNode<?, ?> payload = ImmutableContainerNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create(
685                 QName.create(barInputQname, "input"))).withChild(build).build();
686
687         NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
688                 XYZZY_BAR_PATH, domDataTreeIdentifier, payload);
689
690         Node childAction = checkBasePartOfActionRequest(actionRequest);
691
692         Node childBar = childAction.getFirstChild();
693         checkNode(childBar, "bar", "bar", URN_EXAMPLE_CONFLICT);
694
695         Node childBarId = childBar.getFirstChild();
696         checkNode(childBarId, "bar-id", "bar-id", URN_EXAMPLE_CONFLICT);
697
698         Node childTest = childBarId.getFirstChild();
699         assertEquals(childTest.getNodeValue(), "test");
700
701         Node action = childBar.getLastChild();
702         checkNode(action, XYZZY_QNAME.getLocalName(), XYZZY_QNAME.getLocalName(),
703                 XYZZY_QNAME.getNamespace().toString());
704     }
705
706     @Test
707     public void toActionRequestConflictingInContainerTest() {
708         QName fooInputQname = QName.create(FOO_QNAME, "foo");
709
710         List<PathArgument> nodeIdentifiers = new ArrayList<>();
711         nodeIdentifiers.add(NodeIdentifier.create(FOO_QNAME));
712         DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
713         NormalizedNode<?, ?> payload = initInputAction(fooInputQname, "test");
714
715         NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
716                 XYZZY_FOO_PATH, domDataTreeIdentifier, payload);
717
718         Node childAction = checkBasePartOfActionRequest(actionRequest);
719
720         Node childBar = childAction.getFirstChild();
721         checkNode(childBar, "foo", "foo", URN_EXAMPLE_CONFLICT);
722
723         Node action = childBar.getLastChild();
724         checkNode(action, XYZZY_QNAME.getLocalName(), XYZZY_QNAME.getLocalName(),
725                 XYZZY_QNAME.getNamespace().toString());
726     }
727
728     @Test
729     public void toActionRequestChoiceTest() {
730         List<PathArgument> nodeIdentifiers = new ArrayList<>();
731         nodeIdentifiers.add(NodeIdentifier.create(CONFLICT_CHOICE_QNAME));
732         nodeIdentifiers.add(NodeIdentifier.create(CHOICE_CONT_QNAME));
733         DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
734         NormalizedNode<?, ?> payload = initEmptyInputAction(CHOICE_ACTION_QNAME);
735
736         NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
737                 CHOICE_ACTION_PATH, domDataTreeIdentifier, payload);
738
739         Node childAction = checkBasePartOfActionRequest(actionRequest);
740
741         Node childChoiceCont = childAction.getFirstChild();
742         checkNode(childChoiceCont, "choice-cont", "choice-cont", URN_EXAMPLE_CONFLICT);
743
744         Node action = childChoiceCont.getLastChild();
745         checkNode(action, CHOICE_ACTION_QNAME.getLocalName(), CHOICE_ACTION_QNAME.getLocalName(),
746                 CHOICE_ACTION_QNAME.getNamespace().toString());
747     }
748
749     @Test
750     public void toAugmentedActionRequestListInContainerTest() {
751         QName nameQname = QName.create(INTERFACE_QNAME, "name");
752
753         List<PathArgument> nodeIdentifiers = new ArrayList<>();
754         nodeIdentifiers.add(NodeIdentifier.create(DEVICE_QNAME));
755         nodeIdentifiers.add(NodeIdentifier.create(INTERFACE_QNAME));
756         nodeIdentifiers.add(NodeIdentifierWithPredicates.of(INTERFACE_QNAME, nameQname, "test"));
757
758         DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
759
760         NormalizedNode<?, ?> payload = initEmptyInputAction(INTERFACE_QNAME);
761         NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(
762                 DISABLE_INTERFACE_PATH, domDataTreeIdentifier, payload);
763
764         Node childAction = checkBasePartOfActionRequest(actionRequest);
765
766         Node childDevice = childAction.getFirstChild();
767         checkNode(childDevice, "device", "device", URN_EXAMPLE_SERVER_FARM);
768
769         Node childInterface = childDevice.getFirstChild();
770         checkNode(childInterface, "interface", "interface", URN_EXAMPLE_SERVER_FARM);
771
772         Node childName = childInterface.getFirstChild();
773         checkNode(childName, "name", "name", nameQname.getNamespace().toString());
774
775         Node childTest = childName.getFirstChild();
776         assertEquals(childTest.getNodeValue(), "test");
777
778         Node action = childInterface.getLastChild();
779         checkNode(action, DISABLE_QNAME.getLocalName(), DISABLE_QNAME.getLocalName(),
780                 DISABLE_QNAME.getNamespace().toString());
781     }
782
783     @SuppressWarnings({ "rawtypes", "unchecked" })
784     @Test
785     public void toActionResultTest() throws Exception {
786         NetconfMessage message = new NetconfMessage(XmlUtil.readXmlToDocument(
787                 "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
788                 + "<reset-finished-at xmlns=\"urn:example:server-farm\">"
789                 + "now"
790                 + "</reset-finished-at>"
791                 + "</rpc-reply>"));
792         DOMActionResult actionResult = actionNetconfMessageTransformer.toActionResult(RESET_SERVER_PATH, message);
793         assertNotNull(actionResult);
794         ContainerNode containerNode = actionResult.getOutput().get();
795         assertNotNull(containerNode);
796         LeafNode<String> leaf = (LeafNode) containerNode.getValue().iterator().next();
797         assertEquals("now", leaf.getValue());
798     }
799
800     @Test
801     public void toActionEmptyBodyWithOutputDefinedResultTest() throws Exception {
802         NetconfMessage message = new NetconfMessage(XmlUtil.readXmlToDocument(
803                 "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
804                 + "<ok/>"
805                 + "</rpc-reply>"));
806         DOMActionResult actionResult =
807                 actionNetconfMessageTransformer.toActionResult(CHECK_WITH_OUTPUT_INTERFACE_PATH, message);
808         assertNotNull(actionResult);
809         assertTrue(actionResult.getOutput().isEmpty());
810     }
811
812     @Test
813     public void toActionEmptyBodyWithoutOutputDefinedResultTest() throws Exception {
814         NetconfMessage message = new NetconfMessage(XmlUtil.readXmlToDocument(
815                 "<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
816                 + "<ok/>"
817                 + "</rpc-reply>"));
818         DOMActionResult actionResult =
819                 actionNetconfMessageTransformer.toActionResult(CHECK_WITHOUT_OUTPUT_INTERFACE_PATH, message);
820         assertNotNull(actionResult);
821         assertTrue(actionResult.getOutput().isEmpty());
822     }
823
824     private static void checkAction(final QName actionQname, final Node action , final String inputLocalName,
825             final String inputNodeName, final String inputValue) {
826         checkNode(action, actionQname.getLocalName(), actionQname.getLocalName(),
827                 actionQname.getNamespace().toString());
828
829         Node childResetAt = action.getFirstChild();
830         checkNode(childResetAt, inputLocalName, inputNodeName, actionQname.getNamespace().toString());
831
832         Node firstChild = childResetAt.getFirstChild();
833         assertEquals(firstChild.getNodeValue(), inputValue);
834     }
835
836     private static Node checkBasePartOfActionRequest(final NetconfMessage actionRequest) {
837         Node baseRpc = actionRequest.getDocument().getFirstChild();
838         checkNode(baseRpc, "rpc", "rpc", NetconfUtil.NETCONF_QNAME.getNamespace().toString());
839         assertTrue(baseRpc.getLocalName().equals("rpc"));
840         assertTrue(baseRpc.getNodeName().equals("rpc"));
841
842         Node messageId = baseRpc.getAttributes().getNamedItem("message-id");
843         assertNotNull(messageId);
844         assertTrue(messageId.getNodeValue().contains("m-"));
845
846         Node childAction = baseRpc.getFirstChild();
847         checkNode(childAction, "action", "action", NetconfMessageTransformUtil.NETCONF_ACTION_NAMESPACE.toString());
848         return childAction;
849     }
850
851     private static DOMDataTreeIdentifier prepareDataTreeId(final List<PathArgument> nodeIdentifiers) {
852         YangInstanceIdentifier yangInstanceIdentifier =
853                 YangInstanceIdentifier.builder().append(nodeIdentifiers).build();
854         DOMDataTreeIdentifier domDataTreeIdentifier =
855                 new DOMDataTreeIdentifier(org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION,
856                         yangInstanceIdentifier);
857         return domDataTreeIdentifier;
858     }
859
860     private static ContainerNode initInputAction(final QName qname, final String value) {
861         ImmutableLeafNodeBuilder<String> immutableLeafNodeBuilder = new ImmutableLeafNodeBuilder<>();
862         DataContainerChild<NodeIdentifier, String> build = immutableLeafNodeBuilder.withNodeIdentifier(
863                 NodeIdentifier.create(qname)).withValue(value).build();
864         ContainerNode data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create(
865                 QName.create(qname, "input"))).withChild(build).build();
866         return data;
867     }
868
869     private static ContainerNode initEmptyInputAction(final QName qname) {
870         return ImmutableContainerNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create(
871                 QName.create(qname, "input"))).build();
872     }
873
874     private static void checkNode(final Node childServer, final String expectedLocalName, final String expectedNodeName,
875             final String expectedNamespace) {
876         assertNotNull(childServer);
877         assertEquals(childServer.getLocalName(), expectedLocalName);
878         assertEquals(childServer.getNodeName(), expectedNodeName);
879         assertEquals(childServer.getNamespaceURI(), expectedNamespace);
880     }
881 }