jdk/test/java/net/URI/Test.java
changeset 23725 0190e5c0e70c
parent 23010 6dadb192ad81
child 28567 4121cce98397
equal deleted inserted replaced
23724:c35574e21791 23725:0190e5c0e70c
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
  1365     static void eq(URI u, URI v) throws URISyntaxException {
  1365     static void eq(URI u, URI v) throws URISyntaxException {
  1366         eq0(u, v);
  1366         eq0(u, v);
  1367         cmp0(u, v, true);
  1367         cmp0(u, v, true);
  1368     }
  1368     }
  1369 
  1369 
       
  1370     static void eq(String expected, String actual) {
       
  1371         if (expected == null && actual == null) {
       
  1372             return;
       
  1373         }
       
  1374         if (expected != null && expected.equals(actual)) {
       
  1375             return;
       
  1376         }
       
  1377         throw new AssertionError(String.format(
       
  1378                 "Strings are not equal: '%s', '%s'", expected, actual));
       
  1379     }
       
  1380 
  1370     static void eqeq(URI u, URI v) {
  1381     static void eqeq(URI u, URI v) {
  1371         testCount++;
  1382         testCount++;
  1372         if (u != v)
  1383         if (u != v)
  1373             throw new RuntimeException("Not ==: " + u + " " + v);
  1384             throw new RuntimeException("Not ==: " + u + " " + v);
  1374     }
  1385     }
  1586 
  1597 
  1587 
  1598 
  1588     // miscellaneous bugs/rfes that don't fit in with the test framework
  1599     // miscellaneous bugs/rfes that don't fit in with the test framework
  1589 
  1600 
  1590     static void bugs() {
  1601     static void bugs() {
  1591         // 6339649 - include detail message from nested exception
  1602         b6339649();
       
  1603         b8037396();
       
  1604     }
       
  1605 
       
  1606     // 6339649 - include detail message from nested exception
       
  1607     private static void b6339649() {
  1592         try {
  1608         try {
  1593             URI uri = URI.create("http://nowhere.net/should not be permitted");
  1609             URI uri = URI.create("http://nowhere.net/should not be permitted");
  1594         } catch (IllegalArgumentException e) {
  1610         } catch (IllegalArgumentException e) {
  1595             if ("".equals(e.getMessage()) || e.getMessage() == null) {
  1611             if ("".equals(e.getMessage()) || e.getMessage() == null) {
  1596                 throw new RuntimeException ("No detail message");
  1612                 throw new RuntimeException ("No detail message");
  1597             }
  1613             }
  1598         }
  1614         }
       
  1615     }
       
  1616 
       
  1617     private static void b8037396() {
       
  1618 
       
  1619         // primary checks:
       
  1620 
       
  1621         URI u;
       
  1622         try {
       
  1623             u = new URI("http", "example.org", "/[a b]", "[a b]", "[a b]");
       
  1624         } catch (URISyntaxException e) {
       
  1625             throw new AssertionError("shouldn't ever happen", e);
       
  1626         }
       
  1627         eq("/[a b]", u.getPath());
       
  1628         eq("[a b]", u.getQuery());
       
  1629         eq("[a b]", u.getFragment());
       
  1630 
       
  1631         // additional checks:
       
  1632         //  *   '%' symbols are still decoded outside square brackets
       
  1633         //  *   the getRawXXX() functionality left intact
       
  1634 
       
  1635         try {
       
  1636             u = new URI("http", "example.org", "/a b[c d]", "a b[c d]", "a b[c d]");
       
  1637         } catch (URISyntaxException e) {
       
  1638             throw new AssertionError("shouldn't ever happen", e);
       
  1639         }
       
  1640 
       
  1641         eq("/a b[c d]", u.getPath());
       
  1642         eq("a b[c d]", u.getQuery());
       
  1643         eq("a b[c d]", u.getFragment());
       
  1644 
       
  1645         eq("/a%20b%5Bc%20d%5D", u.getRawPath());
       
  1646         eq("a%20b[c%20d]", u.getRawQuery());
       
  1647         eq("a%20b[c%20d]", u.getRawFragment());
  1599     }
  1648     }
  1600 
  1649 
  1601     public static void main(String[] args) throws Exception {
  1650     public static void main(String[] args) throws Exception {
  1602         switch (args.length) {
  1651         switch (args.length) {
  1603 
  1652