2 * Copyright 2018-present Open Networking Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package io.atomix.utils.net;
18 import org.junit.Ignore;
19 import org.junit.Test;
21 import static org.junit.Assert.assertEquals;
26 public class AddressTest {
28 public void testIPv4Address() throws Exception {
29 Address address = Address.from("127.0.0.1:5000");
30 assertEquals("127.0.0.1", address.host());
31 assertEquals(5000, address.port());
32 assertEquals("localhost", address.address().getHostName());
33 assertEquals("127.0.0.1:5000", address.toString());
37 public void testIPv6Address() throws Exception {
38 Address address = Address.from("[fe80:cd00:0000:0cde:1257:0000:211e:729c]:5000");
39 assertEquals("fe80:cd00:0000:0cde:1257:0000:211e:729c", address.host());
40 assertEquals(5000, address.port());
41 assertEquals("fe80:cd00:0:cde:1257:0:211e:729c", address.address().getHostName());
42 assertEquals("[fe80:cd00:0000:0cde:1257:0000:211e:729c]:5000", address.toString());
47 public void testResolveAddress() throws Exception {
48 Address address = Address.from("localhost", 5000);
49 assertEquals("127.0.0.1", address.address().getHostAddress());
50 assertEquals(5000, address.port());