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.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.netconf.api.DocumentedException;
20 import org.opendaylight.netconf.api.xml.XmlElement;
21 import org.opendaylight.netconf.api.xml.XmlUtil;
22 import org.opendaylight.netconf.mapping.api.HandlingPriority;
23 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
24 import org.opendaylight.netconf.util.test.XmlFileLoader;
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Element;
27 import org.xml.sax.SAXException;
29 public class AbstractNetconfOperationTest {
30 static class NetconfOperationImpl extends AbstractNetconfOperation {
31 public boolean handleRun;
33 protected NetconfOperationImpl(final String netconfSessionIdForReporting) {
34 super(netconfSessionIdForReporting);
35 this.handleRun = false;
39 protected String getOperationName() {
44 protected Element handle(final Document document, final XmlElement message,
45 final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
46 this.handleRun = true;
48 return XmlUtil.readXmlToElement("<element/>");
49 } catch (SAXException | IOException e) {
50 throw DocumentedException.wrap(e);
55 private final NetconfOperationImpl netconfOperation = new NetconfOperationImpl("str");
56 private NetconfOperationChainedExecution operation;
59 public void setUp() throws Exception {
60 operation = mock(NetconfOperationChainedExecution.class);
64 public void testAbstractNetconfOperation() throws Exception {
65 Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/edit_config.xml");
66 assertEquals(netconfOperation.getNetconfSessionIdForReporting(), "str");
67 assertNotNull(netconfOperation.canHandle(helloMessage));
68 assertEquals(netconfOperation.getHandlingPriority(), HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY);
70 netconfOperation.handle(helloMessage, operation);
71 assertTrue(netconfOperation.handleRun);