public void testParse() { AlternateLocation loc = AlternateLocation.parseUriResAltLoc(uriResStr, securityService); assertEquals("1.1.1.1", loc.getHTTPString()); loc = AlternateLocation.parseUriResAltLoc(uriResStr2, securityService); assertEquals("1.1.1.1:6347", loc.getHTTPString()); // test if filename urls are accepted. String altLocStr = "http://123.123.123.123:6347/get/1/phex.zip 2002-04-30T08:30:00Z"; loc = AlternateLocation.parseUriResAltLoc(altLocStr, securityService); // since change alt-locs do not accept url without urn... assertEquals(null, loc); // assertEquals( "\"http://123.123.123.123:6347/get/1/phex.zip\" 2002-04-30T08:30:00Z", // loc.getHTTPString() ); // test if url with private ip in uri res is accepted. altLocStr = privateUriResStr + " 2002-04-30T08:30:00Z"; loc = AlternateLocation.parseUriResAltLoc(altLocStr, securityService); // since change alt-locs do not accept url with private ip... assertEquals(null, loc); // test if wrong port in url is accepted. altLocStr = wrongPortUriResStr + " 2002-04-30T08:30:00Z"; loc = AlternateLocation.parseUriResAltLoc(altLocStr, securityService); // since change alt-locs do not accept url with private ip... assertEquals(null, loc); // test if wrong ip in url is accepted. try { altLocStr = wrongIPUriResStr + " 2002-04-30T08:30:00Z"; loc = AlternateLocation.parseUriResAltLoc(altLocStr, securityService); // since change alt-locs do not accept url with private ip... assertEquals(null, loc); assertTrue(false); } catch (Exception exp) { assertTrue(true); } // test if wrong ip in url is accepted. altLocStr = wrongIPUriResStr2 + " 2002-04-30T08:30:00Z"; loc = AlternateLocation.parseUriResAltLoc(altLocStr, securityService); // since change alt-locs do not accept url with private ip... assertEquals(null, loc); // test if missing port in url is leading to a invalid URL // and not anymore converted to 80 or 6346 on http. altLocStr = noPortUriResStr; loc = AlternateLocation.parseUriResAltLoc(altLocStr, securityService); assertEquals(null, loc); // assertEquals( 80, loc.getHostAddress().getPort() ); // test to parse upper case uri res str altLocStr = uriResStr.toUpperCase(); loc = AlternateLocation.parseUriResAltLoc(altLocStr, securityService); assertNotNull(loc); // test to parse uri res str with long timestamp altLocStr = uriResStr + " 2002-04-30T08:30:00Z"; loc = AlternateLocation.parseUriResAltLoc(altLocStr, securityService); assertEquals("1.1.1.1", loc.getHTTPString()); // test to parse uri res str with short timestamp altLocStr = uriResStr + " 2002-04-30T08:30Z"; loc = AlternateLocation.parseUriResAltLoc(altLocStr, securityService); assertEquals("1.1.1.1", loc.getHTTPString()); }