BUG-5790: BGP Test tool
[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
13 import java.net.InetSocketAddress;
14 import java.util.Arrays;
15 import java.util.List;
16 import org.junit.Assert;
17 import org.junit.Test;
18
19 public class InetSocketAddressUtilTest {
20     private static String ADDRESS1 = "1.1.1.1";
21     private static String ADDRESS2 = "2.2.2.2";
22     private static int PORT1 = 123;
23     private static int PORT2 = 321;
24     private static String ADDRESSES_WO_PORT = ADDRESS1 + "," + ADDRESS2;
25     private static String ADDRESSES = ADDRESS1 + ":" + PORT1 + "," + ADDRESS2 + ":" + PORT2;
26     private static int DEFAULT_PORT = 179;
27
28     @Test
29     public void parseAddresses() throws Exception {
30         final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES, DEFAULT_PORT);
31         Assert.assertEquals(Arrays.asList(new InetSocketAddress(ADDRESS1, PORT1), new InetSocketAddress(ADDRESS2, PORT2)), actualResult);
32     }
33
34     @Test
35     public void parseAddressesDefaultPort() throws Exception {
36         final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES_WO_PORT, DEFAULT_PORT);
37         final List<InetSocketAddress> expected = Arrays.asList(new InetSocketAddress(ADDRESS1, DEFAULT_PORT), new InetSocketAddress(ADDRESS2, DEFAULT_PORT));
38         Assert.assertEquals(expected, actualResult);
39     }
40
41     @Test
42     public void parseAddressesWithoutPort() throws Exception {
43         final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES);
44         Assert.assertEquals(Arrays.asList(new InetSocketAddress(ADDRESS1, PORT1), new InetSocketAddress(ADDRESS2, PORT2)), actualResult);
45     }
46
47     @Test
48     public void getInetSocketAddress() throws Exception {
49         assertEquals(new InetSocketAddress(ADDRESS1, PORT1), InetSocketAddressUtil.getInetSocketAddress(ADDRESS1 + ":" + PORT1, DEFAULT_PORT));
50         assertEquals(new InetSocketAddress(ADDRESS1, DEFAULT_PORT), InetSocketAddressUtil.getInetSocketAddress(ADDRESS1, DEFAULT_PORT));
51     }
52 }