Remove netconf from commons/opendaylight pom
[controller.git] / opendaylight / netconf / netconf-util / src / test / java / org / opendaylight / controller / netconf / util / messages / SendErrorExceptionUtilTest.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.util.messages;
10
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;
16
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.config.util.xml.DocumentedException;
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;
27
28 public class SendErrorExceptionUtilTest {
29
30     NetconfSession netconfSession;
31     ChannelFuture channelFuture;
32     Channel channel;
33     private DocumentedException exception;
34
35     @Before
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 DocumentedException("err");
44     }
45
46     @Test
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));
51     }
52
53     @Test
54     public void testSendErrorMessage2() throws Exception {
55         SendErrorExceptionUtil.sendErrorMessage(channel, exception);
56         verify(channelFuture, times(1)).addListener(any(GenericFutureListener.class));
57     }
58
59     @Test
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));
64     }
65 }