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

pkiraly / metadata-qa-api / #695

13 Jun 2025 03:55PM UTC coverage: 86.677% (-0.3%) from 86.944%
#695

push

pkiraly
Add validLink

61 of 90 new or added lines in 6 files covered. (67.78%)

5608 of 6470 relevant lines covered (86.68%)

0.87 hits per line

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

77.5
/src/main/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/LinkValidityChecker.java
1
package de.gwdg.metadataqa.api.rule.singlefieldchecker;
2

3
import de.gwdg.metadataqa.api.counter.FieldCounter;
4
import de.gwdg.metadataqa.api.json.DataElement;
5
import de.gwdg.metadataqa.api.model.XmlFieldInstance;
6
import de.gwdg.metadataqa.api.model.selector.Selector;
7
import de.gwdg.metadataqa.api.rule.RuleCheckerOutput;
8
import de.gwdg.metadataqa.api.rule.RuleCheckingOutputStatus;
9
import de.gwdg.metadataqa.api.rule.RuleCheckingOutputType;
10
import de.gwdg.metadataqa.api.util.LinkValidator;
11

12
import java.io.IOException;
13
import java.util.List;
14
import java.util.logging.Logger;
15

16
public class LinkValidityChecker extends SingleFieldChecker {
17

18
  private static final Logger LOGGER = Logger.getLogger(LinkValidityChecker.class.getCanonicalName());
1✔
19

20
  public static final String PREFIX = "validLink";
21
  protected LinkValidator linkValidator;
22
  protected Boolean expectedValue;
23

24
  public LinkValidityChecker(DataElement field, Boolean expectedValue) {
25
    this(field, field.getLabel(), expectedValue, LinkValidator.DEFAULT_TIMEOUT);
1✔
26
  }
1✔
27

28
  public LinkValidityChecker(DataElement field, String header, Boolean expectedValue, int timeout) {
29
    super(field, header + ":" + PREFIX);
1✔
30
    this.expectedValue = expectedValue;
1✔
31
    linkValidator = new LinkValidator(timeout);
1✔
32
  }
1✔
33

34
  @Override
35
  public void update(Selector selector, FieldCounter<RuleCheckerOutput> results, RuleCheckingOutputType outputType) {
36
    if (isDebug())
1✔
NEW
37
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id);
×
38

39
    var allPassed = true;
1✔
40
    var isNA = true;
1✔
41
    int instanceCount = 0;
1✔
42
    int failureCount = 0;
1✔
43
    List<XmlFieldInstance> instances = selector.get(field);
1✔
44
    if (instances != null && !instances.isEmpty()) {
1✔
45
      for (XmlFieldInstance instance : instances) {
1✔
46
        if (instance.hasValue()) {
1✔
47
          if (countInstances())
1✔
48
            instanceCount++;
1✔
49
          isNA = false;
1✔
50
          try {
51
            boolean isValid = linkValidator.isValid(instance.getValue());
1✔
52
            if (isDebug())
1✔
NEW
53
              LOGGER.info(String.format("value: '%s' -> '%s'", instance.getValue(), isValid));
×
54
            if (isValid != expectedValue) {
1✔
55
              allPassed = false;
1✔
56
              if (countInstances())
1✔
NEW
57
                failureCount++;
×
58
            }
NEW
59
          } catch (IOException e) {
×
NEW
60
            LOGGER.warning(String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage()));
×
NEW
61
            allPassed = false;
×
NEW
62
            if (countInstances())
×
NEW
63
              failureCount++;
×
64
          }
1✔
65
          if (!countInstances() && !allPassed)
1✔
66
            break;
1✔
67
        }
68
      }
1✔
69
    }
70

71
    addOutput(results, isNA, allPassed, outputType, instanceCount, failureCount);
1✔
72
    if (isDebug())
1✔
NEW
73
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ") result: " + RuleCheckingOutputStatus.create(isNA, allPassed, isMandatory()));
×
74
  }
1✔
75
}
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