BUG-5619 Enable maven parallel build for bgpcep I
[bgpcep.git] / pcep / pcc-mock / src / test / java / org / opendaylight / protocol / pcep / pcc / mock / PCCMockTest.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.pcc.mock;
10
11 import io.netty.channel.Channel;
12 import java.lang.reflect.Constructor;
13 import java.lang.reflect.InvocationTargetException;
14 import java.net.InetSocketAddress;
15 import java.util.Collections;
16 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.protocol.pcep.PCEPCapability;
19 import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
20 import org.opendaylight.protocol.util.InetSocketAddressUtil;
21
22 public final class PCCMockTest extends PCCMockCommon {
23     private final String[] mainInput = new String[] {"--local-address", this.localAddress.getHostString(), "--remote-address",
24         InetSocketAddressUtil.toHostAndPort(this.remoteAddress).toString(), "--pcc", "1", "--lsp", "3", "--log-level", "DEBUG", "-ka", "10", "-d", "40", "--reconnect", "-1",
25         "--redelegation-timeout", "0", "--state-timeout", "-1"};
26
27     @Test
28     public void testSessionEstablishment() throws Exception {
29         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
30         final Channel channel = createServer(factory, this.remoteAddress);
31         Main.main(mainInput);
32         Thread.sleep(1000);
33         //3 reported LSPs + syc
34         final int numMessages = 4;
35         final TestingSessionListener sessionListener = checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
36         checkSession(sessionListener.getSession(), 40, 10);
37     }
38
39
40     @Test
41     public void testMockPCCToManyPCE() throws Exception {
42         final String localAddress2 = "127.0.0.2";
43         final InetSocketAddress serverAddress2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
44         final InetSocketAddress serverAddress3 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
45         final InetSocketAddress serverAddress4 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
46
47         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
48         final TestingSessionListenerFactory factory2 = new TestingSessionListenerFactory();
49         final TestingSessionListenerFactory factory3 = new TestingSessionListenerFactory();
50         final Channel channel = createServer(factory, serverAddress2);
51         final Channel channel2 = createServer(factory2, serverAddress3);
52         final Channel channel3 = createServer(factory3, serverAddress4);
53
54         Main.main(new String[] {"--local-address", this.localAddress.getHostString(), "--remote-address",
55                 InetSocketAddressUtil.toHostAndPort(serverAddress2).toString() + "," +
56                 InetSocketAddressUtil.toHostAndPort(serverAddress3).toString() + "," +
57                 InetSocketAddressUtil.toHostAndPort(serverAddress4).toString(),
58             "--pcc", "2"});
59         Thread.sleep(1000);
60         //PCE1
61         int numMessages = 2;
62         checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
63         checkSessionListener(numMessages, channel, factory, localAddress2);
64         //PCE2
65         checkSessionListener(numMessages, channel2, factory2, this.localAddress.getHostString());
66         checkSessionListener(numMessages, channel2, factory2, localAddress2);
67         //PCE3
68         checkSessionListener(numMessages, channel3, factory3, this.localAddress.getHostString());
69         checkSessionListener(numMessages, channel3, factory3, localAddress2);
70     }
71
72     @Test(expected = UnsupportedOperationException.class)
73     public void testPrivateConstructor() throws Throwable {
74         final Constructor<MsgBuilderUtil> c = MsgBuilderUtil.class.getDeclaredConstructor();
75         c.setAccessible(true);
76         try {
77             c.newInstance();
78         } catch (final InvocationTargetException e) {
79             throw e.getCause();
80         }
81     }
82
83     @Override
84     protected List<PCEPCapability> getCapabilities() {
85         return Collections.emptyList();
86     }
87 }