mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-26 01:05:38 +00:00
(fix) tests
This commit is contained in:
parent
7ca3ef90f3
commit
5b1d0cd467
12 changed files with 92 additions and 56 deletions
|
|
@ -0,0 +1,31 @@
|
|||
package de.kosit.validationtool.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import de.kosit.validationtool.api.Configuration;
|
||||
import de.kosit.validationtool.impl.ContentRepository;
|
||||
import de.kosit.validationtool.impl.Scenario;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
@Data
|
||||
public class TestConfiguration implements Configuration {
|
||||
|
||||
private List<Scenario> scenarios;
|
||||
|
||||
private Scenario fallbackScenario;
|
||||
|
||||
private String author;
|
||||
|
||||
private String name;
|
||||
|
||||
private String date;
|
||||
|
||||
private ContentRepository contentRepository;
|
||||
|
||||
private Map<String, Object> additionalParameters;
|
||||
}
|
||||
|
|
@ -22,12 +22,14 @@ package de.kosit.validationtool.impl;
|
|||
import static de.kosit.validationtool.api.InputFactory.read;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
|
@ -37,14 +39,21 @@ import net.sf.saxon.s9api.XdmNode;
|
|||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class DocumentParserTest {
|
||||
public class DocumentParseActionTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private DocumentParseAction action;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.action = new DocumentParseAction(Helper.createProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
final Result<XdmNode, XMLSyntaxError> result = Helper.parseDocument(read(Simple.SIMPLE_VALID));
|
||||
final Result<XdmNode, XMLSyntaxError> result = this.action.parseDocument(read(Simple.SIMPLE_VALID));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getObject()).isNotNull();
|
||||
assertThat(result.getErrors()).isEmpty();
|
||||
|
|
@ -53,7 +62,7 @@ public class DocumentParserTest {
|
|||
|
||||
@Test
|
||||
public void testIllformed() {
|
||||
final Result<XdmNode, XMLSyntaxError> result = Helper.parseDocument(read(Simple.NOT_WELLFORMED));
|
||||
final Result<XdmNode, XMLSyntaxError> result = this.action.parseDocument(read(Simple.NOT_WELLFORMED));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getErrors()).isNotEmpty();
|
||||
assertThat(result.getObject()).isNull();
|
||||
|
|
@ -63,7 +72,7 @@ public class DocumentParserTest {
|
|||
@Test
|
||||
public void testNullInput() {
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
Helper.parseDocument(null);
|
||||
this.action.parseDocument(null);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -43,6 +43,7 @@ import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
|||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
|
||||
import net.sf.saxon.dom.NodeOverNodeInfo;
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
|
|
@ -161,7 +162,20 @@ public class Helper {
|
|||
return serialize((Document) NodeOverNodeInfo.wrap(node.getUnderlyingNode()));
|
||||
}
|
||||
|
||||
public static Result<XdmNode, XMLSyntaxError> parseDocument(final Processor processor, final Input input) {
|
||||
return new DocumentParseAction(processor).parseDocument(input);
|
||||
}
|
||||
|
||||
public static Result<XdmNode, XMLSyntaxError> parseDocument(final Input input) {
|
||||
return new DocumentParseAction(TestObjectFactory.createProcessor()).parseDocument(input);
|
||||
return new DocumentParseAction(getTestProcessor()).parseDocument(input);
|
||||
}
|
||||
|
||||
public static Processor getTestProcessor() {
|
||||
// is always the same at the moment
|
||||
return createProcessor();
|
||||
}
|
||||
|
||||
public static Processor createProcessor() {
|
||||
return ResolvingMode.STRICT_RELATIVE.getStrategy().getProcessor();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,22 +26,17 @@ import java.io.IOException;
|
|||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import de.kosit.validationtool.api.Configuration;
|
||||
import de.kosit.validationtool.config.TestConfiguration;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.model.scenarios.ScenarioType;
|
||||
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
import net.sf.saxon.s9api.XPathExecutable;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
|
|
@ -53,45 +48,25 @@ import net.sf.saxon.s9api.XdmNode;
|
|||
|
||||
public class ScenarioRepositoryTest {
|
||||
|
||||
@Data
|
||||
private static class DummyConfiguration implements Configuration {
|
||||
|
||||
private List<Scenario> scenarios;
|
||||
|
||||
private Scenario fallbackScenario;
|
||||
|
||||
private String author;
|
||||
|
||||
private String name;
|
||||
|
||||
private String date;
|
||||
|
||||
private Processor processor;
|
||||
|
||||
private ContentRepository contentRepository;
|
||||
|
||||
private Map<String, Object> additionalParameters;
|
||||
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private ScenarioRepository repository;
|
||||
|
||||
private DummyConfiguration configInstance;
|
||||
private TestConfiguration configInstance;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
final Scenario s = createScenario();
|
||||
this.configInstance = new TestConfiguration();
|
||||
this.configInstance.setContentRepository(new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), null));
|
||||
|
||||
this.configInstance = new DummyConfiguration();
|
||||
final Scenario s = createScenario();
|
||||
this.configInstance.setScenarios(new ArrayList<>());
|
||||
this.configInstance.getScenarios().add(s);
|
||||
this.repository = new ScenarioRepository(this.configInstance);
|
||||
}
|
||||
|
||||
private static Scenario createScenario() {
|
||||
private Scenario createScenario() {
|
||||
final Scenario s = new Scenario(new ScenarioType());
|
||||
s.setMatchExecutable(createXpath("//*:name"));
|
||||
return s;
|
||||
|
|
@ -134,11 +109,11 @@ public class ScenarioRepositoryTest {
|
|||
assertThat(scenario.getObject().getName()).isEqualTo("fallback");
|
||||
}
|
||||
|
||||
private static XdmNode load(final URI uri) throws IOException {
|
||||
return Helper.parseDocument(read(uri.toURL())).getObject();
|
||||
private XdmNode load(final URI uri) throws IOException {
|
||||
return Helper.parseDocument(this.configInstance.getContentRepository().getProcessor(), read(uri.toURL())).getObject();
|
||||
}
|
||||
|
||||
private static XPathExecutable createXpath(final String expression) {
|
||||
return new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), null).createXPath(expression, new HashMap<>());
|
||||
private XPathExecutable createXpath(final String expression) {
|
||||
return this.configInstance.getContentRepository().createXPath(expression, new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue