2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.util.mapping;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.mockito.Mockito.mock;
16 import java.io.IOException;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
20 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
21 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;
22 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
23 import org.opendaylight.controller.netconf.util.xml.XmlElement;
24 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Element;
27 import org.xml.sax.SAXException;
29 public class AbstractNetconfOperationTest {
31 class NetconfOperationImpl extends AbstractNetconfOperation {
33 public boolean handleRun;
35 protected NetconfOperationImpl(String netconfSessionIdForReporting) {
36 super(netconfSessionIdForReporting);
37 this.handleRun = false;
41 protected String getOperationName() {
46 protected Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException {
47 this.handleRun = true;
49 return XmlUtil.readXmlToElement("<element/>");
50 } catch (SAXException | IOException e) {
51 throw new RuntimeException(e);
56 private NetconfOperationImpl netconfOperation;
57 private NetconfOperationChainedExecution operation;
60 public void setUp() throws Exception {
61 netconfOperation = new NetconfOperationImpl("str");
62 operation = mock(NetconfOperationChainedExecution.class);
66 public void testAbstractNetconfOperation() throws Exception {
67 Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/edit_config.xml");
68 assertEquals(netconfOperation.getNetconfSessionIdForReporting(), "str");
69 assertNotNull(netconfOperation.canHandle(helloMessage));
70 assertEquals(netconfOperation.getHandlingPriority(), HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY);
72 netconfOperation.handle(helloMessage, operation);
73 assertTrue(netconfOperation.handleRun);