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

pkiraly / metadata-qa-api / #732

04 Nov 2025 08:34AM UTC coverage: 86.286% (-0.06%) from 86.347%
#732

push

web-flow
Merge pull request #271 from pkiraly/dependabot/maven/com.jayway.jsonpath-json-path-2.10.0

build(deps): bump com.jayway.jsonpath:json-path from 2.9.0 to 2.10.0

5669 of 6570 relevant lines covered (86.29%)

0.86 hits per line

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

70.21
/src/main/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/ContentTypeChecker.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.ContentTypeExtractor;
11

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

17
public class ContentTypeChecker extends SingleFieldChecker {
18

19
  private static final long serialVersionUID = 6376677768166208863L;
20
  public static final String PREFIX = "contentType";
21

22
  private static final Logger LOGGER = Logger.getLogger(ContentTypeChecker.class.getCanonicalName());
1✔
23

24
  protected List<String> expectedContentTypes;
25
  private ContentTypeExtractor contentTypeExtractor;
26
  private Pattern skippableUrl;
27

28
  public ContentTypeChecker(DataElement field, List<String> expectedContentTypes) {
29
    this(field, field.getLabel(), expectedContentTypes, ContentTypeExtractor.DEFAULT_TIMEOUT);
1✔
30
  }
1✔
31

32
  public ContentTypeChecker(DataElement field, String header, List<String> expectedContentTypes, int timeout) {
33
    super(field, header + ":" + PREFIX);
1✔
34
    this.expectedContentTypes = expectedContentTypes;
1✔
35
    contentTypeExtractor = new ContentTypeExtractor(timeout);
1✔
36
  }
1✔
37

38
  @Override
39
  public void update(Selector selector, FieldCounter<RuleCheckerOutput> results, RuleCheckingOutputType outputType) {
40
    if (isDebug()) {
1✔
41
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ", debug=" + isDebug());
×
42
      // contentTypeExtractor.setDebug();
43
    }
44

45
    var allPassed = true;
1✔
46
    var isNA = true;
1✔
47
    int instanceCount = 0;
1✔
48
    int failureCount = 0;
1✔
49
    List<XmlFieldInstance> instances = selector.get(field);
1✔
50
    if (instances != null && !instances.isEmpty()) {
1✔
51
      for (XmlFieldInstance instance : instances) {
1✔
52
        if (instance.hasValue()) {
1✔
53
          if (countInstances())
1✔
54
            instanceCount++;
1✔
55
          isNA = false;
1✔
56
          String url = instance.getValue();
1✔
57
          if (skippableUrl == null || !skippableUrl.matcher(url).find()) {
1✔
58
            try {
59
              String contentType = contentTypeExtractor.getContentType(url);
1✔
60
              if (isDebug())
1✔
61
                LOGGER.info(String.format("value: '%s' -> '%s'", url, contentType));
×
62
              if (contentType == null || !expectedContentTypes.contains(contentType)) {
1✔
63
                allPassed = false;
1✔
64
                if (countInstances())
1✔
65
                  failureCount++;
×
66
              }
67
            } catch (IOException e) {
×
68
              LOGGER.warning(String.format("%s: %s (url: %s)", e.getClass().getSimpleName(), e.getMessage(), url));
×
69
              allPassed = false;
×
70
              if (countInstances())
×
71
                failureCount++;
×
72
            }
1✔
73
          }
74
          if (!countInstances() && !allPassed)
1✔
75
            break;
1✔
76
        }
77
      }
1✔
78
    }
79

80
    addOutput(results, isNA, allPassed, outputType, instanceCount, failureCount);
1✔
81
    if (isDebug())
1✔
82
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ") result: " + RuleCheckingOutputStatus.create(isNA, allPassed, isMandatory()));
×
83
  }
1✔
84

85
  public void setSkippableUrl(String skippableUrl) {
86
    this.skippableUrl = Pattern.compile(skippableUrl);
×
87
  }
×
88

89
  @Override
90
  public void setDebug() {
91
    super.setDebug();
×
92
    contentTypeExtractor.setDebug();
×
93
  }
×
94
}
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