You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/06/17 19:49:37 UTC

svn commit: r1686082 - /commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java

Author: sebb
Date: Wed Jun 17 17:49:37 2015
New Revision: 1686082

URL: http://svn.apache.org/r1686082
Log:
Check missing entries to see if they are known to be missing from the root database.

Modified:
    commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java

Modified: commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java?rev=1686082&r1=1686081&r2=1686082&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java (original)
+++ commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java Wed Jun 17 17:49:37 2015
@@ -17,15 +17,18 @@
 package org.apache.commons.validator.routines;
 
 import java.io.BufferedReader;
+import java.io.Closeable;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.net.HttpURLConnection;
 import java.net.IDN;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -364,7 +367,9 @@ public class DomainValidatorTest extends
         // List html entries not in TLD text list
         for(String key : (new TreeMap<String, String[]>(htmlInfo)).keySet()) {
             if (!ianaTlds.contains(key)) {
-                System.err.println("Expected to find text entry for html: "+key);
+                if (!isNotInRootZone(key)) {
+                    System.err.println("Expected to find text entry for html: "+key);                    
+                }
             }
         }
         if (!missingTLD.isEmpty()) {
@@ -486,6 +491,41 @@ public class DomainValidatorTest extends
         return f.lastModified();
     }
 
+    private static boolean isNotInRootZone(String domain) {
+        String tldurl = "http://www.iana.org/domains/root/db/" + domain + ".html";
+        HttpURLConnection hc = null;
+        BufferedReader in = null;
+        try {
+            hc = (HttpURLConnection) new URL(tldurl).openConnection();
+            in = new BufferedReader(
+                    new InputStreamReader(hc.getInputStream()));
+            String inputLine;
+            while ((inputLine = in.readLine()) != null) {
+                if (inputLine.contains("This domain is not present in the root zone at this time.")) {
+                    return true;
+                }
+            }
+            in.close();        
+        } catch (MalformedURLException e) {
+        } catch (IOException e) {
+        } finally {
+            closeQuietly(in);
+            if (hc != null) {
+                hc.disconnect();
+            }
+        }
+        return false;
+    }
+
+    private static void closeQuietly(Closeable in) {
+        if (in != null) {
+            try {
+                in.close();
+            } catch (IOException e) {
+            }
+        }
+    }
+
     // isInIanaList and isSorted are split into two methods.
     // If/when access to the arrays is possible without reflection, the intermediate
     // methods can be dropped