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.util.messages;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
17 import io.netty.channel.Channel;
18 import io.netty.channel.ChannelFuture;
19 import io.netty.util.concurrent.GenericFutureListener;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
23 import org.opendaylight.controller.netconf.api.NetconfMessage;
24 import org.opendaylight.controller.netconf.api.NetconfSession;
25 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
26 import org.w3c.dom.Document;
28 public class SendErrorExceptionUtilTest {
30 NetconfSession netconfSession;
31 ChannelFuture channelFuture;
33 private NetconfDocumentedException exception;
36 public void setUp() throws Exception {
37 netconfSession = mock(NetconfSession.class);
38 channelFuture = mock(ChannelFuture.class);
39 channel = mock(Channel.class);
40 doReturn(channelFuture).when(netconfSession).sendMessage(any(NetconfMessage.class));
41 doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
42 doReturn(channelFuture).when(channel).writeAndFlush(any(NetconfMessage.class));
43 exception = new NetconfDocumentedException("err");
47 public void testSendErrorMessage1() throws Exception {
48 SendErrorExceptionUtil.sendErrorMessage(netconfSession, exception);
49 verify(channelFuture, times(1)).addListener(any(GenericFutureListener.class));
50 verify(netconfSession, times(1)).sendMessage(any(NetconfMessage.class));
54 public void testSendErrorMessage2() throws Exception {
55 SendErrorExceptionUtil.sendErrorMessage(channel, exception);
56 verify(channelFuture, times(1)).addListener(any(GenericFutureListener.class));
60 public void testSendErrorMessage3() throws Exception {
61 Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc.xml");
62 SendErrorExceptionUtil.sendErrorMessage(netconfSession, exception, new NetconfMessage(helloMessage));
63 verify(channelFuture, times(1)).addListener(any(GenericFutureListener.class));