X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fmapping%2FAbstractNetconfOperationTest.java;fp=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fmapping%2FAbstractNetconfOperationTest.java;h=ea4a6e61f23aecd32e2a4261438d5e46f416d328;hb=c9be0a11c57251c8586a3cdfc5401654e1dba21d;hp=0000000000000000000000000000000000000000;hpb=796c16ce147d8a13a95767cca304a1e4cf5193d8;p=controller.git diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperationTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperationTest.java new file mode 100644 index 0000000000..ea4a6e61f2 --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperationTest.java @@ -0,0 +1,75 @@ +/* + * 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.util.mapping; + +import java.io.IOException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; +import org.opendaylight.controller.netconf.util.test.XmlFileLoader; +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; +import org.xml.sax.SAXException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +public class AbstractNetconfOperationTest { + + class NetconfOperationImpl extends AbstractNetconfOperation { + + public boolean handleRun; + + protected NetconfOperationImpl(String netconfSessionIdForReporting) { + super(netconfSessionIdForReporting); + this.handleRun = false; + } + + @Override + protected String getOperationName() { + return null; + } + + @Override + protected Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException { + this.handleRun = true; + try { + return XmlUtil.readXmlToElement(""); + } catch (SAXException | IOException e) { + throw new RuntimeException(e); + } + } + } + + private NetconfOperationImpl netconfOperation; + private NetconfOperationChainedExecution operation; + + @Before + public void setUp() throws Exception { + netconfOperation = new NetconfOperationImpl("str"); + operation = mock(NetconfOperationChainedExecution.class); + } + + @Test + public void testAbstractNetconfOperation() throws Exception { + Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/edit_config.xml"); + assertEquals(netconfOperation.getNetconfSessionIdForReporting(), "str"); + assertNotNull(netconfOperation.canHandle(helloMessage)); + assertEquals(netconfOperation.getHandlingPriority(), HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY); + + netconfOperation.handle(helloMessage, operation); + assertTrue(netconfOperation.handleRun); + } +}