d6b0201ab88a0245e666b4bb7fe2e77552a0075b
[controller.git] / opendaylight / netconf / netconf-impl / src / test / java / org / opendaylight / controller / netconf / impl / mapping / operations / DefaultCloseSessionTest.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.controller.netconf.impl.mapping.operations;
10
11 import org.junit.Test;
12 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
13 import org.opendaylight.controller.netconf.util.xml.XmlElement;
14 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
15 import org.w3c.dom.Document;
16 import static org.mockito.Mockito.doNothing;
17 import static org.mockito.Mockito.doThrow;
18 import static org.mockito.Mockito.mock;
19
20 public class DefaultCloseSessionTest {
21     @Test
22     public void testDefaultCloseSession() throws Exception {
23         AutoCloseable res = mock(AutoCloseable.class);
24         doNothing().when(res).close();
25         DefaultCloseSession session = new DefaultCloseSession("", res);
26         Document doc = XmlUtil.newDocument();
27         XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
28         session.handleWithNoSubsequentOperations(doc, elem);
29     }
30
31     @Test(expected = NetconfDocumentedException.class)
32     public void testDefaultCloseSession2() throws Exception {
33         AutoCloseable res = mock(AutoCloseable.class);
34         doThrow(NetconfDocumentedException.class).when(res).close();
35         DefaultCloseSession session = new DefaultCloseSession("", res);
36         Document doc = XmlUtil.newDocument();
37         XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
38         session.handleWithNoSubsequentOperations(doc, elem);
39     }
40 }