From bfae8a4c16f0fabe4e425aa0849166db1b104671 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Fri, 17 Oct 2014 11:58:07 +0200 Subject: [PATCH] Add get-config commit edit-config to testtool Change-Id: Ie85c839c2077b9d7ca560dc42120268501acb8b0 Signed-off-by: Andrej Socha Signed-off-by: Maros Marsalek --- .../netconf/test/tool/DataList.java | 31 ++++++++ .../test/tool/NetconfDeviceSimulator.java | 11 ++- .../netconf/test/tool/SimulatedCommit.java | 35 +++++++++ .../test/tool/SimulatedEditConfig.java | 71 +++++++++++++++++++ .../netconf/test/tool/SimulatedGet.java | 14 +++- .../netconf/test/tool/SimulatedGetConfig.java | 45 ++++++++++++ 6 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/DataList.java create mode 100644 opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedCommit.java create mode 100644 opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedEditConfig.java create mode 100644 opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedGetConfig.java diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/DataList.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/DataList.java new file mode 100644 index 0000000000..d6dd55cb4e --- /dev/null +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/DataList.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.controller.netconf.test.tool; + +import java.util.Collections; +import java.util.List; +import org.opendaylight.controller.netconf.util.xml.XmlElement; + +public class DataList { + + private List configList = Collections.emptyList(); + + public List getConfigList() { + return configList; + } + + public void setConfigList(List configList) { + this.configList = configList; + } + + public void resetConfigList() { + configList = Collections.emptyList(); + } + +} diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java index 4956c605fc..d0939a288f 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java @@ -369,11 +369,11 @@ public class NetconfDeviceSimulator implements Closeable { static class SimulatedOperationService implements NetconfOperationService { private final Set capabilities; - private static SimulatedGet sGet; + private final long currentSessionId; public SimulatedOperationService(final Set capabilities, final long currentSessionId) { this.capabilities = capabilities; - sGet = new SimulatedGet(String.valueOf(currentSessionId)); + this.currentSessionId = currentSessionId; } @Override @@ -383,7 +383,12 @@ public class NetconfDeviceSimulator implements Closeable { @Override public Set getNetconfOperations() { - return Sets.newHashSet(sGet); + final DataList storage = new DataList(); + final SimulatedGet sGet = new SimulatedGet(String.valueOf(currentSessionId), storage); + final SimulatedEditConfig sEditConfig = new SimulatedEditConfig(String.valueOf(currentSessionId), storage); + final SimulatedGetConfig sGetConfig = new SimulatedGetConfig(String.valueOf(currentSessionId), storage); + final SimulatedCommit sCommit = new SimulatedCommit(String.valueOf(currentSessionId)); + return Sets.newHashSet(sGet, sGetConfig, sEditConfig, sCommit); } @Override diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedCommit.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedCommit.java new file mode 100644 index 0000000000..db3717fab4 --- /dev/null +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedCommit.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.controller.netconf.test.tool; + +import com.google.common.base.Optional; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation; +import org.opendaylight.controller.netconf.util.xml.XmlElement; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +class SimulatedCommit extends AbstractConfigNetconfOperation { + + SimulatedCommit(final String netconfSessionIdForReporting) { + super(null, netconfSessionIdForReporting); + } + + @Override + protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException { + return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); + } + + @Override + protected String getOperationName() { + return XmlNetconfConstants.COMMIT; + } +} diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedEditConfig.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedEditConfig.java new file mode 100644 index 0000000000..e5d068d02c --- /dev/null +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedEditConfig.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.controller.netconf.test.tool; + +import com.google.common.base.Optional; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation; +import org.opendaylight.controller.netconf.confignetconfconnector.operations.editconfig.EditConfigXmlParser; +import org.opendaylight.controller.netconf.util.xml.XmlElement; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +class SimulatedEditConfig extends AbstractConfigNetconfOperation { + private static final String DELETE_EDIT_CONFIG = "delete"; + private static final String OPERATION = "operation"; + private static final String REMOVE_EDIT_CONFIG = "remove"; + private final DataList storage; + + SimulatedEditConfig(final String netconfSessionIdForReporting, final DataList storage) { + super(null, netconfSessionIdForReporting); + this.storage = storage; + } + + @Override + protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException { + final XmlElement configElementData = operationElement.getOnlyChildElement(XmlNetconfConstants.CONFIG_KEY); + + containsDelete(configElementData); + if(containsDelete(configElementData)){ + storage.resetConfigList(); + } else { + storage.setConfigList(configElementData.getChildElements()); + } + + return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); + } + + @Override + protected String getOperationName() { + return EditConfigXmlParser.EDIT_CONFIG; + } + + private boolean containsDelete(final XmlElement element) { + for (final Attr o : element.getAttributes().values()) { + if (o.getLocalName().equals(OPERATION) + && (o.getValue().equals(DELETE_EDIT_CONFIG) || o.getValue() + .equals(REMOVE_EDIT_CONFIG))) { + return true; + } + + } + + for (final XmlElement xmlElement : element.getChildElements()) { + if (containsDelete(xmlElement)) { + return true; + } + + } + + return false; + } +} diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedGet.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedGet.java index b1938c8332..1c24213ca7 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedGet.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedGet.java @@ -19,13 +19,23 @@ import org.w3c.dom.Element; class SimulatedGet extends AbstractConfigNetconfOperation { - SimulatedGet(final String netconfSessionIdForReporting) { + private final DataList storage; + + SimulatedGet(final String netconfSessionIdForReporting, final DataList storage) { super(null, netconfSessionIdForReporting); + this.storage = storage; } @Override protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException { - return XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.absent()); + final Element element = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.absent()); + + for(final XmlElement e : storage.getConfigList()) { + final Element domElement = e.getDomElement(); + element.appendChild(element.getOwnerDocument().importNode(domElement, true)); + } + + return element; } @Override diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedGetConfig.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedGetConfig.java new file mode 100644 index 0000000000..cc1258eee4 --- /dev/null +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/SimulatedGetConfig.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.controller.netconf.test.tool; + +import com.google.common.base.Optional; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation; +import org.opendaylight.controller.netconf.util.xml.XmlElement; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +class SimulatedGetConfig extends AbstractConfigNetconfOperation { + + private final DataList storage; + + SimulatedGetConfig(final String netconfSessionIdForReporting, final DataList storage) { + super(null, netconfSessionIdForReporting); + this.storage = storage; + } + + @Override + protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement) throws NetconfDocumentedException { + final Element element = XmlUtil.createElement(document, XmlNetconfConstants.DATA_KEY, Optional.absent()); + + for(final XmlElement e : storage.getConfigList()) { + final Element domElement = e.getDomElement(); + element.appendChild(element.getOwnerDocument().importNode(domElement, true)); + } + + return element; + } + + @Override + protected String getOperationName() { + return XmlNetconfConstants.GET_CONFIG; + } +} -- 2.36.6