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=ad35b0dfa55d5498815cfdf59b074a565308769d;hb=c188d560dbb324b97e39b4d0480eb17562e5d1be;hp=4d53fa3999b22493b98e3703176d2832d09d1cbc;hpb=e7abbe8b97f494030992ea8f9cc81a982695852b;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 4d53fa3999..ad35b0dfa5 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 @@ -17,12 +17,8 @@ import static org.mockito.Mockito.doAnswer; import com.google.common.io.ByteSource; import com.google.common.util.concurrent.Futures; -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.transform.OutputKeys; import javax.xml.transform.Transformer; @@ -32,9 +28,11 @@ import javax.xml.transform.stream.StreamResult; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker; import org.opendaylight.controller.config.util.xml.DocumentedException; @@ -69,12 +67,14 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; +import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class NetconfMDSalMappingTest { private static final Logger LOG = LoggerFactory.getLogger(NetconfMDSalMappingTest.class); + private static final String TARGET_KEY = "target"; private static final String RPC_REPLY_ELEMENT = "rpc-reply"; private static final String DATA_ELEMENT = "data"; private static final String FILTER_NODE = "filter"; @@ -129,7 +129,8 @@ public class NetconfMDSalMappingTest { XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreAttributeOrder(true); - this.schemaContext = YangParserTestUtils.parseYangStreams(getYangSchemas()); + this.schemaContext = YangParserTestUtils.parseYangResources(NetconfMDSalMappingTest.class, + "/META-INF/yang/config@2013-04-05.yang", "/yang/mdsal-netconf-mapping-test.yang"); schemaContext.getModules(); final SchemaService schemaService = createSchemaService(); @@ -141,7 +142,7 @@ public class NetconfMDSalMappingTest { datastores.put(LogicalDatastoreType.OPERATIONAL, operStore); final ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool( - 16, 16, "CommitFutures"); + 16, 16, "CommitFutures", NetconfMDSalMappingTest.class); final ConcurrentDOMDataBroker cdb = new ConcurrentDOMDataBroker(datastores, listenableFutureExecutor); this.transactionProvider = new TransactionProvider(cdb, SESSION_ID_FOR_REPORTING); @@ -150,7 +151,7 @@ public class NetconfMDSalMappingTest { final SourceIdentifier sId = (SourceIdentifier) invocationOnMock.getArguments()[0]; final YangTextSchemaSource yangTextSchemaSource = YangTextSchemaSource.delegateForByteSource(sId, ByteSource.wrap("module test".getBytes())); - return Futures.immediateCheckedFuture(yangTextSchemaSource); + return Futures.immediateFuture(yangTextSchemaSource); }).when(sourceProvider).getSource(any(SourceIdentifier.class)); @@ -329,11 +330,11 @@ public class NetconfMDSalMappingTest { @Test public void testAugmentedContainerReplace() throws Exception { verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"), - RPC_REPLY_OK); + RPC_REPLY_OK); verifyResponse(commit(), RPC_REPLY_OK); verifyResponse(edit("messages/mapping/editConfigs/editConfig_augmented_container_replace.xml"), - RPC_REPLY_OK); + RPC_REPLY_OK); verifyResponse(commit(), RPC_REPLY_OK); deleteDatastore(); @@ -342,11 +343,11 @@ public class NetconfMDSalMappingTest { @Test public void testLeafFromAugmentReplace() throws Exception { verifyResponse(edit("messages/mapping/editConfigs/editConfig_empty_modules_create.xml"), - RPC_REPLY_OK); + RPC_REPLY_OK); verifyResponse(commit(), RPC_REPLY_OK); verifyResponse(edit("messages/mapping/editConfigs/editConfig_leaf_from_augment_replace.xml"), - RPC_REPLY_OK); + RPC_REPLY_OK); verifyResponse(commit(), RPC_REPLY_OK); deleteDatastore(); @@ -538,6 +539,61 @@ public class NetconfMDSalMappingTest { deleteDatastore(); } + @Test + 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); @@ -765,19 +821,6 @@ public class NetconfMDSalMappingTest { 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 (final String schemaPath : schemaPaths) { - final InputStream resourceAsStream = getClass().getResourceAsStream(schemaPath); - schemas.add(resourceAsStream); - } - - return schemas; - } - private SchemaService createSchemaService() { return new SchemaService() { @@ -818,4 +861,4 @@ public class NetconfMDSalMappingTest { } }; } -} \ No newline at end of file +}