|
| 1 | +/* |
| 2 | + * Copyright (c) 2002-2017 "Neo Technology," |
| 3 | + * Network Engine for Objects in Lund AB [http://neotechnology.com] |
| 4 | + * |
| 5 | + * This file is part of Neo4j. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | +package org.neo4j.driver.internal.net; |
| 20 | + |
| 21 | +import org.junit.Test; |
| 22 | +import org.junit.runner.RunWith; |
| 23 | +import org.junit.runners.Parameterized; |
| 24 | +import org.junit.runners.Parameterized.Parameter; |
| 25 | +import org.junit.runners.Parameterized.Parameters; |
| 26 | + |
| 27 | +import static org.junit.Assert.assertEquals; |
| 28 | +import static org.neo4j.driver.internal.net.BoltServerAddress.DEFAULT_PORT; |
| 29 | + |
| 30 | +@RunWith( Parameterized.class ) |
| 31 | +public class BoltServerAddressParsingTest |
| 32 | +{ |
| 33 | + @Parameter |
| 34 | + public String address; |
| 35 | + @Parameter( 1 ) |
| 36 | + public String expectedHost; |
| 37 | + @Parameter( 2 ) |
| 38 | + public int expectedPort; |
| 39 | + |
| 40 | + @Parameters( name = "{0}" ) |
| 41 | + public static Object[][] addressesToParse() |
| 42 | + { |
| 43 | + return new Object[][]{ |
| 44 | + // Hostname |
| 45 | + {"localhost", "localhost", DEFAULT_PORT}, |
| 46 | + {"localhost:9193", "localhost", 9193}, |
| 47 | + {"neo4j.com", "neo4j.com", DEFAULT_PORT}, |
| 48 | + {"royal-server.com.uk", "royal-server.com.uk", DEFAULT_PORT}, |
| 49 | + {"royal-server.com.uk:4546", "royal-server.com.uk", 4546}, |
| 50 | + |
| 51 | + // Hostname with scheme |
| 52 | + {"bolt://localhost", "localhost", DEFAULT_PORT}, |
| 53 | + {"bolt+routing://localhost", "localhost", DEFAULT_PORT}, |
| 54 | + {"bolt://localhost:9193", "localhost", 9193}, |
| 55 | + {"bolt+routing://localhost:9193", "localhost", 9193}, |
| 56 | + {"bolt://neo4j.com", "neo4j.com", DEFAULT_PORT}, |
| 57 | + {"bolt+routing://neo4j.com", "neo4j.com", DEFAULT_PORT}, |
| 58 | + {"bolt://royal-server.com.uk", "royal-server.com.uk", DEFAULT_PORT}, |
| 59 | + {"bolt+routing://royal-server.com.uk", "royal-server.com.uk", DEFAULT_PORT}, |
| 60 | + {"bolt://royal-server.com.uk:4546", "royal-server.com.uk", 4546}, |
| 61 | + {"bolt+routing://royal-server.com.uk:4546", "royal-server.com.uk", 4546}, |
| 62 | + |
| 63 | + // IPv4 |
| 64 | + {"127.0.0.1", "127.0.0.1", DEFAULT_PORT}, |
| 65 | + {"8.8.8.8:8080", "8.8.8.8", 8080}, |
| 66 | + {"0.0.0.0", "0.0.0.0", DEFAULT_PORT}, |
| 67 | + {"192.0.2.235:4329", "192.0.2.235", 4329}, |
| 68 | + {"172.31.255.255:255", "172.31.255.255", 255}, |
| 69 | + |
| 70 | + // IPv4 with scheme |
| 71 | + {"bolt://198.51.100.0", "198.51.100.0", DEFAULT_PORT}, |
| 72 | + {"bolt://65.21.10.12:5656", "65.21.10.12", 5656}, |
| 73 | + {"bolt+routing://12.0.0.5", "12.0.0.5", DEFAULT_PORT}, |
| 74 | + {"bolt+routing://155.55.20.6:9191", "155.55.20.6", 9191}, |
| 75 | + |
| 76 | + // IPv6 |
| 77 | + {"::1", "[::1]", DEFAULT_PORT}, |
| 78 | + {"ff02::2:ff00:0", "[ff02::2:ff00:0]", DEFAULT_PORT}, |
| 79 | + {"[1afc:0:a33:85a3::ff2f]", "[1afc:0:a33:85a3::ff2f]", DEFAULT_PORT}, |
| 80 | + {"[::1]:1515", "[::1]", 1515}, |
| 81 | + {"[ff0a::101]:8989", "[ff0a::101]", 8989}, |
| 82 | + |
| 83 | + // IPv6 with scheme |
| 84 | + {"bolt://[::1]", "[::1]", DEFAULT_PORT}, |
| 85 | + {"bolt+routing://[::1]", "[::1]", DEFAULT_PORT}, |
| 86 | + {"bolt://[ff02::d]", "[ff02::d]", DEFAULT_PORT}, |
| 87 | + {"bolt+routing://[fe80::b279:2f]", "[fe80::b279:2f]", DEFAULT_PORT}, |
| 88 | + {"bolt://[::1]:8687", "[::1]", 8687}, |
| 89 | + {"bolt+routing://[::1]:1212", "[::1]", 1212}, |
| 90 | + {"bolt://[ff02::d]:9090", "[ff02::d]", 9090}, |
| 91 | + {"bolt+routing://[fe80::b279:2f]:7878", "[fe80::b279:2f]", 7878}, |
| 92 | + |
| 93 | + // IPv6 with zone id |
| 94 | + {"::1%eth0", "[::1%eth0]", DEFAULT_PORT}, |
| 95 | + {"ff02::2:ff00:0%12", "[ff02::2:ff00:0%12]", DEFAULT_PORT}, |
| 96 | + {"[1afc:0:a33:85a3::ff2f%eth1]", "[1afc:0:a33:85a3::ff2f%eth1]", DEFAULT_PORT}, |
| 97 | + {"[::1%eth0]:3030", "[::1%eth0]", 3030}, |
| 98 | + {"[ff0a::101%8]:4040", "[ff0a::101%8]", 4040}, |
| 99 | + |
| 100 | + // IPv6 with scheme and zone id |
| 101 | + {"bolt://[::1%eth5]", "[::1%eth5]", DEFAULT_PORT}, |
| 102 | + {"bolt+routing://[::1%12]", "[::1%12]", DEFAULT_PORT}, |
| 103 | + {"bolt://[ff02::d%3]", "[ff02::d%3]", DEFAULT_PORT}, |
| 104 | + {"bolt+routing://[fe80::b279:2f%eth0]", "[fe80::b279:2f%eth0]", DEFAULT_PORT}, |
| 105 | + {"bolt://[::1%eth3]:8687", "[::1%eth3]", 8687}, |
| 106 | + {"bolt+routing://[::1%2]:1212", "[::1%2]", 1212}, |
| 107 | + {"bolt://[ff02::d%3]:9090", "[ff02::d%3]", 9090}, |
| 108 | + {"bolt+routing://[fe80::b279:2f%eth1]:7878", "[fe80::b279:2f%eth1]", 7878}, |
| 109 | + }; |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + public void shouldParseAddress() |
| 114 | + { |
| 115 | + BoltServerAddress parsed = new BoltServerAddress( address ); |
| 116 | + assertEquals( expectedHost, parsed.host() ); |
| 117 | + assertEquals( expectedPort, parsed.port() ); |
| 118 | + } |
| 119 | +} |
0 commit comments