Import atomix/{storage,utils}
[controller.git] / third-party / atomix / utils / src / test / java / io / atomix / utils / net / AddressTest.java
1 /*
2  * Copyright 2018-present Open Networking Foundation
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package io.atomix.utils.net;
17
18 import org.junit.Ignore;
19 import org.junit.Test;
20
21 import static org.junit.Assert.assertEquals;
22
23 /**
24  * Address test.
25  */
26 public class AddressTest {
27   @Test
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());
34   }
35
36   @Test
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());
43   }
44
45   @Test
46   @Ignore
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());
51   }
52 }