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