import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoop;
import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GenericFutureListener;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.mockito.internal.util.collections.Sets;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
import org.opendaylight.netconf.util.messages.NetconfHelloMessage;
import org.opendaylight.netconf.api.NetconfMessage;
public void setUp() throws Exception {
channel = mock(Channel.class);
channelFuture = mock(ChannelFuture.class);
+ mockEventLoop();
doReturn(channelFuture).when(channel).writeAndFlush(anyObject());
+ doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
caps = Sets.newSet("a", "b");
helloMessage = NetconfHelloMessage.createServerHello(caps, 10);
message = new NetconfMessage(helloMessage.getDocument());
clientSession = new NetconfClientSession(sessionListener, channel, 20L, caps);
}
+ private void mockEventLoop() {
+ final EventLoop eventLoop = mock(EventLoop.class);
+ doReturn(eventLoop).when(channel).eventLoop();
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ final Object[] args = invocation.getArguments();
+ final Runnable runnable = (Runnable) args[0];
+ runnable.run();
+ return null;
+ }
+ }).when(eventLoop).execute(any(Runnable.class));
+ }
+
@Test
public void testSessionDown() throws Exception {
SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();