mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-26 01:05:38 +00:00
support multiple configuration
This commit is contained in:
parent
730d7fefe9
commit
2e6efdd16f
59 changed files with 1136 additions and 608 deletions
|
|
@ -21,7 +21,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -61,12 +60,6 @@ public class ContentRepositoryTest {
|
|||
assertThat(schema).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaCaching() {
|
||||
final Schema schema = this.repository.getReportInputSchema();
|
||||
assertThat(this.repository.getReportInputSchema()).isSameAs(schema);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSchemaNotExisting() throws Exception {
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
|
|
@ -112,36 +105,12 @@ public class ContentRepositoryTest {
|
|||
@Test
|
||||
public void loadFromJar() throws URISyntaxException {
|
||||
assert Helper.JAR_REPOSITORY != null;
|
||||
this.repository = new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), Helper.JAR_REPOSITORY.toURI());
|
||||
this.repository = new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(),
|
||||
Helper.JAR_REPOSITORY.toURI());
|
||||
final XsltExecutable xsltExecutable = this.repository.loadXsltScript(URI.create("report.xsl"));
|
||||
assertThat(xsltExecutable).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadSchema() {
|
||||
final URL main = RelativeUriResolverTest.class.getClassLoader().getResource("loading/main.xsd");
|
||||
assert main != null;
|
||||
final Schema schema = this.repository.createSchema(main, new ClassPathResourceResolver("/loading"));
|
||||
final Schema schema = this.repository.createSchema(URI.create("main.xsd"));
|
||||
assertThat(schema).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadSchemaPackaged() throws URISyntaxException {
|
||||
final URL main = RelativeUriResolverTest.class.getClassLoader().getResource("packaged/main.xsd");
|
||||
assert main != null;
|
||||
final Schema schema = this.repository.createSchema(main,
|
||||
new ClassPathResourceResolver(RelativeUriResolverTest.class.getClassLoader().getResource("packaged/").toURI()));
|
||||
assertThat(schema).isNotNull();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void loadFromJar() throws URISyntaxException {
|
||||
// this.content = new ContentRepository(TestObjectFactory.createProcessor(), Helper.JAR_REPOSITORY.toURI());
|
||||
// this.repository = new ScenarioRepository(this.content);
|
||||
// final CheckConfiguration conf = new CheckConfiguration(
|
||||
// ScenarioRepository.class.getClassLoader().getResource("xrechnung/scenarios.xml").toURI());
|
||||
// ScenarioRepository.initialize(conf);
|
||||
// assertThat(this.repository.getScenarios()).isNotNull();
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,16 +65,17 @@ public class DefaultCheckTest {
|
|||
|
||||
@Before
|
||||
public void setup() throws URISyntaxException {
|
||||
final Configuration validConfig = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build();
|
||||
final Configuration validConfig = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build(Helper.getTestProcessor());
|
||||
this.validCheck = new DefaultCheck(validConfig);
|
||||
|
||||
final Configuration errorConfig = Configuration.load(Simple.ERROR_SCENARIOS, Simple.REPOSITORY_URI).build();
|
||||
final Configuration errorConfig = Configuration.load(Simple.ERROR_SCENARIOS, Simple.REPOSITORY_URI)
|
||||
.build(Helper.getTestProcessor());
|
||||
this.errorCheck = new DefaultCheck(errorConfig);
|
||||
|
||||
final Configuration jarConfig = Configuration
|
||||
.load(requireNonNull(DefaultCheckTest.class.getClassLoader().getResource("simple/packaged/scenarios.xml")).toURI(),
|
||||
requireNonNull(DefaultCheckTest.class.getClassLoader().getResource("simple/packaged/repository/")).toURI())
|
||||
.build();
|
||||
.build(Helper.getTestProcessor());
|
||||
|
||||
this.jarScenarioCheck = new DefaultCheck(jarConfig);
|
||||
}
|
||||
|
|
@ -248,8 +249,7 @@ public class DefaultCheckTest {
|
|||
assertThat(result.isProcessingSuccessful()).isEqualTo(true);
|
||||
|
||||
// test compatible configuration
|
||||
node = this.validCheck.getConfiguration().getContentRepository().getProcessor().newDocumentBuilder()
|
||||
.build(new StreamSource(SIMPLE_VALID.toASCIIString()));
|
||||
node = this.validCheck.getProcessor().newDocumentBuilder().build(new StreamSource(SIMPLE_VALID.toASCIIString()));
|
||||
domInput = InputFactory.read(node, "node test");
|
||||
result = this.validCheck.checkInput(domInput);
|
||||
assertThat(result.isProcessingSuccessful()).isEqualTo(true);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import de.kosit.validationtool.api.Input;
|
|||
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
||||
import de.kosit.validationtool.impl.xml.ProcessorProvider;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
|
|
@ -61,6 +62,8 @@ public class Helper {
|
|||
|
||||
public static final URI SCENARIOS = ROOT.resolve("scenarios.xml");
|
||||
|
||||
public static final URI OTHER_SCENARIOS = ROOT.resolve("otherScenarios.xml");
|
||||
|
||||
public static final URI ERROR_SCENARIOS = ROOT.resolve("scenarios-with-errors.xml");
|
||||
|
||||
public static final URI REPOSITORY_URI = ROOT.resolve("repository/");
|
||||
|
|
@ -83,7 +86,7 @@ public class Helper {
|
|||
|
||||
public static final ContentRepository createContentRepository() {
|
||||
final ResolvingConfigurationStrategy strategy = ResolvingMode.STRICT_RELATIVE.getStrategy();
|
||||
return new ContentRepository(strategy, Simple.REPOSITORY_URI);
|
||||
return new ContentRepository(Helper.getTestProcessor(), strategy, Simple.REPOSITORY_URI);
|
||||
}
|
||||
|
||||
public static URI getSchemaLocation() {
|
||||
|
|
@ -122,6 +125,8 @@ public class Helper {
|
|||
|
||||
public static final URL JAR_REPOSITORY = Helper.class.getClassLoader().getResource("simple/packaged/repository/");
|
||||
|
||||
public static final URI LARGE_XML = Paths.get("pom.xml").toUri();
|
||||
|
||||
/**
|
||||
* Lädt ein XML-Dokument von der gegebenen URL
|
||||
*
|
||||
|
|
@ -171,6 +176,6 @@ public class Helper {
|
|||
}
|
||||
|
||||
public static Processor createProcessor() {
|
||||
return ResolvingMode.STRICT_RELATIVE.getStrategy().getProcessor();
|
||||
return ProcessorProvider.getProcessor();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ public class ScenarioRepositoryTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
this.configInstance = new TestConfiguration();
|
||||
this.configInstance.setContentRepository(new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), null));
|
||||
this.configInstance
|
||||
.setContentRepository(new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(), null));
|
||||
|
||||
final Scenario s = createScenario();
|
||||
this.configInstance.setScenarios(new ArrayList<>());
|
||||
|
|
@ -106,6 +107,25 @@ public class ScenarioRepositoryTest {
|
|||
assertThat(scenario.getObject().getName()).isEqualTo("fallback");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoConfiguration() {
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
this.repository = new ScenarioRepository();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFallbackOnMultipleConfigurations() {
|
||||
final TestConfiguration first = this.configInstance;
|
||||
first.setFallbackScenario(createFallback());
|
||||
setup();// create new one;
|
||||
final TestConfiguration second = this.configInstance;
|
||||
second.setFallbackScenario(createFallback());
|
||||
this.repository = new ScenarioRepository(first, second);
|
||||
final Scenario fallback = this.repository.getFallbackScenario();
|
||||
assertThat(fallback).isSameAs(first.getFallbackScenario());
|
||||
assertThat(fallback).isNotSameAs(second.getFallbackScenario());
|
||||
}
|
||||
|
||||
private XdmNode load(final URI uri) throws IOException {
|
||||
return Helper.parseDocument(this.configInstance.getContentRepository().getProcessor(), read(uri.toURL())).getObject();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class SimpleScenarioCheckTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
final Configuration d = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build();
|
||||
final Configuration d = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build(Helper.getTestProcessor());
|
||||
this.implementation = new DefaultCheck(d);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package de.kosit.validationtool.impl;
|
||||
|
||||
import de.kosit.validationtool.impl.xml.StrictLocalResolvingStrategy;
|
||||
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
|
||||
/**
|
||||
|
|
@ -29,7 +27,7 @@ public class TestObjectFactory {
|
|||
|
||||
public static Processor createProcessor() {
|
||||
if (processor == null) {
|
||||
processor = new StrictLocalResolvingStrategy().getProcessor();
|
||||
processor = Helper.getTestProcessor();
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,25 +59,25 @@ public class VersioningTest {
|
|||
|
||||
@Test
|
||||
public void testBase() throws URISyntaxException {
|
||||
final Scenarios result = this.service.readXml(BASE.toURI(), Scenarios.class, this.repository.getScenarioSchema());
|
||||
final Scenarios result = this.service.readXml(BASE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFrameworkIncrement() throws URISyntaxException {
|
||||
final Scenarios result = this.service.readXml(INCREMENT.toURI(), Scenarios.class, this.repository.getScenarioSchema());
|
||||
final Scenarios result = this.service.readXml(INCREMENT.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewFeature() throws URISyntaxException {
|
||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
||||
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, this.repository.getScenarioSchema());
|
||||
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewVersion() throws URISyntaxException {
|
||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
||||
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, this.repository.getScenarioSchema());
|
||||
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright 2017-2020 Koordinierungsstelle für IT-Standards (KoSIT)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.kosit.validationtool.impl.input;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class StreamHelperTest {
|
||||
|
||||
/**
|
||||
* Simulates a stream that is return 0 for {@link InputStream#available()} even though content is supplied.
|
||||
*/
|
||||
private static class MyLazyStream extends FilterInputStream {
|
||||
|
||||
protected MyLazyStream(final InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyStream() throws IOException {
|
||||
final String myContent = "SomeBytes";
|
||||
try ( final InputStream in = new MyLazyStream(new ByteArrayInputStream(myContent.getBytes())) ) {
|
||||
final BufferedInputStream peekable = StreamHelper.wrapPeekable(in);
|
||||
assertThat(peekable.available()).isGreaterThan(0);
|
||||
final String read = IOUtils.toString(peekable, Charset.defaultCharset());
|
||||
assertThat(read).isEqualTo(myContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ import org.junit.Test;
|
|||
|
||||
import de.kosit.validationtool.api.AcceptRecommendation;
|
||||
import de.kosit.validationtool.impl.ContentRepository;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.ResolvingMode;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
|
||||
|
||||
|
|
@ -121,6 +122,7 @@ public class ComputeAcceptanceActionTest {
|
|||
}
|
||||
|
||||
private static XPathExecutable createXpath(final String expression) {
|
||||
return new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), null).createXPath(expression, new HashMap<>());
|
||||
return new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(), null).createXPath(expression,
|
||||
new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,8 +54,7 @@ public class CreateReportActionTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
this.repository = Simple.createContentRepository();
|
||||
this.action = new CreateReportAction(this.repository.getProcessor(), new ConversionService(), this.repository.getResolver(),
|
||||
this.repository.getUnparsedTextURIResolver());
|
||||
this.action = new CreateReportAction(this.repository.getProcessor(), new ConversionService());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -85,7 +84,7 @@ public class CreateReportActionTest {
|
|||
public void testExecutionException() throws SaxonApiException {
|
||||
final Processor p = mock(Processor.class);
|
||||
final DocumentBuilder documentBuilder = mock(DocumentBuilder.class);
|
||||
this.action = new CreateReportAction(p, new ConversionService(), null, null);
|
||||
this.action = new CreateReportAction(p, new ConversionService());
|
||||
|
||||
when(p.newDocumentBuilder()).thenReturn(documentBuilder);
|
||||
when(documentBuilder.build(any(Source.class))).thenThrow(new SaxonApiException("mocked"));
|
||||
|
|
|
|||
|
|
@ -44,10 +44,10 @@ import de.kosit.validationtool.api.XmlError.Severity;
|
|||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.Scenario;
|
||||
import de.kosit.validationtool.impl.SchemaProvider;
|
||||
import de.kosit.validationtool.impl.TestObjectFactory;
|
||||
import de.kosit.validationtool.impl.input.SourceInput;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
|
||||
import de.kosit.validationtool.impl.xml.StrictRelativeResolvingStrategy;
|
||||
|
||||
/**
|
||||
* Tests die {@link SchemaValidationAction}.
|
||||
|
|
@ -62,7 +62,7 @@ public class SchemaValidatorActionTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.service = new SchemaValidationAction(new StrictRelativeResolvingStrategy(), TestObjectFactory.createProcessor());
|
||||
this.service = new SchemaValidationAction(TestObjectFactory.createProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -89,7 +89,7 @@ public class SchemaValidatorActionTest {
|
|||
|
||||
@Test
|
||||
public void testSchemaReferences() {
|
||||
final Schema reportInputSchema = Simple.createContentRepository().getReportInputSchema();
|
||||
final Schema reportInputSchema = SchemaProvider.getReportInputSchema();
|
||||
assertThat(reportInputSchema).isNotNull();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import de.kosit.validationtool.impl.ConversionService;
|
|||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.Scenario;
|
||||
import de.kosit.validationtool.impl.Scenario.Transformation;
|
||||
import de.kosit.validationtool.impl.xml.RelativeUriResolver;
|
||||
import de.kosit.validationtool.model.scenarios.ResourceType;
|
||||
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
|
|
@ -51,7 +50,7 @@ public class SchematronValidationActionTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.action = new SchematronValidationAction(new RelativeUriResolver(Simple.REPOSITORY_URI), new ConversionService());
|
||||
this.action = new SchematronValidationAction(new ConversionService());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.oclc.purl.dsdl.svrl.SchematronOutput;
|
|||
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
|
||||
import de.kosit.validationtool.impl.ContentRepository;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.ResolvingMode;
|
||||
|
|
@ -82,6 +83,8 @@ public class TestBagBuilder {
|
|||
t.setValidateWithXmlSchema(v);
|
||||
final Scenario scenario = new Scenario(t);
|
||||
scenario.setSchema(createSchema(schemafile.toURL()));
|
||||
final ResolvingConfigurationStrategy strategy = ResolvingMode.STRICT_RELATIVE.getStrategy();
|
||||
scenario.setFactory(strategy);
|
||||
return scenario;
|
||||
} catch (final MalformedURLException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
|
|
@ -89,7 +92,8 @@ public class TestBagBuilder {
|
|||
}
|
||||
|
||||
private static Schema createSchema(final URL toURL) {
|
||||
final ContentRepository contentRepository = new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), null);
|
||||
final ContentRepository contentRepository = new ContentRepository(Helper.getTestProcessor(),
|
||||
ResolvingMode.STRICT_RELATIVE.getStrategy(), null);
|
||||
return contentRepository.createSchema(toURL);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2017-2020 Koordinierungsstelle für IT-Standards (KoSIT)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.kosit.validationtool.impl.xml;
|
||||
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
|
||||
import de.kosit.validationtool.impl.ResolvingMode;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class SchemaProviderTest {
|
||||
|
||||
private final SchemaFactory schemaFactory = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue