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
8 package org.opendaylight.netconf.mdsal.connector.ops;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
12 import static org.junit.Assert.assertTrue;
15 import org.junit.Test;
16 import org.opendaylight.netconf.api.DocumentedException;
17 import org.opendaylight.netconf.api.DocumentedException.ErrorTag;
18 import org.opendaylight.netconf.api.DocumentedException.ErrorType;
19 import org.opendaylight.netconf.api.xml.XmlElement;
20 import org.opendaylight.netconf.api.xml.XmlUtil;
21 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
22 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
23 import org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig;
24 import org.opendaylight.netconf.util.test.XmlFileLoader;
25 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
26 import org.opendaylight.yangtools.yang.common.QName;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.w3c.dom.Document;
29 import org.w3c.dom.Element;
30 import org.w3c.dom.NodeList;
32 public class NetconfMDSalMappingTest extends AbstractNetconfOperationTest {
33 private static final String TARGET_KEY = "target";
34 private static final String FILTER_NODE = "filter";
35 private static final String GET_CONFIG = "get-config";
36 private static final QName TOP = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "top");
37 private static final QName USERS = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "users");
38 private static final QName USER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "user");
39 private static final QName MODULES = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "modules");
40 private static final QName AUGMENTED_CONTAINER = QName.create("urn:opendaylight:mdsal:mapping:test",
41 "2015-02-26", "augmented-container");
42 private static final QName AUGMENTED_STRING_IN_CONT = QName.create("urn:opendaylight:mdsal:mapping:test",
43 "2015-02-26", "identifier");
44 private static final QName CHOICE_NODE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
46 private static final QName AUGMENTED_CASE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
48 private static final QName CHOICE_WRAPPER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
50 private static final QName INNER_CHOICE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
52 private static final QName INNER_CHOICE_TEXT = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
55 private static final YangInstanceIdentifier AUGMENTED_CONTAINER_IN_MODULES =
56 YangInstanceIdentifier.builder().node(TOP).node(MODULES).build();
59 public void testEmptyDatastore() throws Exception {
60 assertEmptyDatastore(get());
61 assertEmptyDatastore(getConfigCandidate());
62 assertEmptyDatastore(getConfigRunning());
66 public void testIncorrectGet() throws Exception {
67 DocumentedException ex = assertThrows(DocumentedException.class,
68 () -> executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
69 getTransactionProvider()), "messages/mapping/bad_getConfig.xml"));
70 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
71 assertEquals(ErrorTag.OPERATION_FAILED, ex.getErrorTag());
72 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
74 ex = assertThrows(DocumentedException.class,
75 () -> executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
76 getTransactionProvider()), "messages/mapping/bad_namespace_getConfig.xml"));
77 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
78 assertEquals(ErrorTag.OPERATION_FAILED, ex.getErrorTag());
79 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
83 public void testConfigMissing() throws Exception {
84 final DocumentedException ex = assertThrows(DocumentedException.class,
85 () -> edit("messages/mapping/editConfigs/editConfig_no_config.xml"));
86 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
87 assertEquals(ErrorTag.MISSING_ELEMENT, ex.getErrorTag());
88 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
92 public void testEditRunning() throws Exception {
93 final DocumentedException ex = assertThrows(DocumentedException.class,
94 () -> edit("messages/mapping/editConfigs/editConfig_running.xml"));
95 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
96 assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
97 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
101 public void testCommitWithoutOpenTransaction() throws Exception {
102 verifyResponse(commit(), RPC_REPLY_OK);
103 assertEmptyDatastore(getConfigCandidate());
107 public void testCandidateTransaction() throws Exception {
108 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK);
109 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
110 "messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
111 assertEmptyDatastore(getConfigRunning());
113 verifyResponse(discardChanges(), RPC_REPLY_OK);
114 assertEmptyDatastore(getConfigCandidate());
118 public void testEditWithCommit() throws Exception {
119 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK);
120 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
121 "messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
123 verifyResponse(commit(), RPC_REPLY_OK);
124 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
125 "messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
131 public void testKeyOrder() throws Exception {
132 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_keys_1.xml"), RPC_REPLY_OK);
133 verifyResponse(commit(), RPC_REPLY_OK);
134 final Document configRunning = getConfigRunning();
135 final String responseAsString = XmlUtil.toString(configRunning);
136 verifyResponse(configRunning, XmlFileLoader.xmlFileToDocument(
137 "messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml"));
139 final int key3 = responseAsString.indexOf("key3");
140 final int key1 = responseAsString.indexOf("key1");
141 final int key2 = responseAsString.indexOf("key2");
143 assertTrue(String.format("Key ordering invalid, should be key3(%d) < key1(%d) < key2(%d)", key3, key1, key2),
144 key3 < key1 && key1 < key2);
150 public void testMultipleEditsWithMerge() throws Exception {
151 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK);
152 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
153 "messages/mapping/editConfigs/editConfig_merge_multiple_control_1.xml"));
154 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK);
155 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
156 "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml"));
157 assertEmptyDatastore(getConfigRunning());
159 verifyResponse(commit(), RPC_REPLY_OK);
160 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
161 "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml"));
167 public void testMoreComplexEditConfigs() throws Exception {
168 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK);
169 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK);
171 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_2.xml"), RPC_REPLY_OK);
172 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
173 "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge.xml"));
175 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_3.xml"), RPC_REPLY_OK);
176 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
177 "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge_2.xml"));
179 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_4_replace.xml"), RPC_REPLY_OK);
180 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
181 "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml"));
182 verifyResponse(commit(), RPC_REPLY_OK);
184 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
185 "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml"));
187 verifyResponse(edit("messages/mapping/editConfigs/editConfig_replace_default.xml"), RPC_REPLY_OK);
188 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
189 "messages/mapping/editConfigs/editConfig_replace_default_control.xml"));
190 verifyResponse(commit(), RPC_REPLY_OK);
192 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
193 "messages/mapping/editConfigs/editConfig_replace_default_control.xml"));
199 public void testOrderedListEdits() throws Exception {
201 verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_create.xml"), RPC_REPLY_OK);
202 verifyResponse(commit(), RPC_REPLY_OK);
204 verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_replace.xml"), RPC_REPLY_OK);
205 verifyResponse(commit(), RPC_REPLY_OK);
211 public void testAugmentedOrderedListEdits() throws Exception {
213 verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_create.xml"),
215 verifyResponse(commit(), RPC_REPLY_OK);
217 verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_replace.xml"),
219 verifyResponse(commit(), RPC_REPLY_OK);
225 public void testAugmentedContainerReplace() throws Exception {
226 verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"),
228 verifyResponse(commit(), RPC_REPLY_OK);
230 verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_container_replace.xml"),
232 verifyResponse(commit(), RPC_REPLY_OK);
238 public void testLeafFromAugmentReplace() throws Exception {
239 verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"),
241 verifyResponse(commit(), RPC_REPLY_OK);
243 verifyResponse(edit("messages/mapping/editConfigs/editConfig_leaf_from_augment_replace.xml"),
245 verifyResponse(commit(), RPC_REPLY_OK);
251 public void testLock() throws Exception {
252 verifyResponse(lockCandidate(), RPC_REPLY_OK);
254 DocumentedException ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::lock);
255 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
256 assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
257 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
259 ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::lockWithoutTarget);
260 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
261 assertEquals(ErrorTag.INVALID_VALUE, ex.getErrorTag());
262 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
266 public void testUnlock() throws Exception {
267 verifyResponse(unlockCandidate(), RPC_REPLY_OK);
269 DocumentedException ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::unlock);
270 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
271 assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
272 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
274 ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::unlockWithoutTarget);
275 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
276 assertEquals(ErrorTag.INVALID_VALUE, ex.getErrorTag());
277 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
281 public void testEditWithCreate() throws Exception {
282 verifyResponse(edit("messages/mapping/editConfigs/editConfig_create.xml"), RPC_REPLY_OK);
283 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
284 "messages/mapping/editConfig_create_n1_control.xml"));
286 final DocumentedException ex = assertThrows(DocumentedException.class,
287 () -> edit("messages/mapping/editConfigs/editConfig_create.xml"));
288 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
289 assertEquals(ErrorTag.DATA_EXISTS, ex.getErrorTag());
290 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
292 verifyResponse(discardChanges(), RPC_REPLY_OK);
296 public void testDeleteNonExisting() throws Exception {
297 assertEmptyDatastore(getConfigCandidate());
298 assertEmptyDatastore(getConfigRunning());
300 final DocumentedException ex = assertThrows(DocumentedException.class,
301 () -> edit("messages/mapping/editConfigs/editConfig_delete-top.xml"));
302 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
303 assertEquals(ErrorTag.DATA_MISSING, ex.getErrorTag());
304 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
308 public void testEditMissingDefaultOperation() throws Exception {
309 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_1.xml"),
311 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_2.xml"),
313 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
314 "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml"));
316 verifyResponse(commit(), RPC_REPLY_OK);
317 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
318 "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml"));
324 public void testEditConfigWithMultipleOperations() throws Exception {
327 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_setup.xml"),
329 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_1.xml"), RPC_REPLY_OK);
331 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_2.xml"), RPC_REPLY_OK);
332 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
333 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_2_control.xml"));
335 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_leaf_operations.xml"),
337 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
338 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_control.xml"));
342 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_setup.xml"),
344 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_default-replace.xml"),
347 DocumentedException ex = assertThrows(DocumentedException.class,
348 () -> edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_create_existing.xml"));
349 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
350 assertEquals(ErrorTag.DATA_EXISTS, ex.getErrorTag());
351 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
354 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete_children_operations.xml"),
356 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
357 "messages/mapping/editConfigs/"
358 + "editConfig_merge_multiple_operations_4_delete_children_operations_control.xml"));
360 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_remove-non-existing.xml"),
362 ex = assertThrows(DocumentedException.class,
363 () -> edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete-non-existing.xml"));
364 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
365 assertEquals(ErrorTag.DATA_MISSING, ex.getErrorTag());
366 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
368 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup.xml"),
370 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
371 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup-control.xml"));
373 // Test files have been modified. RFC6020 requires that at most once case inside a choice is present at any time
374 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2.xml"),
376 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
377 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2-control.xml"));
379 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_delete.xml"),
381 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
382 "messages/mapping/editConfigs"
383 + "/editConfig_merge_multiple_operations_4_delete_children_operations_control.xml"));
389 public void testEditConfigGetElementByTagName() throws Exception {
390 String stringWithoutPrefix =
391 "<rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
396 + " </edit-config>\n"
398 XmlElement xe = getXmlElement(stringWithoutPrefix);
399 NodeList nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
400 assertEquals(1, nodeList.getLength());
402 String stringWithPrefix =
403 "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
404 + " <nc:edit-config>\n"
406 + " <nc:candidate/>\n"
408 + " </nc:edit-config>\n"
411 xe = getXmlElement(stringWithPrefix);
412 nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
413 assertEquals(1, nodeList.getLength());
415 String stringWithoutTarget =
416 "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
417 + " <nc:edit-config>\n"
420 + " </nc:edit-config>\n"
422 xe = getXmlElement(stringWithoutTarget);
424 final NodeList targetKey = EditConfig.getElementsByTagName(xe, TARGET_KEY);
425 assertThrows(DocumentedException.class,
426 () -> XmlElement.fromDomElement((Element) targetKey.item(0)).getOnlyChildElement());
429 private static XmlElement getXmlElement(final String elementAsString) throws Exception {
430 Document document = XmlUtil.readXmlToDocument(elementAsString);
431 Element element = document.getDocumentElement();
432 return XmlElement.fromDomElement(element);
436 public void testReplaceMapEntry() throws Exception {
437 verifyResponse(edit("messages/mapping/editConfigs/edit-config-replace-map-entry.xml"), RPC_REPLY_OK);
438 verifyResponse(commit(), RPC_REPLY_OK);
439 verifyResponse(getConfigRunning(),
440 XmlFileLoader.xmlFileToDocument("messages/mapping/get-config-map-entry.xml"));
444 public void testMergeMapEntry() throws Exception {
445 verifyResponse(edit("messages/mapping/editConfigs/edit-config-merge-map-entry.xml"), RPC_REPLY_OK);
446 verifyResponse(commit(), RPC_REPLY_OK);
447 verifyResponse(getConfigRunning(),
448 XmlFileLoader.xmlFileToDocument("messages/mapping/get-config-map-entry.xml"));
452 public void testFiltering() throws Exception {
453 assertEmptyDatastore(getConfigCandidate());
454 assertEmptyDatastore(getConfigRunning());
456 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-config-empty-filter.xml"),
457 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
458 verifyResponse(getWithFilter("messages/mapping/filters/get-empty-filter.xml"),
459 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
461 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response"
463 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
464 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-users.xml"),
465 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
467 verifyResponse(edit("messages/mapping/editConfigs/editConfig-filtering-setup.xml"), RPC_REPLY_OK);
468 verifyResponse(commit(), RPC_REPLY_OK);
470 verifyFilterIdentifier("messages/mapping/filters/get-filter-alluser.xml",
471 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
472 verifyFilterIdentifier("messages/mapping/filters/get-filter-company-info.xml",
473 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
474 verifyFilterIdentifier("messages/mapping/filters/get-filter-modules-and-admin.xml",
475 YangInstanceIdentifier.builder().node(TOP).build());
476 verifyFilterIdentifier("messages/mapping/filters/get-filter-only-names-types.xml",
477 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
478 verifyFilterIdentifier("messages/mapping/filters/get-filter-specific-module-type-and-user.xml",
479 YangInstanceIdentifier.builder().node(TOP).build());
480 verifyFilterIdentifier("messages/mapping/filters/get-filter-superuser.xml",
481 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
482 verifyFilterIdentifier("messages/mapping/filters/get-filter-users.xml",
483 YangInstanceIdentifier.builder().node(TOP).node(USERS).build());
485 final YangInstanceIdentifier ident = YangInstanceIdentifier
486 .builder(AUGMENTED_CONTAINER_IN_MODULES)
487 .node(AUGMENTED_CONTAINER)
488 .node(AUGMENTED_STRING_IN_CONT).build();
490 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-string.xml", ident);
491 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case.xml",
492 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(AUGMENTED_CASE).build());
494 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case.xml"),
495 XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case.xml"));
498 * RFC6020 requires that at most once case inside a choice is present at any time.
500 * <augmented-case>augmented case</augmented-case>
502 * messages/mapping/editConfigs/editConfig-filtering-setup.xml
503 * cannot exists together with
504 * <text>augmented nested choice text1</text>
506 * messages/mapping/editConfigs/editConfig-filtering-setup2.xml
508 //verifyResponse(edit("messages/mapping/editConfigs/editConfig-filtering-setup2.xml"), RPC_REPLY_OK);
509 //verifyResponse(commit(), RPC_REPLY_OK);
511 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml",
512 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).build());
513 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-case.xml",
514 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).node(INNER_CHOICE)
515 .node(INNER_CHOICE_TEXT).build());
517 // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-string.xml"),
518 // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-string.xml"));
519 // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml"),
520 // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml"));
521 // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-case.xml"),
522 // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml"));
524 verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-top.xml"), RPC_REPLY_OK);
525 verifyResponse(commit(), RPC_REPLY_OK);
529 private void verifyFilterIdentifier(final String resource, final YangInstanceIdentifier identifier)
531 final TestingGetConfig getConfig = new TestingGetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
532 getTransactionProvider());
533 final Document request = XmlFileLoader.xmlFileToDocument(resource);
534 final YangInstanceIdentifier iid = getConfig.getInstanceIdentifierFromDocument(request);
535 assertEquals(identifier, iid);
538 private class TestingGetConfig extends GetConfig {
539 TestingGetConfig(final String sessionId, final CurrentSchemaContext schemaContext,
540 final TransactionProvider transactionProvider) {
541 super(sessionId, schemaContext, transactionProvider);
544 YangInstanceIdentifier getInstanceIdentifierFromDocument(final Document request) throws DocumentedException {
545 final XmlElement filterElement = XmlElement.fromDomDocument(request).getOnlyChildElement(GET_CONFIG)
546 .getOnlyChildElement(FILTER_NODE);
547 return getInstanceIdentifierFromFilter(filterElement);
551 private void deleteDatastore() throws Exception {
552 verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-root.xml"), RPC_REPLY_OK);
553 assertEmptyDatastore(getConfigCandidate());
555 verifyResponse(commit(), RPC_REPLY_OK);
556 assertEmptyDatastore(getConfigRunning());
560 public void testEditUsingConfigFromFile() throws Exception {
561 // Ask class loader for URI of config file and use it as <url> in <edit-config> RPC:
562 final String template = XmlFileLoader.fileToString("messages/mapping/editConfigs/editConfig_from_file.xml");
563 final URI uri = getClass().getClassLoader().getResource("messages/mapping/editConfigs/config_file.xml").toURI();
564 final String copyConfig = template.replaceFirst("URL", uri.toString());
565 final Document request = XmlUtil.readXmlToDocument(copyConfig);
567 verifyResponse(edit(request), RPC_REPLY_OK);
568 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
569 "messages/mapping/editConfigs/editConfig_from_file_control.xml"));