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
8 package org.opendaylight.netconf.server.api.operations;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Mockito.mock;
15 import java.io.IOException;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.netconf.api.DocumentedException;
19 import org.opendaylight.netconf.api.xml.XmlElement;
20 import org.opendaylight.netconf.api.xml.XmlUtil;
21 import org.opendaylight.netconf.util.test.XmlFileLoader;
22 import org.w3c.dom.Document;
23 import org.w3c.dom.Element;
24 import org.xml.sax.SAXException;
26 public class AbstractNetconfOperationTest {
27 private static class NetconfOperationImpl extends AbstractNetconfOperation {
28 public boolean handleRun;
30 NetconfOperationImpl(final String netconfSessionIdForReporting) {
31 super(netconfSessionIdForReporting);
35 protected String getOperationName() {
40 protected Element handle(final Document document, final XmlElement message,
41 final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
44 return XmlUtil.readXmlToElement("<element/>");
45 } catch (SAXException | IOException e) {
46 throw DocumentedException.wrap(e);
51 private final NetconfOperationImpl netconfOperation = new NetconfOperationImpl("str");
52 private NetconfOperationChainedExecution operation;
55 public void setUp() throws Exception {
56 operation = mock(NetconfOperationChainedExecution.class);
60 public void testAbstractNetconfOperation() throws Exception {
61 Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/edit_config.xml");
62 assertEquals(netconfOperation.getNetconfSessionIdForReporting(), "str");
63 assertNotNull(netconfOperation.canHandle(helloMessage));
64 assertEquals(netconfOperation.getHandlingPriority(), HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY);
66 netconfOperation.handle(helloMessage, operation);
67 assertTrue(netconfOperation.handleRun);