BUG-50 : added test for Open Message.
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / ServerSessionMock.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.protocol.pcep.impl;
9
10 import static org.mockito.Mockito.mock;
11 import io.netty.channel.Channel;
12 import io.netty.util.HashedWheelTimer;
13
14 import java.util.concurrent.Future;
15
16 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
17 import org.opendaylight.protocol.pcep.PCEPSessionListener;
18 import org.opendaylight.protocol.pcep.TerminationReason;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
21
22 import com.google.common.util.concurrent.Futures;
23
24 public class ServerSessionMock extends PCEPSessionImpl {
25
26         private final MockPCE client;
27
28         public ServerSessionMock(final PCEPSessionListener listener, final PCEPSessionListener client) {
29                 super(new HashedWheelTimer(), listener, 5, mock(Channel.class), new OpenBuilder().setKeepalive((short) 4).setDeadTimer((short) 9).setSessionId(
30                                 (short) 2).build(), new OpenBuilder().setKeepalive((short) 4).setDeadTimer((short) 9).setSessionId((short) 2).build());
31                 this.client = (MockPCE) client;
32         }
33
34         @Override
35         public Future<Void> sendMessage(final Message msg) {
36                 this.lastMessageSentAt = System.nanoTime();
37                 this.client.onMessage(this, msg);
38                 return Futures.immediateFuture(null);
39         }
40
41         @Override
42         public void close() {
43                 this.client.onSessionTerminated(this, new PCEPCloseTermination(TerminationReason.Unknown));
44         }
45 }