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 org.w3c.dom.Element;
18 import static org.mockito.Mockito.doNothing;
19 import static org.mockito.Mockito.doThrow;
20 import static org.mockito.Mockito.mock;
22 public class DefaultCloseSessionTest {
24 public void testDefaultCloseSession() throws Exception {
25 AutoCloseable res = mock(AutoCloseable.class);
26 doNothing().when(res).close();
27 DefaultCloseSession session = new DefaultCloseSession("", res);
28 Document doc = XmlUtil.newDocument();
29 XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
30 session.handleWithNoSubsequentOperations(doc, elem);
33 @Test(expected = NetconfDocumentedException.class)
34 public void testDefaultCloseSession2() throws Exception {
35 AutoCloseable res = mock(AutoCloseable.class);
36 doThrow(NetconfDocumentedException.class).when(res).close();
37 DefaultCloseSession session = new DefaultCloseSession("", res);
38 Document doc = XmlUtil.newDocument();
39 XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
40 session.handleWithNoSubsequentOperations(doc, elem);