Improve NETCONF session ID handling
[netconf.git] / protocol / netconf-server / src / test / java / org / opendaylight / netconf / server / api / operations / 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 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.doReturn;
13 import static org.mockito.Mockito.mock;
14
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.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
20 import org.opendaylight.yangtools.yang.common.Uint32;
21 import org.w3c.dom.Document;
22 import org.w3c.dom.Element;
23
24 public class AbstractLastNetconfOperationTest {
25     private static final class LastNetconfOperationImplTest extends AbstractLastNetconfOperation {
26         boolean handleWithNoSubsequentOperationsRun;
27
28         protected LastNetconfOperationImplTest(final SessionIdType sessionId) {
29             super(sessionId);
30             handleWithNoSubsequentOperationsRun = false;
31         }
32
33         @Override
34         protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement operationElement)
35                 throws DocumentedException {
36             handleWithNoSubsequentOperationsRun = true;
37             return null;
38         }
39
40         @Override
41         protected String getOperationName() {
42             return "";
43         }
44     }
45
46     LastNetconfOperationImplTest netconfOperation;
47
48     @Before
49     public void setUp() throws Exception {
50         netconfOperation = new LastNetconfOperationImplTest(new SessionIdType(Uint32.ONE));
51     }
52
53     @Test
54     public void testNetconfOperation() throws Exception {
55         netconfOperation.handleWithNoSubsequentOperations(null, null);
56         assertTrue(netconfOperation.handleWithNoSubsequentOperationsRun);
57         assertEquals(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY, netconfOperation.getHandlingPriority());
58     }
59
60     @Test(expected = DocumentedException.class)
61     public void testHandle() throws Exception {
62         NetconfOperationChainedExecution operation = mock(NetconfOperationChainedExecution.class);
63         doReturn("").when(operation).toString();
64
65         doReturn(false).when(operation).isExecutionTermination();
66         netconfOperation.handle(null, null, operation);
67     }
68 }