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.controller.netconf.mdsal.connector.ops;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
16 import com.google.common.base.Preconditions;
17 import com.google.common.io.ByteSource;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.EnumMap;
25 import java.util.List;
26 import java.util.concurrent.ExecutorService;
27 import javax.xml.parsers.ParserConfigurationException;
28 import org.custommonkey.xmlunit.DetailedDiff;
29 import org.custommonkey.xmlunit.Diff;
30 import org.custommonkey.xmlunit.XMLUnit;
31 import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.opendaylight.controller.cluster.datastore.ConcurrentDOMDataBroker;
35 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
36 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreFactory;
37 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
38 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
39 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
40 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;
41 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
42 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
43 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;
44 import org.opendaylight.controller.netconf.mdsal.connector.CurrentSchemaContext;
45 import org.opendaylight.controller.netconf.mdsal.connector.TransactionProvider;
46 import org.opendaylight.controller.netconf.mdsal.connector.ops.get.Get;
47 import org.opendaylight.controller.netconf.mdsal.connector.ops.get.GetConfig;
48 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
49 import org.opendaylight.controller.netconf.util.xml.XmlElement;
50 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
51 import org.opendaylight.controller.sal.core.api.model.SchemaService;
52 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
53 import org.opendaylight.yangtools.concepts.ListenerRegistration;
54 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
55 import org.opendaylight.yangtools.yang.common.QName;
56 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
57 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
58 import org.opendaylight.yangtools.yang.model.api.Module;
59 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
60 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
61 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
62 import org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils;
63 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
64 import org.slf4j.Logger;
65 import org.slf4j.LoggerFactory;
66 import org.w3c.dom.Document;
67 import org.w3c.dom.Node;
68 import org.w3c.dom.NodeList;
69 import org.xml.sax.SAXException;
71 public class NetconfMDSalMappingTest {
73 private static final Logger LOG = LoggerFactory.getLogger(NetconfMDSalMappingTest.class);
75 private static final String RPC_REPLY_ELEMENT = "rpc-reply";
76 private static final String DATA_ELEMENT = "data";
77 private static final String FILTER_NODE = "filter";
78 private static final String GET_CONFIG = "get-config";
79 private static final QName TOP = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "top");
80 private static final QName USERS = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "users");
81 private static final QName USER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "user");
82 private static final QName MODULES = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "modules");
83 private static final QName AUGMENTED_CONTAINER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "augmented-container");
84 private static final QName AUGMENTED_STRING_IN_CONT = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "identifier");
85 private static final QName CHOICE_NODE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "choice-node");
86 private static final QName AUGMENTED_CASE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "augmented-case");
87 private static final QName CHOICE_WRAPPER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "choice-wrapper");
88 private static final QName INNER_CHOICE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "inner-choice");
89 private static final QName INNER_CHOICE_TEXT = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "text");
91 private static final YangInstanceIdentifier AUGMENTED_CONTAINER_IN_MODULES =
92 YangInstanceIdentifier.builder().node(TOP).node(MODULES).build().node(new AugmentationIdentifier(Collections.singleton(AUGMENTED_CONTAINER)));
94 private static Document RPC_REPLY_OK = null;
98 RPC_REPLY_OK = XmlFileLoader.xmlFileToDocument("messages/mapping/rpc-reply_ok.xml");
99 } catch (Exception e) {
100 LOG.debug("unable to load rpc reply ok.", e);
101 RPC_REPLY_OK = XmlUtil.newDocument();
105 private CurrentSchemaContext currentSchemaContext = null;
106 private SchemaContext schemaContext = null;
107 private String sessionIdForReporting = "netconf-test-session1";
109 private TransactionProvider transactionProvider = null;
112 public void setUp() throws Exception {
114 XMLUnit.setIgnoreWhitespace(true);
115 XMLUnit.setIgnoreAttributeOrder(true);
117 this.schemaContext = parseSchemas(getYangSchemas());
118 schemaContext.getModules();
119 final SchemaService schemaService = createSchemaService();
121 final DOMStore operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", schemaService);
122 final DOMStore configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", schemaService);
124 final EnumMap<LogicalDatastoreType, DOMStore> datastores = new EnumMap<>(LogicalDatastoreType.class);
125 datastores.put(LogicalDatastoreType.CONFIGURATION, configStore);
126 datastores.put(LogicalDatastoreType.OPERATIONAL, operStore);
128 ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(
129 16, 16, "CommitFutures");
131 final ConcurrentDOMDataBroker cdb = new ConcurrentDOMDataBroker(datastores, listenableFutureExecutor);
132 this.transactionProvider = new TransactionProvider(cdb, sessionIdForReporting);
133 this.currentSchemaContext = new CurrentSchemaContext(schemaService);
138 public void testEmptyDatastore() throws Exception {
139 assertEmptyDatastore(get());
140 assertEmptyDatastore(getConfigCandidate());
141 assertEmptyDatastore(getConfigRunning());
145 public void testEditRunning() throws Exception {
148 edit("messages/mapping/editConfigs/editConfig_running.xml");
149 fail("Should have failed - edit config on running datastore is not supported");
150 } catch (NetconfDocumentedException e) {
151 assertTrue(e.getErrorSeverity() == ErrorSeverity.error);
152 assertTrue(e.getErrorTag() == ErrorTag.operation_not_supported);
153 assertTrue(e.getErrorType() == ErrorType.protocol);
159 public void testCandidateTransaction() throws Exception {
161 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK);
162 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
163 assertEmptyDatastore(getConfigRunning());
165 verifyResponse(discardChanges(), RPC_REPLY_OK);
166 assertEmptyDatastore(getConfigCandidate());
171 public void testEditWithCommit() throws Exception {
173 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK);
174 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
176 verifyResponse(commit(), RPC_REPLY_OK);
177 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_n1_control.xml"));
184 public void testMultipleEditsWithMerge() throws Exception {
186 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK);
187 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_control_1.xml"));
188 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK);
189 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml"));
190 assertEmptyDatastore(getConfigRunning());
192 verifyResponse(commit(), RPC_REPLY_OK);
193 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml"));
200 public void testMoreComplexEditConfigs() throws Exception {
202 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK);
203 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK);
205 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_2.xml"), RPC_REPLY_OK);
206 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge.xml"));
208 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_3.xml"), RPC_REPLY_OK);
209 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge_2.xml"));
211 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_4_replace.xml"), RPC_REPLY_OK);
212 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml"));
213 verifyResponse(commit(), RPC_REPLY_OK);
215 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml"));
217 verifyResponse(edit("messages/mapping/editConfigs/editConfig_replace_default.xml"), RPC_REPLY_OK);
218 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_replace_default_control.xml"));
219 verifyResponse(commit(), RPC_REPLY_OK);
221 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_replace_default_control.xml"));
228 public void testLock() throws Exception {
230 verifyResponse(lockCandidate(), RPC_REPLY_OK);
234 fail("Should have failed - locking of running datastore is not supported");
235 } catch (NetconfDocumentedException e) {
236 assertTrue(e.getErrorSeverity() == ErrorSeverity.error);
237 assertTrue(e.getErrorTag() == ErrorTag.operation_not_supported);
238 assertTrue(e.getErrorType() == ErrorType.application);
243 public void testUnlock() throws Exception {
245 verifyResponse(unlockCandidate(), RPC_REPLY_OK);
249 fail("Should have failed - unlocking of running datastore is not supported");
250 } catch (NetconfDocumentedException e) {
251 assertTrue(e.getErrorSeverity() == ErrorSeverity.error);
252 assertTrue(e.getErrorTag() == ErrorTag.operation_not_supported);
253 assertTrue(e.getErrorType() == ErrorType.application);
258 public void testEditWithCreate() throws Exception {
260 verifyResponse(edit("messages/mapping/editConfigs/editConfig_create.xml"), RPC_REPLY_OK);
261 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfig_create_n1_control.xml"));
265 edit("messages/mapping/editConfigs/editConfig_create.xml");
266 fail("Create should have failed - data already exists");
267 } catch (NetconfDocumentedException e) {
268 assertTrue(e.getErrorSeverity() == ErrorSeverity.error);
269 assertTrue(e.getErrorTag() == ErrorTag.data_exists);
270 assertTrue(e.getErrorType() == ErrorType.protocol);
273 verifyResponse(discardChanges(), RPC_REPLY_OK);
278 public void testDeleteNonExisting() throws Exception {
280 assertEmptyDatastore(getConfigCandidate());
281 assertEmptyDatastore(getConfigRunning());
284 edit("messages/mapping/editConfigs/editConfig_delete-root.xml");
285 fail("Delete should have failed - data is missing");
286 } catch (NetconfDocumentedException e) {
287 assertTrue(e.getErrorSeverity() == ErrorSeverity.error);
288 assertTrue(e.getErrorTag() == ErrorTag.data_missing);
289 assertTrue(e.getErrorType() == ErrorType.protocol);
295 public void testEditMissingDefaultOperation() throws Exception {
297 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_1.xml"), RPC_REPLY_OK);
298 verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_2.xml"), RPC_REPLY_OK);
299 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml"));
301 verifyResponse(commit(), RPC_REPLY_OK);
302 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml"));
308 public void testFiltering() throws Exception {
310 assertEmptyDatastore(getConfigCandidate());
311 assertEmptyDatastore(getConfigRunning());
313 verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
314 verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
315 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-users.xml"),
316 XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml"));
318 verifyResponse(edit("messages/mapping/editConfigs/editConfig-filtering-setup.xml"), RPC_REPLY_OK);
319 verifyResponse(commit(), RPC_REPLY_OK);
321 verifyFilterIdentifier("messages/mapping/filters/get-filter-alluser.xml",
322 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
323 verifyFilterIdentifier("messages/mapping/filters/get-filter-company-info.xml",
324 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
325 verifyFilterIdentifier("messages/mapping/filters/get-filter-modules-and-admin.xml",
326 YangInstanceIdentifier.builder().node(TOP).build());
327 verifyFilterIdentifier("messages/mapping/filters/get-filter-only-names-types.xml",
328 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
329 verifyFilterIdentifier("messages/mapping/filters/get-filter-specific-module-type-and-user.xml",
330 YangInstanceIdentifier.builder().node(TOP).build());
331 verifyFilterIdentifier("messages/mapping/filters/get-filter-superuser.xml",
332 YangInstanceIdentifier.builder().node(TOP).node(USERS).node(USER).build());
333 verifyFilterIdentifier("messages/mapping/filters/get-filter-users.xml",
334 YangInstanceIdentifier.builder().node(TOP).node(USERS).build());
336 YangInstanceIdentifier ident = YangInstanceIdentifier.
337 builder(AUGMENTED_CONTAINER_IN_MODULES).
338 node(AUGMENTED_CONTAINER).
339 node(AUGMENTED_STRING_IN_CONT).build();
341 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-string.xml", ident);
342 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case.xml",
343 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(AUGMENTED_CASE).build());
345 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case.xml"),
346 XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case.xml"));
347 verifyResponse(edit("messages/mapping/editConfigs/editConfig-filtering-setup2.xml"), RPC_REPLY_OK);
348 verifyResponse(commit(), RPC_REPLY_OK);
350 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml",
351 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).build());
352 verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-case.xml",
353 YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).node(INNER_CHOICE).node(INNER_CHOICE_TEXT).build());
355 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-string.xml"),
356 XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-string.xml"));
357 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml"),
358 XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml"));
359 verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-case-inner-case.xml"),
360 XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-case-inner-choice.xml"));
362 verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-top.xml"), RPC_REPLY_OK);
363 verifyResponse(commit(), RPC_REPLY_OK);
367 private void verifyFilterIdentifier(String resource, YangInstanceIdentifier identifier) throws Exception{
368 TestingGetConfig getConfig = new TestingGetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider);
369 Document request = XmlFileLoader.xmlFileToDocument(resource);
370 YangInstanceIdentifier iid = getConfig.getInstanceIdentifierFromDocument(request);
371 assertTrue(iid.equals(identifier));
374 private class TestingGetConfig extends GetConfig{
375 public TestingGetConfig(String sessionId, CurrentSchemaContext schemaContext, TransactionProvider transactionProvider) {
376 super(sessionId, schemaContext, transactionProvider);
379 public YangInstanceIdentifier getInstanceIdentifierFromDocument(Document request) throws NetconfDocumentedException {
380 XmlElement filterElement = XmlElement.fromDomDocument(request).getOnlyChildElement(GET_CONFIG).getOnlyChildElement(FILTER_NODE);
381 return getInstanceIdentifierFromFilter(filterElement);
385 private void deleteDatastore() throws Exception{
386 verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-root.xml"), RPC_REPLY_OK);
387 assertEmptyDatastore(getConfigCandidate());
389 verifyResponse(commit(), RPC_REPLY_OK);
390 assertEmptyDatastore(getConfigRunning());
393 private void verifyResponse(Document response, Document template){
394 DetailedDiff dd = new DetailedDiff(new Diff(response, template));
395 dd.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
396 assertTrue(dd.similar());
399 private void assertEmptyDatastore(Document response) {
401 NodeList nodes = response.getChildNodes();
402 assertTrue(nodes.getLength() == 1);
404 assertEquals(nodes.item(0).getLocalName(),RPC_REPLY_ELEMENT);
406 NodeList replyNodes = nodes.item(0).getChildNodes();
407 assertTrue(replyNodes.getLength() == 1);
409 Node dataNode = replyNodes.item(0);
410 assertEquals(dataNode.getLocalName(), DATA_ELEMENT);
411 assertFalse(dataNode.hasChildNodes());
415 private Document commit() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
416 Commit commit = new Commit(sessionIdForReporting, transactionProvider);
417 return executeOperation(commit, "messages/mapping/commit.xml");
420 private Document discardChanges() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
421 DiscardChanges discardOp = new DiscardChanges(sessionIdForReporting, transactionProvider);
422 return executeOperation(discardOp, "messages/mapping/discardChanges.xml");
425 private Document edit(String resource) throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
426 EditConfig editConfig = new EditConfig(sessionIdForReporting, currentSchemaContext, transactionProvider);
427 return executeOperation(editConfig, resource);
430 private Document get() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
431 Get get = new Get(sessionIdForReporting, currentSchemaContext, transactionProvider);
432 return executeOperation(get, "messages/mapping/get.xml");
435 private Document getConfigRunning() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
436 GetConfig getConfig = new GetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider);
437 return executeOperation(getConfig, "messages/mapping/getConfig.xml");
440 private Document getConfigCandidate() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
441 GetConfig getConfig = new GetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider);
442 return executeOperation(getConfig, "messages/mapping/getConfig_candidate.xml");
445 private Document getConfigWithFilter(String resource) throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
446 GetConfig getConfig = new GetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider);
447 return executeOperation(getConfig, resource);
450 private Document lock() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
451 Lock lock = new Lock(sessionIdForReporting);
452 return executeOperation(lock, "messages/mapping/lock.xml");
455 private Document unlock() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
456 Unlock unlock = new Unlock(sessionIdForReporting);
457 return executeOperation(unlock, "messages/mapping/unlock.xml");
460 private Document lockCandidate() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
461 Lock lock = new Lock(sessionIdForReporting);
462 return executeOperation(lock, "messages/mapping/lock_candidate.xml");
465 private Document unlockCandidate() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
466 Unlock unlock = new Unlock(sessionIdForReporting);
467 return executeOperation(unlock, "messages/mapping/unlock_candidate.xml");
470 private Document executeOperation(NetconfOperation op, String filename) throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
471 final Document request = XmlFileLoader.xmlFileToDocument(filename);
473 HandlingPriority priority = op.canHandle(request);
474 Preconditions.checkState(priority != HandlingPriority.CANNOT_HANDLE);
476 final Document response = op.handle(request, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT);
478 LOG.debug("Got response {}" , response);
483 private Collection<InputStream> getYangSchemas() {
484 final List<String> schemaPaths = Arrays.asList("/META-INF/yang/config.yang", "/yang/mdsal-netconf-mapping-test.yang");
485 final List<InputStream> schemas = new ArrayList<>();
487 for (String schemaPath : schemaPaths) {
488 InputStream resourceAsStream = getClass().getResourceAsStream(schemaPath);
489 schemas.add(resourceAsStream);
495 private SchemaContext parseSchemas(Collection<InputStream> schemas) throws IOException, YangSyntaxErrorException {
496 final YangParserImpl parser = new YangParserImpl();
497 Collection<ByteSource> sources = BuilderUtils.streamsToByteSources(schemas);
498 return parser.parseSources(sources);
501 private SchemaService createSchemaService() {
502 return new SchemaService() {
505 public void addModule(Module module) {
509 public void removeModule(Module module) {
514 public SchemaContext getSessionContext() {
515 return schemaContext;
519 public SchemaContext getGlobalContext() {
520 return schemaContext;
524 public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(final SchemaContextListener listener) {
525 listener.onGlobalContextUpdated(getGlobalContext());
526 return new ListenerRegistration<SchemaContextListener>() {
528 public void close() {
533 public SchemaContextListener getInstance() {