BUG-6647 Increase code coverage and clean up I
[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.concurrent.Future;
13 import io.netty.util.concurrent.GlobalEventExecutor;
14
15 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
16 import org.opendaylight.protocol.pcep.PCEPSessionListener;
17 import org.opendaylight.protocol.pcep.TerminationReason;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
20
21 public class ServerSessionMock extends PCEPSessionImpl {
22
23     private final MockPCE client;
24
25     public ServerSessionMock(final PCEPSessionListener listener, final PCEPSessionListener client) {
26         super(listener, 5, mock(Channel.class), new OpenBuilder().setKeepalive((short) 4).setDeadTimer((short) 9).setSessionId(
27                 (short) 2).build(), new OpenBuilder().setKeepalive((short) 4).setDeadTimer((short) 9).setSessionId((short) 2).build());
28         this.client = (MockPCE) client;
29     }
30
31     @Override
32     public Future<Void> sendMessage(final Message msg) {
33         this.lastMessageSentAt = System.nanoTime();
34         this.client.onMessage(this, msg);
35         return GlobalEventExecutor.INSTANCE.newSucceededFuture(null);
36     }
37
38     @Override
39     public void close() {
40         this.client.onSessionTerminated(this, new PCEPCloseTermination(TerminationReason.UNKNOWN));
41     }
42 }