Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testMatchesIP()
        internal virtual void TestMatchesIP()
        {
            // Given

            HostnamePort hostnamePortSinglePort = new HostnamePort("1.2.3.4:1234");
            HostnamePort hostnamePortWithRange  = new HostnamePort("1.2.3.4:1234-1236");

            // When & Then

            // Should match, same host and port
            assertTrue(hostnamePortSinglePort.Matches(URI.create("ha://1.2.3.4:1234")));
            // Should fail, different host or port
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://1.2.3.4:1235")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://5.6.7.8:1234")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://5.6.7.8:1235")));
            // Should fail, no port
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://1.2.3.4")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://5.6.7.8")));

            // Should match, port in range and host the same
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://1.2.3.4:1234")));
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://1.2.3.4:1235")));
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://1.2.3.4:1236")));
            // Should not match, different host
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://5.6.7.8:1234")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://5.6.7.8:1235")));
            // Should not match, port outside of range
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://1.2.3.4:1233")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://1.2.3.4:1237")));
            // Should not match, no port
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://1.2.3.4")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://5.6.7.8")));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testMatchesNullHostWithKnownHost() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestMatchesNullHostWithKnownHost()
        {
            HostnamePort hostnamePortSinglePort = new HostnamePort(":1234");
            string       host1 = InetAddress.LocalHost.HostName;

            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host1 + ":1234")));
        }
Beispiel #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testPortRangeOnly()
        internal virtual void TestPortRangeOnly()
        {
            HostnamePort hostnamePort = new HostnamePort(":1230-1240");

            assertNull(hostnamePort.Host);
            assertThat(hostnamePort.Port, equalTo(1230));
            assertThat(hostnamePort.Ports, equalTo(new int[] { 1230, 1240 }));
        }
Beispiel #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testHostnameOnly()
        internal virtual void TestHostnameOnly()
        {
            HostnamePort hostnamePort = new HostnamePort("myhost");

            assertThat(hostnamePort.Host, equalTo("myhost"));
            assertThat(hostnamePort.Port, equalTo(0));
            assertThat(hostnamePort.Ports, equalTo(new int[] { 0, 0 }));
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testIPv6LocalhostWithSchemeAndPort()
        internal virtual void TestIPv6LocalhostWithSchemeAndPort()
        {
            HostnamePort hostnamePort = new HostnamePort("foo://[::1]:6362");

            assertThat(hostnamePort.GetHost(null), equalTo("[::1]"));
            assertThat(hostnamePort.Port, equalTo(6362));
            assertThat(hostnamePort.Ports, equalTo(new int[] { 6362, 6362 }));
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testIPv6Localhost()
        internal virtual void TestIPv6Localhost()
        {
            HostnamePort hostnamePort = new HostnamePort("[::1]");

            assertThat(hostnamePort.GetHost(null), equalTo("[::1]"));
            assertThat(hostnamePort.Port, equalTo(0));
            assertThat(hostnamePort.Ports, equalTo(new int[] { 0, 0 }));
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testHostnamePortRange()
        internal virtual void TestHostnamePortRange()
        {
            HostnamePort hostnamePort = new HostnamePort("myhost:1234-1243");

            assertThat(hostnamePort.Host, equalTo("myhost"));
            assertThat(hostnamePort.Port, equalTo(1234));
            assertThat(hostnamePort.Ports, equalTo(new int[] { 1234, 1243 }));
        }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testHostnamePortRangeInversed()
        internal virtual void TestHostnamePortRangeInversed()
        {
            HostnamePort hostnamePort = new HostnamePort("myhost:1243-1234");

            assertThat(hostnamePort.Host, equalTo("myhost"));
            assertThat(hostnamePort.Port, equalTo(1243));
            assertThat(hostnamePort.Ports, equalTo(new int[] { 1243, 1234 }));
        }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testSinglePortOnly()
        internal virtual void TestSinglePortOnly()
        {
            HostnamePort hostnamePort = new HostnamePort(":1234");

            assertNull(hostnamePort.Host);
            assertThat(hostnamePort.Port, equalTo(1234));
            assertThat(hostnamePort.Ports, equalTo(new int[] { 1234, 1234 }));
        }
Beispiel #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testIPv6AddressWithSchemeAndPort()
        internal virtual void TestIPv6AddressWithSchemeAndPort()
        {
            HostnamePort hostnamePort = new HostnamePort("foo://[ff02::1:1]:9191");

            assertThat(hostnamePort.GetHost(null), equalTo("[ff02::1:1]"));
            assertThat(hostnamePort.Port, equalTo(9191));
            assertThat(hostnamePort.Ports, equalTo(new int[] { 9191, 9191 }));
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testIPv6Address()
        internal virtual void TestIPv6Address()
        {
            HostnamePort hostnamePort = new HostnamePort("[2001:cdba:0:0:0:0:3257:9652]");

            assertThat(hostnamePort.GetHost(null), equalTo("[2001:cdba:0:0:0:0:3257:9652]"));
            assertThat(hostnamePort.Port, equalTo(0));
            assertThat(hostnamePort.Ports, equalTo(new int[] { 0, 0 }));
        }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testGetHostAddressUnknown()
        internal virtual void TestGetHostAddressUnknown()
        {
            // Given
            string unknownHost = "unknownHost";

            assertThrows(typeof(UnknownHostException), () => InetAddress.getByName(unknownHost));

            // should return hostname when it is unknown
            assertThat(HostnamePort.GetHostAddress(unknownHost, "default"), equalTo(unknownHost));
        }
Beispiel #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testMatchesNullHostWithUnknownHost()
        internal virtual void TestMatchesNullHostWithUnknownHost()
        {
            // Given
            HostnamePort hostnamePortSinglePort = new HostnamePort(":1234");
            string       unknownHost            = "unknownHost";

            assertThrows(typeof(UnknownHostException), () => InetAddress.getByName(unknownHost));
            // When & Then

            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + unknownHost + ":1234")));
        }
Beispiel #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testGetHostAddress() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestGetHostAddress()
        {
            // Given
            string hostName = InetAddress.LocalHost.HostName;

            // When & Then

            // should return default, when host is null
            assertThat(HostnamePort.GetHostAddress(null, "default"), equalTo("default"));

            // should return host ip address when host is known
            assertThat(HostnamePort.GetHostAddress(hostName, "default"), equalTo(hostName));
        }
Beispiel #15
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }
            HostnamePort that = ( HostnamePort )o;

            return(Objects.Equals(_host, that._host) && Arrays.Equals(_ports, that._ports));
        }
Beispiel #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testMatchesKnownHostWithIP() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestMatchesKnownHostWithIP()
        {
            // Given

            string hostname1 = InetAddress.LocalHost.HostName.replace('.', '-');
            string host1     = InetAddress.LocalHost.HostAddress;
            // Building fake IP for host2
            StringBuilder host2 = new StringBuilder();

            string[] host1Parts = host1.Split("\\.", true);
            foreach (string part in host1Parts)
            {
                int partnum = int.Parse(part);
                host2.Append(++partnum % 256 + ".");
            }
            host2.Remove(host2.Length - 1, 1);

            HostnamePort hostnamePortSinglePort = new HostnamePort(hostname1 + ":1234");
            HostnamePort hostnamePortWithRange  = new HostnamePort(hostname1 + ":1234-1236");

            // When & Then

            // Should match, same host and port
            assertTrue(hostnamePortSinglePort.Matches(URI.create("ha://" + hostname1 + ":1234")));
            // Should fail, different host or port
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + hostname1 + ":1235")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host2 + ":1234")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host2 + ":1235")));
            // Should fail, no port
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host1)));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host2)));

            // Should match, port in range and host the same
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://" + hostname1 + ":1234")));
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://" + hostname1 + ":1235")));
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://" + hostname1 + ":1236")));
            // Should not match, different host
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + host2 + ":1234")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + host2 + ":1235")));
            // Should not match, port outside of range
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + hostname1 + ":1233")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + hostname1 + ":1237")));
            // Should not match, no port
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + hostname1)));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + host2)));
        }
Beispiel #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testMatchesUnknownHosts() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestMatchesUnknownHosts()
        {
            // Given
            string knownHost    = InetAddress.LocalHost.HostName;
            string unknownHost1 = "unknownHost1";
            string unknownHost2 = "unknownHost2";

            assertThrows(typeof(UnknownHostException), () => InetAddress.getByName(unknownHost1));
            assertThrows(typeof(UnknownHostException), () => InetAddress.getByName(unknownHost2));

            HostnamePort hostnamePortSinglePort = new HostnamePort(unknownHost1 + ":1234");
            HostnamePort hostnamePortWithRange  = new HostnamePort(unknownHost1 + ":1234-1236");

            // When & Then

            // Should match, same host and port
            assertTrue(hostnamePortSinglePort.Matches(URI.create("ha://" + unknownHost1 + ":1234")));
            // Should fail, different host or port
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + unknownHost1 + ":1235")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + unknownHost2 + ":1234")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + unknownHost2 + ":1235")));
            // Should fail, no port
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + unknownHost1 + "")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + unknownHost2 + "")));

            // Unknown host should never match with any IP or known host
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://1.2.3.4:1234")));

            // Should return false with any other known host
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + knownHost + ":1234")));

            // Should match, port in range and host the same
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost1 + ":1234")));
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost1 + ":1235")));
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost1 + ":1236")));
            // Should not match, different host
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost2 + ":1234")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost2 + ":1235")));
            // Should not match, port outside of range
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost1 + ":1233")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost1 + ":1237")));
            // Should not match, no port
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost1)));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost2)));
        }
Beispiel #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testMatchesKnownHostWithHostUnknown() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestMatchesKnownHostWithHostUnknown()
        {
            // Given
            string host1       = InetAddress.LocalHost.HostName;
            string unknownHost = "unknownHost";

            assertThrows(typeof(UnknownHostException), () => InetAddress.getByName(unknownHost));

            HostnamePort hostnamePortSinglePort = new HostnamePort(host1 + ":1234");
            HostnamePort hostnamePortWithRange  = new HostnamePort(host1 + ":1234-1236");

            // When & Then

            // should return false if matched with any unknown host
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + unknownHost + ":1234")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost + ":1234")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost + ":1235")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + unknownHost + ":1236")));
        }
Beispiel #19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testMatchesKnownHostWithHost() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestMatchesKnownHostWithHost()
        {
            // Given

            string host1 = InetAddress.LocalHost.HostName.replace('.', '-');
            // any other hostname?
            string host2 = "neo4j.org";

            assertDoesNotThrow(() => InetAddress.getByName(host2));
            assumeFalse(host1.Equals(host2));

            HostnamePort hostnamePortSinglePort = new HostnamePort(host1 + ":1234");
            HostnamePort hostnamePortWithRange  = new HostnamePort(host1 + ":1234-1236");

            // When & Then

            // Should match, same host and port
            assertTrue(hostnamePortSinglePort.Matches(URI.create("ha://" + host1 + ":1234")));
            // Should fail, different host or port
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host1 + ":1235")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host2 + ":1234")));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host2 + ":1235")));
            // Should fail, no port
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host1)));
            assertFalse(hostnamePortSinglePort.Matches(URI.create("ha://" + host2)));

            // Should match, port in range and host the same
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://" + host1 + ":1234")));
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://" + host1 + ":1235")));
            assertTrue(hostnamePortWithRange.Matches(URI.create("ha://" + host1 + ":1236")));
            // Should not match, different host
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + host2 + ":1234")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + host2 + ":1235")));
            // Should not match, port outside of range
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + host1 + ":1233")));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + host1 + ":1237")));
            // Should not match, no port
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + host1)));
            assertFalse(hostnamePortWithRange.Matches(URI.create("ha://" + host2)));
        }
Beispiel #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testDefaultHost()
        internal virtual void TestDefaultHost()
        {
            HostnamePort hostnamePort = new HostnamePort(":1234");

            assertThat(hostnamePort.GetHost("1.2.3.4"), equalTo("1.2.3.4"));
        }