Changeset 10222 in josm for trunk/test/unit/org/openstreetmap/josm/data/validation/routines
- Timestamp:
- 2016-05-15T21:14:06+02:00 (9 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/data/validation/routines
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/validation/routines/DomainValidatorTestIT.java
r10219 r10222 48 48 import org.junit.Test; 49 49 50 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 51 50 52 /** 51 53 * Integration tests for the DomainValidator. … … 82 84 download(htmlFile, "http://www.iana.org/domains/root/db", timestamp); 83 85 84 BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(txtFile), StandardCharsets.UTF_8)); 85 String line; 86 final String header; 87 line = br.readLine(); // header 88 if (line != null && line.startsWith("# Version ")) { 89 header = line.substring(2); 90 } else { 91 br.close(); 92 throw new IOException("File does not have expected Version header"); 93 } 94 final boolean generateUnicodeTlds = false; // Change this to generate Unicode TLDs as well 95 96 // Parse html page to get entries 97 Map<String, String[]> htmlInfo = getHtmlInfo(htmlFile); 98 Map<String, String> missingTLD = new TreeMap<>(); // stores entry and comments as String[] 99 Map<String, String> missingCC = new TreeMap<>(); 100 while ((line = br.readLine()) != null) { 101 if (!line.startsWith("#")) { 102 final String unicodeTld; // only different from asciiTld if that was punycode 103 final String asciiTld = line.toLowerCase(Locale.ENGLISH); 104 if (line.startsWith("XN--")) { 105 unicodeTld = IDN.toUnicode(line); 106 } else { 107 unicodeTld = asciiTld; 108 } 109 if (!dv.isValidTld(asciiTld)) { 110 String[] info = htmlInfo.get(asciiTld); 111 if (info != null) { 112 String type = info[0]; 113 String comment = info[1]; 114 if ("country-code".equals(type)) { // Which list to use? 115 missingCC.put(asciiTld, unicodeTld + " " + comment); 116 if (generateUnicodeTlds) { 117 missingCC.put(unicodeTld, asciiTld + " " + comment); 86 try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(txtFile), StandardCharsets.UTF_8))) { 87 String line; 88 final String header; 89 line = br.readLine(); // header 90 if (line != null && line.startsWith("# Version ")) { 91 header = line.substring(2); 92 } else { 93 throw new IOException("File does not have expected Version header"); 94 } 95 final boolean generateUnicodeTlds = false; // Change this to generate Unicode TLDs as well 96 97 // Parse html page to get entries 98 Map<String, String[]> htmlInfo = getHtmlInfo(htmlFile); 99 Map<String, String> missingTLD = new TreeMap<>(); // stores entry and comments as String[] 100 Map<String, String> missingCC = new TreeMap<>(); 101 while ((line = br.readLine()) != null) { 102 if (!line.startsWith("#")) { 103 final String unicodeTld; // only different from asciiTld if that was punycode 104 final String asciiTld = line.toLowerCase(Locale.ENGLISH); 105 if (line.startsWith("XN--")) { 106 unicodeTld = IDN.toUnicode(line); 107 } else { 108 unicodeTld = asciiTld; 109 } 110 if (!dv.isValidTld(asciiTld)) { 111 String[] info = htmlInfo.get(asciiTld); 112 if (info != null) { 113 String type = info[0]; 114 String comment = info[1]; 115 if ("country-code".equals(type)) { // Which list to use? 116 missingCC.put(asciiTld, unicodeTld + " " + comment); 117 if (generateUnicodeTlds) { 118 missingCC.put(unicodeTld, asciiTld + " " + comment); 119 } 120 } else { 121 missingTLD.put(asciiTld, unicodeTld + " " + comment); 122 if (generateUnicodeTlds) { 123 missingTLD.put(unicodeTld, asciiTld + " " + comment); 124 } 118 125 } 119 126 } else { 120 missingTLD.put(asciiTld, unicodeTld + " " + comment); 121 if (generateUnicodeTlds) { 122 missingTLD.put(unicodeTld, asciiTld + " " + comment); 123 } 124 } 127 System.err.println("Expected to find HTML info for "+ asciiTld); 128 } 129 } 130 ianaTlds.add(asciiTld); 131 // Don't merge these conditions; generateUnicodeTlds is final so needs to be separate to avoid a warning 132 if (generateUnicodeTlds) { 133 if (!unicodeTld.equals(asciiTld)) { 134 ianaTlds.add(unicodeTld); 135 } 136 } 137 } 138 } 139 // List html entries not in TLD text list 140 for (String key : (new TreeMap<>(htmlInfo)).keySet()) { 141 if (!ianaTlds.contains(key)) { 142 if (isNotInRootZone(key)) { 143 System.out.println("INFO: HTML entry not yet in root zone: "+key); 125 144 } else { 126 System.err.println("Expected to find HTML info for "+ asciiTld); 127 } 128 } 129 ianaTlds.add(asciiTld); 130 // Don't merge these conditions; generateUnicodeTlds is final so needs to be separate to avoid a warning 131 if (generateUnicodeTlds) { 132 if (!unicodeTld.equals(asciiTld)) { 133 ianaTlds.add(unicodeTld); 134 } 135 } 136 } 137 } 138 br.close(); 139 // List html entries not in TLD text list 140 for (String key : (new TreeMap<>(htmlInfo)).keySet()) { 141 if (!ianaTlds.contains(key)) { 142 if (isNotInRootZone(key)) { 143 System.out.println("INFO: HTML entry not yet in root zone: "+key); 144 } else { 145 System.err.println("WARN: Expected to find text entry for html: "+key); 146 } 147 } 148 } 149 if (!missingTLD.isEmpty()) { 150 printMap(header, missingTLD, "TLD"); 151 fail("missing TLD"); 152 } 153 if (!missingCC.isEmpty()) { 154 printMap(header, missingCC, "CC"); 155 fail("missing CC"); 145 System.err.println("WARN: Expected to find text entry for html: "+key); 146 } 147 } 148 } 149 if (!missingTLD.isEmpty()) { 150 printMap(header, missingTLD, "TLD"); 151 fail("missing TLD"); 152 } 153 if (!missingCC.isEmpty()) { 154 printMap(header, missingCC, "CC"); 155 fail("missing CC"); 156 } 156 157 } 157 158 // Check if internal tables contain any additional entries … … 175 176 } 176 177 178 @SuppressFBWarnings(value = "PERFORMANCE") 177 179 private static Map<String, String[]> getHtmlInfo(final File f) throws IOException { 178 180 final Map<String, String[]> info = new HashMap<>(); … … 186 188 final Pattern comment = Pattern.compile("\\s+<td>([^<]+)</td>"); 187 189 188 final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8)); 189 String line; 190 while ((line = br.readLine()) != null) { 191 Matcher m = domain.matcher(line); 192 if (m.lookingAt()) { 193 String dom = m.group(1); 194 String typ = "??"; 195 String com = "??"; 196 line = br.readLine(); 197 while (line != null && line.matches("^\\s*$")) { // extra blank lines introduced 190 try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8))) { 191 String line; 192 while ((line = br.readLine()) != null) { 193 Matcher m = domain.matcher(line); 194 if (m.lookingAt()) { 195 String dom = m.group(1); 196 String typ = "??"; 197 String com = "??"; 198 198 line = br.readLine(); 199 } 200 Matcher t = type.matcher(line); 201 if (t.lookingAt()) { 202 typ = t.group(1); 203 line = br.readLine(); 204 if (line != null && line.matches("\\s+<!--.*")) { 205 while (line != null && !line.matches(".*-->.*")) { 199 while (line != null && line.matches("^\\s*$")) { // extra blank lines introduced 200 line = br.readLine(); 201 } 202 Matcher t = type.matcher(line); 203 if (t.lookingAt()) { 204 typ = t.group(1); 205 line = br.readLine(); 206 if (line != null && line.matches("\\s+<!--.*")) { 207 while (line != null && !line.matches(".*-->.*")) { 208 line = br.readLine(); 209 } 206 210 line = br.readLine(); 207 211 } 208 line = br.readLine(); 209 } 210 // Should have comment; is it wrapped? 211 while (line != null && !line.matches(".*</td>.*")) { 212 line += " " +br.readLine(); 213 } 214 Matcher n = comment.matcher(line); 215 if (n.lookingAt()) { 216 com = n.group(1); 217 } 218 // Don't save unused entries 219 if (com.contains("Not assigned") || com.contains("Retired") || typ.equals("test")) { 220 // System.out.println("Ignored: " + typ + " " + dom + " " +com); 212 // Should have comment; is it wrapped? 213 while (line != null && !line.matches(".*</td>.*")) { 214 line += " " +br.readLine(); 215 } 216 Matcher n = comment.matcher(line); 217 if (n.lookingAt()) { 218 com = n.group(1); 219 } 220 // Don't save unused entries 221 if (com.contains("Not assigned") || com.contains("Retired") || typ.equals("test")) { 222 // System.out.println("Ignored: " + typ + " " + dom + " " +com); 223 } else { 224 info.put(dom.toLowerCase(Locale.ENGLISH), new String[]{typ, com}); 225 // System.out.println("Storing: " + typ + " " + dom + " " +com); 226 } 221 227 } else { 222 info.put(dom.toLowerCase(Locale.ENGLISH), new String[]{typ, com}); 223 // System.out.println("Storing: " + typ + " " + dom + " " +com); 224 } 225 } else { 226 System.err.println("Unexpected type: " + line); 227 } 228 } 229 } 230 br.close(); 228 System.err.println("Unexpected type: " + line); 229 } 230 } 231 } 232 } 231 233 return info; 232 234 } … … 262 264 System.out.println("Downloading " + tldurl); 263 265 byte[] buff = new byte[1024]; 264 InputStream is = hc.getInputStream(); 265 266 FileOutputStream fos = new FileOutputStream(f); 267 int len; 268 while ((len = is.read(buff)) != -1) { 269 fos.write(buff, 0, len); 270 } 271 fos.close(); 272 is.close(); 266 try (InputStream is = hc.getInputStream(); 267 FileOutputStream fos = new FileOutputStream(f)) { 268 int len; 269 while ((len = is.read(buff)) != -1) { 270 fos.write(buff, 0, len); 271 } 272 } 273 273 System.out.println("Done"); 274 274 } -
trunk/test/unit/org/openstreetmap/josm/data/validation/routines/EmailValidatorTest.java
r10202 r10222 37 37 * rules from the xml file. 38 38 */ 39 protected static String FORM_KEY = "emailForm"; 39 protected static final String FORM_KEY = "emailForm"; 40 40 41 41 /** 42 42 * The key used to retrieve the validator action. 43 43 */ 44 protected static String ACTION = "email"; 44 protected static final String ACTION = "email"; 45 45 46 46 private EmailValidator validator; -
trunk/test/unit/org/openstreetmap/josm/data/validation/routines/UrlValidatorTest.java
r10133 r10222 31 31 public class UrlValidatorTest { 32 32 33 private final boolean printStatus = false; 34 private final boolean printIndex = false; //print index that indicates current scheme,host,port,path, query test were using. 33 private static final boolean printStatus = false; 34 private static final boolean printIndex = false; //print index that indicates current scheme,host,port,path, query test were using. 35 35 36 36 /**
Note:
See TracChangeset
for help on using the changeset viewer.