X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fmdsal-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fmdsal%2Fconnector%2Fops%2FNetconfMDSalMappingTest.java;h=625acb29994c70a0d2dabdfd1d70a352f9db915e;hb=09fdf0b97f3a6fa3e3ed8416e445025eeb592487;hp=11c8473606401e541355a8e7b8eaf98e2521e0d0;hpb=d5db0ba4b6233134e2c90b88e2a4fc4d9590749a;p=netconf.git diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java index 11c8473606..625acb2999 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/NetconfMDSalMappingTest.java @@ -5,163 +5,68 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.netconf.mdsal.connector.ops; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doAnswer; -import com.google.common.io.ByteSource; -import com.google.common.util.concurrent.Futures; -import java.io.IOException; -import java.io.InputStream; import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumMap; -import java.util.List; -import java.util.concurrent.ExecutorService; -import javax.xml.parsers.ParserConfigurationException; +import java.net.URI; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import org.custommonkey.xmlunit.DetailedDiff; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLUnit; -import org.junit.Before; +import org.junit.Assert; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker; -import org.opendaylight.controller.config.util.xml.DocumentedException; -import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorSeverity; -import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorTag; -import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorType; -import org.opendaylight.controller.config.util.xml.XmlElement; -import org.opendaylight.controller.config.util.xml.XmlUtil; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreFactory; -import org.opendaylight.controller.sal.core.api.model.SchemaService; -import org.opendaylight.controller.sal.core.spi.data.DOMStore; -import org.opendaylight.netconf.mapping.api.NetconfOperation; -import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution; +import org.mockito.Mockito; +import org.opendaylight.netconf.api.DocumentedException; +import org.opendaylight.netconf.api.DocumentedException.ErrorSeverity; +import org.opendaylight.netconf.api.DocumentedException.ErrorTag; +import org.opendaylight.netconf.api.DocumentedException.ErrorType; +import org.opendaylight.netconf.api.xml.XmlElement; +import org.opendaylight.netconf.api.xml.XmlUtil; import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext; import org.opendaylight.netconf.mdsal.connector.TransactionProvider; -import org.opendaylight.netconf.mdsal.connector.ops.get.Get; import org.opendaylight.netconf.mdsal.connector.ops.get.GetConfig; -import org.opendaylight.netconf.util.test.NetconfXmlUnitRecursiveQualifier; import org.opendaylight.netconf.util.test.XmlFileLoader; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.util.concurrent.SpecialExecutors; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; -import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; -import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; -import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; -import org.w3c.dom.Node; +import org.w3c.dom.Element; import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -public class NetconfMDSalMappingTest { +public class NetconfMDSalMappingTest extends AbstractNetconfOperationTest { private static final Logger LOG = LoggerFactory.getLogger(NetconfMDSalMappingTest.class); - private static final String RPC_REPLY_ELEMENT = "rpc-reply"; - private static final String DATA_ELEMENT = "data"; + private static final String TARGET_KEY = "target"; private static final String FILTER_NODE = "filter"; private static final String GET_CONFIG = "get-config"; private static final QName TOP = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "top"); private static final QName USERS = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "users"); private static final QName USER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "user"); private static final QName MODULES = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "modules"); - private static final QName AUGMENTED_CONTAINER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "augmented-container"); - private static final QName AUGMENTED_STRING_IN_CONT = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "identifier"); - private static final QName CHOICE_NODE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "choice-node"); - private static final QName AUGMENTED_CASE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "augmented-case"); - private static final QName CHOICE_WRAPPER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "choice-wrapper"); - private static final QName INNER_CHOICE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "inner-choice"); - private static final QName INNER_CHOICE_TEXT = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", "text"); + private static final QName AUGMENTED_CONTAINER = QName.create("urn:opendaylight:mdsal:mapping:test", + "2015-02-26", "augmented-container"); + private static final QName AUGMENTED_STRING_IN_CONT = QName.create("urn:opendaylight:mdsal:mapping:test", + "2015-02-26", "identifier"); + private static final QName CHOICE_NODE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", + "choice-node"); + private static final QName AUGMENTED_CASE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", + "augmented-case"); + private static final QName CHOICE_WRAPPER = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", + "choice-wrapper"); + private static final QName INNER_CHOICE = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", + "inner-choice"); + private static final QName INNER_CHOICE_TEXT = QName.create("urn:opendaylight:mdsal:mapping:test", "2015-02-26", + "text"); private static final YangInstanceIdentifier AUGMENTED_CONTAINER_IN_MODULES = YangInstanceIdentifier.builder().node(TOP).node(MODULES).build(); - private static Document RPC_REPLY_OK = null; - - static { - try { - RPC_REPLY_OK = XmlFileLoader.xmlFileToDocument("messages/mapping/rpc-reply_ok.xml"); - } catch (Exception e) { - LOG.debug("unable to load rpc reply ok.", e); - RPC_REPLY_OK = XmlUtil.newDocument(); - } - } - - private CurrentSchemaContext currentSchemaContext = null; - private SchemaContext schemaContext = null; - private String sessionIdForReporting = "netconf-test-session1"; - - private TransactionProvider transactionProvider = null; - - @Mock - private SchemaSourceProvider sourceProvider; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - - XMLUnit.setIgnoreWhitespace(true); - XMLUnit.setIgnoreAttributeOrder(true); - - this.schemaContext = parseYangStreams(getYangSchemas()); - schemaContext.getModules(); - final SchemaService schemaService = createSchemaService(); - - final DOMStore operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", schemaService); - final DOMStore configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", schemaService); - - final EnumMap datastores = new EnumMap<>(LogicalDatastoreType.class); - datastores.put(LogicalDatastoreType.CONFIGURATION, configStore); - datastores.put(LogicalDatastoreType.OPERATIONAL, operStore); - - ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool( - 16, 16, "CommitFutures"); - - final ConcurrentDOMDataBroker cdb = new ConcurrentDOMDataBroker(datastores, listenableFutureExecutor); - this.transactionProvider = new TransactionProvider(cdb, sessionIdForReporting); - - doAnswer(new Answer() { - @Override - public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { - final SourceIdentifier sId = (SourceIdentifier) invocationOnMock.getArguments()[0]; - final YangTextSchemaSource yangTextSchemaSource = - YangTextSchemaSource.delegateForByteSource(sId, ByteSource.wrap("module test".getBytes())); - return Futures.immediateCheckedFuture(yangTextSchemaSource); - - } - }).when(sourceProvider).getSource(any(SourceIdentifier.class)); - - this.currentSchemaContext = new CurrentSchemaContext(schemaService, sourceProvider); - - } - @Test public void testEmptyDatastore() throws Exception { assertEmptyDatastore(get()); @@ -171,40 +76,49 @@ public class NetconfMDSalMappingTest { @Test public void testIncorrectGet() throws Exception { - try { - executeOperation(new GetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider), "messages/mapping/bad_getConfig.xml"); + executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(), + getTransactionProvider()), "messages/mapping/bad_getConfig.xml"); fail("Should have failed, this is an incorrect request"); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.operation_failed); - assertTrue(e.getErrorType() == ErrorType.application); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.OPERATION_FAILED); + assertTrue(e.getErrorType() == ErrorType.APPLICATION); } try { - executeOperation(new GetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider), "messages/mapping/bad_namespace_getConfig.xml"); + executeOperation(new GetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(), + getTransactionProvider()), "messages/mapping/bad_namespace_getConfig.xml"); fail("Should have failed, this is an incorrect request"); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.operation_failed); - assertTrue(e.getErrorType() == ErrorType.application); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.OPERATION_FAILED); + assertTrue(e.getErrorType() == ErrorType.APPLICATION); } + } - + @Test + public void testConfigMissing() throws Exception { + try { + edit("messages/mapping/editConfigs/editConfig_no_config.xml"); + fail("Should have failed - neither nor element is present"); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.MISSING_ELEMENT); + assertTrue(e.getErrorType() == ErrorType.PROTOCOL); + } } @Test public void testEditRunning() throws Exception { - try { edit("messages/mapping/editConfigs/editConfig_running.xml"); fail("Should have failed - edit config on running datastore is not supported"); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.operation_not_supported); - assertTrue(e.getErrorType() == ErrorType.protocol); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.OPERATION_NOT_SUPPORTED); + assertTrue(e.getErrorType() == ErrorType.PROTOCOL); } - } @Test @@ -215,27 +129,26 @@ public class NetconfMDSalMappingTest { @Test public void testCandidateTransaction() throws Exception { - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_n1_control.xml")); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_n1_control.xml")); assertEmptyDatastore(getConfigRunning()); verifyResponse(discardChanges(), RPC_REPLY_OK); assertEmptyDatastore(getConfigCandidate()); - } @Test public void testEditWithCommit() throws Exception { - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_n1.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_n1_control.xml")); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_n1_control.xml")); verifyResponse(commit(), RPC_REPLY_OK); - verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_n1_control.xml")); + verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_n1_control.xml")); deleteDatastore(); - } @Test @@ -244,7 +157,8 @@ public class NetconfMDSalMappingTest { verifyResponse(commit(), RPC_REPLY_OK); final Document configRunning = getConfigRunning(); final String responseAsString = XmlUtil.toString(configRunning); - verifyResponse(configRunning, XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml")); + verifyResponse(configRunning, XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_keys_1_control.xml")); final int key3 = responseAsString.indexOf("key3"); final int key1 = responseAsString.indexOf("key1"); @@ -259,157 +173,212 @@ public class NetconfMDSalMappingTest { @Test public void testMultipleEditsWithMerge() throws Exception { - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_control_1.xml")); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_control_1.xml")); verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml")); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml")); assertEmptyDatastore(getConfigRunning()); verifyResponse(commit(), RPC_REPLY_OK); - verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml")); + verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_control_2.xml")); deleteDatastore(); - } @Test public void testMoreComplexEditConfigs() throws Exception { - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_1.xml"), RPC_REPLY_OK); verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_single_1.xml"), RPC_REPLY_OK); verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_2.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge.xml")); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge.xml")); verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_3.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge_2.xml")); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_after_more_complex_merge_2.xml")); verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_4_replace.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml")); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml")); verifyResponse(commit(), RPC_REPLY_OK); - verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml")); + verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_after_replace.xml")); verifyResponse(edit("messages/mapping/editConfigs/editConfig_replace_default.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_replace_default_control.xml")); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_replace_default_control.xml")); verifyResponse(commit(), RPC_REPLY_OK); - verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_replace_default_control.xml")); + verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_replace_default_control.xml")); + + deleteDatastore(); + } + + @Test + public void testOrderedListEdits() throws Exception { + + verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_create.xml"), RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + verifyResponse(edit("messages/mapping/editConfigs/editConfig_ordered_list_replace.xml"), RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); deleteDatastore(); } @Test - public void testLock() throws Exception { + public void testAugmentedOrderedListEdits() throws Exception { + + verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_create.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_ordered_list_replace.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + deleteDatastore(); + + } + + @Test + public void testAugmentedContainerReplace() throws Exception { + verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_container_replace.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + deleteDatastore(); + } + + @Test + public void testLeafFromAugmentReplace() throws Exception { + verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + verifyResponse(edit("messages/mapping/editConfigs/editConfig_leaf_from_augment_replace.xml"), + RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + + deleteDatastore(); + } + @Test + public void testLock() throws Exception { verifyResponse(lockCandidate(), RPC_REPLY_OK); try { lock(); fail("Should have failed - locking of running datastore is not supported"); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.operation_not_supported); - assertTrue(e.getErrorType() == ErrorType.application); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.OPERATION_NOT_SUPPORTED); + assertTrue(e.getErrorType() == ErrorType.APPLICATION); } - try { lockWithoutTarget(); fail("Should have failed, target is missing"); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.invalid_value); - assertTrue(e.getErrorType() == ErrorType.application); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.INVALID_VALUE); + assertTrue(e.getErrorType() == ErrorType.APPLICATION); } } @Test public void testUnlock() throws Exception { - verifyResponse(unlockCandidate(), RPC_REPLY_OK); try { unlock(); fail("Should have failed - unlocking of running datastore is not supported"); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.operation_not_supported); - assertTrue(e.getErrorType() == ErrorType.application); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.OPERATION_NOT_SUPPORTED); + assertTrue(e.getErrorType() == ErrorType.APPLICATION); } try { unlockWithoutTarget(); fail("Should have failed, target is missing"); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.invalid_value); - assertTrue(e.getErrorType() == ErrorType.application); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.INVALID_VALUE); + assertTrue(e.getErrorType() == ErrorType.APPLICATION); } } @Test public void testEditWithCreate() throws Exception { - verifyResponse(edit("messages/mapping/editConfigs/editConfig_create.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfig_create_n1_control.xml")); - + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfig_create_n1_control.xml")); try { edit("messages/mapping/editConfigs/editConfig_create.xml"); fail("Create should have failed - data already exists"); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.data_exists); - assertTrue(e.getErrorType() == ErrorType.protocol); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.DATA_EXISTS); + assertTrue(e.getErrorType() == ErrorType.PROTOCOL); } verifyResponse(discardChanges(), RPC_REPLY_OK); - } @Test public void testDeleteNonExisting() throws Exception { - assertEmptyDatastore(getConfigCandidate()); assertEmptyDatastore(getConfigRunning()); try { edit("messages/mapping/editConfigs/editConfig_delete-top.xml"); fail("Delete should have failed - data is missing"); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.data_missing); - assertTrue(e.getErrorType() == ErrorType.protocol); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.DATA_MISSING); + assertTrue(e.getErrorType() == ErrorType.PROTOCOL); } - } @Test public void testEditMissingDefaultOperation() throws Exception { - - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_1.xml"), RPC_REPLY_OK); - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_2.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml")); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_1.xml"), + RPC_REPLY_OK); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_2.xml"), + RPC_REPLY_OK); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml")); verifyResponse(commit(), RPC_REPLY_OK); - verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml")); + verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_missing_default-operation_control.xml")); deleteDatastore(); } - public static void printDocument(Document doc) throws IOException, TransformerException { - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); + private static void printDocument(final Document doc) throws Exception { + final TransformerFactory tf = TransformerFactory.newInstance(); + final Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); - StringWriter writer = new StringWriter(); + final StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(writer)); LOG.warn(writer.getBuffer().toString()); @@ -419,58 +388,151 @@ public class NetconfMDSalMappingTest { public void testEditConfigWithMultipleOperations() throws Exception { deleteDatastore(); - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_setup.xml"), RPC_REPLY_OK); - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_1.xml"), RPC_REPLY_OK); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_setup.xml"), + RPC_REPLY_OK); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_1.xml"), + RPC_REPLY_OK); - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_2.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_operations_2_control.xml")); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_2.xml"), + RPC_REPLY_OK); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_operations_2_control.xml")); - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_leaf_operations.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_control.xml")); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_leaf_operations.xml"), + RPC_REPLY_OK); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_operations_3_control.xml")); deleteDatastore(); - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_setup.xml"), RPC_REPLY_OK); - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_default-replace.xml"), RPC_REPLY_OK); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_setup.xml"), + RPC_REPLY_OK); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_default-replace.xml"), + RPC_REPLY_OK); try { edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_create_existing.xml"); fail(); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.data_exists); - assertTrue(e.getErrorType() == ErrorType.protocol); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.DATA_EXISTS); + assertTrue(e.getErrorType() == ErrorType.PROTOCOL); } - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete_children_operations.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete_children_operations_control.xml")); - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_remove-non-existing.xml"), RPC_REPLY_OK); - + verifyResponse(edit( + "messages/mapping/editConfigs/" + + "editConfig_merge_multiple_operations_4_delete_children_operations.xml"), + RPC_REPLY_OK); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/" + + "editConfig_merge_multiple_operations_4_delete_children_operations_control.xml")); + verifyResponse(edit( + "messages/mapping/editConfigs/" + + "editConfig_merge_multiple_operations_4_remove-non-existing.xml"), + RPC_REPLY_OK); try { - edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete-non-existing.xml"); + edit("messages/mapping/editConfigs/" + + "editConfig_merge_multiple_operations_4_delete-non-existing.xml"); fail(); - } catch (DocumentedException e) { - assertTrue(e.getErrorSeverity() == ErrorSeverity.error); - assertTrue(e.getErrorTag() == ErrorTag.data_missing); - assertTrue(e.getErrorType() == ErrorType.protocol); + } catch (final DocumentedException e) { + assertTrue(e.getErrorSeverity() == ErrorSeverity.ERROR); + assertTrue(e.getErrorTag() == ErrorTag.DATA_MISSING); + assertTrue(e.getErrorType() == ErrorType.PROTOCOL); } - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup-control.xml")); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup.xml"), + RPC_REPLY_OK); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup-control.xml")); // Test files have been modified. RFC6020 requires that at most once case inside a choice is present at any time - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2-control.xml")); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2.xml"), + RPC_REPLY_OK); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_setup2-control.xml")); - verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_delete.xml"), RPC_REPLY_OK); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/editConfigs/editConfig_merge_multiple_operations_4_delete_children_operations_control.xml")); + verifyResponse(edit("messages/mapping/editConfigs/editConfig_merge_multiple_operations_5_choice_delete.xml"), + RPC_REPLY_OK); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs" + + "/editConfig_merge_multiple_operations_4_delete_children_operations_control.xml")); deleteDatastore(); } @Test - public void testFiltering() throws Exception { + public void testEditConfigGetElementByTagName() throws Exception { + EditConfig editConfig = new EditConfig("test_edit-config", Mockito.mock(CurrentSchemaContext.class), + Mockito.mock(TransactionProvider.class)); + + String stringWithoutPrefix = + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + XmlElement xe = getXmlElement(stringWithoutPrefix); + NodeList nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY); + Assert.assertEquals(1, nodeList.getLength()); + + String stringWithPrefix = + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + xe = getXmlElement(stringWithPrefix); + nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY); + Assert.assertEquals(1, nodeList.getLength()); + + String stringWithoutTarget = + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + xe = getXmlElement(stringWithoutTarget); + + try { + nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY); + XmlElement.fromDomElement((Element) nodeList.item(0)).getOnlyChildElement(); + Assert.fail("Not specified target, we should fail"); + } catch (DocumentedException documentedException) { + // Ignore + } + + } + + private static XmlElement getXmlElement(final String elementAsString) throws Exception { + Document document = XmlUtil.readXmlToDocument(elementAsString); + Element element = document.getDocumentElement(); + return XmlElement.fromDomElement(element); + } + + @Test + public void testReplaceMapEntry() throws Exception { + verifyResponse(edit("messages/mapping/editConfigs/edit-config-replace-map-entry.xml"), RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + verifyResponse(getConfigRunning(), + XmlFileLoader.xmlFileToDocument("messages/mapping/get-config-map-entry.xml")); + } + + @Test + public void testMergeMapEntry() throws Exception { + verifyResponse(edit("messages/mapping/editConfigs/edit-config-merge-map-entry.xml"), RPC_REPLY_OK); + verifyResponse(commit(), RPC_REPLY_OK); + verifyResponse(getConfigRunning(), + XmlFileLoader.xmlFileToDocument("messages/mapping/get-config-map-entry.xml")); + } + @Test + public void testFiltering() throws Exception { assertEmptyDatastore(getConfigCandidate()); assertEmptyDatastore(getConfigRunning()); @@ -479,7 +541,8 @@ public class NetconfMDSalMappingTest { verifyResponse(getWithFilter("messages/mapping/filters/get-empty-filter.xml"), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml")); - verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml")); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response" + + ".xml")); verifyResponse(getConfigRunning(), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml")); verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-users.xml"), XmlFileLoader.xmlFileToDocument("messages/mapping/get-empty-response.xml")); @@ -502,10 +565,10 @@ public class NetconfMDSalMappingTest { verifyFilterIdentifier("messages/mapping/filters/get-filter-users.xml", YangInstanceIdentifier.builder().node(TOP).node(USERS).build()); - YangInstanceIdentifier ident = YangInstanceIdentifier. - builder(AUGMENTED_CONTAINER_IN_MODULES). - node(AUGMENTED_CONTAINER). - node(AUGMENTED_STRING_IN_CONT).build(); + final YangInstanceIdentifier ident = YangInstanceIdentifier + .builder(AUGMENTED_CONTAINER_IN_MODULES) + .node(AUGMENTED_CONTAINER) + .node(AUGMENTED_STRING_IN_CONT).build(); verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-string.xml", ident); verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case.xml", @@ -531,7 +594,8 @@ public class NetconfMDSalMappingTest { verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-choice.xml", YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).build()); verifyFilterIdentifier("messages/mapping/filters/get-filter-augmented-case-inner-case.xml", - YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).node(INNER_CHOICE).node(INNER_CHOICE_TEXT).build()); + YangInstanceIdentifier.builder().node(TOP).node(CHOICE_NODE).node(CHOICE_WRAPPER).node(INNER_CHOICE) + .node(INNER_CHOICE_TEXT).build()); // verifyResponse(getConfigWithFilter("messages/mapping/filters/get-filter-augmented-string.xml"), // XmlFileLoader.xmlFileToDocument("messages/mapping/filters/response-augmented-string.xml")); @@ -545,25 +609,29 @@ public class NetconfMDSalMappingTest { } - private void verifyFilterIdentifier(String resource, YangInstanceIdentifier identifier) throws Exception{ - TestingGetConfig getConfig = new TestingGetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider); - Document request = XmlFileLoader.xmlFileToDocument(resource); - YangInstanceIdentifier iid = getConfig.getInstanceIdentifierFromDocument(request); + private void verifyFilterIdentifier(final String resource, final YangInstanceIdentifier identifier) + throws Exception { + final TestingGetConfig getConfig = new TestingGetConfig(SESSION_ID_FOR_REPORTING, getCurrentSchemaContext(), + getTransactionProvider()); + final Document request = XmlFileLoader.xmlFileToDocument(resource); + final YangInstanceIdentifier iid = getConfig.getInstanceIdentifierFromDocument(request); assertEquals(identifier, iid); } - private class TestingGetConfig extends GetConfig{ - public TestingGetConfig(String sessionId, CurrentSchemaContext schemaContext, TransactionProvider transactionProvider) { + private class TestingGetConfig extends GetConfig { + TestingGetConfig(final String sessionId, final CurrentSchemaContext schemaContext, + final TransactionProvider transactionProvider) { super(sessionId, schemaContext, transactionProvider); } - public YangInstanceIdentifier getInstanceIdentifierFromDocument(Document request) throws DocumentedException { - XmlElement filterElement = XmlElement.fromDomDocument(request).getOnlyChildElement(GET_CONFIG).getOnlyChildElement(FILTER_NODE); + YangInstanceIdentifier getInstanceIdentifierFromDocument(final Document request) throws DocumentedException { + final XmlElement filterElement = XmlElement.fromDomDocument(request).getOnlyChildElement(GET_CONFIG) + .getOnlyChildElement(FILTER_NODE); return getInstanceIdentifierFromFilter(filterElement); } } - private void deleteDatastore() throws Exception{ + private void deleteDatastore() throws Exception { verifyResponse(edit("messages/mapping/editConfigs/editConfig_delete-root.xml"), RPC_REPLY_OK); assertEmptyDatastore(getConfigCandidate()); @@ -571,171 +639,16 @@ public class NetconfMDSalMappingTest { assertEmptyDatastore(getConfigRunning()); } - private void verifyResponse(Document response, Document template) throws IOException, TransformerException { - DetailedDiff dd = new DetailedDiff(new Diff(response, template)); - dd.overrideElementQualifier(new NetconfXmlUnitRecursiveQualifier()); - - printDocument(response); - printDocument(template); - - assertTrue(dd.toString(), dd.similar()); - } - - private void assertEmptyDatastore(Document response) { - - NodeList nodes = response.getChildNodes(); - assertTrue(nodes.getLength() == 1); - - assertEquals(nodes.item(0).getLocalName(), RPC_REPLY_ELEMENT); - - NodeList replyNodes = nodes.item(0).getChildNodes(); - assertTrue(replyNodes.getLength() == 1); - - Node dataNode = replyNodes.item(0); - assertEquals(dataNode.getLocalName(), DATA_ELEMENT); - assertFalse(dataNode.hasChildNodes()); - - } - - private Document commit() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - Commit commit = new Commit(sessionIdForReporting, transactionProvider); - return executeOperation(commit, "messages/mapping/commit.xml"); - } - - private Document discardChanges() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - DiscardChanges discardOp = new DiscardChanges(sessionIdForReporting, transactionProvider); - return executeOperation(discardOp, "messages/mapping/discardChanges.xml"); - } - - private Document edit(String resource) throws DocumentedException, ParserConfigurationException, SAXException, IOException { - EditConfig editConfig = new EditConfig(sessionIdForReporting, currentSchemaContext, transactionProvider); - return executeOperation(editConfig, resource); - } - - private Document get() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - Get get = new Get(sessionIdForReporting, currentSchemaContext, transactionProvider); - return executeOperation(get, "messages/mapping/get.xml"); - } - - private Document getWithFilter(String resource) throws DocumentedException, ParserConfigurationException, SAXException, IOException { - Get get = new Get(sessionIdForReporting, currentSchemaContext, transactionProvider); - return executeOperation(get, resource); - } - - private Document getConfigRunning() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - GetConfig getConfig = new GetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider); - return executeOperation(getConfig, "messages/mapping/getConfig.xml"); - } - - private Document getConfigCandidate() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - GetConfig getConfig = new GetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider); - return executeOperation(getConfig, "messages/mapping/getConfig_candidate.xml"); - } - - private Document getConfigWithFilter(String resource) throws DocumentedException, ParserConfigurationException, SAXException, IOException { - GetConfig getConfig = new GetConfig(sessionIdForReporting, currentSchemaContext, transactionProvider); - return executeOperation(getConfig, resource); - } - - private Document lock() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - Lock lock = new Lock(sessionIdForReporting); - return executeOperation(lock, "messages/mapping/lock.xml"); - } - - private Document unlock() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - Unlock unlock = new Unlock(sessionIdForReporting); - return executeOperation(unlock, "messages/mapping/unlock.xml"); - } - - private Document lockWithoutTarget() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - Lock lock = new Lock(sessionIdForReporting); - return executeOperation(lock, "messages/mapping/lock_notarget.xml"); - } - - private Document unlockWithoutTarget() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - Unlock unlock = new Unlock(sessionIdForReporting); - return executeOperation(unlock, "messages/mapping/unlock_notarget.xml"); - } - - private Document lockCandidate() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - Lock lock = new Lock(sessionIdForReporting); - return executeOperation(lock, "messages/mapping/lock_candidate.xml"); - } - - private Document unlockCandidate() throws DocumentedException, ParserConfigurationException, SAXException, IOException { - Unlock unlock = new Unlock(sessionIdForReporting); - return executeOperation(unlock, "messages/mapping/unlock_candidate.xml"); - } - - private Document executeOperation(NetconfOperation op, String filename) throws ParserConfigurationException, SAXException, IOException, DocumentedException { - final Document request = XmlFileLoader.xmlFileToDocument(filename); - final Document response = op.handle(request, NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT); - - LOG.debug("Got response {}" , response); - return response; - } - - private List getYangSchemas() { - final List schemaPaths = Arrays.asList("/META-INF/yang/config.yang", "/yang/mdsal-netconf-mapping-test.yang"); - final List schemas = new ArrayList<>(); - - for (String schemaPath : schemaPaths) { - InputStream resourceAsStream = getClass().getResourceAsStream(schemaPath); - schemas.add(resourceAsStream); - } - - return schemas; - } - - private static SchemaContext parseYangStreams(final List streams) { - CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR - .newBuild(); - final SchemaContext schemaContext; - try { - schemaContext = reactor.buildEffective(streams); - } catch (ReactorException e) { - throw new RuntimeException("Unable to build schema context from " + streams, e); - } - return schemaContext; - } - - private SchemaService createSchemaService() { - return new SchemaService() { - - @Override - public void addModule(Module module) { - } - - @Override - public void removeModule(Module module) { - - } - - @Override - public SchemaContext getSessionContext() { - return schemaContext; - } - - @Override - public SchemaContext getGlobalContext() { - return schemaContext; - } - - @Override - public ListenerRegistration registerSchemaContextListener(final SchemaContextListener listener) { - listener.onGlobalContextUpdated(getGlobalContext()); - return new ListenerRegistration() { - @Override - public void close() { - - } - - @Override - public SchemaContextListener getInstance() { - return listener; - } - }; - } - }; - } -} \ No newline at end of file + @Test + public void testEditUsingConfigFromFile() throws Exception { + // Ask class loader for URI of config file and use it as in RPC: + final String template = XmlFileLoader.fileToString("messages/mapping/editConfigs/editConfig_from_file.xml"); + final URI uri = getClass().getClassLoader().getResource("messages/mapping/editConfigs/config_file.xml").toURI(); + final String copyConfig = template.replaceFirst("URL", uri.toString()); + final Document request = XmlUtil.readXmlToDocument(copyConfig); + + verifyResponse(edit(request), RPC_REPLY_OK); + verifyResponse(getConfigCandidate(), XmlFileLoader.xmlFileToDocument( + "messages/mapping/editConfigs/editConfig_from_file_control.xml")); + } +}