-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/test/java/de/gwdg/metadataqa/api/rule/singlefieldchecker/UniquenessCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package de.gwdg.metadataqa.api.rule.singlefieldchecker; | ||
|
||
import de.gwdg.metadataqa.api.calculator.Indexer; | ||
import de.gwdg.metadataqa.api.counter.FieldCounter; | ||
import de.gwdg.metadataqa.api.json.JsonBranch; | ||
import de.gwdg.metadataqa.api.model.PathCacheFactory; | ||
import de.gwdg.metadataqa.api.model.pathcache.CsvPathCache; | ||
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.BaseSchema; | ||
import de.gwdg.metadataqa.api.schema.CsvAwareSchema; | ||
import de.gwdg.metadataqa.api.schema.Format; | ||
import de.gwdg.metadataqa.api.schema.Schema; | ||
import de.gwdg.metadataqa.api.uniqueness.SolrClientMock; | ||
import de.gwdg.metadataqa.api.uniqueness.SolrConfiguration; | ||
import de.gwdg.metadataqa.api.util.CsvReader; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class UniquenessCheckerTest { | ||
|
||
CsvPathCache cache; | ||
SolrClientMock solrClient; | ||
Schema schema; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
SolrConfiguration solrConfiguration = new SolrConfiguration("localhost", "8983", "solr"); | ||
schema = getSchema(Format.CSV); | ||
solrClient = new SolrClientMock(solrConfiguration); | ||
|
||
cache = (CsvPathCache) PathCacheFactory.getInstance(schema.getFormat(), "URL,two three"); | ||
cache.setCsvReader(new CsvReader().setHeader( ((CsvAwareSchema) schema).getHeader() )); | ||
} | ||
|
||
@Test | ||
public void success() { | ||
UniquenessChecker checker = new UniquenessChecker(schema.getPathByLabel("name")); | ||
checker.setSolrClient(solrClient); | ||
|
||
FieldCounter<RuleCheckerOutput> fieldCounter = new FieldCounter<>(); | ||
checker.update(cache, fieldCounter, RuleCheckingOutputType.BOTH); | ||
|
||
assertEquals(2, fieldCounter.size()); | ||
assertEquals("name:uniqueness", checker.getHeaderWithoutId()); | ||
assertEquals("name:uniqueness:0", checker.getHeader()); | ||
assertTrue(Pattern.compile("^name:uniqueness:\\d+$").matcher(checker.getHeader()).matches()); | ||
assertEquals(RuleCheckingOutputStatus.PASSED, fieldCounter.get(checker.getHeader(RuleCheckingOutputType.STATUS)).getStatus()); | ||
} | ||
|
||
@Test | ||
public void failure() { | ||
UniquenessChecker checker = new UniquenessChecker(schema.getPathByLabel("url")); | ||
checker.setSolrClient(solrClient); | ||
|
||
FieldCounter<RuleCheckerOutput> fieldCounter = new FieldCounter<>(); | ||
checker.update(cache, fieldCounter, RuleCheckingOutputType.BOTH); | ||
|
||
assertEquals(2, fieldCounter.size()); | ||
assertEquals("url:uniqueness", checker.getHeaderWithoutId()); | ||
assertEquals("url:uniqueness:0", checker.getHeader()); | ||
assertTrue(Pattern.compile("^url:uniqueness:\\d+$").matcher(checker.getHeader()).matches()); | ||
assertEquals(RuleCheckingOutputStatus.FAILED, fieldCounter.get(checker.getHeader(RuleCheckingOutputType.STATUS)).getStatus()); | ||
} | ||
|
||
private Schema getSchema(Format format) { | ||
BaseSchema schema = new BaseSchema() | ||
.setFormat(format) | ||
.addField(new JsonBranch("url").setExtractable().setIndexField("url")) | ||
.addField(new JsonBranch("name").setExtractable().setIndexField("name")); | ||
schema.setRecordId(schema.getPathByLabel("url")); | ||
return schema; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters