mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
support multiple configuration
This commit is contained in:
parent
730d7fefe9
commit
2e6efdd16f
59 changed files with 1136 additions and 608 deletions
|
|
@ -114,22 +114,22 @@ public class CommandLine {
|
|||
}
|
||||
|
||||
public static String getOutput() {
|
||||
return new String(out.getOut().toByteArray());
|
||||
return out.getOut().toString();
|
||||
}
|
||||
|
||||
public static String getErrorOutput() {
|
||||
return new String(error.getOut().toByteArray());
|
||||
return error.getOut().toString();
|
||||
}
|
||||
|
||||
public List<String> getOutputLines() {
|
||||
public static List<String> getOutputLines() {
|
||||
return readLines(out.getOut().toByteArray());
|
||||
}
|
||||
|
||||
public List<String> getErrorLines() {
|
||||
public static List<String> getErrorLines() {
|
||||
return readLines(error.getOut().toByteArray());
|
||||
}
|
||||
|
||||
private List<String> readLines(final byte[] bytes) {
|
||||
private static List<String> readLines(final byte[] bytes) {
|
||||
try ( final ByteArrayInputStream in = new ByteArrayInputStream(bytes);
|
||||
final Reader r = new InputStreamReader(in) ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public class CommandlineApplicationTest {
|
|||
if (Files.exists(this.output)) {
|
||||
FileUtils.deleteDirectory(this.output.toFile());
|
||||
}
|
||||
TypeConverter.counter.clear();
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
@ -76,20 +77,20 @@ public class CommandlineApplicationTest {
|
|||
final String[] args = new String[] { "-?" };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getErrorOutput()).isEmpty();
|
||||
checkForHelp(this.commandLine.getOutputLines());
|
||||
checkForHelp(CommandLine.getOutputLines());
|
||||
}
|
||||
|
||||
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(" ")));
|
||||
assertThat(outputLines.size()).isPositive();
|
||||
assertThat(outputLines.stream().filter(l -> l.startsWith("Usage: KoSIT Validator"))).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredScenarioFile() {
|
||||
final String[] args = new String[] { "-d", "arguments", "egal welche", "argument drin sind" };
|
||||
final String[] args = new String[] { "arguments", "egal welche", "argumente drin sind" };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(CommandLine.getErrorOutput()).contains("Missing required option: s");
|
||||
assertThat(CommandLine.getErrorOutput()).contains("Missing required option: '--scenarios");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -102,10 +103,11 @@ public class CommandlineApplicationTest {
|
|||
|
||||
@Test
|
||||
public void testIncorrectRepository() {
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), Paths.get(Simple.NOT_EXISTING).toString() };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.NOT_EXISTING).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(CommandLine.getErrorOutput()).contains("Can not resolve");
|
||||
assertThat(CommandLine.getErrorOutput()).contains("Not a valid path for repository");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -168,7 +170,7 @@ public class CommandlineApplicationTest {
|
|||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||
Paths.get(Simple.REPOSITORY_URI).toString(), };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
checkForHelp(this.commandLine.getOutputLines());
|
||||
checkForHelp(CommandLine.getOutputLines());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -178,7 +180,7 @@ public class CommandlineApplicationTest {
|
|||
Paths.get(Simple.REPOSITORY_URI).toString(), "-o", this.output.toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(this.commandLine.getOutputLines()).haveAtLeastOne(new Condition<>(
|
||||
assertThat(CommandLine.getOutputLines()).haveAtLeastOne(new Condition<>(
|
||||
s -> StringUtils.contains(s, "<?xml version=\"1.0\" " + "encoding=\"UTF-8\"?>"), "Must " + "contain xml preambel"));
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +191,7 @@ public class CommandlineApplicationTest {
|
|||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(Files.list(this.output).filter(f -> f.toString().endsWith(".html")).count()).isGreaterThan(0);
|
||||
assertThat(Files.list(this.output).filter(f -> f.toString().endsWith(".html")).count()).isPositive();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -227,4 +229,76 @@ public class CommandlineApplicationTest {
|
|||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnexpectedDaemonFlag() {
|
||||
final String[] args = new String[] { "-D", "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getErrorOutput()).contains("Will ignore cli mode options");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingError() {
|
||||
final String[] args = new String[] { "-s", "-r", Paths.get(Simple.REPOSITORY_URI).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getErrorOutput()).contains("Expected parameter for option");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadMultipleScenarios() {
|
||||
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS).toString(), "-s",
|
||||
"s2=" + Paths.get(Simple.OTHER_SCENARIOS).toString(), "-r", "s1=" + Paths.get(Simple.REPOSITORY_URI).toString(), "-r",
|
||||
"s2=" + Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getOutput()).contains("Processing of 1 objects completed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadMultipleScenariosSingleRepository() {
|
||||
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS).toString(), "-s",
|
||||
"s2=" + Paths.get(Simple.OTHER_SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY_URI).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getOutput()).contains("Processing of 1 objects completed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadMultipleScenariosMissingRepository() {
|
||||
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS).toString(), "-s",
|
||||
"s2=" + Paths.get(Simple.OTHER_SCENARIOS).toString(), "-r", "s1=" + Paths.get(Simple.REPOSITORY_URI).toString(), "-r",
|
||||
"typo=" + Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getErrorOutput()).contains("No repository location for scenario definition 's2' specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadMultipleOrderedScenarios() {
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-s",
|
||||
Paths.get(Simple.OTHER_SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY_URI).toString(), "-r",
|
||||
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getOutput()).contains("Processing of 1 objects completed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkUnusedRepository() {
|
||||
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||
"s1=" + Paths.get(Simple.REPOSITORY_URI).toString(), "-r", "unused=" + Paths.get(Simple.REPOSITORY_URI).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getOutput()).contains("Processing of 1 objects completed");
|
||||
assertThat(CommandLine.getErrorOutput()).contains("Warning: repository definition \"unused\" is not used");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkDuplicationScenarioDefinition() {
|
||||
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||
"s1=" + Paths.get(Simple.REPOSITORY_URI).toString(), "-r", "unused=" + Paths.get(Simple.REPOSITORY_URI).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(CommandLine.getOutput()).contains("Processing of 1 objects completed");
|
||||
assertThat(CommandLine.getErrorOutput()).contains("Warning: repository definition \"unused\" is not used");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
|
||||
/**
|
||||
* Test {@link ConfigurationBuilder}.
|
||||
*
|
||||
|
|
@ -45,7 +47,7 @@ public class ConfigurationBuilderTest {
|
|||
@Test
|
||||
public void testNoConfiguration() {
|
||||
this.exceptions.expect(IllegalStateException.class);
|
||||
new ConfigurationBuilder().build();
|
||||
new ConfigurationBuilder().build(Helper.getTestProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -54,7 +56,7 @@ public class ConfigurationBuilderTest {
|
|||
this.exceptions.expectMessage(Matchers.containsString("fallback"));
|
||||
final ConfigurationBuilder builder = createSimpleConfiguration();
|
||||
builder.with((FallbackBuilder) null);
|
||||
builder.build();
|
||||
builder.build(Helper.getTestProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -63,7 +65,7 @@ public class ConfigurationBuilderTest {
|
|||
this.exceptions.expectMessage(Matchers.containsString("schema"));
|
||||
final ConfigurationBuilder builder = createSimpleConfiguration();
|
||||
builder.getScenarios().get(0).validate((SchemaBuilder) null);
|
||||
builder.build();
|
||||
builder.build(Helper.getTestProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -72,7 +74,7 @@ public class ConfigurationBuilderTest {
|
|||
this.exceptions.expectMessage(Matchers.containsString("schematron"));
|
||||
final ConfigurationBuilder builder = createSimpleConfiguration();
|
||||
builder.getScenarios().get(0).validate(schematron("invalid").source(URI.create("DoesNotExist")));
|
||||
builder.build();
|
||||
builder.build(Helper.getTestProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -81,7 +83,7 @@ public class ConfigurationBuilderTest {
|
|||
this.exceptions.expectMessage(Matchers.containsString("schematron"));
|
||||
final ConfigurationBuilder builder = createSimpleConfiguration();
|
||||
builder.getScenarios().get(0).validate(schematron("invalid"));
|
||||
builder.build();
|
||||
builder.build(Helper.getTestProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -90,15 +92,18 @@ public class ConfigurationBuilderTest {
|
|||
this.exceptions.expectMessage(Matchers.containsString("report"));
|
||||
final ConfigurationBuilder builder = createSimpleConfiguration();
|
||||
builder.getScenarios().get(0).with(report("invalid"));
|
||||
builder.build();
|
||||
builder.build(Helper.getTestProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDate() {
|
||||
assertThat(createSimpleConfiguration().date(EPOCH).build().getDate()).isEqualTo("1970-01-01");
|
||||
assertThat(createSimpleConfiguration().date(new Date(EPOCH.toEpochDay())).build().getDate()).isEqualTo("1970-01-01");
|
||||
assertThat(createSimpleConfiguration().date((Date) null).build().getDate()).isEqualTo(LocalDate.now().toString());
|
||||
assertThat(createSimpleConfiguration().date((LocalDate) null).build().getDate()).isEqualTo(LocalDate.now().toString());
|
||||
assertThat(createSimpleConfiguration().date(EPOCH).build(Helper.getTestProcessor()).getDate()).isEqualTo("1970-01-01");
|
||||
assertThat(createSimpleConfiguration().date(new Date(EPOCH.toEpochDay())).build(Helper.getTestProcessor()).getDate())
|
||||
.isEqualTo("1970-01-01");
|
||||
assertThat(createSimpleConfiguration().date((Date) null).build(Helper.getTestProcessor()).getDate())
|
||||
.isEqualTo(LocalDate.now().toString());
|
||||
assertThat(createSimpleConfiguration().date((LocalDate) null).build(Helper.getTestProcessor()).getDate())
|
||||
.isEqualTo(LocalDate.now().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import org.junit.Test;
|
||||
|
||||
import de.kosit.validationtool.api.Configuration;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.ResolvingMode;
|
||||
import de.kosit.validationtool.impl.xml.RemoteResolvingStrategy;
|
||||
import de.kosit.validationtool.impl.xml.StrictRelativeResolvingStrategy;
|
||||
|
|
@ -35,7 +36,7 @@ public class ConfigurationLoaderTest {
|
|||
final ConfigurationLoader loader = TestConfigurationFactory.loadSimpleConfiguration();
|
||||
loader.setResolvingStrategy(new StrictRelativeResolvingStrategy());
|
||||
loader.setResolvingMode(ResolvingMode.ALLOW_REMOTE);
|
||||
final Configuration config = loader.build();
|
||||
final Configuration config = loader.build(Helper.getTestProcessor());
|
||||
assertThat(config.getContentRepository().getResolvingConfigurationStrategy()).isNotInstanceOf(RemoteResolvingStrategy.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import de.kosit.validationtool.api.Configuration;
|
|||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.api.Result;
|
||||
import de.kosit.validationtool.impl.DefaultCheck;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
|
||||
/**
|
||||
|
|
@ -35,7 +36,7 @@ public class SimpleConfigTest {
|
|||
@Test
|
||||
public void testSimpleWithApi() {
|
||||
//@formatter:off
|
||||
final Configuration config = createSimpleConfiguration().build();
|
||||
final Configuration config = createSimpleConfiguration().build(Helper.getTestProcessor());
|
||||
//@formatter:on
|
||||
final DefaultCheck check = new DefaultCheck(config);
|
||||
final Result result = check.checkInput(InputFactory.read(Simple.SIMPLE_VALID));
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import org.apache.commons.io.IOUtils;
|
|||
import org.apache.http.HttpStatus;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
|
||||
import io.restassured.builder.MultiPartSpecBuilder;
|
||||
|
|
@ -81,4 +82,11 @@ public class CheckHandlerIT extends BaseIT {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLarge() throws IOException {
|
||||
try ( final InputStream io = Helper.LARGE_XML.toURL().openStream() ) {
|
||||
given().contentType(APPLICATION_XML).body(toContent(io)).when().post("/").then().statusCode(SC_NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
|
@ -38,6 +39,7 @@ import com.sun.net.httpserver.HttpExchange;
|
|||
import de.kosit.validationtool.api.Configuration;
|
||||
import de.kosit.validationtool.config.TestConfigurationFactory;
|
||||
import de.kosit.validationtool.impl.ConversionService;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
|
|
@ -51,8 +53,8 @@ public class ConfigHandlerTest {
|
|||
final OutputStream stream = mock(OutputStream.class);
|
||||
when(exchange.getResponseHeaders()).thenReturn(headers);
|
||||
when(exchange.getResponseBody()).thenReturn(stream);
|
||||
final Configuration config = TestConfigurationFactory.createSimpleConfiguration().build();
|
||||
final ConfigHandler handler = new ConfigHandler(config, new ConversionService());
|
||||
final Configuration config = TestConfigurationFactory.createSimpleConfiguration().build(Helper.getTestProcessor());
|
||||
final ConfigHandler handler = new ConfigHandler(Collections.singletonList(config), new ConversionService());
|
||||
handler.handle(exchange);
|
||||
verify(exchange, times(1)).sendResponseHeaders(HttpStatus.SC_OK, 0);
|
||||
verify(stream, atLeast(1)).write(any());
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -61,12 +60,6 @@ public class ContentRepositoryTest {
|
|||
assertThat(schema).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaCaching() {
|
||||
final Schema schema = this.repository.getReportInputSchema();
|
||||
assertThat(this.repository.getReportInputSchema()).isSameAs(schema);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSchemaNotExisting() throws Exception {
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
|
|
@ -112,36 +105,12 @@ public class ContentRepositoryTest {
|
|||
@Test
|
||||
public void loadFromJar() throws URISyntaxException {
|
||||
assert Helper.JAR_REPOSITORY != null;
|
||||
this.repository = new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), Helper.JAR_REPOSITORY.toURI());
|
||||
this.repository = new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(),
|
||||
Helper.JAR_REPOSITORY.toURI());
|
||||
final XsltExecutable xsltExecutable = this.repository.loadXsltScript(URI.create("report.xsl"));
|
||||
assertThat(xsltExecutable).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadSchema() {
|
||||
final URL main = RelativeUriResolverTest.class.getClassLoader().getResource("loading/main.xsd");
|
||||
assert main != null;
|
||||
final Schema schema = this.repository.createSchema(main, new ClassPathResourceResolver("/loading"));
|
||||
final Schema schema = this.repository.createSchema(URI.create("main.xsd"));
|
||||
assertThat(schema).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadSchemaPackaged() throws URISyntaxException {
|
||||
final URL main = RelativeUriResolverTest.class.getClassLoader().getResource("packaged/main.xsd");
|
||||
assert main != null;
|
||||
final Schema schema = this.repository.createSchema(main,
|
||||
new ClassPathResourceResolver(RelativeUriResolverTest.class.getClassLoader().getResource("packaged/").toURI()));
|
||||
assertThat(schema).isNotNull();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void loadFromJar() throws URISyntaxException {
|
||||
// this.content = new ContentRepository(TestObjectFactory.createProcessor(), Helper.JAR_REPOSITORY.toURI());
|
||||
// this.repository = new ScenarioRepository(this.content);
|
||||
// final CheckConfiguration conf = new CheckConfiguration(
|
||||
// ScenarioRepository.class.getClassLoader().getResource("xrechnung/scenarios.xml").toURI());
|
||||
// ScenarioRepository.initialize(conf);
|
||||
// assertThat(this.repository.getScenarios()).isNotNull();
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,16 +65,17 @@ public class DefaultCheckTest {
|
|||
|
||||
@Before
|
||||
public void setup() throws URISyntaxException {
|
||||
final Configuration validConfig = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build();
|
||||
final Configuration validConfig = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build(Helper.getTestProcessor());
|
||||
this.validCheck = new DefaultCheck(validConfig);
|
||||
|
||||
final Configuration errorConfig = Configuration.load(Simple.ERROR_SCENARIOS, Simple.REPOSITORY_URI).build();
|
||||
final Configuration errorConfig = Configuration.load(Simple.ERROR_SCENARIOS, Simple.REPOSITORY_URI)
|
||||
.build(Helper.getTestProcessor());
|
||||
this.errorCheck = new DefaultCheck(errorConfig);
|
||||
|
||||
final Configuration jarConfig = Configuration
|
||||
.load(requireNonNull(DefaultCheckTest.class.getClassLoader().getResource("simple/packaged/scenarios.xml")).toURI(),
|
||||
requireNonNull(DefaultCheckTest.class.getClassLoader().getResource("simple/packaged/repository/")).toURI())
|
||||
.build();
|
||||
.build(Helper.getTestProcessor());
|
||||
|
||||
this.jarScenarioCheck = new DefaultCheck(jarConfig);
|
||||
}
|
||||
|
|
@ -248,8 +249,7 @@ public class DefaultCheckTest {
|
|||
assertThat(result.isProcessingSuccessful()).isEqualTo(true);
|
||||
|
||||
// test compatible configuration
|
||||
node = this.validCheck.getConfiguration().getContentRepository().getProcessor().newDocumentBuilder()
|
||||
.build(new StreamSource(SIMPLE_VALID.toASCIIString()));
|
||||
node = this.validCheck.getProcessor().newDocumentBuilder().build(new StreamSource(SIMPLE_VALID.toASCIIString()));
|
||||
domInput = InputFactory.read(node, "node test");
|
||||
result = this.validCheck.checkInput(domInput);
|
||||
assertThat(result.isProcessingSuccessful()).isEqualTo(true);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import de.kosit.validationtool.api.Input;
|
|||
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
||||
import de.kosit.validationtool.impl.xml.ProcessorProvider;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
|
|
@ -61,6 +62,8 @@ public class Helper {
|
|||
|
||||
public static final URI SCENARIOS = ROOT.resolve("scenarios.xml");
|
||||
|
||||
public static final URI OTHER_SCENARIOS = ROOT.resolve("otherScenarios.xml");
|
||||
|
||||
public static final URI ERROR_SCENARIOS = ROOT.resolve("scenarios-with-errors.xml");
|
||||
|
||||
public static final URI REPOSITORY_URI = ROOT.resolve("repository/");
|
||||
|
|
@ -83,7 +86,7 @@ public class Helper {
|
|||
|
||||
public static final ContentRepository createContentRepository() {
|
||||
final ResolvingConfigurationStrategy strategy = ResolvingMode.STRICT_RELATIVE.getStrategy();
|
||||
return new ContentRepository(strategy, Simple.REPOSITORY_URI);
|
||||
return new ContentRepository(Helper.getTestProcessor(), strategy, Simple.REPOSITORY_URI);
|
||||
}
|
||||
|
||||
public static URI getSchemaLocation() {
|
||||
|
|
@ -122,6 +125,8 @@ public class Helper {
|
|||
|
||||
public static final URL JAR_REPOSITORY = Helper.class.getClassLoader().getResource("simple/packaged/repository/");
|
||||
|
||||
public static final URI LARGE_XML = Paths.get("pom.xml").toUri();
|
||||
|
||||
/**
|
||||
* Lädt ein XML-Dokument von der gegebenen URL
|
||||
*
|
||||
|
|
@ -171,6 +176,6 @@ public class Helper {
|
|||
}
|
||||
|
||||
public static Processor createProcessor() {
|
||||
return ResolvingMode.STRICT_RELATIVE.getStrategy().getProcessor();
|
||||
return ProcessorProvider.getProcessor();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ public class ScenarioRepositoryTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
this.configInstance = new TestConfiguration();
|
||||
this.configInstance.setContentRepository(new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), null));
|
||||
this.configInstance
|
||||
.setContentRepository(new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(), null));
|
||||
|
||||
final Scenario s = createScenario();
|
||||
this.configInstance.setScenarios(new ArrayList<>());
|
||||
|
|
@ -106,6 +107,25 @@ public class ScenarioRepositoryTest {
|
|||
assertThat(scenario.getObject().getName()).isEqualTo("fallback");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoConfiguration() {
|
||||
this.expectedException.expect(IllegalArgumentException.class);
|
||||
this.repository = new ScenarioRepository();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFallbackOnMultipleConfigurations() {
|
||||
final TestConfiguration first = this.configInstance;
|
||||
first.setFallbackScenario(createFallback());
|
||||
setup();// create new one;
|
||||
final TestConfiguration second = this.configInstance;
|
||||
second.setFallbackScenario(createFallback());
|
||||
this.repository = new ScenarioRepository(first, second);
|
||||
final Scenario fallback = this.repository.getFallbackScenario();
|
||||
assertThat(fallback).isSameAs(first.getFallbackScenario());
|
||||
assertThat(fallback).isNotSameAs(second.getFallbackScenario());
|
||||
}
|
||||
|
||||
private XdmNode load(final URI uri) throws IOException {
|
||||
return Helper.parseDocument(this.configInstance.getContentRepository().getProcessor(), read(uri.toURL())).getObject();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class SimpleScenarioCheckTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
final Configuration d = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build();
|
||||
final Configuration d = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build(Helper.getTestProcessor());
|
||||
this.implementation = new DefaultCheck(d);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package de.kosit.validationtool.impl;
|
||||
|
||||
import de.kosit.validationtool.impl.xml.StrictLocalResolvingStrategy;
|
||||
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
|
||||
/**
|
||||
|
|
@ -29,7 +27,7 @@ public class TestObjectFactory {
|
|||
|
||||
public static Processor createProcessor() {
|
||||
if (processor == null) {
|
||||
processor = new StrictLocalResolvingStrategy().getProcessor();
|
||||
processor = Helper.getTestProcessor();
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,25 +59,25 @@ public class VersioningTest {
|
|||
|
||||
@Test
|
||||
public void testBase() throws URISyntaxException {
|
||||
final Scenarios result = this.service.readXml(BASE.toURI(), Scenarios.class, this.repository.getScenarioSchema());
|
||||
final Scenarios result = this.service.readXml(BASE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFrameworkIncrement() throws URISyntaxException {
|
||||
final Scenarios result = this.service.readXml(INCREMENT.toURI(), Scenarios.class, this.repository.getScenarioSchema());
|
||||
final Scenarios result = this.service.readXml(INCREMENT.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewFeature() throws URISyntaxException {
|
||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
||||
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, this.repository.getScenarioSchema());
|
||||
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewVersion() throws URISyntaxException {
|
||||
this.exception.expect(ConversionService.ConversionExeption.class);
|
||||
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, this.repository.getScenarioSchema());
|
||||
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright 2017-2020 Koordinierungsstelle für IT-Standards (KoSIT)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.kosit.validationtool.impl.input;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class StreamHelperTest {
|
||||
|
||||
/**
|
||||
* Simulates a stream that is return 0 for {@link InputStream#available()} even though content is supplied.
|
||||
*/
|
||||
private static class MyLazyStream extends FilterInputStream {
|
||||
|
||||
protected MyLazyStream(final InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyStream() throws IOException {
|
||||
final String myContent = "SomeBytes";
|
||||
try ( final InputStream in = new MyLazyStream(new ByteArrayInputStream(myContent.getBytes())) ) {
|
||||
final BufferedInputStream peekable = StreamHelper.wrapPeekable(in);
|
||||
assertThat(peekable.available()).isGreaterThan(0);
|
||||
final String read = IOUtils.toString(peekable, Charset.defaultCharset());
|
||||
assertThat(read).isEqualTo(myContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ import org.junit.Test;
|
|||
|
||||
import de.kosit.validationtool.api.AcceptRecommendation;
|
||||
import de.kosit.validationtool.impl.ContentRepository;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.ResolvingMode;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
|
||||
|
||||
|
|
@ -121,6 +122,7 @@ public class ComputeAcceptanceActionTest {
|
|||
}
|
||||
|
||||
private static XPathExecutable createXpath(final String expression) {
|
||||
return new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), null).createXPath(expression, new HashMap<>());
|
||||
return new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(), null).createXPath(expression,
|
||||
new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,8 +54,7 @@ public class CreateReportActionTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
this.repository = Simple.createContentRepository();
|
||||
this.action = new CreateReportAction(this.repository.getProcessor(), new ConversionService(), this.repository.getResolver(),
|
||||
this.repository.getUnparsedTextURIResolver());
|
||||
this.action = new CreateReportAction(this.repository.getProcessor(), new ConversionService());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -85,7 +84,7 @@ public class CreateReportActionTest {
|
|||
public void testExecutionException() throws SaxonApiException {
|
||||
final Processor p = mock(Processor.class);
|
||||
final DocumentBuilder documentBuilder = mock(DocumentBuilder.class);
|
||||
this.action = new CreateReportAction(p, new ConversionService(), null, null);
|
||||
this.action = new CreateReportAction(p, new ConversionService());
|
||||
|
||||
when(p.newDocumentBuilder()).thenReturn(documentBuilder);
|
||||
when(documentBuilder.build(any(Source.class))).thenThrow(new SaxonApiException("mocked"));
|
||||
|
|
|
|||
|
|
@ -44,10 +44,10 @@ import de.kosit.validationtool.api.XmlError.Severity;
|
|||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.Scenario;
|
||||
import de.kosit.validationtool.impl.SchemaProvider;
|
||||
import de.kosit.validationtool.impl.TestObjectFactory;
|
||||
import de.kosit.validationtool.impl.input.SourceInput;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
|
||||
import de.kosit.validationtool.impl.xml.StrictRelativeResolvingStrategy;
|
||||
|
||||
/**
|
||||
* Tests die {@link SchemaValidationAction}.
|
||||
|
|
@ -62,7 +62,7 @@ public class SchemaValidatorActionTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.service = new SchemaValidationAction(new StrictRelativeResolvingStrategy(), TestObjectFactory.createProcessor());
|
||||
this.service = new SchemaValidationAction(TestObjectFactory.createProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -89,7 +89,7 @@ public class SchemaValidatorActionTest {
|
|||
|
||||
@Test
|
||||
public void testSchemaReferences() {
|
||||
final Schema reportInputSchema = Simple.createContentRepository().getReportInputSchema();
|
||||
final Schema reportInputSchema = SchemaProvider.getReportInputSchema();
|
||||
assertThat(reportInputSchema).isNotNull();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import de.kosit.validationtool.impl.ConversionService;
|
|||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.Scenario;
|
||||
import de.kosit.validationtool.impl.Scenario.Transformation;
|
||||
import de.kosit.validationtool.impl.xml.RelativeUriResolver;
|
||||
import de.kosit.validationtool.model.scenarios.ResourceType;
|
||||
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
|
|
@ -51,7 +50,7 @@ public class SchematronValidationActionTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.action = new SchematronValidationAction(new RelativeUriResolver(Simple.REPOSITORY_URI), new ConversionService());
|
||||
this.action = new SchematronValidationAction(new ConversionService());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.oclc.purl.dsdl.svrl.SchematronOutput;
|
|||
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
|
||||
import de.kosit.validationtool.impl.ContentRepository;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.ResolvingMode;
|
||||
|
|
@ -82,6 +83,8 @@ public class TestBagBuilder {
|
|||
t.setValidateWithXmlSchema(v);
|
||||
final Scenario scenario = new Scenario(t);
|
||||
scenario.setSchema(createSchema(schemafile.toURL()));
|
||||
final ResolvingConfigurationStrategy strategy = ResolvingMode.STRICT_RELATIVE.getStrategy();
|
||||
scenario.setFactory(strategy);
|
||||
return scenario;
|
||||
} catch (final MalformedURLException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
|
|
@ -89,7 +92,8 @@ public class TestBagBuilder {
|
|||
}
|
||||
|
||||
private static Schema createSchema(final URL toURL) {
|
||||
final ContentRepository contentRepository = new ContentRepository(ResolvingMode.STRICT_RELATIVE.getStrategy(), null);
|
||||
final ContentRepository contentRepository = new ContentRepository(Helper.getTestProcessor(),
|
||||
ResolvingMode.STRICT_RELATIVE.getStrategy(), null);
|
||||
return contentRepository.createSchema(toURL);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2017-2020 Koordinierungsstelle für IT-Standards (KoSIT)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.kosit.validationtool.impl.xml;
|
||||
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
|
||||
import de.kosit.validationtool.impl.ResolvingMode;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class SchemaProviderTest {
|
||||
|
||||
private final SchemaFactory schemaFactory = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
|
||||
|
||||
}
|
||||
95
src/test/resources/examples/simple/otherScenarios.xml
Normal file
95
src/test/resources/examples/simple/otherScenarios.xml
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2017-2020 Koordinierungsstelle für IT-Standards (KoSIT)
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<scenarios xmlns="http://www.xoev.de/de/validator/framework/1/scenarios" frameworkVersion="1.1.2">
|
||||
<name>HTML-TestSuite</name>
|
||||
<author>QA</author>
|
||||
<date>2017-08-08</date>
|
||||
<description>
|
||||
<p>Szenario für Tests</p>
|
||||
</description>
|
||||
|
||||
<scenario>
|
||||
<name>Simple</name>
|
||||
<description>
|
||||
<p>Nur Schemaprüfung.</p>
|
||||
</description>
|
||||
<namespace prefix="cri">http://www.xoev.de/de/validator/framework/1/createreportinput
|
||||
</namespace>
|
||||
<namespace prefix="test">
|
||||
http://validator.kosit.de/test-sample</namespace>
|
||||
<namespace prefix="rpt">http://validator.kosit.de/test-report</namespace>
|
||||
<match>/test:doesNotMatch</match>
|
||||
|
||||
<validateWithXmlSchema>
|
||||
<resource>
|
||||
<name>Sample Schema</name>
|
||||
<location>simple.xsd</location>
|
||||
</resource>
|
||||
</validateWithXmlSchema>
|
||||
<validateWithSchematron>
|
||||
<resource>
|
||||
<name>Sample Schematron</name>
|
||||
<location>simple.xsl</location>
|
||||
</resource>
|
||||
</validateWithSchematron>
|
||||
<createReport>
|
||||
<resource>
|
||||
<name>Report für eRechnung</name>
|
||||
<location>report.xsl</location>
|
||||
</resource>
|
||||
</createReport>
|
||||
<acceptMatch>count(//test:rejected) = 0</acceptMatch>
|
||||
</scenario>
|
||||
|
||||
<scenario>
|
||||
<name>NoAcceptMatch</name>
|
||||
<description>
|
||||
<p>Nur Schemaprüfung. Keine AcceptMatch deklaration</p>
|
||||
<p>Testen, ob auch alte Konfiguration funktionioeren</p>
|
||||
</description>
|
||||
<namespace prefix="test">http://validator.kosit.de/test-sample</namespace>
|
||||
<match>/test:DoesNotMatchfoo</match>
|
||||
<validateWithXmlSchema>
|
||||
<resource>
|
||||
<name>Sample Schema</name>
|
||||
<location>simple.xsd</location>
|
||||
</resource>
|
||||
</validateWithXmlSchema>
|
||||
<validateWithSchematron>
|
||||
<resource>
|
||||
<name>Sample Schematron</name>
|
||||
<location>simple.xsl</location>
|
||||
</resource>
|
||||
</validateWithSchematron>
|
||||
<createReport>
|
||||
<resource>
|
||||
<name>Report für eRechnung</name>
|
||||
<location>report.xsl</location>
|
||||
</resource>
|
||||
</createReport>
|
||||
</scenario>
|
||||
|
||||
|
||||
<noScenarioReport>
|
||||
<resource>
|
||||
<name>default</name>
|
||||
<location>report.xsl</location>
|
||||
</resource>
|
||||
</noScenarioReport>
|
||||
|
||||
</scenarios>
|
||||
Loading…
Add table
Add a link
Reference in a new issue