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.test.util.XmlFileLoader;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
23 import org.opendaylight.yangtools.yang.common.Uint32;
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26 import org.xml.sax.SAXException;
28 public class AbstractNetconfOperationTest {
29 private static class NetconfOperationImpl extends AbstractNetconfOperation {
30 public boolean handleRun;
32 NetconfOperationImpl(final SessionIdType sessionId) {
37 protected String getOperationName() {
42 protected Element handle(final Document document, final XmlElement message,
43 final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
46 return XmlUtil.readXmlToElement("<element/>");
47 } catch (SAXException | IOException e) {
48 throw DocumentedException.wrap(e);
53 private final NetconfOperationImpl netconfOperation = new NetconfOperationImpl(new SessionIdType(Uint32.ONE));
54 private NetconfOperationChainedExecution operation;
57 public void setUp() throws Exception {
58 operation = mock(NetconfOperationChainedExecution.class);
62 public void testAbstractNetconfOperation() throws Exception {
63 Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/edit_config.xml");
64 assertEquals(new SessionIdType(Uint32.ONE), netconfOperation.sessionId());
65 assertNotNull(netconfOperation.canHandle(helloMessage));
66 assertEquals(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY, netconfOperation.getHandlingPriority());
68 netconfOperation.handle(helloMessage, operation);
69 assertTrue(netconfOperation.handleRun);