mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-26 01:05:38 +00:00
Moved validation tool one level up, as it is now the sole content of this repository
This commit is contained in:
parent
7383efd257
commit
9ad51731ab
97 changed files with 260 additions and 315 deletions
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.validation.Schema;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import net.sf.saxon.s9api.XPathExecutable;
|
||||
import net.sf.saxon.s9api.XsltExecutable;
|
||||
|
||||
/**
|
||||
* Testet das ContentRepository.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class ContentRepositoryTest {
|
||||
|
||||
private ContentRepository repository;
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
repository = new ContentRepository(ObjectFactory.createProcessor(), Helper.REPOSITORY);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCreateSchema() throws MalformedURLException {
|
||||
final Schema schema = repository.createSchema(Helper.ASSERTION_SCHEMA.toURL());
|
||||
assertThat(schema).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaCaching() throws MalformedURLException {
|
||||
final Schema schema = repository.getReportInputSchema();
|
||||
assertThat(repository.getReportInputSchema()).isSameAs(schema);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSchemaNotExisting()throws Exception {
|
||||
exception.expect(IllegalStateException.class);
|
||||
repository.createSchema(Helper.ASSERTION_SCHEMA.resolve("noexisting").toURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadXSLT() throws MalformedURLException {
|
||||
final XsltExecutable executable = repository.loadXsltScript(Helper.SAMPLE_XSLT);
|
||||
assertThat(executable).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadXSLTNotExisting() throws MalformedURLException {
|
||||
exception.expect(IllegalStateException.class);
|
||||
repository.loadXsltScript(Helper.SAMPLE_XSLT.resolve("notexisting"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXpathCreation() throws MalformedURLException {
|
||||
XPathExecutable xPath = repository.createXPath("//html", null);
|
||||
assertThat(xPath).isNotNull();
|
||||
xPath = repository.createXPath("//html", Collections.emptyMap());
|
||||
assertThat(xPath).isNotNull();
|
||||
Map<String,String> namespace = new HashMap<>();
|
||||
namespace.put("html", "http://www.w3.org/1999/xhtml");
|
||||
xPath = repository.createXPath("//html:html", namespace );
|
||||
assertThat(xPath).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXpathCreationWithoutNamespace(){
|
||||
exception.expect(IllegalStateException.class);
|
||||
repository.createXPath("//html:html", null );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIllegalXpath(){
|
||||
exception.expect(IllegalStateException.class);
|
||||
repository.createXPath("kein Xpath Ausdruck", null );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.model.scenarios.Scenarios;
|
||||
|
||||
/**
|
||||
* Simple test for testing the jaxb conversion service.
|
||||
*
|
||||
* @author apenski
|
||||
*/
|
||||
public class ConversionServiceTest {
|
||||
|
||||
private static final URL VALID_XML = ConversionServiceTest.class.getResource("/valid/scenarios.xml");
|
||||
|
||||
private static final URL INVALID_XML = ConversionServiceTest.class.getResource("/invalid/scenarios-invalid.xml");
|
||||
|
||||
private static final URL ILLFORMED_XML = ConversionServiceTest.class.getResource("/invalid/scenarios-illformed.xml");
|
||||
|
||||
private static final URL SCHEMA = ConversionServiceTest.class.getResource("/xsd/scenarios.xsd");
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private ConversionService service;
|
||||
|
||||
private ContentRepository repository;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
service = new ConversionService();
|
||||
repository = new ContentRepository(ObjectFactory.createProcessor(), new File("src/test/resources/examples/repository").toURI());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarshalNull() {
|
||||
exception.expect(ConversionService.ConversionExeption.class);
|
||||
service.writeXml(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarshalUnknown() {
|
||||
exception.expect(ConversionService.ConversionExeption.class);
|
||||
service.writeXml(new Serializable() {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshal() throws URISyntaxException {
|
||||
final Scenarios s = service.readXml(VALID_XML.toURI(), Scenarios.class);
|
||||
assertThat(s).isNotNull();
|
||||
assertThat(s.getName()).isEqualToIgnoringCase("XInneres");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalWithSchema() throws URISyntaxException {
|
||||
final Scenarios s = service.readXml(VALID_XML.toURI(), Scenarios.class, repository.createSchema(SCHEMA));
|
||||
assertThat(s).isNotNull();
|
||||
assertThat(s.getName()).isEqualToIgnoringCase("XInneres");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalInvalidXml() throws URISyntaxException {
|
||||
exception.expect(ConversionService.ConversionExeption.class);
|
||||
service.readXml(INVALID_XML.toURI(), Scenarios.class, repository.createSchema(SCHEMA));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalIllFormed() throws URISyntaxException {
|
||||
exception.expect(ConversionService.ConversionExeption.class);
|
||||
service.readXml(ILLFORMED_XML.toURI(), Scenarios.class, repository.createSchema(SCHEMA));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalEmpty() {
|
||||
exception.expect(ConversionService.ConversionExeption.class);
|
||||
service.readXml(null, Scenarios.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalUnknownType() throws URISyntaxException {
|
||||
exception.expect(ConversionService.ConversionExeption.class);
|
||||
service.readXml(VALID_XML.toURI(), ConversionService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalWithoutType() throws URISyntaxException {
|
||||
exception.expect(ConversionService.ConversionExeption.class);
|
||||
service.readXml(VALID_XML.toURI(), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import de.kosit.validationtool.api.CheckConfiguration;
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static de.kosit.validationtool.api.InputFactory.read;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test das Check-Interface
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class DefaultCheckTest {
|
||||
|
||||
private static final URL SCENARIO_DEFINITION = ScenarioRepositoryTest.class.getResource("/examples/UBLReady/scenarios-2.xml");
|
||||
|
||||
private static final URL VALID_EXAMPLE = ScenarioRepositoryTest.class
|
||||
.getResource("/examples/UBLReady/UBLReady_EU_UBL-NL_20170102_FULL.xml");
|
||||
|
||||
public static final int MULTI_COUNT = 5;
|
||||
|
||||
private DefaultCheck implementation;
|
||||
|
||||
@Before
|
||||
public void setup() throws URISyntaxException {
|
||||
CheckConfiguration d = new CheckConfiguration(SCENARIO_DEFINITION.toURI());
|
||||
d.setScenarioRepository(new File("src/test/resources/examples/repository").toURI());
|
||||
implementation = new DefaultCheck(d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHappyCase() throws Exception {
|
||||
final Document doc = implementation.check(read(VALID_EXAMPLE));
|
||||
assertThat(doc).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleCase() throws Exception {
|
||||
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(VALID_EXAMPLE)).collect(Collectors.toList());
|
||||
final List<Document> docs = implementation.check(input);
|
||||
assertThat(docs).isNotNull();
|
||||
assertThat(docs).hasSize(MULTI_COUNT);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static de.kosit.validationtool.api.InputFactory.read;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class DocumentParserTest {
|
||||
|
||||
private static final URL CONTENT = ConversionServiceTest.class.getResource("/valid/scenarios.xml");
|
||||
|
||||
private static final URL ILLFORMED = ConversionServiceTest.class.getResource("/invalid/scenarios-illformed.xml");
|
||||
|
||||
private static final URL NOT_EXISTING = ConversionServiceTest.class.getResource("/does not exist.xml");
|
||||
|
||||
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private DocumentParseAction parser;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
parser = new DocumentParseAction();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple() throws IOException {
|
||||
final Result<Document, XMLSyntaxError> result = parser.parseDocument(read(CONTENT));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getObject()).isNotNull();
|
||||
assertThat(result.getErrors()).isEmpty();
|
||||
assertThat(result.isValid()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIllformed() throws IOException {
|
||||
final Result<Document, XMLSyntaxError> result = parser.parseDocument(read(ILLFORMED));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getErrors()).isNotEmpty();
|
||||
assertThat(result.getObject()).isNull();
|
||||
assertThat(result.isValid()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullInput() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
parser.parseDocument(null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
102
src/test/java/de/kosit/validationtool/impl/Helper.java
Normal file
102
src/test/java/de/kosit/validationtool/impl/Helper.java
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
|
||||
/**
|
||||
* Helferlein für Test-Artefakte
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class Helper {
|
||||
|
||||
public static final URI SOURCE_ROOT = Paths.get("src/main/resources").toUri();
|
||||
|
||||
public static final URI MODEL_ROOT = Paths.get("src/main/model").toUri();
|
||||
|
||||
public static final URI ASSERTION_SCHEMA = MODEL_ROOT.resolve("xsd/assertions.xsd");
|
||||
|
||||
public static final URI SCENARIO_SCHEMA = MODEL_ROOT.resolve("xsd/scenarios.xsd");
|
||||
|
||||
public static final URI TEST_ROOT = Paths.get("src/test/resources").toUri();
|
||||
|
||||
|
||||
|
||||
public static final URI EXAMPLES_DIR = TEST_ROOT.resolve("examples/");
|
||||
public static final URI ASSERTIONS = EXAMPLES_DIR.resolve("assertions/tests-xrechnung.xml");
|
||||
|
||||
public static final URI SCENARIO_FILE = EXAMPLES_DIR.resolve("UBLReady/scenarios-2.xml");
|
||||
|
||||
|
||||
public static final URI REPOSITORY = EXAMPLES_DIR.resolve("repository/");
|
||||
|
||||
public static final URI NOT_EXISTING = EXAMPLES_DIR.resolve("doesnotexist");
|
||||
|
||||
public static final URI SAMPLE_DIR = EXAMPLES_DIR.resolve("UBLReady/");
|
||||
public static final URI SAMPLE_XSLT = EXAMPLES_DIR.resolve("repository/resources/eRechnung/report.xsl");
|
||||
public static final URI SAMPLE = SAMPLE_DIR.resolve("UBLReady_EU_UBL-NL_20170102_FULL.xml");
|
||||
|
||||
public static final URI SAMPLE2 = SAMPLE_DIR.resolve("UBLReady_EU_UBL-NL_20170102_FULL-invalid.xml");
|
||||
|
||||
|
||||
/**
|
||||
* Lädt ein XML-Dokument von der gegebenen URL
|
||||
*
|
||||
* @param url die url die geladen werden soll
|
||||
* @return ein result objekt mit Dokument
|
||||
*/
|
||||
public static Result<Document, XMLSyntaxError> load(URL url) {
|
||||
DocumentParseAction a = new DocumentParseAction();
|
||||
CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(url));
|
||||
a.check(b);
|
||||
return b.getParserResult();
|
||||
}
|
||||
|
||||
public static <T> T load(URL url, Class<T> type) throws URISyntaxException {
|
||||
ConversionService c = new ConversionService();
|
||||
c.initialize(de.kosit.validationtool.model.reportInput.ObjectFactory.class.getPackage(),
|
||||
de.kosit.validationtool.cmd.assertions.ObjectFactory.class.getPackage(),
|
||||
de.kosit.validationtool.model.scenarios.ObjectFactory.class.getPackage());
|
||||
return c.readXml(url.toURI(), type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt das default test repository mit Artefacten für Unit-Tests
|
||||
*
|
||||
* @return ein {@link ContentRepository}
|
||||
*/
|
||||
public static ContentRepository loadTestRepository() {
|
||||
return new ContentRepository(ObjectFactory.createProcessor(), new File("src/test/resources/examples/repository").toURI());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.URIResolver;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
/**
|
||||
* Testet den Uri-Resolver der relative auflösen soll
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class RelativeUriResolverTest {
|
||||
|
||||
private static final URI BASE;
|
||||
|
||||
static {
|
||||
try {
|
||||
BASE = RelativeUriResolver.class.getResource("/examples/assertions/").toURI();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private URIResolver resolver = new RelativeUriResolver(BASE);
|
||||
|
||||
@Test
|
||||
public void testSucces() throws TransformerException {
|
||||
final Source resource = resolver.resolve("ubl-0001.xml", BASE.toASCIIString());
|
||||
assertThat(resource).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotExisting() throws TransformerException {
|
||||
exception.expect(IllegalStateException.class);
|
||||
resolver.resolve("ubl-0001", BASE.toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutOfPath() throws TransformerException {
|
||||
exception.expect(IllegalStateException.class);
|
||||
resolver.resolve("../results/report.xml", BASE.toASCIIString());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import net.sf.saxon.s9api.*;
|
||||
|
||||
/**
|
||||
* Testet verschiedene Saxon Security Einstellungen.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
@Slf4j
|
||||
public class SaxonSecurityTest {
|
||||
|
||||
@Test
|
||||
public void testEvilStylesheets() throws IOException {
|
||||
Processor p = ObjectFactory.createProcessor();
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
try {
|
||||
URL resource = SaxonSecurityTest.class.getResource(String.format("/evil/evil%s.xsl", i));
|
||||
final XsltCompiler compiler = p.newXsltCompiler();
|
||||
final RelativeUriResolver resolver = new RelativeUriResolver(Helper.REPOSITORY);
|
||||
compiler.setURIResolver(resolver);
|
||||
final XsltExecutable exetuable = compiler.compile(new StreamSource(resource.openStream()));
|
||||
final XsltTransformer transformer = exetuable.load();
|
||||
final Document document = ObjectFactory.createDocumentBuilder(false).newDocument();
|
||||
document.createElement("root");
|
||||
Document result = ObjectFactory.createDocumentBuilder(false).newDocument();
|
||||
transformer.getUnderlyingController().setUnparsedTextURIResolver(resolver);
|
||||
transformer.setURIResolver(resolver);
|
||||
transformer.setSource(new DOMSource(document));
|
||||
transformer.setDestination(new DOMDestination(result));
|
||||
transformer.transform();
|
||||
|
||||
// wenn der Punkt erreicht wird, sollte wenigstens, das Element evil nicht mit 'bösen' Inhalten gefüllt sein!
|
||||
if (StringUtils.isNotBlank(result.getDocumentElement().getTextContent())) {
|
||||
fail(String.format("Saxon configuration should prevent expansion within %s", resource));
|
||||
}
|
||||
|
||||
} catch (SaxonApiException | RuntimeException e) {
|
||||
log.info("Expected exception detected", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static de.kosit.validationtool.api.InputFactory.read;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
||||
import de.kosit.validationtool.model.scenarios.ScenarioType;
|
||||
import de.kosit.validationtool.model.scenarios.Scenarios;
|
||||
|
||||
/**
|
||||
* Testet das {@link ScenarioRepository}.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
|
||||
public class ScenarioRepositoryTest {
|
||||
|
||||
private static final URL SAMPLE = ScenarioRepositoryTest.class.getResource("/valid/scenarios.xml");
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
ContentRepository content;
|
||||
|
||||
private ScenarioRepository repository;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
content = new ContentRepository(ObjectFactory.createProcessor(), new File("src/test/resources/examples/repository").toURI());
|
||||
Scenarios def = new Scenarios();
|
||||
ScenarioType t = new ScenarioType();
|
||||
t.setMatch("//*:name");
|
||||
t.setName("Test");
|
||||
t.initialize(content, true);
|
||||
def.getScenario().add(t);
|
||||
repository = new ScenarioRepository(ObjectFactory.createProcessor(), content);
|
||||
repository.initialize(def);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHappyCase() throws Exception {
|
||||
final Result<ScenarioType, String> scenario = repository.selectScenario(load(SAMPLE));
|
||||
assertThat(scenario).isNotNull();
|
||||
assertThat(scenario.isValid()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonMatch() throws Exception {
|
||||
repository.getScenarios().getScenario().clear();
|
||||
final Result<ScenarioType, String> scenario = repository.selectScenario(load(SAMPLE));
|
||||
assertThat(scenario).isNotNull();
|
||||
assertThat(scenario.isValid()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiMatch() throws Exception {
|
||||
ScenarioType t = new ScenarioType();
|
||||
t.setMatch("//*:name");
|
||||
t.setName("Test");
|
||||
t.initialize(content, true);
|
||||
repository.getScenarios().getScenario().add(t);
|
||||
final Result<ScenarioType, String> scenario = repository.selectScenario(load(SAMPLE));
|
||||
assertThat(scenario).isNotNull();
|
||||
assertThat(scenario.isValid()).isFalse();
|
||||
}
|
||||
|
||||
private Document load(URL url) throws IOException {
|
||||
DocumentParseAction p = new DocumentParseAction();
|
||||
return p.parseDocument(read(url)).getObject();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.xml.validation.Schema;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
import de.kosit.validationtool.impl.tasks.SchemaValidationAction;
|
||||
import de.kosit.validationtool.model.reportInput.CreateReportInput;
|
||||
import de.kosit.validationtool.model.scenarios.ResourceType;
|
||||
import de.kosit.validationtool.model.scenarios.ScenarioType;
|
||||
import de.kosit.validationtool.model.scenarios.ValidateWithXmlSchema;
|
||||
|
||||
/**
|
||||
* Testet die {@linkSchemaValidatorAction}.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class SchemaValidatorActionTest {
|
||||
|
||||
private static final URL VALID_EXAMPLE = SchemaValidatorActionTest.class
|
||||
.getResource("/examples/UBLReady/UBLReady_EU_UBL-NL_20170102_FULL.xml");
|
||||
|
||||
private static final URI INVALID_EXAMPLE = Helper.TEST_ROOT.resolve("invalid/scenarios-invalid.xml");
|
||||
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private SchemaValidationAction service;
|
||||
|
||||
private ContentRepository repository;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
service = new SchemaValidationAction();
|
||||
repository = new ContentRepository(ObjectFactory.createProcessor(), Helper.REPOSITORY);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
CheckAction.Bag bag = new CheckAction.Bag(InputFactory.read(VALID_EXAMPLE), new CreateReportInput());
|
||||
bag.setParserResult(Helper.load(VALID_EXAMPLE));
|
||||
ScenarioType t = new ScenarioType();
|
||||
ValidateWithXmlSchema v = new ValidateWithXmlSchema();
|
||||
ResourceType r = new ResourceType();
|
||||
r.setLocation("resources/eRechnung/UBL-2.1/xsdrt/maindoc/UBL-Invoice-2.1.xsd");
|
||||
r.setName("invoice");
|
||||
v.getResource().add(r);
|
||||
t.setValidateWithXmlSchema(v);
|
||||
t.initialize(repository, true);
|
||||
bag.setScenarioSelectionResult(new Result<>(t, Collections.emptyList()));
|
||||
service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationFailure() throws MalformedURLException {
|
||||
CheckAction.Bag bag = new CheckAction.Bag(InputFactory.read(INVALID_EXAMPLE.toURL()), new CreateReportInput());
|
||||
bag.setParserResult(Helper.load(INVALID_EXAMPLE.toURL()));
|
||||
ScenarioType t = new ScenarioType();
|
||||
ValidateWithXmlSchema v = new ValidateWithXmlSchema();
|
||||
ResourceType r = new ResourceType();
|
||||
r.setLocation(Helper.REPOSITORY.relativize(Helper.SCENARIO_SCHEMA).getRawPath());
|
||||
r.setName("invoice");
|
||||
v.getResource().add(r);
|
||||
t.setValidateWithXmlSchema(v);
|
||||
t.initialize(repository, true);
|
||||
bag.setScenarioSelectionResult(new Result<>(t, Collections.emptyList()));
|
||||
service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isFalse();
|
||||
bag.getSchemaValidationResult().getErrors().forEach(e->{
|
||||
assertThat(e.getRowNumber()).isGreaterThan(0);
|
||||
assertThat(e.getColumnNumber()).isGreaterThan(0);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaReferences() {
|
||||
final Schema reportInputSchema = repository.getReportInputSchema();
|
||||
assertThat(reportInputSchema).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
|
||||
* one or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. KoSIT licenses this file
|
||||
* to you 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;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.model.scenarios.Scenarios;
|
||||
|
||||
/**
|
||||
* Testet die Versionierung von Scenario-Dateien aka Konfigurationsdaten.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class VersioningTest {
|
||||
|
||||
private static final URL BASE = VersioningTest.class.getResource("/examples/versioning/scenarios-base.xml");
|
||||
|
||||
private static final URL INCREMENT = VersioningTest.class.getResource("/examples/versioning/scenarios-increment.xml");
|
||||
|
||||
private static final URL NEW_FEATURE = VersioningTest.class.getResource("/examples/versioning/scenarios-newfeature.xml");
|
||||
|
||||
private static final URL NEW_VERSION = VersioningTest.class.getResource("/examples/versioning/scenarios-newVersion.xml");
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private ConversionService service;
|
||||
|
||||
private ContentRepository repository;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
service = new ConversionService();
|
||||
repository = new ContentRepository(ObjectFactory.createProcessor(), new File("src/test/resources/examples/repository").toURI());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBase() throws URISyntaxException {
|
||||
final Scenarios result = service.readXml(BASE.toURI(), Scenarios.class, repository.getScenarioSchema());
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFrameworkIncrement() throws URISyntaxException {
|
||||
final Scenarios result = service.readXml(INCREMENT.toURI(), Scenarios.class, repository.getScenarioSchema());
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewFeature() throws URISyntaxException {
|
||||
exception.expect(ConversionService.ConversionExeption.class);
|
||||
service.readXml(NEW_FEATURE.toURI(), Scenarios.class, repository.getScenarioSchema());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewVersion() throws URISyntaxException {
|
||||
exception.expect(ConversionService.ConversionExeption.class);
|
||||
service.readXml(NEW_VERSION.toURI(), Scenarios.class, repository.getScenarioSchema());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue