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

pkiraly / metadata-qa-api / #644

03 Apr 2025 09:28AM UTC coverage: 87.234% (-0.2%) from 87.454%
#644

push

pkiraly
Add mandatory and scope as generic rule properties #225

70 of 87 new or added lines in 12 files covered. (80.46%)

6 existing lines in 4 files now uncovered.

5453 of 6251 relevant lines covered (87.23%)

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/rule/singlefieldchecker/HasValueChecker.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

11
import java.util.List;
12

13
public class HasValueChecker extends SingleFieldChecker {
14

15
  private static final long serialVersionUID = 1114999259831619599L;
16
  public static final String PREFIX = "hasValue";
17
  protected String fixedValue;
18

19
  /**
20
   * @param field The field
21
   * @param fixedValue The fixed value  check against
22
   */
23
  public HasValueChecker(DataElement field, String fixedValue) {
24
    this(field, field.getLabel(), fixedValue);
1✔
25
  }
1✔
26

27
  public HasValueChecker(DataElement field, String header, String fixedValue) {
28
    super(field, header + ":" + PREFIX);
1✔
29
    this.fixedValue = fixedValue;
1✔
30
  }
1✔
31

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

37
    var isNA = true;
1✔
38
    boolean hasFailed = false;
1✔
39
    int passCount = 0;
1✔
40
    List<XmlFieldInstance> instances = cache.get(field);
1✔
41
    if (instances != null && !instances.isEmpty()) {
1✔
42
      for (XmlFieldInstance instance : instances) {
1✔
43
        if (instance.hasValue()) {
1✔
44
          isNA = false;
1✔
45
          if (isDebug())
1✔
46
            LOGGER.info("value: " + instance.getValue());
×
47
          if (!instance.getValue().equals(fixedValue)) {
1✔
48
            hasFailed = true;
1✔
49
            if (scopeIsAllOf()) {
1✔
NEW
50
              break;
×
51
            }
52
          } else {
53
            passCount++;
1✔
54
          }
55
        }
56
      }
1✔
57
    }
58
    boolean allPassed = isPassed(passCount, hasFailed);
1✔
59
    addOutput(results, isNA, allPassed, outputType);
1✔
60
    if (isDebug())
1✔
61
      LOGGER.info(this.getClass().getSimpleName() + " " + this.id + ") result: " + RuleCheckingOutputStatus.create(isNA, allPassed, isMandatory()));
×
62
  }
1✔
63
}
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