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;
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;
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";
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();
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);
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));
}
+ @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);
deleteDatastore();
}
+ @Test
+ public void testEditConfigGetElementByTagName() throws Exception {
+ EditConfig editConfig = new EditConfig("test_edit-config", Mockito.mock(CurrentSchemaContext.class),
+ Mockito.mock(TransactionProvider.class));
+
+ String stringWithoutPrefix =
+ "<rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
+ + " <edit-config>\n"
+ + " <target>\n"
+ + " <candidate/>\n"
+ + " </target>\n"
+ + " </edit-config>\n"
+ + "</rpc>";
+ XmlElement xe = getXmlElement(stringWithoutPrefix);
+ NodeList nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
+ Assert.assertEquals(1, nodeList.getLength());
+
+ String stringWithPrefix =
+ "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
+ + " <nc:edit-config>\n"
+ + " <nc:target>\n"
+ + " <nc:candidate/>\n"
+ + " </nc:target>\n"
+ + " </nc:edit-config>\n"
+ + "</nc:rpc>";
+
+ xe = getXmlElement(stringWithPrefix);
+ nodeList = EditConfig.getElementsByTagName(xe, TARGET_KEY);
+ Assert.assertEquals(1, nodeList.getLength());
+
+ String stringWithoutTarget =
+ "<nc:rpc xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"0\">\n"
+ + " <nc:edit-config>\n"
+ + " <nc:target>\n"
+ + " </nc:target>\n"
+ + " </nc:edit-config>\n"
+ + "</nc:rpc>";
+ 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);
return response;
}
- private List<InputStream> getYangSchemas() {
- final List<String> schemaPaths = Arrays.asList("/META-INF/yang/config.yang",
- "/yang/mdsal-netconf-mapping-test.yang");
- final List<InputStream> 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() {
}
};
}
-}
\ No newline at end of file
+}