mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-26 01:05:38 +00:00
#39 The supplied Input unnecessarily is not written into memory
This commit is contained in:
parent
d7ee019194
commit
efd4fd5fff
63 changed files with 1111 additions and 18196 deletions
|
|
@ -23,17 +23,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.impl.ConversionServiceTest;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.input.SourceInput;
|
||||
|
||||
/**
|
||||
* Testet den Hashcode-Service.
|
||||
|
|
@ -42,23 +47,22 @@ import de.kosit.validationtool.impl.ConversionServiceTest;
|
|||
*/
|
||||
public class InputFactoryTest {
|
||||
|
||||
private static final URL CONTENT = ConversionServiceTest.class.getResource("/valid/scenarios.xml");
|
||||
|
||||
private static final URL OTHER_CONTENT = ConversionServiceTest.class.getResource("/valid/report.xml");
|
||||
|
||||
public static final String SOME_VALUE = "some value";
|
||||
|
||||
private static URL NOT_EXISTING;
|
||||
|
||||
private static final int EOF = -1;
|
||||
|
||||
private static final int DEFAULT_BUFFER_SIZE = 4096;
|
||||
|
||||
static {
|
||||
try {
|
||||
NOT_EXISTING = new URL("file://localhost/somefile.text");
|
||||
} catch (MalformedURLException e) {
|
||||
} catch (final MalformedURLException e) {
|
||||
// just ignore;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
|
|
@ -69,25 +73,40 @@ public class InputFactoryTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
final byte[] s1 = InputFactory.read(CONTENT).getHashCode();
|
||||
final byte[] s2 = InputFactory.read(CONTENT).getHashCode();
|
||||
final byte[] s3 = InputFactory.read(OTHER_CONTENT).getHashCode();
|
||||
public void testHashCodeGeneration() throws IOException {
|
||||
final byte[] s1 = drain(InputFactory.read(Simple.SIMPLE_VALID.toURL())).getHashCode();
|
||||
final byte[] s2 = drain(InputFactory.read(Simple.SIMPLE_VALID.toURL())).getHashCode();
|
||||
final byte[] s3 = drain(InputFactory.read(Simple.INVALID.toURL())).getHashCode();
|
||||
assertThat(s1).isNotEmpty();
|
||||
assertThat(s1).isEqualTo(s2);
|
||||
assertThat(s3).isNotEmpty();
|
||||
assertThat(s1).isNotEqualTo(s3);
|
||||
}
|
||||
|
||||
private static Input drain(final Input input) throws IOException {
|
||||
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
|
||||
final StreamSource s = (StreamSource) input.getSource();
|
||||
try ( final InputStream stream = s.getInputStream() ) {
|
||||
|
||||
int n;
|
||||
while (EOF != (n = stream.read(buffer))) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
}
|
||||
return input;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongAlgorithm() {
|
||||
expectedException.expect(IllegalStateException.class);
|
||||
InputFactory service = new InputFactory("unknown");
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
new InputFactory("unknown");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullInputURL() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
InputFactory.read((URL) null);
|
||||
}
|
||||
|
||||
|
|
@ -105,43 +124,71 @@ public class InputFactoryTest {
|
|||
|
||||
@Test
|
||||
public void testNullStream() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
final Input input = InputFactory.read((InputStream)null, SOME_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputFile() throws URISyntaxException {
|
||||
final Input input = InputFactory.read(new File(CONTENT.toURI()));
|
||||
final Input input = InputFactory.read(new File(Simple.SIMPLE_VALID));
|
||||
assertThat(input).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInputPath() throws URISyntaxException {
|
||||
final Input input = InputFactory.read(Paths.get(CONTENT.toURI()));
|
||||
final Input input = InputFactory.read(Paths.get(Simple.SIMPLE_VALID));
|
||||
assertThat(input).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullInput() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
InputFactory.read((byte[]) null, SOME_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullInputName() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
InputFactory.read(SOME_VALUE.getBytes(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyInputName() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
InputFactory.read(SOME_VALUE.getBytes(), "");
|
||||
public void testEmptyInputName() throws IOException {
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
final Input input = InputFactory.read(SOME_VALUE.getBytes(), "");
|
||||
drain(input);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceInput() throws IOException {
|
||||
try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream() ) {
|
||||
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(s));
|
||||
assertThat(input.getSource()).isNotNull();
|
||||
drain(input);
|
||||
assertThat(input.getHashCode()).isNotNull();
|
||||
assertThat(input.getLength()).isGreaterThan(0L);
|
||||
this.expectedException.expect(IllegalStateException.class);
|
||||
input.getSource();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceInputReader() throws IOException {
|
||||
try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream();
|
||||
final InputStreamReader reader = new InputStreamReader(s) ) {
|
||||
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader));
|
||||
assertThat(input.getSource()).isNotNull();
|
||||
drain(input);
|
||||
assertThat(input.getHashCode()).isNotNull();
|
||||
assertThat(input.getLength()).isGreaterThan(0L);
|
||||
this.expectedException.expect(IllegalStateException.class);
|
||||
input.getSource();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnexistingInput() {
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
InputFactory.read(NOT_EXISTING);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,12 +20,6 @@
|
|||
package de.kosit.validationtool.cmd;
|
||||
|
||||
import static de.kosit.validationtool.impl.Helper.ASSERTIONS;
|
||||
import static de.kosit.validationtool.impl.Helper.NOT_EXISTING;
|
||||
import static de.kosit.validationtool.impl.Helper.REPOSITORY;
|
||||
import static de.kosit.validationtool.impl.Helper.SAMPLE;
|
||||
import static de.kosit.validationtool.impl.Helper.SAMPLE2;
|
||||
import static de.kosit.validationtool.impl.Helper.SAMPLE_DIR;
|
||||
import static de.kosit.validationtool.impl.Helper.SCENARIO_FILE;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -34,9 +28,12 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
|
||||
/**
|
||||
* Testet die Parameter des Kommandozeilen-Tools.
|
||||
*
|
||||
|
|
@ -51,88 +48,88 @@ public class CommandlineApplicationTest {
|
|||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
commandLine = new CommandLine();
|
||||
commandLine.activate();
|
||||
this.commandLine = new CommandLine();
|
||||
this.commandLine.activate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHelp() {
|
||||
String[] args = new String[] { "-?" };
|
||||
final String[] args = new String[] { "-?" };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).isEmpty();
|
||||
checkForHelp(commandLine.getOutputLines());
|
||||
assertThat(this.commandLine.getErrorOutput()).isEmpty();
|
||||
checkForHelp(this.commandLine.getOutputLines());
|
||||
}
|
||||
|
||||
private void checkForHelp(List<String> outputLines) {
|
||||
private static void checkForHelp(final List<String> outputLines) {
|
||||
assertThat(outputLines.size()).isGreaterThan(0);
|
||||
outputLines.subList(1, outputLines.size() - 1).forEach(l -> assertThat(l.startsWith(" -") || l.startsWith(" ")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredScenarioFile() {
|
||||
String[] args = new String[] { "-d", "arguments", "egal welche", "argument drin sind" };
|
||||
final String[] args = new String[] { "-d", "arguments", "egal welche", "argument drin sind" };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(commandLine.getErrorOutput()).contains("Missing required option: s");
|
||||
assertThat(this.commandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Missing required option: s");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotExistingScenarioFile() {
|
||||
String[] args = new String[] { "-s", Paths.get(NOT_EXISTING).toString(), Paths.get(NOT_EXISTING).toString() };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.NOT_EXISTING).toString(), Paths.get(Simple.NOT_EXISTING).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(commandLine.getErrorOutput()).contains("Not a valid path for scenario definition specified");
|
||||
assertThat(this.commandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Not a valid path for scenario definition specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncorrectRepository() {
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), Paths.get(NOT_EXISTING).toString() };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), Paths.get(Simple.NOT_EXISTING).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(commandLine.getErrorOutput()).contains("Can not load schema from sources");
|
||||
assertThat(this.commandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Can not load schema from sources");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotExistingTestTarget() {
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), "-r", Paths.get(REPOSITORY).toString(),
|
||||
Paths.get(NOT_EXISTING).toString() };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(),
|
||||
Paths.get(Simple.NOT_EXISTING).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(commandLine.getErrorOutput()).contains("No test targets found");
|
||||
assertThat(this.commandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("No test targets found");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidMinimalConfiguration() {
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), "-r", Paths.get(REPOSITORY).toString(),
|
||||
Paths.get(SAMPLE).toString() };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidMultipleInput() {
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), "-r", Paths.get(REPOSITORY).toString(),
|
||||
Paths.get(SAMPLE).toString(), Paths.get(SAMPLE2).toString() };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString(), Paths.get(Simple.FOO).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).contains("Processing 2 object(s) completed");
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Processing 2 object(s) completed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidDirectoryInput() {
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), "-r", Paths.get(REPOSITORY).toString(),
|
||||
Paths.get(SAMPLE_DIR).toString() };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(),
|
||||
Paths.get(Simple.EXAMPLES).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).contains("Processing 4 object(s) completed");
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Processing 5 object(s) completed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidOutputConfiguration() throws IOException {
|
||||
Path output = Paths.get("output");
|
||||
// assertThat(output).doesNotExist();
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), "-o", output.getFileName().toString(), "-r",
|
||||
Paths.get(REPOSITORY).toString(), Paths.get(SAMPLE).toString() };
|
||||
final Path output = Paths.get("output");
|
||||
FileUtils.deleteDirectory(output.toFile());
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", output.getFileName().toString(), "-r",
|
||||
Paths.get(Simple.REPOSITORY).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(output).exists();
|
||||
assertThat(Files.list(output)).hasSize(1);
|
||||
}
|
||||
|
|
@ -140,45 +137,47 @@ public class CommandlineApplicationTest {
|
|||
@Test
|
||||
public void testNoInput() {
|
||||
// assertThat(output).doesNotExist();
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), "-r", Paths.get(REPOSITORY).toString(), };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(), };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
checkForHelp(commandLine.getOutputLines());
|
||||
checkForHelp(this.commandLine.getOutputLines());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrint() {
|
||||
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), "-p", "-r", Paths.get(REPOSITORY).toString(),
|
||||
Paths.get(SAMPLE).toString() };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-p", "-r",
|
||||
Paths.get(Simple.REPOSITORY).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(commandLine.getOutputLines().get(0)).contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(this.commandLine.getOutputLines().get(0)).contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHtmlExtraktion() throws IOException {
|
||||
Path output = Files.createTempDirectory("pruef-tool-test");
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), "-h", "-o", output.toAbsolutePath().toString(), "-r",
|
||||
Paths.get(REPOSITORY).toString(), Paths.get(SAMPLE).toString() };
|
||||
final Path output = Files.createTempDirectory("pruef-tool-test");
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-h", "-o", output.toAbsolutePath().toString(),
|
||||
"-r", Paths.get(Simple.REPOSITORY).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(Files.list(output).filter(f -> f.toString().endsWith(".html")).count()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssertionsExtraktion() throws IOException {
|
||||
String[] args = new String[] { "-d", "-s", Paths.get(SCENARIO_FILE).toString(), "-r", Paths.get(REPOSITORY).toString(), "-c",
|
||||
Paths.get(ASSERTIONS).toString(), Paths.get(REPOSITORY).toString(), Paths.get(SAMPLE).toString() };
|
||||
final String[] args = new String[] { "-d", "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||
Paths.get(Simple.REPOSITORY).toString(), "-c", Paths.get(ASSERTIONS).toString(), Paths.get(Simple.REPOSITORY).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(commandLine.getErrorOutput()).contains("Can not find assertions for ");
|
||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Can not find assertions for ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDebugFlag() throws IOException {
|
||||
String[] args = new String[] { "-s", Paths.get(SCENARIO_FILE).toString(), "-r", "unknown", "-d", Paths.get(ASSERTIONS).toString() };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", "unknown", "-d",
|
||||
Paths.get(ASSERTIONS).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).contains("at de.kosit.validationtool");
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("at de.kosit.validationtool");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import org.junit.Before;
|
|||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
|
||||
|
|
@ -20,11 +22,9 @@ import io.restassured.http.ContentType;
|
|||
*/
|
||||
public class DaemonIT {
|
||||
|
||||
private static final String EXAMPLE_FILE = "examples/UBLReady/UBLReady_EU_UBL-NL_20170102_FULL.xml";
|
||||
|
||||
private static final String APPLICATION_XML = "application/xml";
|
||||
|
||||
private static final String INVALID_XML = "examples/UBLReady/UBLReady_EU_UBL-NL_20170102_FULL-invalid.xml";
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
|
@ -41,7 +41,7 @@ public class DaemonIT {
|
|||
|
||||
@Test
|
||||
public void makeSureThatSuccessTest() throws IOException {
|
||||
try ( final InputStream io = DaemonIT.class.getClassLoader().getResourceAsStream(EXAMPLE_FILE) ) {
|
||||
try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) {
|
||||
given().contentType(ContentType.XML).body(toContent(io)).when().post("/").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ public class DaemonIT {
|
|||
@Test
|
||||
@Ignore // no default error report yet
|
||||
public void internalServerErrorTest() throws IOException {
|
||||
try ( final InputStream io = DaemonIT.class.getClassLoader().getResourceAsStream(INVALID_XML) ) {
|
||||
try ( final InputStream io = Simple.INVALID.toURL().openStream() ) {
|
||||
given().contentType(APPLICATION_XML).body(toContent(io)).when().post("/").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
|
@ -75,7 +75,8 @@ public class DaemonIT {
|
|||
|
||||
@Test
|
||||
public void xmlResultTest() throws IOException {
|
||||
try ( final InputStream io = DaemonIT.class.getClassLoader().getResourceAsStream(EXAMPLE_FILE) ) {
|
||||
|
||||
try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) {
|
||||
given().body(toContent(io)).when().post("/").then().contentType(APPLICATION_XML).and().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
|
||||
import net.sf.saxon.s9api.XPathExecutable;
|
||||
import net.sf.saxon.s9api.XsltExecutable;
|
||||
|
||||
|
|
@ -53,7 +55,7 @@ public class ContentRepositoryTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.repository = new ContentRepository(ObjectFactory.createProcessor(), Helper.REPOSITORY);
|
||||
this.repository = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -71,19 +73,19 @@ public class ContentRepositoryTest {
|
|||
@Test
|
||||
public void testCreateSchemaNotExisting() throws Exception {
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
ContentRepository.createSchema(Helper.ASSERTION_SCHEMA.resolve("noexisting").toURL());
|
||||
ContentRepository.createSchema(Simple.NOT_EXISTING.toURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadXSLT() {
|
||||
final XsltExecutable executable = this.repository.loadXsltScript(Helper.SAMPLE_XSLT);
|
||||
final XsltExecutable executable = this.repository.loadXsltScript(Simple.REPORT_XSL);
|
||||
assertThat(executable).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadXSLTNotExisting() {
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
this.repository.loadXsltScript(Helper.SAMPLE_XSLT.resolve("notexisting"));
|
||||
this.repository.loadXsltScript(Simple.NOT_EXISTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -119,8 +121,8 @@ public class ContentRepositoryTest {
|
|||
|
||||
@Test
|
||||
public void testLoadSchema() {
|
||||
final URL main = RelativeUriResolverTest.class.getClassLoader().getResource("simple/main.xsd");
|
||||
final Schema schema = ContentRepository.createSchema(main, new ClassPathResourceResolver("/simple"));
|
||||
final URL main = RelativeUriResolverTest.class.getClassLoader().getResource("loading/main.xsd");
|
||||
final Schema schema = ContentRepository.createSchema(main, new ClassPathResourceResolver("/loading"));
|
||||
assertThat(schema).isNotNull();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.impl.Helper.Invalid;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.model.scenarios.Scenarios;
|
||||
|
||||
/**
|
||||
|
|
@ -40,12 +42,6 @@ import de.kosit.validationtool.model.scenarios.Scenarios;
|
|||
*/
|
||||
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
|
||||
|
|
@ -77,28 +73,28 @@ public class ConversionServiceTest {
|
|||
|
||||
@Test
|
||||
public void testUnmarshal() throws URISyntaxException {
|
||||
final Scenarios s = this.service.readXml(VALID_XML.toURI(), Scenarios.class);
|
||||
final Scenarios s = this.service.readXml(Simple.SCENARIOS, Scenarios.class);
|
||||
assertThat(s).isNotNull();
|
||||
assertThat(s.getName()).isEqualToIgnoringCase("XInneres");
|
||||
assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalWithSchema() throws URISyntaxException {
|
||||
final Scenarios s = this.service.readXml(VALID_XML.toURI(), Scenarios.class, ContentRepository.createSchema(SCHEMA));
|
||||
public void testUnmarshalWithSchema() {
|
||||
final Scenarios s = this.service.readXml(Simple.SCENARIOS, Scenarios.class, ContentRepository.createSchema(SCHEMA));
|
||||
assertThat(s).isNotNull();
|
||||
assertThat(s.getName()).isEqualToIgnoringCase("XInneres");
|
||||
assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalInvalidXml() throws URISyntaxException {
|
||||
public void testUnmarshalInvalidXml() {
|
||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
||||
this.service.readXml(INVALID_XML.toURI(), Scenarios.class, ContentRepository.createSchema(SCHEMA));
|
||||
this.service.readXml(Invalid.SCENARIOS, Scenarios.class, ContentRepository.createSchema(SCHEMA));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalIllFormed() throws URISyntaxException {
|
||||
public void testUnmarshalIllFormed() {
|
||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
||||
this.service.readXml(ILLFORMED_XML.toURI(), Scenarios.class, ContentRepository.createSchema(SCHEMA));
|
||||
this.service.readXml(Invalid.SCENARIOS_ILLFORMED, Scenarios.class, ContentRepository.createSchema(SCHEMA));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -110,13 +106,13 @@ public class ConversionServiceTest {
|
|||
@Test
|
||||
public void testUnmarshalUnknownType() throws URISyntaxException {
|
||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
||||
this.service.readXml(VALID_XML.toURI(), ConversionService.class);
|
||||
this.service.readXml(Simple.SCENARIOS, ConversionService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalWithoutType() throws URISyntaxException {
|
||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
||||
this.service.readXml(VALID_XML.toURI(), null);
|
||||
this.service.readXml(Simple.SCENARIOS, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
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;
|
||||
|
|
@ -39,6 +38,7 @@ import de.kosit.validationtool.api.AcceptRecommendation;
|
|||
import de.kosit.validationtool.api.CheckConfiguration;
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import de.kosit.validationtool.api.Result;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
|
||||
/**
|
||||
* Test das Check-Interface
|
||||
|
|
@ -47,10 +47,7 @@ import de.kosit.validationtool.api.Result;
|
|||
*/
|
||||
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;
|
||||
|
||||
|
|
@ -58,14 +55,23 @@ public class DefaultCheckTest {
|
|||
|
||||
@Before
|
||||
public void setup() throws URISyntaxException {
|
||||
final CheckConfiguration d = new CheckConfiguration(SCENARIO_DEFINITION.toURI());
|
||||
d.setScenarioRepository(new File("src/test/resources/examples/repository").toURI());
|
||||
final CheckConfiguration d = new CheckConfiguration(Simple.SCENARIOS);
|
||||
d.setScenarioRepository(new File(Simple.REPOSITORY).toURI());
|
||||
this.implementation = new DefaultCheck(d);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHappyCase() {
|
||||
final Result doc = this.implementation.checkInput(read(VALID_EXAMPLE));
|
||||
final Result doc = this.implementation.checkInput(read(Simple.SIMPLE_VALID));
|
||||
assertThat(doc).isNotNull();
|
||||
assertThat(doc.getReport()).isNotNull();
|
||||
assertThat(doc.isAcceptable()).isTrue();
|
||||
assertThat(doc.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutAcceptMatch() {
|
||||
final Result doc = this.implementation.checkInput(read(Simple.FOO));
|
||||
assertThat(doc).isNotNull();
|
||||
assertThat(doc.getReport()).isNotNull();
|
||||
assertThat(doc.isAcceptable()).isFalse();
|
||||
|
|
@ -74,13 +80,13 @@ public class DefaultCheckTest {
|
|||
|
||||
@Test
|
||||
public void testHappyCaseDocument() {
|
||||
final Document doc = this.implementation.check(read(VALID_EXAMPLE));
|
||||
final Document doc = this.implementation.check(read(Simple.SIMPLE_VALID));
|
||||
assertThat(doc).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleCase() {
|
||||
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(VALID_EXAMPLE)).collect(Collectors.toList());
|
||||
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(Simple.SIMPLE_VALID)).collect(Collectors.toList());
|
||||
final List<Result> docs = this.implementation.checkInput(input);
|
||||
assertThat(docs).isNotNull();
|
||||
assertThat(docs).hasSize(MULTI_COUNT);
|
||||
|
|
@ -88,7 +94,7 @@ public class DefaultCheckTest {
|
|||
|
||||
@Test
|
||||
public void testMultipleCaseDocument() {
|
||||
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(VALID_EXAMPLE)).collect(Collectors.toList());
|
||||
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(Simple.SIMPLE_VALID)).collect(Collectors.toList());
|
||||
final List<Document> docs = this.implementation.check(input);
|
||||
assertThat(docs).isNotNull();
|
||||
assertThat(docs).hasSize(MULTI_COUNT);
|
||||
|
|
@ -96,10 +102,10 @@ public class DefaultCheckTest {
|
|||
|
||||
@Test
|
||||
public void testExtractHtml() {
|
||||
final DefaultResult doc = (DefaultResult) this.implementation.checkInput(read(VALID_EXAMPLE));
|
||||
final DefaultResult doc = (DefaultResult) this.implementation.checkInput(read(Simple.SIMPLE_VALID));
|
||||
assertThat(doc).isNotNull();
|
||||
assertThat(doc.getReport()).isNotNull();
|
||||
assertThat(doc.isAcceptable()).isFalse();
|
||||
assertThat(doc.isAcceptable()).isTrue();
|
||||
assertThat(doc.extractHtmlAsString()).isNotEmpty();
|
||||
assertThat(doc.extractHtmlAsElement()).isNotEmpty();
|
||||
assertThat(doc.extractHtml()).isNotEmpty();
|
||||
|
|
|
|||
|
|
@ -22,13 +22,11 @@ package de.kosit.validationtool.impl;
|
|||
import static de.kosit.validationtool.api.InputFactory.read;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
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.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
|
|
@ -42,25 +40,12 @@ import net.sf.saxon.s9api.XdmNode;
|
|||
*/
|
||||
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() {
|
||||
this.parser = new DocumentParseAction();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
final Result<XdmNode, XMLSyntaxError> result = DocumentParseAction.parseDocument(read(CONTENT));
|
||||
final Result<XdmNode, XMLSyntaxError> result = DocumentParseAction.parseDocument(read(Simple.SIMPLE_VALID));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getObject()).isNotNull();
|
||||
assertThat(result.getErrors()).isEmpty();
|
||||
|
|
@ -69,7 +54,7 @@ public class DocumentParserTest {
|
|||
|
||||
@Test
|
||||
public void testIllformed() {
|
||||
final Result<XdmNode, XMLSyntaxError> result = DocumentParseAction.parseDocument(read(ILLFORMED));
|
||||
final Result<XdmNode, XMLSyntaxError> result = DocumentParseAction.parseDocument(read(Simple.NOT_WELLFORMED));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getErrors()).isNotEmpty();
|
||||
assertThat(result.getObject()).isNull();
|
||||
|
|
|
|||
|
|
@ -37,12 +37,14 @@ import net.sf.saxon.s9api.XdmNode;
|
|||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class Helper {
|
||||
|
||||
public class Helper {
|
||||
public static class Simple {
|
||||
|
||||
public static final URI ROOT = EXAMPLES_DIR.resolve("simple/");
|
||||
|
||||
public static final URI EXAMPLES = ROOT.resolve("input/");
|
||||
|
||||
public static final URI SIMPLE_VALID = Simple.ROOT.resolve("input/simple.xml");
|
||||
|
||||
public static final URI FOO = Simple.ROOT.resolve("input/foo.xml");
|
||||
|
|
@ -58,15 +60,30 @@ public class Helper {
|
|||
public static final URI UNKNOWN = ROOT.resolve("input/unknown.xml");
|
||||
|
||||
public static final URI GARBAGE = ROOT.resolve("input/no-xml.file");
|
||||
|
||||
public static final URI NOT_EXISTING = EXAMPLES_DIR.resolve("doesnotexist");
|
||||
|
||||
public static final URI REPORT_XSL = REPOSITORY.resolve("report.xsl");
|
||||
|
||||
public static URI getSchemaLocation() {
|
||||
return ROOT.resolve("repository/simple.xsd");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Invalid {
|
||||
|
||||
public static final URI ROOT = EXAMPLES_DIR.resolve("invaid/");
|
||||
|
||||
public static final URI SCENARIOS = ROOT.resolve("scenarios.xml");
|
||||
|
||||
public static final URI SCENARIOS_ILLFORMED = ROOT.resolve("scenarios-illformed.xml");
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
|
@ -74,21 +91,14 @@ public class Helper {
|
|||
|
||||
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 URL JAR_REPOSITORY = Helper.class.getClassLoader().getResource("xrechnung/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
|
||||
|
|
|
|||
|
|
@ -75,8 +75,8 @@ public class RelativeUriResolverTest {
|
|||
|
||||
@Test
|
||||
public void testClasspathLocal() throws URISyntaxException, TransformerException {
|
||||
this.resolver = new RelativeUriResolver(RelativeUriResolver.class.getClassLoader().getResource("simple").toURI());
|
||||
final URL moz = RelativeUriResolverTest.class.getClassLoader().getResource("simple/main.xsd");
|
||||
this.resolver = new RelativeUriResolver(RelativeUriResolver.class.getClassLoader().getResource("loading").toURI());
|
||||
final URL moz = RelativeUriResolverTest.class.getClassLoader().getResource("loading/main.xsd");
|
||||
final Source resolved = this.resolver.resolve("./resources/reference.xsd", moz.toURI().toASCIIString());
|
||||
assertThat(resolved).isNotNull();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,14 @@ import org.w3c.dom.Document;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import net.sf.saxon.s9api.*;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
|
||||
import net.sf.saxon.s9api.DOMDestination;
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.XsltCompiler;
|
||||
import net.sf.saxon.s9api.XsltExecutable;
|
||||
import net.sf.saxon.s9api.XsltTransformer;
|
||||
|
||||
/**
|
||||
* Testet verschiedene Saxon Security Einstellungen.
|
||||
|
|
@ -45,18 +52,18 @@ public class SaxonSecurityTest {
|
|||
|
||||
@Test
|
||||
public void testEvilStylesheets() throws IOException {
|
||||
Processor p = ObjectFactory.createProcessor();
|
||||
final 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 URL resource = SaxonSecurityTest.class.getResource(String.format("/evil/evil%s.xsl", i));
|
||||
final XsltCompiler compiler = p.newXsltCompiler();
|
||||
final RelativeUriResolver resolver = new RelativeUriResolver(Helper.REPOSITORY);
|
||||
final RelativeUriResolver resolver = new RelativeUriResolver(Simple.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();
|
||||
final Document result = ObjectFactory.createDocumentBuilder(false).newDocument();
|
||||
transformer.getUnderlyingController().setUnparsedTextURIResolver(resolver);
|
||||
transformer.setURIResolver(resolver);
|
||||
transformer.setSource(new DOMSource(document));
|
||||
|
|
@ -68,7 +75,7 @@ public class SaxonSecurityTest {
|
|||
fail(String.format("Saxon configuration should prevent expansion within %s", resource));
|
||||
}
|
||||
|
||||
} catch (SaxonApiException | RuntimeException e) {
|
||||
} catch (final SaxonApiException | RuntimeException e) {
|
||||
log.info("Expected exception detected", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,9 @@ 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.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
|
@ -33,6 +32,7 @@ import org.junit.Test;
|
|||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.api.CheckConfiguration;
|
||||
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.scenarios.ScenarioType;
|
||||
|
|
@ -48,8 +48,6 @@ import net.sf.saxon.s9api.XdmNode;
|
|||
|
||||
public class ScenarioRepositoryTest {
|
||||
|
||||
private static final URL SAMPLE = ScenarioRepositoryTest.class.getResource("/valid/scenarios.xml");
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
|
|
@ -59,7 +57,7 @@ public class ScenarioRepositoryTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.content = new ContentRepository(ObjectFactory.createProcessor(), new File("src/test/resources/examples/repository").toURI());
|
||||
this.content = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY);
|
||||
final Scenarios def = new Scenarios();
|
||||
final ScenarioType t = new ScenarioType();
|
||||
t.setMatch("//*:name");
|
||||
|
|
@ -72,7 +70,7 @@ public class ScenarioRepositoryTest {
|
|||
|
||||
@Test
|
||||
public void testHappyCase() throws Exception {
|
||||
final Result<ScenarioType, String> scenario = this.repository.selectScenario(load(SAMPLE));
|
||||
final Result<ScenarioType, String> scenario = this.repository.selectScenario(load(Simple.SCENARIOS));
|
||||
assertThat(scenario).isNotNull();
|
||||
assertThat(scenario.isValid()).isTrue();
|
||||
}
|
||||
|
|
@ -83,7 +81,7 @@ public class ScenarioRepositoryTest {
|
|||
final ScenarioType fallback = new ScenarioType();
|
||||
fallback.setName("fallback");
|
||||
this.repository.setFallbackScenario(fallback);
|
||||
final Result<ScenarioType, String> scenario = this.repository.selectScenario(load(SAMPLE));
|
||||
final Result<ScenarioType, String> scenario = this.repository.selectScenario(load(Simple.SCENARIOS));
|
||||
assertThat(scenario).isNotNull();
|
||||
assertThat(scenario.isValid()).isFalse();
|
||||
assertThat(scenario.getObject().getName()).isEqualTo("fallback");
|
||||
|
|
@ -100,15 +98,15 @@ public class ScenarioRepositoryTest {
|
|||
final ScenarioType fallback = new ScenarioType();
|
||||
fallback.setName("fallback");
|
||||
this.repository.setFallbackScenario(fallback);
|
||||
final Result<ScenarioType, String> scenario = this.repository.selectScenario(load(SAMPLE));
|
||||
final Result<ScenarioType, String> scenario = this.repository.selectScenario(load(Simple.SCENARIOS));
|
||||
assertThat(scenario).isNotNull();
|
||||
assertThat(scenario.isValid()).isFalse();
|
||||
assertThat(scenario.getObject().getName()).isEqualTo("fallback");
|
||||
}
|
||||
|
||||
private static XdmNode load(final URL url) throws IOException {
|
||||
private static XdmNode load(final URI uri) throws IOException {
|
||||
final DocumentParseAction p = new DocumentParseAction();
|
||||
return DocumentParseAction.parseDocument(read(url)).getObject();
|
||||
return DocumentParseAction.parseDocument(read(uri.toURL())).getObject();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* 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());
|
||||
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());
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ public class SimpleScenarioCheck {
|
|||
public void testUnknown() throws MalformedURLException {
|
||||
final Result result = this.implementation.checkInput(InputFactory.read(Simple.UNKNOWN.toURL()));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
|
||||
assertThat(result.isProcessingSuccessful()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* 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.tasks;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.validation.Schema;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.impl.ContentRepository;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.ObjectFactory;
|
||||
import de.kosit.validationtool.impl.input.SourceInput;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests die {@link SchemaValidationAction}.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class SchemaValidatorActionTest {
|
||||
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private SchemaValidationAction service;
|
||||
|
||||
private ContentRepository repository;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.service = new SchemaValidationAction();
|
||||
this.repository = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimple() throws MalformedURLException {
|
||||
final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()));
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationFailure() throws MalformedURLException {
|
||||
final Input input = InputFactory.read(Simple.INVALID.toURL());
|
||||
final CheckAction.Bag bag = createBag(input);
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isFalse();
|
||||
bag.getSchemaValidationResult().getErrors().forEach(e->{
|
||||
assertThat(e.getRowNumber()).isGreaterThan(0);
|
||||
assertThat(e.getColumnNumber()).isGreaterThan(0);
|
||||
});
|
||||
}
|
||||
|
||||
private Bag createBag(final Input input) {
|
||||
final Bag bag = new Bag(input, new CreateReportInput());
|
||||
bag.setScenarioSelectionResult(new Result<>(createScenario(Helper.Simple.getSchemaLocation())));
|
||||
return bag;
|
||||
}
|
||||
|
||||
private ScenarioType createScenario(final URI schemafile) {
|
||||
final ScenarioType t = new ScenarioType();
|
||||
final ValidateWithXmlSchema v = new ValidateWithXmlSchema();
|
||||
final ResourceType r = new ResourceType();
|
||||
r.setLocation(schemafile.getRawPath());
|
||||
r.setName("invoice");
|
||||
v.getResource().add(r);
|
||||
t.setValidateWithXmlSchema(v);
|
||||
t.initialize(this.repository, true);
|
||||
return t;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaReferences() {
|
||||
final Schema reportInputSchema = this.repository.getReportInputSchema();
|
||||
assertThat(reportInputSchema).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRepeatableRead() throws Exception {
|
||||
try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream() ) {
|
||||
final Bag bag = createBag(InputFactory.read(new StreamSource(inputStream)));
|
||||
// don't read the real inputstream here!
|
||||
bag.setParserResult(DocumentParseAction.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRepeatableReadBigFile() throws Exception {
|
||||
try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream() ) {
|
||||
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(inputStream));
|
||||
final Bag bag = createBag(input);
|
||||
// set limit and length for serialization to 5 bytes
|
||||
this.service.setInMemoryLimit(5L);
|
||||
input.setLength(6L);
|
||||
|
||||
bag.setParserResult(DocumentParseAction.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRepeatableReaderInput() throws Exception {
|
||||
try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream();
|
||||
final Reader reader = new InputStreamReader(inputStream) ) {
|
||||
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader));
|
||||
final Bag bag = createBag(input);
|
||||
bag.setParserResult(DocumentParseAction.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
this.service.check(bag);
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRepeatableReaderInputBigFile() throws Exception {
|
||||
try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream();
|
||||
final Reader reader = new InputStreamReader(inputStream) ) {
|
||||
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader));
|
||||
final Bag bag = createBag(input);
|
||||
// set limit and length for serialization to 5 bytes
|
||||
this.service.setInMemoryLimit(5L);
|
||||
bag.setParserResult(DocumentParseAction.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
this.service.check(bag);
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue