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.Ignore;
16 import org.junit.Test;
17 import org.opendaylight.netconf.api.DocumentedException;
18 import org.opendaylight.netconf.api.xml.XmlElement;
19 import org.opendaylight.netconf.api.xml.XmlUtil;
20 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
21 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
22 import org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig;
23 import org.opendaylight.netconf.test.util.XmlFileLoader;
24 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
25 import org.opendaylight.yangtools.yang.common.ErrorTag;
26 import org.opendaylight.yangtools.yang.common.ErrorType;
27 import org.opendaylight.yangtools.yang.common.QName;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.w3c.dom.Document;
30 import org.w3c.dom.Element;
31 import org.w3c.dom.NodeList;
33 public class NetconfMDSalMappingTest extends AbstractNetconfOperationTest {
34 private static final String TARGET_KEY = "target";
35 private static final String FILTER_NODE = "filter";
36 private static final String GET_CONFIG = "get-config";
37 private static final QName TOP = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "top");
38 private static final QName USERS = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "users");
39 private static final QName USER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "user");
40 private static final QName MODULES = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "modules");
41 private static final QName AUGMENTED_CONTAINER = QName.create("urn:opendaylight:mdsal:mapping:test",
42 "2015-02-26", "augmented-container");
43 private static final QName AUGMENTED_STRING_IN_CONT = QName.create("urn:opendaylight:mdsal:mapping:test",
44 "2015-02-26", "identifier");
45 private static final QName CHOICE_NODE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
47 private static final QName AUGMENTED_CASE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
49 private static final QName CHOICE_WRAPPER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
51 private static final QName INNER_CHOICE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
53 private static final QName INNER_CHOICE_TEXT = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26",
56 private static final YangInstanceIdentifier AUGMENTED_CONTAINER_IN_MODULES =
57 YangInstanceIdentifier.builder().node(TOP).node(MODULES).build();
60 public void testEmptyDatastore() throws Exception {
61 assertEmptyDatastore(get());
62 assertEmptyDatastore(getConfigCandidate());
63 assertEmptyDatastore(getConfigRunning());
67 public void testIncorrectGet() throws Exception {
68 DocumentedException ex = assertThrows(DocumentedException.class,
69 () -> executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
70 getTransactionProvider()), "messages/mapping/bad_getConfig.xml"));
71 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
72 assertEquals(ErrorTag.OPERATION_FAILED, ex.getErrorTag());
73 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
75 ex = assertThrows(DocumentedException.class,
76 () -> executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
77 getTransactionProvider()), "messages/mapping/bad_namespace_getConfig.xml"));
78 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
79 assertEquals(ErrorTag.OPERATION_FAILED, ex.getErrorTag());
80 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
84 public void testConfigMissing() throws Exception {
85 final DocumentedException ex = assertThrows(DocumentedException.class,
86 () -> edit("messages/mapping/editConfigs/editConfig_no_config.xml"));
87 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
88 assertEquals(ErrorTag.MISSING_ELEMENT, ex.getErrorTag());
89 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
93 public void testEditRunning() throws Exception {
94 final DocumentedException ex = assertThrows(DocumentedException.class,
95 () -> edit("messages/mapping/editConfigs/editConfig_running.xml"));
96 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
97 assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
98 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
102 public void testCommitWithoutOpenTransaction() throws Exception {
103 verifyResponse(commit(), RPC_REPLY_OK);
104 assertEmptyDatastore(getConfigCandidate());
108 public void testCandidateTransaction() throws Exception {
109 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK);
110 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
111 "messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
112 assertEmptyDatastore(getConfigRunning());
114 verifyResponse(discardChanges(), RPC_REPLY_OK);
115 assertEmptyDatastore(getConfigCandidate());
119 public void testEditWithCommit() throws Exception {
120 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK);
121 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
122 "messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
124 verifyResponse(commit(), RPC_REPLY_OK);
125 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
126 "messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
132 public void testKeyOrder() throws Exception {
133 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_keys_1.xml"), RPC_REPLY_OK);
134 verifyResponse(commit(), RPC_REPLY_OK);
135 final Document configRunning = getConfigRunning();
136 final String responseAsString = XmlUtil.toString(configRunning);
137 verifyResponse(configRunning, XmlFileLoader.xmlFileToDocument(
138 "messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml"));
140 final int key3 = responseAsString.indexOf("key3");
141 final int key1 = responseAsString.indexOf("key1");
142 final int key2 = responseAsString.indexOf("key2");
144 assertTrue(String.format("Key ordering invalid, should be key3(%d) < key1(%d) < key2(%d)", key3, key1, key2),
145 key3 < key1 && key1 < key2);
151 public void testMultipleEditsWithMerge() throws Exception {
152 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK);
153 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
154 "messages/mapping/editConfigs/editConfig_merge_multiple_control_1.xml"));
155 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK);
156 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
157 "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml"));
158 assertEmptyDatastore(getConfigRunning());
160 verifyResponse(commit(), RPC_REPLY_OK);
161 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
162 "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml"));
168 public void testMoreComplexEditConfigs() throws Exception {
169 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK);
170 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK);
172 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_2.xml"), RPC_REPLY_OK);
173 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
174 "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge.xml"));
176 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_3.xml"), RPC_REPLY_OK);
177 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
178 "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge_2.xml"));
180 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_4_replace.xml"), RPC_REPLY_OK);
181 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
182 "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml"));
183 verifyResponse(commit(), RPC_REPLY_OK);
185 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
186 "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml"));
188 verifyResponse(edit("messages/mapping/editConfigs/editConfig_replace_default.xml"), RPC_REPLY_OK);
189 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
190 "messages/mapping/editConfigs/editConfig_replace_default_control.xml"));
191 verifyResponse(commit(), RPC_REPLY_OK);
193 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
194 "messages/mapping/editConfigs/editConfig_replace_default_control.xml"));
200 public void testOrderedListEdits() throws Exception {
202 verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_create.xml"), RPC_REPLY_OK);
203 verifyResponse(commit(), RPC_REPLY_OK);
205 verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_replace.xml"), RPC_REPLY_OK);
206 verifyResponse(commit(), RPC_REPLY_OK);
212 public void testAugmentedOrderedListEdits() throws Exception {
214 verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_create.xml"),
216 verifyResponse(commit(), RPC_REPLY_OK);
218 verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_replace.xml"),
220 verifyResponse(commit(), RPC_REPLY_OK);
226 public void testAugmentedContainerReplace() throws Exception {
227 verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"),
229 verifyResponse(commit(), RPC_REPLY_OK);
231 verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_container_replace.xml"),
233 verifyResponse(commit(), RPC_REPLY_OK);
239 public void testLeafFromAugmentReplace() throws Exception {
240 verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"),
242 verifyResponse(commit(), RPC_REPLY_OK);
244 verifyResponse(edit("messages/mapping/editConfigs/editConfig_leaf_from_augment_replace.xml"),
246 verifyResponse(commit(), RPC_REPLY_OK);
252 public void testLock() throws Exception {
253 verifyResponse(lockCandidate(), RPC_REPLY_OK);
255 DocumentedException ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::lock);
256 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
257 assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
258 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
260 ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::lockWithoutTarget);
261 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
262 assertEquals(ErrorTag.INVALID_VALUE, ex.getErrorTag());
263 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
267 public void testUnlock() throws Exception {
268 verifyResponse(unlockCandidate(), RPC_REPLY_OK);
270 DocumentedException ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::unlock);
271 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
272 assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
273 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
275 ex = assertThrows(DocumentedException.class, NetconfMDSalMappingTest::unlockWithoutTarget);
276 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
277 assertEquals(ErrorTag.INVALID_VALUE, ex.getErrorTag());
278 assertEquals(ErrorType.APPLICATION, ex.getErrorType());
282 public void testEditWithCreate() throws Exception {
283 verifyResponse(edit("messages/mapping/editConfigs/editConfig_create.xml"), RPC_REPLY_OK);
284 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
285 "messages/mapping/editConfig_create_n1_control.xml"));
287 final DocumentedException ex = assertThrows(DocumentedException.class,
288 () -> edit("messages/mapping/editConfigs/editConfig_create.xml"));
289 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
290 assertEquals(ErrorTag.DATA_EXISTS, ex.getErrorTag());
291 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
293 verifyResponse(discardChanges(), RPC_REPLY_OK);
297 public void testDeleteNonExisting() throws Exception {
298 assertEmptyDatastore(getConfigCandidate());
299 assertEmptyDatastore(getConfigRunning());
301 final DocumentedException ex = assertThrows(DocumentedException.class,
302 () -> edit("messages/mapping/editConfigs/editConfig_delete-top.xml"));
303 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
304 assertEquals(ErrorTag.DATA_MISSING, ex.getErrorTag());
305 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
309 public void testEditMissingDefaultOperation() throws Exception {
310 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_1.xml"),
312 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_2.xml"),
314 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
315 "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml"));
317 verifyResponse(commit(), RPC_REPLY_OK);
318 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument(
319 "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml"));
325 public void testEditConfigWithMultipleOperations() throws Exception {
328 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_setup.xml"),
330 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_1.xml"), RPC_REPLY_OK);
332 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_2.xml"), RPC_REPLY_OK);
333 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
334 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_2_control.xml"));
336 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_leaf_operations.xml"),
338 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
339 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_control.xml"));
343 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_setup.xml"),
345 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_default-replace.xml"),
348 DocumentedException ex = assertThrows(DocumentedException.class,
349 () -> edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_create_existing.xml"));
350 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
351 assertEquals(ErrorTag.DATA_EXISTS, ex.getErrorTag());
352 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
355 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete_children_operations.xml"),
357 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
358 "messages/mapping/editConfigs/"
359 + "editConfig_merge_multiple_operations_4_delete_children_operations_control.xml"));
361 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_remove-non-existing.xml"),
363 ex = assertThrows(DocumentedException.class,
364 () -> edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete-non-existing.xml"));
365 assertEquals(ErrorSeverity.ERROR, ex.getErrorSeverity());
366 assertEquals(ErrorTag.DATA_MISSING, ex.getErrorTag());
367 assertEquals(ErrorType.PROTOCOL, ex.getErrorType());
369 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup.xml"),
371 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
372 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup-control.xml"));
374 // Test files have been modified. RFC6020 requires that at most once case inside a choice is present at any time
375 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2.xml"),
377 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
378 "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2-control.xml"));
380 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_delete.xml"),
382 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
383 "messages/mapping/editConfigs"
384 + "/editConfig_merge_multiple_operations_4_delete_children_operations_control.xml"));
390 public void testEditConfigGetElementByTagName() throws Exception {
391 String stringWithoutPrefix =
392 "<rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
397 + " </edit-config>\n"
399 XmlElement xe = getXmlElement(stringWithoutPrefix);
400 NodeList nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
401 assertEquals(1, nodeList.getLength());
403 String stringWithPrefix =
404 "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
405 + " <nc:edit-config>\n"
407 + " <nc:candidate/>\n"
409 + " </nc:edit-config>\n"
412 xe = getXmlElement(stringWithPrefix);
413 nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
414 assertEquals(1, nodeList.getLength());
416 String stringWithoutTarget =
417 "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
418 + " <nc:edit-config>\n"
421 + " </nc:edit-config>\n"
423 xe = getXmlElement(stringWithoutTarget);
425 final NodeList targetKey = EditConfig.getElementsByTagName(xe, TARGET_KEY);
426 assertThrows(DocumentedException.class,
427 () -> XmlElement.fromDomElement((Element) targetKey.item(0)).getOnlyChildElement());
430 private static XmlElement getXmlElement(final String elementAsString) throws Exception {
431 Document document = XmlUtil.readXmlToDocument(elementAsString);
432 Element element = document.getDocumentElement();
433 return XmlElement.fromDomElement(element);
437 public void testReplaceMapEntry() throws Exception {
438 verifyResponse(edit("messages/mapping/editConfigs/edit-config-replace-map-entry.xml"), RPC_REPLY_OK);
439 verifyResponse(commit(), RPC_REPLY_OK);
440 verifyResponse(getConfigRunning(),
441 XmlFileLoader.xmlFileToDocument("messages/mapping/get-config-map-entry.xml"));
445 public void testMergeMapEntry() throws Exception {
446 verifyResponse(edit("messages/mapping/editConfigs/edit-config-merge-map-entry.xml"), RPC_REPLY_OK);
447 verifyResponse(commit(), RPC_REPLY_OK);
448 verifyResponse(getConfigRunning(),
449 XmlFileLoader.xmlFileToDocument("messages/mapping/get-config-map-entry.xml"));
452 @Ignore("Needs to have YIID parsing fixed, currently everything is a NodeIdentifier which breaks"
453 + "SchemaInferenceStack")
455 public void testFiltering() throws Exception {
456 assertEmptyDatastore(getConfigCandidate());
457 assertEmptyDatastore(getConfigRunning());
459 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-config-empty-filter.xml"),
460 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
461 verifyResponse(getWithFilter("messages/mapping/filters/get-empty-filter.xml"),
462 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
464 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response"
466 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
467 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-users.xml"),
468 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
470 verifyResponse(edit("messages/mapping/editConfigs/editConfig-filtering-setup.xml"), RPC_REPLY_OK);
471 verifyResponse(commit(), RPC_REPLY_OK);
473 verifyFilterIdentifier("messages/mapping/filters/get-filter-alluser.xml",
474 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
475 verifyFilterIdentifier("messages/mapping/filters/get-filter-company-info.xml",
476 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
477 verifyFilterIdentifier("messages/mapping/filters/get-filter-modules-and-admin.xml",
478 YangInstanceIdentifier.builder().node(TOP).build());
479 verifyFilterIdentifier("messages/mapping/filters/get-filter-only-names-types.xml",
480 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
481 verifyFilterIdentifier("messages/mapping/filters/get-filter-specific-module-type-and-user.xml",
482 YangInstanceIdentifier.builder().node(TOP).build());
483 verifyFilterIdentifier("messages/mapping/filters/get-filter-superuser.xml",
484 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
485 verifyFilterIdentifier("messages/mapping/filters/get-filter-users.xml",
486 YangInstanceIdentifier.builder().node(TOP).node(USERS).build());
488 final YangInstanceIdentifier ident = YangInstanceIdentifier
489 .builder(AUGMENTED_CONTAINER_IN_MODULES)
490 .node(AUGMENTED_CONTAINER)
491 .node(AUGMENTED_STRING_IN_CONT).build();
493 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-string.xml", ident);
494 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case.xml",
495 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(AUGMENTED_CASE).build());
497 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case.xml"),
498 XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case.xml"));
501 * RFC6020 requires that at most once case inside a choice is present at any time.
503 * <augmented-case>augmented case</augmented-case>
505 * messages/mapping/editConfigs/editConfig-filtering-setup.xml
506 * cannot exists together with
507 * <text>augmented nested choice text1</text>
509 * messages/mapping/editConfigs/editConfig-filtering-setup2.xml
511 //verifyResponse(edit("messages/mapping/editConfigs/editConfig-filtering-setup2.xml"), RPC_REPLY_OK);
512 //verifyResponse(commit(), RPC_REPLY_OK);
514 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml",
515 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).build());
516 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-case.xml",
517 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).node(INNER_CHOICE)
518 .node(INNER_CHOICE_TEXT).build());
520 // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-string.xml"),
521 // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-string.xml"));
522 // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml"),
523 // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml"));
524 // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-case.xml"),
525 // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml"));
527 verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-top.xml"), RPC_REPLY_OK);
528 verifyResponse(commit(), RPC_REPLY_OK);
532 private void verifyFilterIdentifier(final String resource, final YangInstanceIdentifier identifier)
534 final TestingGetConfig getConfig = new TestingGetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(),
535 getTransactionProvider());
536 final Document request = XmlFileLoader.xmlFileToDocument(resource);
537 final YangInstanceIdentifier iid = getConfig.getInstanceIdentifierFromDocument(request);
538 assertEquals(identifier, iid);
541 private class TestingGetConfig extends GetConfig {
542 TestingGetConfig(final String sessionId, final CurrentSchemaContext schemaContext,
543 final TransactionProvider transactionProvider) {
544 super(sessionId, schemaContext, transactionProvider);
547 YangInstanceIdentifier getInstanceIdentifierFromDocument(final Document request) throws DocumentedException {
548 final XmlElement filterElement = XmlElement.fromDomDocument(request).getOnlyChildElement(GET_CONFIG)
549 .getOnlyChildElement(FILTER_NODE);
550 return getInstanceIdentifierFromFilter(filterElement);
554 private void deleteDatastore() throws Exception {
555 verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-root.xml"), RPC_REPLY_OK);
556 assertEmptyDatastore(getConfigCandidate());
558 verifyResponse(commit(), RPC_REPLY_OK);
559 assertEmptyDatastore(getConfigRunning());
563 public void testEditUsingConfigFromFile() throws Exception {
564 // Ask class loader for URI of config file and use it as <url> in <edit-config> RPC:
565 final String template = XmlFileLoader.fileToString("messages/mapping/editConfigs/editConfig_from_file.xml");
566 final URI uri = getClass().getClassLoader().getResource("messages/mapping/editConfigs/config_file.xml").toURI();
567 final String copyConfig = template.replaceFirst("URL", uri.toString());
568 final Document request = XmlUtil.readXmlToDocument(copyConfig);
570 verifyResponse(edit(request), RPC_REPLY_OK);
571 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument(
572 "messages/mapping/editConfigs/editConfig_from_file_control.xml"));