Move netconf-dom-api
[netconf.git] / netconf / netconf-util / src / test / java / org / opendaylight / netconf / util / mapping / AbstractLastNetconfOperationTest.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
9 package org.opendaylight.netconf.util.mapping;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15
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.mapping.api.HandlingPriority;
21 import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution;
22 import org.w3c.dom.Document;
23 import org.w3c.dom.Element;
24
25 public class AbstractLastNetconfOperationTest {
26     class LastNetconfOperationImplTest extends AbstractLastNetconfOperation {
27
28         boolean handleWithNoSubsequentOperationsRun;
29
30         protected LastNetconfOperationImplTest(String netconfSessionIdForReporting) {
31             super(netconfSessionIdForReporting);
32             handleWithNoSubsequentOperationsRun = false;
33         }
34
35         @Override
36         protected Element handleWithNoSubsequentOperations(Document document,
37                                                            XmlElement operationElement) throws DocumentedException {
38             handleWithNoSubsequentOperationsRun = true;
39             return null;
40         }
41
42         @Override
43         protected String getOperationName() {
44             return "";
45         }
46     }
47
48     LastNetconfOperationImplTest netconfOperation;
49
50     @Before
51     public void setUp() throws Exception {
52         netconfOperation = new LastNetconfOperationImplTest("");
53     }
54
55     @Test
56     public void testNetconfOperation() throws Exception {
57         netconfOperation.handleWithNoSubsequentOperations(null, null);
58         assertTrue(netconfOperation.handleWithNoSubsequentOperationsRun);
59         assertEquals(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY, netconfOperation.getHandlingPriority());
60     }
61
62     @Test(expected = DocumentedException.class)
63     public void testHandle() throws Exception {
64         NetconfOperationChainedExecution operation = mock(NetconfOperationChainedExecution.class);
65         doReturn("").when(operation).toString();
66
67         doReturn(false).when(operation).isExecutionTermination();
68         netconfOperation.handle(null, null, operation);
69     }
70 }