diff --git a/src/main/java/de/gwdg/metadataqa/api/schema/SchemaUtils.java b/src/main/java/de/gwdg/metadataqa/api/schema/SchemaUtils.java index 78dc4638..cf49ea23 100644 --- a/src/main/java/de/gwdg/metadataqa/api/schema/SchemaUtils.java +++ b/src/main/java/de/gwdg/metadataqa/api/schema/SchemaUtils.java @@ -153,6 +153,7 @@ private static List processRule(Schema schema, DataElement dataElem for (RuleChecker ruleChecker : ruleCheckers) { ruleChecker.setFailureScore(rule.getFailureScore()); ruleChecker.setSuccessScore(rule.getSuccessScore()); + ruleChecker.setNaScore(rule.getNaScore()); String idValue = StringUtils.isNotBlank(rule.getId()) ? rule.getId() : String.valueOf(++id); ruleChecker.setId(idValue); if (rule.getHidden().equals(Boolean.TRUE)) diff --git a/src/test/java/de/gwdg/metadataqa/api/rule/logical/AndCheckerTest.java b/src/test/java/de/gwdg/metadataqa/api/rule/logical/AndCheckerTest.java index b096afef..8dd48cd7 100644 --- a/src/test/java/de/gwdg/metadataqa/api/rule/logical/AndCheckerTest.java +++ b/src/test/java/de/gwdg/metadataqa/api/rule/logical/AndCheckerTest.java @@ -23,6 +23,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; public class AndCheckerTest { @@ -38,7 +39,13 @@ public void setUp() throws Exception { .addField("title") .addField("alt") ; - schema.getPathByLabel("name").setRule(Arrays.asList(new Rule().withAnd(Arrays.asList(new Rule().withMinCount(1), new Rule().withMaxCount(1))))); + schema.getPathByLabel("name") + .setRule(Arrays.asList( + new Rule().withAnd(Arrays.asList( + new Rule().withMinCount(1), + new Rule().withMaxCount(1))) + .withNaScore(-1) + )); cache = (CsvSelector) SelectorFactory.getInstance(schema.getFormat(), "a,b,a"); cache.setCsvReader(new CsvReader().setHeader(((CsvAwareSchema) schema).getHeader())); @@ -54,12 +61,15 @@ public void update() { List checkers = schema.getRuleCheckers(); AndChecker andChecker = (AndChecker) checkers.get(0); assertEquals(2, andChecker.getCheckers().size()); + assertEquals(-1, (int) andChecker.getNaScore()); assertEquals(MinCountChecker.class, andChecker.getCheckers().get(0).getClass()); MinCountChecker minCountChecker = (MinCountChecker) andChecker.getCheckers().get(0); + assertNull(minCountChecker.getNaScore()); assertEquals(MaxCountChecker.class, andChecker.getCheckers().get(1).getClass()); MaxCountChecker maxCountChecker = (MaxCountChecker) andChecker.getCheckers().get(1); + assertNull(maxCountChecker.getNaScore()); FieldCounter fieldCounter = new FieldCounter<>(); andChecker.update(cache, fieldCounter, RuleCheckingOutputType.BOTH); diff --git a/src/test/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MaxCountCheckerTest.java b/src/test/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MaxCountCheckerTest.java index e61eca22..d0c55751 100644 --- a/src/test/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MaxCountCheckerTest.java +++ b/src/test/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MaxCountCheckerTest.java @@ -25,8 +25,8 @@ public void prefix() { public void success() { MaxCountChecker checker = (MaxCountChecker) new MaxCountChecker(schema.getPathByLabel("name"), 1) .withSuccessScore(1) - .withNaScore(0) - .withFailureScore(-1); + .withNaScore(-1) + .withFailureScore(-2); FieldCounter fieldCounter = new FieldCounter<>(); checker.update(cache, fieldCounter, RuleCheckingOutputType.BOTH); @@ -42,8 +42,8 @@ public void success() { public void failure() { MaxCountChecker checker = (MaxCountChecker) new MaxCountChecker(schema.getPathByLabel("name"), 0) .withSuccessScore(1) - .withNaScore(0) - .withFailureScore(-1); + .withNaScore(-1) + .withFailureScore(-2); FieldCounter fieldCounter = new FieldCounter<>(); checker.update(cache, fieldCounter, RuleCheckingOutputType.BOTH); @@ -51,15 +51,15 @@ public void failure() { assertEquals(2, fieldCounter.size()); assertEquals("name:maxCount", checker.getHeaderWithoutId()); Assert.assertEquals(RuleCheckingOutputStatus.FAILED, fieldCounter.get(checker.getHeader(RuleCheckingOutputType.STATUS)).getStatus()); - Assert.assertEquals(-1, (int) fieldCounter.get(checker.getHeader(RuleCheckingOutputType.SCORE)).getScore()); + Assert.assertEquals(-2, (int) fieldCounter.get(checker.getHeader(RuleCheckingOutputType.SCORE)).getScore()); } @Test public void na() { MaxCountChecker checker = (MaxCountChecker) new MaxCountChecker(schema.getPathByLabel("name"), 1) .withSuccessScore(1) - .withNaScore(0) - .withFailureScore(-1); + .withNaScore(-1) + .withFailureScore(-2); cache = (CsvSelector) SelectorFactory.getInstance(schema.getFormat(), ""); cache.setCsvReader(new CsvReader().setHeader( ((CsvAwareSchema) schema).getHeader() )); @@ -70,6 +70,6 @@ public void na() { assertEquals(2, fieldCounter.size()); assertEquals("name:maxCount", checker.getHeaderWithoutId()); Assert.assertEquals(RuleCheckingOutputStatus.NA, fieldCounter.get(checker.getHeader(RuleCheckingOutputType.STATUS)).getStatus()); - Assert.assertEquals(0, (int) fieldCounter.get(checker.getHeader(RuleCheckingOutputType.SCORE)).getScore()); + Assert.assertEquals(-1, (int) fieldCounter.get(checker.getHeader(RuleCheckingOutputType.SCORE)).getScore()); } } \ No newline at end of file diff --git a/src/test/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MaxLenghCheckerTest.java b/src/test/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MaxLenghCheckerTest.java index 601f89f1..cab6f519 100644 --- a/src/test/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MaxLenghCheckerTest.java +++ b/src/test/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/MaxLenghCheckerTest.java @@ -1,10 +1,14 @@ package de.gwdg.metadataqa.api.rule.singlefieldchecker; import de.gwdg.metadataqa.api.counter.FieldCounter; +import de.gwdg.metadataqa.api.model.selector.CsvSelector; +import de.gwdg.metadataqa.api.model.selector.SelectorFactory; import de.gwdg.metadataqa.api.rule.CheckerTestBase; import de.gwdg.metadataqa.api.rule.RuleCheckerOutput; import de.gwdg.metadataqa.api.rule.RuleCheckingOutputStatus; import de.gwdg.metadataqa.api.rule.RuleCheckingOutputType; +import de.gwdg.metadataqa.api.schema.CsvAwareSchema; +import de.gwdg.metadataqa.api.util.CsvReader; import org.junit.Assert; import org.junit.Test; @@ -40,4 +44,24 @@ public void failure() { assertEquals("name:maxLength", checker.getHeaderWithoutId()); assertEquals(RuleCheckingOutputStatus.FAILED, fieldCounter.get(checker.getHeader(RuleCheckingOutputType.STATUS)).getStatus()); } + + @Test + public void na() { + MaxLengthChecker checker = (MaxLengthChecker) new MaxLengthChecker(schema.getPathByLabel("name"), 1) + .withSuccessScore(1) + .withNaScore(-1) + .withFailureScore(-2); + + cache = (CsvSelector) SelectorFactory.getInstance(schema.getFormat(), ""); + cache.setCsvReader(new CsvReader().setHeader( ((CsvAwareSchema) schema).getHeader() )); + + FieldCounter fieldCounter = new FieldCounter<>(); + checker.update(cache, fieldCounter, RuleCheckingOutputType.BOTH); + System.err.println(checker.getHeader()); + + assertEquals(2, fieldCounter.size()); + assertEquals("name:maxLength", checker.getHeaderWithoutId()); + Assert.assertEquals(RuleCheckingOutputStatus.NA, fieldCounter.get(checker.getHeader(RuleCheckingOutputType.STATUS)).getStatus()); + Assert.assertEquals(-1, (int) fieldCounter.get(checker.getHeader(RuleCheckingOutputType.SCORE)).getScore()); + } } \ No newline at end of file