コード例 #1
0
  /**
   * Asserts that both URLs are equal, comparing credentials and properties as requested. If both
   * the <code>compareCredentials</code> and <code>compareProperties</code> parameters are <code>
   * true</code>, this method asserts that the hashcode of both URLs are the same.
   *
   * @param url1 first url to test
   * @param url2 second url to test
   * @param compareCredentials if <code>true</code>, the login and password parts of both FileURL
   *     need to be equal (case-sensitive) for the FileURL instances to be equal
   * @param compareProperties if <code>true</code>, all properties need to be equal (case-sensitive)
   *     in both FileURL for them to be equal
   */
  protected void assertEquals(
      FileURL url1, FileURL url2, boolean compareCredentials, boolean compareProperties) {
    assert url1.equals(url2, compareCredentials, compareProperties);
    assert url2.equals(url1, compareCredentials, compareProperties);

    // Compare hash codes only if both flags are true.
    if (compareCredentials && compareProperties) assert url1.hashCode() == url2.hashCode();
  }
コード例 #2
0
  /**
   * Creates a URL from the given parts, ensuring that parsing it yields the given parts, and
   * returns it.
   *
   * @param login login part, may be <code>null</code>
   * @param password password part, may be <code>null</code>
   * @param host host part, may be <code>null</code>
   * @param port port part, <code>-1</code> for none
   * @param path path part
   * @param query query part, may be <code>null</code>
   * @return a URL corresponding to the given parts
   * @throws MalformedURLException if the URL cannot be parsed
   */
  protected FileURL getURL(
      String login, String password, String host, int port, String path, String query)
      throws MalformedURLException {
    String scheme = getScheme();
    StringBuffer sb = new StringBuffer(scheme + "://");

    if (host != null) {
      if (login != null) {
        sb.append(login);

        if (password != null) {
          sb.append(':');
          sb.append(password);
        }

        sb.append('@');
      }

      sb.append(host);

      if (port != -1) {
        sb.append(':');
        sb.append(port);
      }
    }

    path = getSchemePath(path);
    sb.append(path);

    if (query != null) {
      sb.append('?');
      sb.append(query);
    }

    // Assert that each of the url's parts match

    FileURL url = FileURL.getFileURL(sb.toString());

    assert scheme.equals(url.getScheme());

    if (host != null) {
      if (login != null) {
        assert login.equals(url.getLogin());
        assert url.containsCredentials();

        if (password != null) assert password.equals(url.getPassword());

        assert new Credentials(login, password).equals(url.getCredentials(), true);
      }

      assert host.equals(url.getHost());
      assert port == url.getPort();
    }

    if (query != null && !isQueryParsed()) {
      assert url.getQuery() == null;
      path = path + "?" + query;
    } else if (query == null) assert url.getQuery() == null;
    else assert query.equals(url.getQuery());

    assertPathEquals(path, url);

    // Test the URL's string representation
    assert url.equals(FileURL.getFileURL(url.toString(true, false)));
    assert url.equals(FileURL.getFileURL(url.toString(false, false)), false, false);

    return url;
  }
コード例 #3
0
 /**
  * Asserts that both URLs are not equal, comparing credentials and properties as requested.
  *
  * @param url1 first url to test
  * @param url2 second url to test
  * @param compareCredentials if <code>true</code>, the login and password parts of both FileURL
  *     need to be equal (case-sensitive) for the FileURL instances to be equal
  * @param compareProperties if <code>true</code>, all properties need to be equal (case-sensitive)
  *     in both FileURL for them to be equal
  */
 protected void assertNotEquals(
     FileURL url1, FileURL url2, boolean compareCredentials, boolean compareProperties) {
   assert !url1.equals(url2, compareCredentials, compareProperties);
   assert !url2.equals(url1, compareCredentials, compareProperties);
 }
コード例 #4
0
 /**
  * Asserts that both URLs are not equal.
  *
  * @param url1 first url to test
  * @param url2 second url to test
  */
 protected void assertNotEquals(FileURL url1, FileURL url2) {
   assert !url1.equals(url2);
   assert !url2.equals(url1);
 }
コード例 #5
0
 /**
  * Asserts that both URLs are equal, and that their hashcodes are the same.
  *
  * @param url1 first url to test
  * @param url2 second url to test
  */
 protected void assertEquals(FileURL url1, FileURL url2) {
   assert url1.equals(url2);
   assert url2.equals(url1);
   assert url1.hashCode() == url2.hashCode();
 }