You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2019/07/28 03:13:29 UTC

[GitHub] [commons-text] kinow commented on a change in pull request #118: [TEXT-170] Add String lookup for host names and IP addresses

kinow commented on a change in pull request #118: [TEXT-170] Add String lookup for host names and IP addresses
URL: https://github.com/apache/commons-text/pull/118#discussion_r307983692
 
 

 ##########
 File path: src/test/java/org/apache/commons/text/lookup/DnsStringLookupTest.java
 ##########
 @@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.commons.text.lookup;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link DnsStringLookup}.
+ */
+public class DnsStringLookupTest {
+
+    @Test
+    public void testAddressFromHostAddress() throws UnknownHostException {
+        final InetAddress localHost = InetAddress.getLocalHost();
+        Assertions.assertEquals(localHost.getHostAddress(),
+                DnsStringLookup.INSTANCE.lookup("address|" + localHost.getHostAddress()));
+    }
+
+    @Test
+    public void testAddressFromHostName() throws UnknownHostException {
+        final InetAddress localHost = InetAddress.getLocalHost();
+        Assertions.assertEquals(localHost.getHostAddress(),
+                DnsStringLookup.INSTANCE.lookup("address|" + localHost.getHostName()));
+    }
+
+    @Test
+    public void testCanonicalNameFromHostAddress() throws UnknownHostException {
+        final InetAddress localHost = InetAddress.getLocalHost();
+        Assertions.assertEquals(localHost.getCanonicalHostName(),
+                DnsStringLookup.INSTANCE.lookup("canonical-name|" + localHost.getHostAddress()));
+    }
+
+    @Test
+    public void testCanonicalNameFromHostName() throws UnknownHostException {
+        final InetAddress localHost = InetAddress.getLocalHost();
+        Assertions.assertEquals(localHost.getCanonicalHostName(),
+                DnsStringLookup.INSTANCE.lookup("canonical-name|" + localHost.getHostName()));
+    }
+
+    @Test
+    public void testName() throws UnknownHostException {
+        final InetAddress localHost = InetAddress.getByName("127.0.0.1");
 
 Review comment:
   Yup, have also seen 127.0.1.1 as localhost.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services