2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.testtool;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
14 import org.junit.Test;
15 import org.opendaylight.protocol.util.InetSocketAddressUtil;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.KeepaliveMessage;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
20 public class PCEPTestingToolTest {
23 public void testSessionEstablishment() throws Exception {
24 final String serverAddr = InetSocketAddressUtil
25 .toHostAndPort(InetSocketAddressUtil.getRandomLoopbackInetSocketAddress()).toString();
26 Main.main(new String[] {"-a", serverAddr,
27 "-ka", "10", "-d", "0", "--stateful", "--active", "--instant"});
28 PCCMock.main(new String[] {serverAddr});
32 public void testSimpleSessionListener() {
33 final TestingSessionListener ssl = new TestingSessionListener();
34 assertEquals(0, ssl.messages().size());
35 ssl.onMessage(null, new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build());
36 assertEquals(1, ssl.messages().size());
37 assertTrue(ssl.messages().get(0) instanceof KeepaliveMessage);
38 assertFalse(ssl.isUp());
39 ssl.onSessionUp(null);
40 assertTrue(ssl.isUp());
41 ssl.onSessionDown(null, null);
42 assertFalse(ssl.isUp());