2 * Copyright (c) 2016 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
9 package org.opendaylight.protocol.util;
11 import static org.junit.Assert.assertEquals;
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;
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;
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);
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);
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);
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));