Merge "Bug-1517: Introduce topology data-change counter"
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / AbstractPCEPSessionTest.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.protocol.pcep.impl;
10
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doAnswer;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15
16 import com.google.common.collect.Lists;
17 import io.netty.channel.Channel;
18 import io.netty.channel.ChannelFuture;
19 import io.netty.channel.ChannelHandler;
20 import io.netty.channel.ChannelPipeline;
21 import io.netty.channel.DefaultChannelPromise;
22 import io.netty.channel.EventLoop;
23 import io.netty.util.concurrent.ScheduledFuture;
24 import java.net.InetSocketAddress;
25 import java.net.SocketAddress;
26 import java.util.List;
27 import java.util.concurrent.TimeUnit;
28 import org.junit.Before;
29 import org.mockito.Mock;
30 import org.mockito.MockitoAnnotations;
31 import org.mockito.invocation.InvocationOnMock;
32 import org.mockito.stubbing.Answer;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Open;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.OpenBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.OpenMessageBuilder;
39 import org.opendaylight.yangtools.yang.binding.Notification;
40
41 public class AbstractPCEPSessionTest {
42
43     @Mock
44     protected Channel channel;
45
46     @Mock
47     private EventLoop eventLoop;
48
49     @Mock
50     private ScheduledFuture<?> future;
51
52     @Mock
53     private ChannelPipeline pipeline;
54
55     @Mock
56     private SocketAddress address;
57
58     protected final List<Notification> msgsSend = Lists.newArrayList();
59
60     protected Open openMsg;
61
62     protected Keepalive kaMsg;
63
64     protected SimpleSessionListener listener;
65
66     @Before
67     public final void setUp() {
68         MockitoAnnotations.initMocks(this);
69         final ChannelFuture future = new DefaultChannelPromise(this.channel);
70         doAnswer(new Answer<Object>() {
71             @Override
72             public Object answer(final InvocationOnMock invocation) {
73                 final Object[] args = invocation.getArguments();
74                 AbstractPCEPSessionTest.this.msgsSend.add((Notification) args[0]);
75                 return future;
76             }
77         }).when(this.channel).writeAndFlush(any(Notification.class));
78         doReturn("TestingChannel").when(this.channel).toString();
79         doReturn(this.pipeline).when(this.channel).pipeline();
80         doReturn(this.address).when(this.channel).localAddress();
81         doReturn(this.address).when(this.channel).remoteAddress();
82         doReturn(this.eventLoop).when(this.channel).eventLoop();
83         doReturn(true).when(this.future).cancel(false);
84         doReturn(this.future).when(this.eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
85         doReturn(this.pipeline).when(this.pipeline).replace(any(ChannelHandler.class), any(String.class), any(ChannelHandler.class));
86         doReturn(true).when(this.channel).isActive();
87         doReturn(mock(ChannelFuture.class)).when(this.channel).close();
88         doReturn(InetSocketAddress.createUnresolved("127.0.0.1", 4189)).when(this.channel).remoteAddress();
89         doReturn(InetSocketAddress.createUnresolved("127.0.0.1", 4189)).when(this.channel).localAddress();
90         this.openMsg = new OpenBuilder().setOpenMessage(
91                 new OpenMessageBuilder().setOpen(
92                         new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder().setDeadTimer(
93                                 (short) 45).setKeepalive((short) 15).build()).build()).build();
94         this.kaMsg = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
95
96         this.listener = new SimpleSessionListener();
97     }
98
99 }