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
9 package org.opendaylight.controller.netconf.impl.mapping.operations;
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;
20 public class DefaultCloseSessionTest {
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);
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);