• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pkiraly / metadata-qa-api / #716

27 Aug 2025 07:52AM UTC coverage: 86.526% (-0.03%) from 86.556%
#716

push

pkiraly
Fix test for content type

5651 of 6531 relevant lines covered (86.53%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/main/java/de/gwdg/metadataqa/api/util/LinkValidator.java
1
package de.gwdg.metadataqa.api.util;
2

3
import java.io.IOException;
4
import java.net.HttpURLConnection;
5
import java.net.URL;
6
import java.util.logging.Logger;
7

8
public class LinkValidator {
9
  private static final Logger LOGGER = Logger.getLogger(LinkValidator.class.getCanonicalName());
1✔
10
  public static final int DEFAULT_TIMEOUT = 5000;
11
  private int timeout;
12

13
  public LinkValidator() {
14
    this(DEFAULT_TIMEOUT);
×
15
  }
×
16

17
  public LinkValidator(int timeout) {
1✔
18
    this.timeout = timeout;
1✔
19
  }
1✔
20

21
  public boolean isValid(String url) throws IOException {
22
    URL urlObj = new URL(url);
1✔
23
    HttpURLConnection urlConnection = (HttpURLConnection) urlObj.openConnection();
1✔
24

25
    urlConnection.setConnectTimeout(timeout);
1✔
26
    urlConnection.setReadTimeout(timeout);
1✔
27
    urlConnection.connect();
1✔
28
    int responseCode = urlConnection.getResponseCode();
1✔
29
    if (responseCode == 200) {
1✔
30
      return true;
1✔
31
    } else if (responseCode == 301 // Moved Permanently
1✔
32
            || responseCode == 302 // Found
33
            || responseCode == 303 // See Other
34
            || responseCode == 304 // Not Modified
35
            || responseCode == 307 // Temporary Redirect
36
            || responseCode == 308 // Permanent Redirect
37
    ) {
38
      String location = urlConnection.getHeaderField("Location");
1✔
39
      return isValid(location);
1✔
40
    } else if (responseCode == 401 // Unauthorized
1✔
41
            || responseCode == 402 // Payment Required
42
            || responseCode == 403 // Forbidden
43
            || responseCode == 407 // Proxy Authentication Required
44
            || responseCode == 429 // Too Many Requests
45
    ) {
46
      return true;
×
47
    } else {
48
      LOGGER.warning(String.format("URL %s returns unhandled status code: %d.\n", url, responseCode));
1✔
49
    }
50
    return false;
1✔
51
  }
52

53
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc