BUG-5619 Enable maven parallel build for bgpcep I
[bgpcep.git] / testtool-util / src / test / java / org / opendaylight / protocol / util / InetSocketAddressUtilTest.java
1 /*
2  * Copyright (c) 2016 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.util;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
13 import static org.junit.Assert.assertNotNull;
14
15 import java.net.InetSocketAddress;
16 import java.util.Arrays;
17 import java.util.List;
18 import org.junit.Assert;
19 import org.junit.Test;
20
21 public class InetSocketAddressUtilTest {
22     private static String ADDRESS1 = "1.1.1.1";
23     private static String ADDRESS2 = "2.2.2.2";
24     private static int PORT1 = 123;
25     private static int PORT2 = 321;
26     private static String ADDRESSES_WO_PORT = ADDRESS1 + "," + ADDRESS2;
27     private static String ADDRESSES = ADDRESS1 + ":" + PORT1 + "," + ADDRESS2 + ":" + PORT2;
28     private static int DEFAULT_PORT = 179;
29
30     @Test
31     public void parseAddresses() throws Exception {
32         final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES, DEFAULT_PORT);
33         Assert.assertEquals(Arrays.asList(new InetSocketAddress(ADDRESS1, PORT1), new InetSocketAddress(ADDRESS2, PORT2)), actualResult);
34     }
35
36     @Test
37     public void parseAddressesDefaultPort() throws Exception {
38         final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES_WO_PORT, DEFAULT_PORT);
39         final List<InetSocketAddress> expected = Arrays.asList(new InetSocketAddress(ADDRESS1, DEFAULT_PORT), new InetSocketAddress(ADDRESS2, DEFAULT_PORT));
40         Assert.assertEquals(expected, actualResult);
41     }
42
43     @Test
44     public void parseAddressesWithoutPort() throws Exception {
45         final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES);
46         Assert.assertEquals(Arrays.asList(new InetSocketAddress(ADDRESS1, PORT1), new InetSocketAddress(ADDRESS2, PORT2)), actualResult);
47     }
48
49     @Test
50     public void getInetSocketAddress() throws Exception {
51         assertEquals(new InetSocketAddress(ADDRESS1, PORT1), InetSocketAddressUtil.getInetSocketAddress(ADDRESS1 + ":" + PORT1, DEFAULT_PORT));
52         assertEquals(new InetSocketAddress(ADDRESS1, DEFAULT_PORT), InetSocketAddressUtil.getInetSocketAddress(ADDRESS1, DEFAULT_PORT));
53     }
54
55     @Test
56     public void getRandomLoopbackInetSocketAddressTest() throws Exception {
57         final InetSocketAddress addr1 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
58         final InetSocketAddress addr2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
59         assertNotNull(addr1);
60         assertNotNull(addr2);
61         assertNotEquals(addr1, addr2);
62         assertNotEquals(addr1.getHostString(), addr2.getHostString());
63         assertNotEquals(addr1.getPort(), addr2.getPort());
64     }
65 }