//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"))); }
//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"))); }
//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"))); }
//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"))); }
//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))); }
//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))); }
//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))); }