Skip to content

Commit

Permalink
multilingual rule #192
Browse files Browse the repository at this point in the history
  • Loading branch information
pkiraly committed Aug 23, 2024
1 parent e88cd78 commit 709cb52
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package de.gwdg.metadataqa.api.rule.singlefieldchecker;

import de.gwdg.metadataqa.api.configuration.ConfigurationReader;
import de.gwdg.metadataqa.api.counter.FieldCounter;
import de.gwdg.metadataqa.api.model.selector.JsonSelector;
import de.gwdg.metadataqa.api.model.selector.Selector;
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.util.FileUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.regex.Pattern;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class MultilingalCheckerTest extends CheckerTestBase {
private Selector cache;

@Before
public void setUp() throws Exception {
schema = ConfigurationReader
.readSchemaYaml("src/test/resources/configuration/schema/rules/multilingual/isMultilingual.yaml")
.asSchema();
cache = new JsonSelector(FileUtils
.readFirstLineFromResource("configuration/schema/rules/multilingual/multilingual.json"));
}

@Test
public void success() {
MultilingualChecker checker = new MultilingualChecker(schema.getPathByLabel("description"));

FieldCounter<RuleCheckerOutput> fieldCounter = new FieldCounter<>();
checker.update(cache, fieldCounter, RuleCheckingOutputType.BOTH);

assertEquals(2, fieldCounter.size());
assertEquals("description", checker.getHeaderWithoutId());
assertTrue(Pattern.compile("^description:\\d+$").matcher(checker.getHeader()).matches());
Assert.assertEquals(
RuleCheckingOutputStatus.PASSED,
fieldCounter.get(checker.getHeader(RuleCheckingOutputType.STATUS)).getStatus()
);
}

}
1 change: 0 additions & 1 deletion src/test/resources/configuration/multilingual.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
format: json
fields:
- name: id
path: $.['id']
- name: description
path: $.['description']
asLanguageTagged: true
rules:
- isMultilingual: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":"1","description":{"de":["Portr\u00e4t"],"zh":["\u8096\u50cf"]}}

0 comments on commit 709cb52

Please sign in to comment.