2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.netconf.mdsal.connector.ops;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
15 import java.io.StringWriter;
16 import javax.xml.transform.OutputKeys;
17 import javax.xml.transform.Transformer;
18 import javax.xml.transform.TransformerFactory;
19 import javax.xml.transform.dom.DOMSource;
20 import javax.xml.transform.stream.StreamResult;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.mockito.Mockito;
24 import org.opendaylight.netconf.api.DocumentedException;
25 import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity;
26 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
27 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
28 import org.opendaylight.netconf.api.xml.XmlElement;
29 import org.opendaylight.netconf.api.xml.XmlUtil;
30 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
31 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
32 import org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig;
33 import org.opendaylight.netconf.util.test.XmlFileLoader;
34 import org.opendaylight.yangtools.yang.common.QName;
35 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
36 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
37 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.w3c.dom.Document;
41 import org.w3c.dom.Element;
42 import org.w3c.dom.NodeList;
44 public class NetconfMDSalMappingTest extends AbstractNetconfOperationTest {
45 private static final Logger LOG = LoggerFactory.getLogger(NetconfMDSalMappingTest.class);
47 private static final String TARGET_KEY = "target";
48 private static final String FILTER_NODE = "filter";
49 private static final String GET_CONFIG = "get-config";
50 private static final QName TOP = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "top");
51 private static final QName USERS = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "users");
52 private static final QName USER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "user");
53 private static final QName MODULES = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "modules");
54 private static final QName AUGMENTED_CONTAINER = QName.create("urn:opendaylight:mdsal:mapping:test",
55 "2015-02-26", "augmented-container");
56 private static final QName AUGMENTED_STRING_IN_CONT = QName.create("urn:opendaylight:mdsal:mapping:test",
57 "2015-02-26", "identifier");
58 private static final QName CHOICE_NODE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
60 private static final QName AUGMENTED_CASE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
62 private static final QName CHOICE_WRAPPER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
64 private static final QName INNER_CHOICE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
66 private static final QName INNER_CHOICE_TEXT = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
69 private static final YangInstanceIdentifier AUGMENTED_CONTAINER_IN_MODULES =
70 YangInstanceIdentifier.builder().node(TOP).node(MODULES).build();
73 protected SchemaContext getSchemaContext() {
74 return YangParserTestUtils.parseYangResources(NetconfMDSalMappingTest.class,
75 "/yang/mdsal-netconf-mapping-test.yang");
79 public void testEmptyDatastore() throws Exception {
80 assertEmptyDatastore(get());
81 assertEmptyDatastore(getConfigCandidate());
82 assertEmptyDatastore(getConfigRunning());
86 public void testIncorrectGet() throws Exception {
88 executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
89 getTransactionProvider()), "messages/mapping/bad_getConfig.xml");
90 fail("Should have failed, this is an incorrect request");
91 } catch (final DocumentedException e) {
92 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
93 assertTrue(e.getErrorTag() == ErrorTag.OPERATION_FAILED);
94 assertTrue(e.getErrorType() == ErrorType.APPLICATION);
98 executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
99 getTransactionProvider()), "messages/mapping/bad_namespace_getConfig.xml");
100 fail("Should have failed, this is an incorrect request");
101 } catch (final DocumentedException e) {
102 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
103 assertTrue(e.getErrorTag() == ErrorTag.OPERATION_FAILED);
104 assertTrue(e.getErrorType() == ErrorType.APPLICATION);
109 public void testEditRunning() throws Exception {
111 edit("messages/mapping/editConfigs/editConfig_running.xml");
112 fail("Should have failed - edit config on running datastore is not supported");
113 } catch (final DocumentedException e) {
114 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
115 assertTrue(e.getErrorTag() == ErrorTag.OPERATION_NOT_SUPPORTED);
116 assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
121 public void testCommitWithoutOpenTransaction() throws Exception {
122 verifyResponse(commit(), RPC_REPLY_OK);
123 assertEmptyDatastore(getConfigCandidate());
127 public void testCandidateTransaction() throws Exception {
128 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK);
129 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
130 "messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
131 assertEmptyDatastore(getConfigRunning());
133 verifyResponse(discardChanges(), RPC_REPLY_OK);
134 assertEmptyDatastore(getConfigCandidate());
138 public void testEditWithCommit() throws Exception {
139 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK);
140 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
141 "messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
143 verifyResponse(commit(), RPC_REPLY_OK);
144 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
145 "messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
151 public void testKeyOrder() throws Exception {
152 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_keys_1.xml"), RPC_REPLY_OK);
153 verifyResponse(commit(), RPC_REPLY_OK);
154 final Document configRunning = getConfigRunning();
155 final String responseAsString = XmlUtil.toString(configRunning);
156 verifyResponse(configRunning, XmlFileLoader.xmlFileToDocument(
157 "messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml"));
159 final int key3 = responseAsString.indexOf("key3");
160 final int key1 = responseAsString.indexOf("key1");
161 final int key2 = responseAsString.indexOf("key2");
163 assertTrue(String.format("Key ordering invalid, should be key3(%d) < key1(%d) < key2(%d)", key3, key1, key2),
164 key3 < key1 && key1 < key2);
171 public void testMultipleEditsWithMerge() throws Exception {
172 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK);
173 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
174 "messages/mapping/editConfigs/editConfig_merge_multiple_control_1.xml"));
175 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK);
176 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
177 "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml"));
178 assertEmptyDatastore(getConfigRunning());
180 verifyResponse(commit(), RPC_REPLY_OK);
181 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
182 "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml"));
188 public void testMoreComplexEditConfigs() throws Exception {
189 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK);
190 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK);
192 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_2.xml"), RPC_REPLY_OK);
193 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
194 "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge.xml"));
196 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_3.xml"), RPC_REPLY_OK);
197 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
198 "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge_2.xml"));
200 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_4_replace.xml"), RPC_REPLY_OK);
201 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
202 "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml"));
203 verifyResponse(commit(), RPC_REPLY_OK);
205 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
206 "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml"));
208 verifyResponse(edit("messages/mapping/editConfigs/editConfig_replace_default.xml"), RPC_REPLY_OK);
209 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
210 "messages/mapping/editConfigs/editConfig_replace_default_control.xml"));
211 verifyResponse(commit(), RPC_REPLY_OK);
213 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
214 "messages/mapping/editConfigs/editConfig_replace_default_control.xml"));
220 public void testOrderedListEdits() throws Exception {
222 verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_create.xml"), RPC_REPLY_OK);
223 verifyResponse(commit(), RPC_REPLY_OK);
225 verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_replace.xml"), RPC_REPLY_OK);
226 verifyResponse(commit(), RPC_REPLY_OK);
233 public void testAugmentedOrderedListEdits() throws Exception {
235 verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_create.xml"),
237 verifyResponse(commit(), RPC_REPLY_OK);
239 verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_replace.xml"),
241 verifyResponse(commit(), RPC_REPLY_OK);
248 public void testAugmentedContainerReplace() throws Exception {
249 verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"),
251 verifyResponse(commit(), RPC_REPLY_OK);
253 verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_container_replace.xml"),
255 verifyResponse(commit(), RPC_REPLY_OK);
261 public void testLeafFromAugmentReplace() throws Exception {
262 verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"),
264 verifyResponse(commit(), RPC_REPLY_OK);
266 verifyResponse(edit("messages/mapping/editConfigs/editConfig_leaf_from_augment_replace.xml"),
268 verifyResponse(commit(), RPC_REPLY_OK);
274 public void testLock() throws Exception {
275 verifyResponse(lockCandidate(), RPC_REPLY_OK);
279 fail("Should have failed - locking of running datastore is not supported");
280 } catch (final DocumentedException e) {
281 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
282 assertTrue(e.getErrorTag() == ErrorTag.OPERATION_NOT_SUPPORTED);
283 assertTrue(e.getErrorType() == ErrorType.APPLICATION);
288 fail("Should have failed, target is missing");
289 } catch (final DocumentedException e) {
290 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
291 assertTrue(e.getErrorTag() == ErrorTag.INVALID_VALUE);
292 assertTrue(e.getErrorType() == ErrorType.APPLICATION);
297 public void testUnlock() throws Exception {
298 verifyResponse(unlockCandidate(), RPC_REPLY_OK);
302 fail("Should have failed - unlocking of running datastore is not supported");
303 } catch (final DocumentedException e) {
304 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
305 assertTrue(e.getErrorTag() == ErrorTag.OPERATION_NOT_SUPPORTED);
306 assertTrue(e.getErrorType() == ErrorType.APPLICATION);
310 unlockWithoutTarget();
311 fail("Should have failed, target is missing");
312 } catch (final DocumentedException e) {
313 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
314 assertTrue(e.getErrorTag() == ErrorTag.INVALID_VALUE);
315 assertTrue(e.getErrorType() == ErrorType.APPLICATION);
320 public void testEditWithCreate() throws Exception {
321 verifyResponse(edit("messages/mapping/editConfigs/editConfig_create.xml"), RPC_REPLY_OK);
322 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
323 "messages/mapping/editConfig_create_n1_control.xml"));
326 edit("messages/mapping/editConfigs/editConfig_create.xml");
327 fail("Create should have failed - data already exists");
328 } catch (final DocumentedException e) {
329 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
330 assertTrue(e.getErrorTag() == ErrorTag.DATA_EXISTS);
331 assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
334 verifyResponse(discardChanges(), RPC_REPLY_OK);
338 public void testDeleteNonExisting() throws Exception {
339 assertEmptyDatastore(getConfigCandidate());
340 assertEmptyDatastore(getConfigRunning());
343 edit("messages/mapping/editConfigs/editConfig_delete-top.xml");
344 fail("Delete should have failed - data is missing");
345 } catch (final DocumentedException e) {
346 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
347 assertTrue(e.getErrorTag() == ErrorTag.DATA_MISSING);
348 assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
353 public void testEditMissingDefaultOperation() throws Exception {
354 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_1.xml"),
356 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_2.xml"),
358 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
359 "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml"));
361 verifyResponse(commit(), RPC_REPLY_OK);
362 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
363 "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml"));
368 private static void printDocument(final Document doc) throws Exception {
369 final TransformerFactory tf = TransformerFactory.newInstance();
370 final Transformer transformer = tf.newTransformer();
371 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
372 transformer.setOutputProperty(OutputKeys.METHOD, "xml");
373 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
374 transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
375 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
377 final StringWriter writer = new StringWriter();
378 transformer.transform(new DOMSource(doc),
379 new StreamResult(writer));
380 LOG.warn(writer.getBuffer().toString());
384 public void testEditConfigWithMultipleOperations() throws Exception {
387 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_setup.xml"),
389 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_1.xml"),
392 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_2.xml"),
394 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
395 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_2_control.xml"));
397 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_leaf_operations.xml"),
399 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
400 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_control.xml"));
404 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_setup.xml"),
406 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_default-replace.xml"),
410 edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_create_existing.xml");
412 } catch (final DocumentedException e) {
413 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
414 assertTrue(e.getErrorTag() == ErrorTag.DATA_EXISTS);
415 assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
419 "messages/mapping/editConfigs/"
420 + "editConfig_merge_multiple_operations_4_delete_children_operations.xml"),
422 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
423 "messages/mapping/editConfigs/"
424 + "editConfig_merge_multiple_operations_4_delete_children_operations_control.xml"));
426 "messages/mapping/editConfigs/"
427 + "editConfig_merge_multiple_operations_4_remove-non-existing.xml"),
430 edit("messages/mapping/editConfigs/"
431 + "editConfig_merge_multiple_operations_4_delete-non-existing.xml");
433 } catch (final DocumentedException e) {
434 assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR);
435 assertTrue(e.getErrorTag() == ErrorTag.DATA_MISSING);
436 assertTrue(e.getErrorType() == ErrorType.PROTOCOL);
439 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup.xml"),
441 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
442 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup-control.xml"));
444 // Test files have been modified. RFC6020 requires that at most once case inside a choice is present at any time
445 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2.xml"),
447 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
448 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2-control.xml"));
450 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_delete.xml"),
452 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
453 "messages/mapping/editConfigs"
454 + "/editConfig_merge_multiple_operations_4_delete_children_operations_control.xml"));
460 public void testEditConfigGetElementByTagName() throws Exception {
461 EditConfig editConfig = new EditConfig("test_edit-config", Mockito.mock(CurrentSchemaContext.class),
462 Mockito.mock(TransactionProvider.class));
464 String stringWithoutPrefix =
465 "<rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
470 + " </edit-config>\n"
472 XmlElement xe = getXmlElement(stringWithoutPrefix);
473 NodeList nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
474 Assert.assertEquals(1, nodeList.getLength());
476 String stringWithPrefix =
477 "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
478 + " <nc:edit-config>\n"
480 + " <nc:candidate/>\n"
482 + " </nc:edit-config>\n"
485 xe = getXmlElement(stringWithPrefix);
486 nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
487 Assert.assertEquals(1, nodeList.getLength());
489 String stringWithoutTarget =
490 "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
491 + " <nc:edit-config>\n"
494 + " </nc:edit-config>\n"
496 xe = getXmlElement(stringWithoutTarget);
499 nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
500 XmlElement.fromDomElement((Element) nodeList.item(0)).getOnlyChildElement();
501 Assert.fail("Not specified target, we should fail");
502 } catch (DocumentedException documentedException) {
508 private static XmlElement getXmlElement(final String elementAsString) throws Exception {
509 Document document = XmlUtil.readXmlToDocument(elementAsString);
510 Element element = document.getDocumentElement();
511 return XmlElement.fromDomElement(element);
515 public void testReplaceMapEntry() throws Exception {
516 verifyResponse(edit("messages/mapping/editConfigs/edit-config-replace-map-entry.xml"), RPC_REPLY_OK);
517 verifyResponse(commit(), RPC_REPLY_OK);
518 verifyResponse(getConfigRunning(),
519 XmlFileLoader.xmlFileToDocument("messages/mapping/get-config-map-entry.xml"));
523 public void testMergeMapEntry() throws Exception {
524 verifyResponse(edit("messages/mapping/editConfigs/edit-config-merge-map-entry.xml"), RPC_REPLY_OK);
525 verifyResponse(commit(), RPC_REPLY_OK);
526 verifyResponse(getConfigRunning(),
527 XmlFileLoader.xmlFileToDocument("messages/mapping/get-config-map-entry.xml"));
531 public void testFiltering() throws Exception {
532 assertEmptyDatastore(getConfigCandidate());
533 assertEmptyDatastore(getConfigRunning());
535 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-config-empty-filter.xml"),
536 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
537 verifyResponse(getWithFilter("messages/mapping/filters/get-empty-filter.xml"),
538 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
540 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response"
542 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
543 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-users.xml"),
544 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
546 verifyResponse(edit("messages/mapping/editConfigs/editConfig-filtering-setup.xml"), RPC_REPLY_OK);
547 verifyResponse(commit(), RPC_REPLY_OK);
549 verifyFilterIdentifier("messages/mapping/filters/get-filter-alluser.xml",
550 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
551 verifyFilterIdentifier("messages/mapping/filters/get-filter-company-info.xml",
552 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
553 verifyFilterIdentifier("messages/mapping/filters/get-filter-modules-and-admin.xml",
554 YangInstanceIdentifier.builder().node(TOP).build());
555 verifyFilterIdentifier("messages/mapping/filters/get-filter-only-names-types.xml",
556 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
557 verifyFilterIdentifier("messages/mapping/filters/get-filter-specific-module-type-and-user.xml",
558 YangInstanceIdentifier.builder().node(TOP).build());
559 verifyFilterIdentifier("messages/mapping/filters/get-filter-superuser.xml",
560 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
561 verifyFilterIdentifier("messages/mapping/filters/get-filter-users.xml",
562 YangInstanceIdentifier.builder().node(TOP).node(USERS).build());
564 final YangInstanceIdentifier ident = YangInstanceIdentifier
565 .builder(AUGMENTED_CONTAINER_IN_MODULES)
566 .node(AUGMENTED_CONTAINER)
567 .node(AUGMENTED_STRING_IN_CONT).build();
569 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-string.xml", ident);
570 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case.xml",
571 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(AUGMENTED_CASE).build());
573 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case.xml"),
574 XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case.xml"));
577 * RFC6020 requires that at most once case inside a choice is present at any time.
579 * <augmented-case>augmented case</augmented-case>
581 * messages/mapping/editConfigs/editConfig-filtering-setup.xml
582 * cannot exists together with
583 * <text>augmented nested choice text1</text>
585 * messages/mapping/editConfigs/editConfig-filtering-setup2.xml
587 //verifyResponse(edit("messages/mapping/editConfigs/editConfig-filtering-setup2.xml"), RPC_REPLY_OK);
588 //verifyResponse(commit(), RPC_REPLY_OK);
590 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml",
591 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).build());
592 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-case.xml",
593 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).node(INNER_CHOICE)
594 .node(INNER_CHOICE_TEXT).build());
596 // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-string.xml"),
597 // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-string.xml"));
598 // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml"),
599 // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml"));
600 // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-case.xml"),
601 // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml"));
603 verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-top.xml"), RPC_REPLY_OK);
604 verifyResponse(commit(), RPC_REPLY_OK);
608 private void verifyFilterIdentifier(final String resource, final YangInstanceIdentifier identifier)
610 final TestingGetConfig getConfig = new TestingGetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
611 getTransactionProvider());
612 final Document request = XmlFileLoader.xmlFileToDocument(resource);
613 final YangInstanceIdentifier iid = getConfig.getInstanceIdentifierFromDocument(request);
614 assertEquals(identifier, iid);
617 private class TestingGetConfig extends GetConfig {
618 TestingGetConfig(final String sessionId, final CurrentSchemaContext schemaContext,
619 final TransactionProvider transactionProvider) {
620 super(sessionId, schemaContext, transactionProvider);
623 YangInstanceIdentifier getInstanceIdentifierFromDocument(final Document request) throws DocumentedException {
624 final XmlElement filterElement = XmlElement.fromDomDocument(request).getOnlyChildElement(GET_CONFIG)
625 .getOnlyChildElement(FILTER_NODE);
626 return getInstanceIdentifierFromFilter(filterElement);
630 private void deleteDatastore() throws Exception {
631 verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-root.xml"), RPC_REPLY_OK);
632 assertEmptyDatastore(getConfigCandidate());
634 verifyResponse(commit(), RPC_REPLY_OK);
635 assertEmptyDatastore(getConfigRunning());