Eliminate HandlingPriority.CANNOT_HANDLE
[netconf.git] / protocol / netconf-server / src / test / java / org / opendaylight / netconf / server / api / operations / AbstractNetconfOperationTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.server.api.operations;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.Mockito.mock;
13
14 import java.io.IOException;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.netconf.api.DocumentedException;
18 import org.opendaylight.netconf.api.xml.XmlElement;
19 import org.opendaylight.netconf.api.xml.XmlUtil;
20 import org.opendaylight.netconf.test.util.XmlFileLoader;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
22 import org.opendaylight.yangtools.yang.common.Uint32;
23 import org.w3c.dom.Document;
24 import org.w3c.dom.Element;
25 import org.xml.sax.SAXException;
26
27 public class AbstractNetconfOperationTest {
28     private static class NetconfOperationImpl extends AbstractNetconfOperation {
29         public boolean handleRun;
30
31         NetconfOperationImpl(final SessionIdType sessionId) {
32             super(sessionId);
33         }
34
35         @Override
36         protected String getOperationName() {
37             return "edit-config";
38         }
39
40         @Override
41         protected Element handle(final Document document, final XmlElement message,
42                 final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
43             handleRun = true;
44             try {
45                 return XmlUtil.readXmlToElement("<element/>");
46             } catch (SAXException | IOException e) {
47                 throw DocumentedException.wrap(e);
48             }
49         }
50     }
51
52     private final NetconfOperationImpl netconfOperation = new NetconfOperationImpl(new SessionIdType(Uint32.ONE));
53     private NetconfOperationChainedExecution operation;
54
55     @Before
56     public void setUp() throws Exception {
57         operation = mock(NetconfOperationChainedExecution.class);
58     }
59
60     @Test
61     public void testAbstractNetconfOperation() throws Exception {
62         Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/edit_config.xml");
63         assertEquals(new SessionIdType(Uint32.ONE), netconfOperation.sessionId());
64         assertEquals(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY, netconfOperation.canHandle(helloMessage));
65
66         netconfOperation.handle(helloMessage, operation);
67         assertTrue(netconfOperation.handleRun);
68     }
69 }