26-AddAndApplyOpenRewrite

This commit is contained in:
Adrian-Devries 2025-04-24 12:54:14 +02:00
parent 2466f9cf5d
commit 24509aae31
77 changed files with 508 additions and 413 deletions

94
pom.xml
View file

@ -87,13 +87,17 @@
<version.jakarta.xml.bind-api>4.0.2</version.jakarta.xml.bind-api> <version.jakarta.xml.bind-api>4.0.2</version.jakarta.xml.bind-api>
<version.jansi>2.4.1</version.jansi> <version.jansi>2.4.1</version.jansi>
<version.jaxb-runtime>4.0.5</version.jaxb-runtime> <version.jaxb-runtime>4.0.5</version.jaxb-runtime>
<version.junit>4.13.2</version.junit> <version.junit-jupiter-api>5.12.2</version.junit-jupiter-api>
<version.lombok>1.18.38</version.lombok> <version.lombok>1.18.38</version.lombok>
<version.mockito-core>5.17.0</version.mockito-core> <version.mockito-core>5.17.0</version.mockito-core>
<version.packaged-test-scenarios>1.0.2</version.packaged-test-scenarios> <version.packaged-test-scenarios>1.0.2</version.packaged-test-scenarios>
<version.picocli>4.7.7</version.picocli> <version.picocli>4.7.7</version.picocli>
<version.pmd>7.12.0</version.pmd> <version.pmd>7.12.0</version.pmd>
<version.rest-assured>5.5.1</version.rest-assured> <version.rest-assured>5.5.1</version.rest-assured>
<version.rewrite-logging-frameworks>3.6.1</version.rewrite-logging-frameworks>
<version.rewrite-migrate-java>3.7.0</version.rewrite-migrate-java>
<version.rewrite-static-analysis>2.7.1</version.rewrite-static-analysis>
<version.rewrite-testing-frameworks>3.6.1</version.rewrite-testing-frameworks>
<version.saxon-he>12.5</version.saxon-he> <version.saxon-he>12.5</version.saxon-he>
<version.slf4j-api>2.0.17</version.slf4j-api> <version.slf4j-api>2.0.17</version.slf4j-api>
<version.slf4j-simple>2.0.17</version.slf4j-simple> <version.slf4j-simple>2.0.17</version.slf4j-simple>
@ -124,6 +128,7 @@
<version.maven-site-plugin>3.21.0</version.maven-site-plugin> <version.maven-site-plugin>3.21.0</version.maven-site-plugin>
<version.maven-source-plugin>3.3.1</version.maven-source-plugin> <version.maven-source-plugin>3.3.1</version.maven-source-plugin>
<version.maven-surefire-plugin>3.5.3</version.maven-surefire-plugin> <version.maven-surefire-plugin>3.5.3</version.maven-surefire-plugin>
<version.rewrite-maven-plugin>6.6.1</version.rewrite-maven-plugin>
<version.spotbugs-maven-plugin>4.9.3.0</version.spotbugs-maven-plugin> <version.spotbugs-maven-plugin>4.9.3.0</version.spotbugs-maven-plugin>
<version.versions-maven-plugin>2.18.0</version.versions-maven-plugin> <version.versions-maven-plugin>2.18.0</version.versions-maven-plugin>
</properties> </properties>
@ -211,18 +216,18 @@
<version>${version.rest-assured}</version> <version>${version.rest-assured}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.assertj</groupId> <groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId> <artifactId>assertj-core</artifactId>
<version>${version.assertj-core}</version> <version>${version.assertj-core}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.junit-jupiter-api}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
@ -230,6 +235,7 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<!--
<repositories> <repositories>
<repository> <repository>
<id>project.local</id> <id>project.local</id>
@ -237,6 +243,7 @@
<url>file:${project.basedir}/libs</url> <url>file:${project.basedir}/libs</url>
</repository> </repository>
</repositories> </repositories>
-->
<build> <build>
<resources> <resources>
<resource> <resource>
@ -786,6 +793,79 @@
<outputFormat>xml</outputFormat> <outputFormat>xml</outputFormat>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>${version.rewrite-maven-plugin}</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>dryRunNoFork</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-logging-frameworks</artifactId>
<version>${version.rewrite-logging-frameworks}</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>${version.rewrite-migrate-java}</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-static-analysis</artifactId>
<version>${version.rewrite-static-analysis}</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-testing-frameworks</artifactId>
<version>${version.rewrite-testing-frameworks}</version>
</dependency>
</dependencies>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.maven.BestPractices</recipe>
<recipe>org.openrewrite.maven.ModernizeObsoletePoms</recipe>
<recipe>org.openrewrite.maven.OrderPomElements</recipe>
<!-- <recipe>org.openrewrite.java.OrderImports</recipe> -->
<recipe>org.openrewrite.java.RemoveUnusedImports</recipe>
<recipe>org.openrewrite.java.ShortenFullyQualifiedTypeReferences</recipe>
<!-- <recipe>org.openrewrite.java.format.AutoFormat</recipe> -->
<recipe>org.openrewrite.java.format.BlankLines</recipe>
<recipe>org.openrewrite.java.format.EmptyNewlineAtEndOfFile</recipe>
<recipe>org.openrewrite.java.format.MethodParamPad</recipe>
<recipe>org.openrewrite.java.format.NoWhitespaceAfter</recipe>
<recipe>org.openrewrite.java.format.NoWhitespaceBefore</recipe>
<recipe>org.openrewrite.java.format.NormalizeFormat</recipe>
<recipe>org.openrewrite.java.format.NormalizeLineBreaks</recipe>
<recipe>org.openrewrite.java.format.NormalizeTabsOrSpaces</recipe>
<recipe>org.openrewrite.java.format.RemoveTrailingWhitespace</recipe>
<recipe>org.openrewrite.java.format.SingleLineComments</recipe>
<recipe>org.openrewrite.java.format.Spaces</recipe>
<!-- <recipe>org.openrewrite.java.format.TabsAndIndents</recipe> -->
<recipe>org.openrewrite.java.format.TypecastParenPad</recipe>
<recipe>org.openrewrite.java.format.WrappingAndBraces</recipe>
<recipe>org.openrewrite.java.logging.PrintStackTraceToLogError</recipe>
<recipe>org.openrewrite.java.logging.slf4j.Slf4jBestPractices</recipe>
<recipe>org.openrewrite.java.migrate.UpgradeToJava8</recipe>
<recipe>org.openrewrite.java.testing.junit5.JUnit4to5Migration</recipe>
<recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>
<recipe>org.openrewrite.staticanalysis.CovariantEquals</recipe>
<!-- <recipe>org.openrewrite.staticanalysis.FinalizeLocalVariables</recipe> -->
<recipe>org.openrewrite.staticanalysis.HideUtilityClassConstructor</recipe>
<recipe>org.openrewrite.staticanalysis.UnnecessaryParentheses</recipe>
</activeRecipes>
<activeStyles>
<style>org.openrewrite.java.IntelliJ</style>
</activeStyles>
<checkstyleDetectionEnabled>false</checkstyleDetectionEnabled>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<reporting> <reporting>

View file

@ -20,6 +20,7 @@ import de.kosit.validationtool.cmd.CommandLineApplication.Level;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.slf4j.simple.SimpleLogger;
import picocli.CommandLine.ArgGroup; import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command; import picocli.CommandLine.Command;
import picocli.CommandLine.Help.Visibility; import picocli.CommandLine.Help.Visibility;
@ -172,9 +173,9 @@ public class CommandLineOptions implements Callable<ReturnValue> {
private static void configureLogging(final CommandLineOptions cmd) { private static void configureLogging(final CommandLineOptions cmd) {
if (cmd.isDebugLog()) { if (cmd.isDebugLog()) {
System.setProperty(org.slf4j.simple.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG"); System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
} else { } else {
System.setProperty(org.slf4j.simple.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, cmd.getLogLevel().name()); System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, cmd.getLogLevel().name());
} }
} }

View file

@ -73,14 +73,14 @@ class InternalCheck extends DefaultCheck {
private static Grid createResultGrid(final Map<String, Result> results) { private static Grid createResultGrid(final Map<String, Result> results) {
final Grid grid = new Grid( final Grid grid = new Grid(
//@formatter:off // @formatter:off
new ColumnDefinition("File", 60, 10, 1), new ColumnDefinition("File", 60, 10, 1),
new ColumnDefinition("Schema", 7).justify(Justify.CENTER), new ColumnDefinition("Schema", 7).justify(Justify.CENTER),
new ColumnDefinition("Schematron", 10).justify(Justify.CENTER), new ColumnDefinition("Schematron", 10).justify(Justify.CENTER),
new ColumnDefinition("Acceptance", 10, 5).justify(Justify.CENTER), new ColumnDefinition("Acceptance", 10, 5).justify(Justify.CENTER),
new ColumnDefinition("Error/Description", 60,20,3) new ColumnDefinition("Error/Description", 60, 20, 3)
); );
//@formatter:on // @formatter:on
results.entrySet().stream().sorted(Entry.comparingByKey()).forEach(e -> { results.entrySet().stream().sorted(Entry.comparingByKey()).forEach(e -> {
final Result value = e.getValue(); final Result value = e.getValue();

View file

@ -16,6 +16,7 @@
package de.kosit.validationtool.cmd; package de.kosit.validationtool.cmd;
import de.kosit.validationtool.impl.tasks.CheckAction;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.text.NumberFormat; import java.text.NumberFormat;
@ -27,7 +28,7 @@ import java.text.NumberFormat;
* @author Andreas Penski * @author Andreas Penski
*/ */
@Slf4j @Slf4j
class PrintMemoryStats implements de.kosit.validationtool.impl.tasks.CheckAction { class PrintMemoryStats implements CheckAction {
private static final int BYTES_PER_K = 1024; private static final int BYTES_PER_K = 1024;

View file

@ -93,4 +93,7 @@ class TypeConverter {
return TypeConverter.convert(ScenarioDefinition.class, value); return TypeConverter.convert(ScenarioDefinition.class, value);
} }
} }
private TypeConverter() {
}
} }

View file

@ -25,6 +25,7 @@ import de.kosit.validationtool.cmd.CommandLineOptions.Definition;
import de.kosit.validationtool.cmd.CommandLineOptions.RepositoryDefinition; import de.kosit.validationtool.cmd.CommandLineOptions.RepositoryDefinition;
import de.kosit.validationtool.cmd.CommandLineOptions.ScenarioDefinition; import de.kosit.validationtool.cmd.CommandLineOptions.ScenarioDefinition;
import de.kosit.validationtool.cmd.assertions.Assertions; import de.kosit.validationtool.cmd.assertions.Assertions;
import de.kosit.validationtool.cmd.assertions.ObjectFactory;
import de.kosit.validationtool.cmd.report.Line; import de.kosit.validationtool.cmd.report.Line;
import de.kosit.validationtool.daemon.Daemon; import de.kosit.validationtool.daemon.Daemon;
import de.kosit.validationtool.impl.ConversionService; import de.kosit.validationtool.impl.ConversionService;
@ -91,7 +92,7 @@ public class Validator {
if (cmd.isDebugOutput()) { if (cmd.isDebugOutput()) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} else { } else {
log.error(e.getMessage()); log.error("", e);
} }
return ReturnValue.CONFIGURATION_ERROR; return ReturnValue.CONFIGURATION_ERROR;
} }
@ -246,7 +247,7 @@ public class Validator {
Assertions a = null; Assertions a = null;
if (Files.exists(p)) { if (Files.exists(p)) {
final ConversionService c = new ConversionService(); final ConversionService c = new ConversionService();
c.initialize(de.kosit.validationtool.cmd.assertions.ObjectFactory.class.getPackage()); c.initialize(ObjectFactory.class.getPackage());
a = c.readXml(p.toUri(), Assertions.class); a = c.readXml(p.toUri(), Assertions.class);
} }
return a; return a;

View file

@ -280,7 +280,7 @@ public class ConfigurationBuilder {
configuration.setName(this.name); configuration.setName(this.name);
configuration.setContentRepository(contentRepository); configuration.setContentRepository(contentRepository);
configuration.getAdditionalParameters().put(Keys.SCENARIO_DEFINITION, createDefinition(configuration)); configuration.getAdditionalParameters().put(Keys.SCENARIO_DEFINITION, createDefinition(configuration));
return (configuration); return configuration;
} }
private Scenarios createDefinition(final DefaultConfiguration configuration) { private Scenarios createDefinition(final DefaultConfiguration configuration) {

View file

@ -168,7 +168,7 @@ public class ConfigurationLoader {
configuration.setContentRepository(contentRepository); configuration.setContentRepository(contentRepository);
configuration.getAdditionalParameters().put(Keys.SCENARIOS_FILE, this.scenarioDefinition); configuration.getAdditionalParameters().put(Keys.SCENARIOS_FILE, this.scenarioDefinition);
configuration.getAdditionalParameters().put(Keys.SCENARIO_DEFINITION, def); configuration.getAdditionalParameters().put(Keys.SCENARIO_DEFINITION, def);
return (configuration); return configuration;
} }
private ResolvingConfigurationStrategy getResolvingConfigurationStrategy() { private ResolvingConfigurationStrategy getResolvingConfigurationStrategy() {

View file

@ -80,8 +80,7 @@ class CheckHandler extends BaseHandler {
} }
} }
private static boolean isContentAvailable(final com.sun.net.httpserver.HttpExchange httpExchange, final BufferedInputStream buffered) private static boolean isContentAvailable(final HttpExchange httpExchange, final BufferedInputStream buffered) throws IOException {
throws IOException {
final String length = httpExchange.getRequestHeaders().getFirst("Content-length"); final String length = httpExchange.getRequestHeaders().getFirst("Content-length");
if (StringUtils.isNumeric(length)) { if (StringUtils.isNumeric(length)) {
return Integer.parseInt(length) > 0; return Integer.parseInt(length) > 0;

View file

@ -16,6 +16,7 @@
package de.kosit.validationtool.impl; package de.kosit.validationtool.impl;
import de.kosit.validationtool.model.reportInput.ObjectFactory;
import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
@ -112,7 +113,7 @@ public class ConversionService {
*/ */
public void initialize() { public void initialize() {
final Collection<Package> p = new ArrayList<>(); final Collection<Package> p = new ArrayList<>();
p.add(de.kosit.validationtool.model.reportInput.ObjectFactory.class.getPackage()); p.add(ObjectFactory.class.getPackage());
p.add(de.kosit.validationtool.model.scenarios.ObjectFactory.class.getPackage()); p.add(de.kosit.validationtool.model.scenarios.ObjectFactory.class.getPackage());
initialize(p); initialize(p);
} }

View file

@ -84,4 +84,7 @@ public class SchemaProvider {
return createSchema(sf, resolve(Objects.requireNonNull(SchemaProvider.class.getResource("/xsd/scenarios.xsd")))); return createSchema(sf, resolve(Objects.requireNonNull(SchemaProvider.class.getResource("/xsd/scenarios.xsd"))));
} }
private SchemaProvider() {
}
} }

View file

@ -69,7 +69,7 @@ public class DocumentParseAction implements CheckAction {
result = new Result<>(doc, Collections.emptyList()); result = new Result<>(doc, Collections.emptyList());
} }
} catch (final SaxonApiException | IOException e) { } catch (final SaxonApiException | IOException e) {
log.debug("Exception while parsing {}", content.getName(), e); log.error("Exception while parsing {}", content.getName(), e);
final XMLSyntaxError error = new XMLSyntaxError(); final XMLSyntaxError error = new XMLSyntaxError();
error.setSeverityCode(XMLSyntaxErrorSeverity.SEVERITY_FATAL_ERROR); error.setSeverityCode(XMLSyntaxErrorSeverity.SEVERITY_FATAL_ERROR);
error.setMessage(String.format("IOException while reading resource %s: %s", content.getName(), e.getMessage())); error.setMessage(String.format("IOException while reading resource %s: %s", content.getName(), e.getMessage()));

View file

@ -58,7 +58,7 @@ public abstract class BaseResolvingStrategy implements ResolvingConfigurationStr
if (lenient) { if (lenient) {
log.warn(errorMessage); log.warn(errorMessage);
log.debug(e.getMessage(), e); log.error(e.getMessage(), e);
} else { } else {
throw new IllegalStateException(errorMessage); throw new IllegalStateException(errorMessage);
} }

View file

@ -116,4 +116,7 @@ public class ProcessorProvider {
.setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(XMLConstants.ACCESS_EXTERNAL_DTD), false); // NOSONAR .setConfigurationProperty(FeatureKeys.XML_PARSER_FEATURE + encode(XMLConstants.ACCESS_EXTERNAL_DTD), false); // NOSONAR
return processor; return processor;
} }
private ProcessorProvider() {
}
} }

View file

@ -52,7 +52,7 @@
<xs:complexType name="AssertionType"> <xs:complexType name="AssertionType">
<xs:annotation> <xs:annotation>
<xs:documentation>Zusicherung: für das in report-doc angegebene Dokument (relativ zum aktuellen <xs:documentation>Zusicherung: für das in report-doc angegebene Dokument (relativ zum aktuellen
Ausgabeverzeichnis) hat der angebene Ausgabeverzeichnis) hat der angegebene
XPath-Test den "Effective Truth Value" true(). Im Textknoten kann eine textuelle Zusammenfassung des XPath-Test den "Effective Truth Value" true(). Im Textknoten kann eine textuelle Zusammenfassung des
Tests stehen. Tests stehen.
</xs:documentation> </xs:documentation>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -17,7 +17,7 @@
package de.kosit.validationtool.api; package de.kosit.validationtool.api;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -27,10 +27,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andreas Penski * @author Andreas Penski
*/ */
@Deprecated @Deprecated
public class CheckConfigurationTest { class CheckConfigurationTest {
@Test @Test
public void testDelegation() { void delegation() {
final CheckConfiguration config = new CheckConfiguration(Simple.SCENARIOS); final CheckConfiguration config = new CheckConfiguration(Simple.SCENARIOS);
config.setScenarioRepository(Simple.REPOSITORY_URI); config.setScenarioRepository(Simple.REPOSITORY_URI);
assertThat(config.getScenarios()).isNotEmpty(); assertThat(config.getScenarios()).isNotEmpty();

View file

@ -27,7 +27,7 @@ import net.sf.saxon.s9api.BuildingContentHandler;
import net.sf.saxon.s9api.DocumentBuilder; import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode; import net.sf.saxon.s9api.XdmNode;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;
@ -45,7 +45,7 @@ import java.nio.file.Paths;
import static de.kosit.validationtool.impl.Helper.Simple.SIMPLE_VALID; import static de.kosit.validationtool.impl.Helper.Simple.SIMPLE_VALID;
import static de.kosit.validationtool.impl.input.StreamHelper.drain; import static de.kosit.validationtool.impl.input.StreamHelper.drain;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Testet den Hashcode-Service. * Testet den Hashcode-Service.
@ -57,13 +57,13 @@ public class InputFactoryTest {
public static final String SOME_VALUE = "some value"; public static final String SOME_VALUE = "some value";
@Test @Test
public void testDefaultDigestAlgorithm() { void defaultDigestAlgorithm() {
assertThat(new InputFactory().getAlgorithm()).isEqualTo(InputFactory.DEFAULT_ALGORITHM); assertThat(new InputFactory().getAlgorithm()).isEqualTo(InputFactory.DEFAULT_ALGORITHM);
assertThat(new InputFactory("").getAlgorithm()).isEqualTo(InputFactory.DEFAULT_ALGORITHM); assertThat(new InputFactory("").getAlgorithm()).isEqualTo(InputFactory.DEFAULT_ALGORITHM);
} }
@Test @Test
public void testHashCodeGeneration() throws IOException { void hashCodeGeneration() throws IOException {
final byte[] s1 = drain(InputFactory.read(Simple.SIMPLE_VALID.toURL())).getHashCode(); final byte[] s1 = drain(InputFactory.read(Simple.SIMPLE_VALID.toURL())).getHashCode();
final byte[] s2 = 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.SCHEMA_INVALID.toURL())).getHashCode(); final byte[] s3 = drain(InputFactory.read(Simple.SCHEMA_INVALID.toURL())).getHashCode();
@ -74,64 +74,61 @@ public class InputFactoryTest {
} }
@Test @Test
public void testWrongAlgorithm() { void wrongAlgorithm() {
assertThrows(IllegalArgumentException.class, () -> new InputFactory("unknown")); assertThrows(IllegalArgumentException.class, () -> new InputFactory("unknown"));
} }
@Test @Test
public void testNullInputURL() { void nullInputURL() {
assertThrows(IllegalArgumentException.class, () -> InputFactory.read((URL) null)); assertThrows(IllegalArgumentException.class, () -> InputFactory.read((URL) null));
} }
@Test @Test
public void testInputByte() { void inputByte() {
final Input input = InputFactory.read(SOME_VALUE.getBytes(), SOME_VALUE); final Input input = InputFactory.read(SOME_VALUE.getBytes(), SOME_VALUE);
assertThat(input).isNotNull(); assertThat(input).isNotNull();
} }
@Test @Test
public void testInputStream() { void inputStream() {
final Input input = InputFactory.read(new ByteArrayInputStream(SOME_VALUE.getBytes()), SOME_VALUE); final Input input = InputFactory.read(new ByteArrayInputStream(SOME_VALUE.getBytes()), SOME_VALUE);
assertThat(input).isNotNull(); assertThat(input).isNotNull();
} }
@Test @Test
public void testNullStream() { void nullStream() {
assertThrows(IllegalArgumentException.class, () -> InputFactory.read((InputStream) null, SOME_VALUE)); assertThrows(IllegalArgumentException.class, () -> InputFactory.read((InputStream) null, SOME_VALUE));
} }
@Test @Test
public void testInputFile() { void inputFile() {
final Input input = InputFactory.read(new File(Simple.SIMPLE_VALID)); final Input input = InputFactory.read(new File(Simple.SIMPLE_VALID));
assertThat(input).isNotNull(); assertThat(input).isNotNull();
} }
@Test @Test
public void testInputPath() { void inputPath() {
final Input input = InputFactory.read(Paths.get(Simple.SIMPLE_VALID)); final Input input = InputFactory.read(Paths.get(Simple.SIMPLE_VALID));
assertThat(input).isNotNull(); assertThat(input).isNotNull();
} }
@Test @Test
public void testNullInput() { void nullInput() {
assertThrows(IllegalArgumentException.class, () -> InputFactory.read((byte[]) null, SOME_VALUE)); assertThrows(IllegalArgumentException.class, () -> InputFactory.read((byte[]) null, SOME_VALUE));
} }
@Test @Test
public void testNullInputName() { void nullInputName() {
assertThrows(IllegalArgumentException.class, () -> InputFactory.read(SOME_VALUE.getBytes(), null)); assertThrows(IllegalArgumentException.class, () -> InputFactory.read(SOME_VALUE.getBytes(), null));
} }
@Test @Test
public void testEmptyInputName() { void emptyInputName() {
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> InputFactory.read(SOME_VALUE.getBytes(), ""));
final Input input = InputFactory.read(SOME_VALUE.getBytes(), "");
drain(input);
});
} }
@Test @Test
public void testSourceInput() throws IOException { void sourceInput() throws IOException {
try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream() ) { try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream() ) {
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(s)); final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(s));
assertThat(input.getSource()).isNotNull(); assertThat(input.getSource()).isNotNull();
@ -143,7 +140,7 @@ public class InputFactoryTest {
} }
@Test @Test
public void testSourceInputReader() throws IOException { void sourceInputReader() throws IOException {
try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream(); try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream();
final InputStreamReader reader = new InputStreamReader(s) ) { final InputStreamReader reader = new InputStreamReader(s) ) {
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader)); final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader));
@ -156,12 +153,12 @@ public class InputFactoryTest {
} }
@Test @Test
public void testNotExistingInput() { void notExistingInput() {
assertThrows(IllegalArgumentException.class, () -> InputFactory.read(Simple.NOT_EXISTING)); assertThrows(IllegalArgumentException.class, () -> InputFactory.read(Simple.NOT_EXISTING));
} }
@Test @Test
public void testDomSource() throws SaxonApiException, SAXException, IOException { void domSource() throws SaxonApiException, SAXException, IOException {
final DocumentBuilder builder = TestObjectFactory.createProcessor().newDocumentBuilder(); final DocumentBuilder builder = TestObjectFactory.createProcessor().newDocumentBuilder();
final BuildingContentHandler handler = builder.newBuildingContentHandler(); final BuildingContentHandler handler = builder.newBuildingContentHandler();
@ -179,7 +176,7 @@ public class InputFactoryTest {
} }
@Test @Test
public void testXdmNode() throws Exception { void xdmNode() throws Exception {
final XdmNode node = TestObjectFactory.createProcessor().newDocumentBuilder().build(new StreamSource(SIMPLE_VALID.toASCIIString())); final XdmNode node = TestObjectFactory.createProcessor().newDocumentBuilder().build(new StreamSource(SIMPLE_VALID.toASCIIString()));
final Input nodeInput = InputFactory.read(node, "node test"); final Input nodeInput = InputFactory.read(node, "node test");
assertThat(nodeInput).isNotNull(); assertThat(nodeInput).isNotNull();

View file

@ -22,8 +22,8 @@ import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.TestObjectFactory; import de.kosit.validationtool.impl.TestObjectFactory;
import de.kosit.validationtool.impl.tasks.CheckAction; import de.kosit.validationtool.impl.tasks.CheckAction;
import de.kosit.validationtool.model.reportInput.CreateReportInput; import de.kosit.validationtool.model.reportInput.CreateReportInput;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class CheckAssertionActionTest { class CheckAssertionActionTest {
private static final URL SAMPLE = CheckAssertionActionTest.class.getResource("/examples/assertions/ubl-0001.xml"); private static final URL SAMPLE = CheckAssertionActionTest.class.getResource("/examples/assertions/ubl-0001.xml");
@ -43,20 +43,20 @@ public class CheckAssertionActionTest {
private static final URL SAMPLE_ASSERTIONS = CheckAssertionActionTest.class.getResource("/examples/assertions/tests-xrechnung.xml"); private static final URL SAMPLE_ASSERTIONS = CheckAssertionActionTest.class.getResource("/examples/assertions/tests-xrechnung.xml");
@Before @BeforeEach
public void setup() { void setup() {
CommandLine.activate(); CommandLine.activate();
} }
@Test @Test
public void testEmptyInput() { void emptyInput() {
final CheckAssertionAction a = new CheckAssertionAction(new Assertions(), TestObjectFactory.createProcessor()); final CheckAssertionAction a = new CheckAssertionAction(new Assertions(), TestObjectFactory.createProcessor());
a.check(new CheckAction.Bag(InputFactory.read(SAMPLE), new CreateReportInput())); a.check(new CheckAction.Bag(InputFactory.read(SAMPLE), new CreateReportInput()));
assertThat(CommandLine.getErrorOutput()).contains("Can not find assertions for"); assertThat(CommandLine.getErrorOutput()).contains("Can not find assertions for");
} }
@Test @Test
public void testSimple() throws URISyntaxException { void simple() throws URISyntaxException {
final CheckAction.Bag bag = new CheckAction.Bag(InputFactory.read(SAMPLE), new CreateReportInput()); final CheckAction.Bag bag = new CheckAction.Bag(InputFactory.read(SAMPLE), new CreateReportInput());
bag.setReport(Helper.load(SAMPLE_REPORT)); bag.setReport(Helper.load(SAMPLE_REPORT));

View file

@ -151,4 +151,7 @@ public class CommandLine {
setStandardInput(nullInputStream()); setStandardInput(nullInputStream());
} }
private CommandLine() {
}
} }

View file

@ -21,9 +21,9 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.assertj.core.api.Condition; import org.assertj.core.api.Condition;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@ -47,8 +47,8 @@ public class CommandlineApplicationTest {
private final Path output = Paths.get("target/test-output"); private final Path output = Paths.get("target/test-output");
@Before @BeforeEach
public void setup() throws IOException { void setup() throws IOException {
CommandLine.activate(); CommandLine.activate();
if (Files.exists(this.output)) { if (Files.exists(this.output)) {
FileUtils.deleteDirectory(this.output.toFile()); FileUtils.deleteDirectory(this.output.toFile());
@ -56,8 +56,8 @@ public class CommandlineApplicationTest {
TypeConverter.counter.clear(); TypeConverter.counter.clear();
} }
@After @AfterEach
public void cleanup() throws IOException { void cleanup() throws IOException {
try ( Stream<Path> stream = Files.list(Paths.get("")) ) { try ( Stream<Path> stream = Files.list(Paths.get("")) ) {
stream.filter(p -> p.getFileName().toString().endsWith("-report.xml")).forEach(path -> { stream.filter(p -> p.getFileName().toString().endsWith("-report.xml")).forEach(path -> {
try { try {
@ -71,7 +71,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testHelp() { void help() {
final String[] args = new String[] { "-?" }; final String[] args = new String[] { "-?" };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
assertThat(CommandLine.getErrorOutput()).isEmpty(); assertThat(CommandLine.getErrorOutput()).isEmpty();
@ -84,7 +84,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testRequiredScenarioFile() { void requiredScenarioFile() {
final String[] args = new String[] { "arguments", "egal welche", "argumente drin sind" }; final String[] args = new String[] { "arguments", "egal welche", "argumente drin sind" };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
assertThat(CommandLine.getErrorOutput()).isNotEmpty(); assertThat(CommandLine.getErrorOutput()).isNotEmpty();
@ -92,7 +92,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testNotExistingScenarioFile() { void notExistingScenarioFile() {
final String s = Paths.get(Simple.NOT_EXISTING).toString(); final String s = Paths.get(Simple.NOT_EXISTING).toString();
final String[] args = new String[] { "-s", s, s }; final String[] args = new String[] { "-s", s, s };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -101,7 +101,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testIncorrectRepository() { void incorrectRepository() {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", 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() }; Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -110,7 +110,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testNotExistingTestTarget() { void notExistingTestTarget() {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.NOT_EXISTING).toString() }; Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.NOT_EXISTING).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -119,7 +119,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testValidMinimalConfiguration() { void validMinimalConfiguration() {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() }; Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -127,7 +127,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testValidNamingConfiguration() { void validNamingConfiguration() {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString(), "--report-prefix", "somePrefix", Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString(), "--report-prefix", "somePrefix",
"--report-postfix", "somePostfix" }; "--report-postfix", "somePostfix" };
@ -137,7 +137,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testValidMultipleInput() { void validMultipleInput() {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString(), Paths.get(Simple.FOO).toString() }; Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString(), Paths.get(Simple.FOO).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -145,7 +145,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testValidDirectoryInput() { void validDirectoryInput() {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.EXAMPLES).toString() }; Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.EXAMPLES).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -153,7 +153,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testValidOutputConfiguration() throws IOException { void validOutputConfiguration() throws IOException {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() }; Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -163,7 +163,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testNoInput() { void noInput() {
// assertThat(output).doesNotExist(); // assertThat(output).doesNotExist();
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), }; Paths.get(Simple.REPOSITORY_URI).toString(), };
@ -172,7 +172,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testPrint() { void print() {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-p", "-r", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-p", "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), "-o", this.output.toString(), Paths.get(Simple.SIMPLE_VALID).toString() }; Paths.get(Simple.REPOSITORY_URI).toString(), "-o", this.output.toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -182,7 +182,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testHtmlExtraktion() throws IOException { void htmlExtraktion() throws IOException {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-h", "-o", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-h", "-o",
this.output.toAbsolutePath().toString(), "-r", Paths.get(Simple.REPOSITORY_URI).toString(), this.output.toAbsolutePath().toString(), "-r", Paths.get(Simple.REPOSITORY_URI).toString(),
Paths.get(Simple.SIMPLE_VALID).toString() }; Paths.get(Simple.SIMPLE_VALID).toString() };
@ -194,7 +194,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testAssertionsExtraktion() { void assertionsExtraktion() {
final String s = Paths.get(Simple.REPOSITORY_URI).toString(); final String s = Paths.get(Simple.REPOSITORY_URI).toString();
final String[] args = new String[] { "-d", "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", s, "-o", this.output.toString(), final String[] args = new String[] { "-d", "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", s, "-o", this.output.toString(),
"-c", Paths.get(ASSERTIONS).toString(), s, Paths.get(Simple.SIMPLE_VALID).toString() }; "-c", Paths.get(ASSERTIONS).toString(), s, Paths.get(Simple.SIMPLE_VALID).toString() };
@ -204,7 +204,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testDebugFlag() { void debugFlag() {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", "unknown", "-o", this.output.toString(), final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", "unknown", "-o", this.output.toString(),
"-d", Paths.get(ASSERTIONS).toString() }; "-d", Paths.get(ASSERTIONS).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -212,7 +212,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testPrintMemoryStats() { void printMemoryStats() {
final String[] args = new String[] { "-m", "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", final String[] args = new String[] { "-m", "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() }; Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -221,7 +221,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testReadFromPipe() throws IOException { void readFromPipe() throws IOException {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString() }; Paths.get(Simple.REPOSITORY_URI).toString() };
CommandLine.setStandardInput(Files.newInputStream(Paths.get(Simple.SIMPLE_VALID))); CommandLine.setStandardInput(Files.newInputStream(Paths.get(Simple.SIMPLE_VALID)));
@ -230,7 +230,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testUnexpectedDaemonFlag() { void unexpectedDaemonFlag() {
final String[] args = new String[] { "-D", "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", 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() }; Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -238,7 +238,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void testParsingError() { void parsingError() {
final String[] args = new String[] { "-s", "-r", Paths.get(Simple.REPOSITORY_URI).toString(), final String[] args = new String[] { "-s", "-r", Paths.get(Simple.REPOSITORY_URI).toString(),
Paths.get(Simple.SIMPLE_VALID).toString() }; Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -246,7 +246,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void loadMultipleScenarios() { void loadMultipleScenarios() {
final Path p = Paths.get(Simple.REPOSITORY_URI); final Path p = Paths.get(Simple.REPOSITORY_URI);
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-s", "s2=" + Paths.get(Simple.OTHER_SCENARIOS), final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-s", "s2=" + Paths.get(Simple.OTHER_SCENARIOS),
"-r", "s1=" + p, "-r", "s2=" + p, Paths.get(Simple.SIMPLE_VALID).toString() }; "-r", "s1=" + p, "-r", "s2=" + p, Paths.get(Simple.SIMPLE_VALID).toString() };
@ -255,7 +255,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void loadMultipleScenariosSingleRepository() { void loadMultipleScenariosSingleRepository() {
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-s", "s2=" + Paths.get(Simple.OTHER_SCENARIOS), final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-s", "s2=" + Paths.get(Simple.OTHER_SCENARIOS),
"-r", Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() }; "-r", Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args); CommandLineApplication.mainProgram(args);
@ -263,7 +263,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void loadMultipleScenariosMissingRepository() { void loadMultipleScenariosMissingRepository() {
final Path p = Paths.get(Simple.REPOSITORY_URI); final Path p = Paths.get(Simple.REPOSITORY_URI);
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-s", "s2=" + Paths.get(Simple.OTHER_SCENARIOS), final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-s", "s2=" + Paths.get(Simple.OTHER_SCENARIOS),
"-r", "s1=" + p, "-r", "typo=" + p, Paths.get(Simple.SIMPLE_VALID).toString() }; "-r", "s1=" + p, "-r", "typo=" + p, Paths.get(Simple.SIMPLE_VALID).toString() };
@ -272,7 +272,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void loadMultipleOrderedScenarios() { void loadMultipleOrderedScenarios() {
final String s = Paths.get(Simple.REPOSITORY_URI).toString(); final String s = Paths.get(Simple.REPOSITORY_URI).toString();
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-s", final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-s",
Paths.get(Simple.OTHER_SCENARIOS).toString(), "-r", s, "-r", s, Paths.get(Simple.SIMPLE_VALID).toString() }; Paths.get(Simple.OTHER_SCENARIOS).toString(), "-r", s, "-r", s, Paths.get(Simple.SIMPLE_VALID).toString() };
@ -281,7 +281,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void checkUnusedRepository() { void checkUnusedRepository() {
final Path p = Paths.get(Simple.REPOSITORY_URI); final Path p = Paths.get(Simple.REPOSITORY_URI);
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-r", "s1=" + p, "-r", "unused=" + p, final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-r", "s1=" + p, "-r", "unused=" + p,
Paths.get(Simple.SIMPLE_VALID).toString() }; Paths.get(Simple.SIMPLE_VALID).toString() };
@ -291,7 +291,7 @@ public class CommandlineApplicationTest {
} }
@Test @Test
public void checkDuplicationScenarioDefinition() { void checkDuplicationScenarioDefinition() {
final Path p = Paths.get(Simple.REPOSITORY_URI); final Path p = Paths.get(Simple.REPOSITORY_URI);
final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-r", "s1=" + p, "-r", "unused=" + p, final String[] args = new String[] { "-s", "s1=" + Paths.get(Simple.SCENARIOS), "-r", "s1=" + p, "-r", "unused=" + p,
Paths.get(Simple.SIMPLE_VALID).toString() }; Paths.get(Simple.SIMPLE_VALID).toString() };

View file

@ -16,19 +16,20 @@
package de.kosit.validationtool.cmd; package de.kosit.validationtool.cmd;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Tests {@link DefaultNamingStrategy} * Tests {@link DefaultNamingStrategy}
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class DefaultNamingStrategyTest { class DefaultNamingStrategyTest {
@Test @Test
public void testSimple() { void simple() {
final DefaultNamingStrategy strategy = new DefaultNamingStrategy(); final DefaultNamingStrategy strategy = new DefaultNamingStrategy();
assertThat(strategy.createName("test")).isEqualTo("test-report.xml"); assertThat(strategy.createName("test")).isEqualTo("test-report.xml");
strategy.setPrefix("prefix"); strategy.setPrefix("prefix");
@ -40,7 +41,7 @@ public class DefaultNamingStrategyTest {
} }
@Test @Test
public void testDotted() { void dotted() {
final DefaultNamingStrategy strategy = new DefaultNamingStrategy(); final DefaultNamingStrategy strategy = new DefaultNamingStrategy();
assertThat(strategy.createName("test.xml")).isEqualTo("test-report.xml"); assertThat(strategy.createName("test.xml")).isEqualTo("test-report.xml");
strategy.setPrefix("prefix"); strategy.setPrefix("prefix");
@ -52,7 +53,7 @@ public class DefaultNamingStrategyTest {
} }
@Test @Test
public void testDoubleDotted() { void doubleDotted() {
final DefaultNamingStrategy strategy = new DefaultNamingStrategy(); final DefaultNamingStrategy strategy = new DefaultNamingStrategy();
assertThat(strategy.createName("test.second.xml")).isEqualTo("test.second-report.xml"); assertThat(strategy.createName("test.second.xml")).isEqualTo("test.second-report.xml");
strategy.setPrefix("prefix"); strategy.setPrefix("prefix");
@ -64,7 +65,7 @@ public class DefaultNamingStrategyTest {
} }
@Test @Test
public void testUnknownExtension() { void unknownExtension() {
final DefaultNamingStrategy strategy = new DefaultNamingStrategy(); final DefaultNamingStrategy strategy = new DefaultNamingStrategy();
assertThat(strategy.createName("test.ext")).isEqualTo("test.ext-report.xml"); assertThat(strategy.createName("test.ext")).isEqualTo("test.ext-report.xml");
strategy.setPrefix("prefix"); strategy.setPrefix("prefix");
@ -75,8 +76,8 @@ public class DefaultNamingStrategyTest {
assertThat(strategy.createName("test.ext")).isEqualTo("test.ext-postfix.xml"); assertThat(strategy.createName("test.ext")).isEqualTo("test.ext-postfix.xml");
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testEmptyInput() { void emptyInput() {
new DefaultNamingStrategy().createName(null); assertThrows(IllegalArgumentException.class, () -> new DefaultNamingStrategy().createName(null));
} }
} }

View file

@ -22,9 +22,9 @@ import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.TestObjectFactory; import de.kosit.validationtool.impl.TestObjectFactory;
import de.kosit.validationtool.impl.tasks.CheckAction; import de.kosit.validationtool.impl.tasks.CheckAction;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@ -39,25 +39,25 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class ExtractHtmlActionTest { class ExtractHtmlActionTest {
private ExtractHtmlContentAction action; private ExtractHtmlContentAction action;
private Path tmpDirectory; private Path tmpDirectory;
@Before @BeforeEach
public void setup() throws IOException { void setup() throws IOException {
this.tmpDirectory = Files.createTempDirectory("checktool"); this.tmpDirectory = Files.createTempDirectory("checktool");
this.action = new ExtractHtmlContentAction(TestObjectFactory.createProcessor(), this.tmpDirectory); this.action = new ExtractHtmlContentAction(TestObjectFactory.createProcessor(), this.tmpDirectory);
} }
@After @AfterEach
public void tearDown() throws IOException { void tearDown() throws IOException {
FileUtils.deleteDirectory(this.tmpDirectory.toFile()); FileUtils.deleteDirectory(this.tmpDirectory.toFile());
} }
@Test @Test
public void testSimple() throws IOException { void simple() throws IOException {
final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(Simple.SIMPLE_VALID)); final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(Simple.SIMPLE_VALID));
assertThat(this.action.isSkipped(b)).isTrue(); assertThat(this.action.isSkipped(b)).isTrue();
b.setReport(Helper.load(Simple.SIMPLE_VALID.toURL())); b.setReport(Helper.load(Simple.SIMPLE_VALID.toURL()));

View file

@ -21,9 +21,9 @@ import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.TestObjectFactory; import de.kosit.validationtool.impl.TestObjectFactory;
import de.kosit.validationtool.impl.tasks.CheckAction; import de.kosit.validationtool.impl.tasks.CheckAction;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -32,23 +32,23 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Andreas Penski * @author Andreas Penski
*/ */
public class PrintReportActionTest { class PrintReportActionTest {
private PrintReportAction action; private PrintReportAction action;
@Before @BeforeEach
public void setup() { void setup() {
CommandLine.activate(); CommandLine.activate();
this.action = new PrintReportAction(TestObjectFactory.createProcessor()); this.action = new PrintReportAction(TestObjectFactory.createProcessor());
} }
@After @AfterEach
public void tearDown() { void tearDown() {
CommandLine.deactivate(); CommandLine.deactivate();
} }
@Test @Test
public void testSimpleSerialize() throws MalformedURLException { void simpleSerialize() throws MalformedURLException {
final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(Simple.SIMPLE_VALID)); final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(Simple.SIMPLE_VALID));
b.setReport(Helper.load(Simple.SIMPLE_VALID.toURL())); b.setReport(Helper.load(Simple.SIMPLE_VALID.toURL()));
assertThat(this.action.isSkipped(b)).isFalse(); assertThat(this.action.isSkipped(b)).isFalse();

View file

@ -22,9 +22,9 @@ import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.TestObjectFactory; import de.kosit.validationtool.impl.TestObjectFactory;
import de.kosit.validationtool.impl.tasks.CheckAction; import de.kosit.validationtool.impl.tasks.CheckAction;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -36,26 +36,26 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Andreas Penski * @author Andreas Penski
*/ */
public class SerializeReportActionTest { class SerializeReportActionTest {
private Path tmpDirectory; private Path tmpDirectory;
private SerializeReportAction action; private SerializeReportAction action;
@Before @BeforeEach
public void setup() throws IOException { void setup() throws IOException {
this.tmpDirectory = Files.createTempDirectory("checktool"); this.tmpDirectory = Files.createTempDirectory("checktool");
final DefaultNamingStrategy namingStrategy = new DefaultNamingStrategy(); final DefaultNamingStrategy namingStrategy = new DefaultNamingStrategy();
this.action = new SerializeReportAction(this.tmpDirectory, TestObjectFactory.createProcessor(), namingStrategy); this.action = new SerializeReportAction(this.tmpDirectory, TestObjectFactory.createProcessor(), namingStrategy);
} }
@After @AfterEach
public void tearDown() throws IOException { void tearDown() throws IOException {
FileUtils.deleteDirectory(this.tmpDirectory.toFile()); FileUtils.deleteDirectory(this.tmpDirectory.toFile());
} }
@Test @Test
public void testSimpleSerialize() throws MalformedURLException { void simpleSerialize() throws MalformedURLException {
final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(Simple.SIMPLE_VALID)); final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(Simple.SIMPLE_VALID));
assertThat(this.action.isSkipped(b)).isTrue(); assertThat(this.action.isSkipped(b)).isTrue();
b.setReport(Helper.load(Simple.SIMPLE_VALID.toURL())); b.setReport(Helper.load(Simple.SIMPLE_VALID.toURL()));
@ -67,7 +67,7 @@ public class SerializeReportActionTest {
// ERPT-83 // ERPT-83
@Test @Test
public void testName() { void name() {
final String name = "some.name.with.dots"; final String name = "some.name.with.dots";
final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read("ega".getBytes(), name + ".xml")); final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read("ega".getBytes(), name + ".xml"));
assertThat(b.getName()).isEqualTo(name); assertThat(b.getName()).isEqualTo(name);

View file

@ -20,9 +20,9 @@ import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.impl.ConversionService; import de.kosit.validationtool.impl.ConversionService;
import de.kosit.validationtool.impl.tasks.CheckAction; import de.kosit.validationtool.impl.tasks.CheckAction;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@ -33,25 +33,25 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Andreas Penski * @author Andreas Penski
*/ */
public class SerializeReportInputActionTest { class SerializeReportInputActionTest {
private Path tmpDirectory; private Path tmpDirectory;
private SerializeReportInputAction action; private SerializeReportInputAction action;
@Before @BeforeEach
public void setup() throws IOException { void setup() throws IOException {
this.tmpDirectory = Files.createTempDirectory("validator"); this.tmpDirectory = Files.createTempDirectory("validator");
this.action = new SerializeReportInputAction(this.tmpDirectory, new ConversionService()); this.action = new SerializeReportInputAction(this.tmpDirectory, new ConversionService());
} }
@After @AfterEach
public void tearDown() throws IOException { void tearDown() throws IOException {
FileUtils.deleteDirectory(this.tmpDirectory.toFile()); FileUtils.deleteDirectory(this.tmpDirectory.toFile());
} }
@Test @Test
public void testSimpleSerialize() { void simpleSerialize() {
final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read("someBytes".getBytes(), "someDoc")); final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read("someBytes".getBytes(), "someDoc"));
assertThat(this.action.isSkipped(b)).isFalse(); assertThat(this.action.isSkipped(b)).isFalse();
this.action.check(b); this.action.check(b);

View file

@ -20,15 +20,14 @@ import static de.kosit.validationtool.config.ConfigurationBuilder.report;
import static de.kosit.validationtool.config.ConfigurationBuilder.schematron; import static de.kosit.validationtool.config.ConfigurationBuilder.schematron;
import static de.kosit.validationtool.config.TestConfigurationFactory.createSimpleConfiguration; import static de.kosit.validationtool.config.TestConfigurationFactory.createSimpleConfiguration;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.URI; import java.net.URI;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Date; import java.util.Date;
import org.junit.Test;
import de.kosit.validationtool.impl.Helper; import de.kosit.validationtool.impl.Helper;
import org.junit.jupiter.api.Test;
/** /**
* Test {@link ConfigurationBuilder}. * Test {@link ConfigurationBuilder}.
@ -40,12 +39,12 @@ public class ConfigurationBuilderTest {
public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1); public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
@Test @Test
public void testNoConfiguration() { void noConfiguration() {
assertThrows(IllegalStateException.class, () -> new ConfigurationBuilder().build(Helper.getTestProcessor())); assertThrows(IllegalStateException.class, () -> new ConfigurationBuilder().build(Helper.getTestProcessor()));
} }
@Test @Test
public void testNoFallback() { void noFallback() {
final ConfigurationBuilder builder = createSimpleConfiguration(); final ConfigurationBuilder builder = createSimpleConfiguration();
builder.with((FallbackBuilder) null); builder.with((FallbackBuilder) null);
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor())); Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
@ -53,7 +52,7 @@ public class ConfigurationBuilderTest {
} }
@Test @Test
public void testNoSchema() { void noSchema() {
final ConfigurationBuilder builder = createSimpleConfiguration(); final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate((SchemaBuilder) null); builder.getScenarios().get(0).validate((SchemaBuilder) null);
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor())); Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
@ -61,7 +60,7 @@ public class ConfigurationBuilderTest {
} }
@Test @Test
public void testInvalidSchematron() { void invalidSchematron() {
final ConfigurationBuilder builder = createSimpleConfiguration(); final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid").source(URI.create("DoesNotExist"))); builder.getScenarios().get(0).validate(schematron("invalid").source(URI.create("DoesNotExist")));
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor())); Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
@ -69,7 +68,7 @@ public class ConfigurationBuilderTest {
} }
@Test @Test
public void testInsufficientSchematron() { void insufficientSchematron() {
final ConfigurationBuilder builder = createSimpleConfiguration(); final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid")); builder.getScenarios().get(0).validate(schematron("invalid"));
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor())); Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
@ -77,7 +76,7 @@ public class ConfigurationBuilderTest {
} }
@Test @Test
public void testNoReport() { void noReport() {
final ConfigurationBuilder builder = createSimpleConfiguration(); final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).with(report("invalid")); builder.getScenarios().get(0).with(report("invalid"));
Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor())); Throwable e = assertThrows(IllegalStateException.class, () -> builder.build(Helper.getTestProcessor()));
@ -85,7 +84,7 @@ public class ConfigurationBuilderTest {
} }
@Test @Test
public void testDate() { void date() {
assertThat(createSimpleConfiguration().date(EPOCH).build(Helper.getTestProcessor()).getDate()).isEqualTo("1970-01-01"); assertThat(createSimpleConfiguration().date(EPOCH).build(Helper.getTestProcessor()).getDate()).isEqualTo("1970-01-01");
assertThat(createSimpleConfiguration().date(new Date(EPOCH.toEpochDay())).build(Helper.getTestProcessor()).getDate()) assertThat(createSimpleConfiguration().date(new Date(EPOCH.toEpochDay())).build(Helper.getTestProcessor()).getDate())
.isEqualTo("1970-01-01"); .isEqualTo("1970-01-01");

View file

@ -18,21 +18,20 @@ package de.kosit.validationtool.config;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import de.kosit.validationtool.api.Configuration; import de.kosit.validationtool.api.Configuration;
import de.kosit.validationtool.impl.Helper; import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.ResolvingMode; import de.kosit.validationtool.impl.ResolvingMode;
import de.kosit.validationtool.impl.xml.RemoteResolvingStrategy; import de.kosit.validationtool.impl.xml.RemoteResolvingStrategy;
import de.kosit.validationtool.impl.xml.StrictRelativeResolvingStrategy; import de.kosit.validationtool.impl.xml.StrictRelativeResolvingStrategy;
import org.junit.jupiter.api.Test;
/** /**
* @author Andreas Penski * @author Andreas Penski
*/ */
public class ConfigurationLoaderTest { class ConfigurationLoaderTest {
@Test @Test
public void testCustomResolvingStrategy() { void customResolvingStrategy() {
final ConfigurationLoader loader = TestConfigurationFactory.loadSimpleConfiguration(); final ConfigurationLoader loader = TestConfigurationFactory.loadSimpleConfiguration();
loader.setResolvingStrategy(new StrictRelativeResolvingStrategy()); loader.setResolvingStrategy(new StrictRelativeResolvingStrategy());
loader.setResolvingMode(ResolvingMode.ALLOW_REMOTE); loader.setResolvingMode(ResolvingMode.ALLOW_REMOTE);

View file

@ -24,8 +24,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.text.RandomStringGenerator; import org.apache.commons.text.RandomStringGenerator;
import org.junit.Test; import org.junit.jupiter.api.Test;
import de.kosit.validationtool.impl.ContentRepository; import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.Scenario; import de.kosit.validationtool.impl.Scenario;
@ -40,17 +39,17 @@ import net.sf.saxon.s9api.XPathExecutable;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class ScenarioBuilderTest { class ScenarioBuilderTest {
@Test @Test
public void simpleValid() { void simpleValid() {
final Result<Scenario, String> result = createScenario().build(Simple.createContentRepository()); final Result<Scenario, String> result = createScenario().build(Simple.createContentRepository());
assertThat(result.isValid()).isTrue(); assertThat(result.isValid()).isTrue();
assertThat(result.getObject().getConfiguration()).isNotNull(); assertThat(result.getObject().getConfiguration()).isNotNull();
} }
@Test @Test
public void testNoSchema() { void noSchema() {
final ScenarioBuilder builder = createScenario(); final ScenarioBuilder builder = createScenario();
builder.validate((SchemaBuilder) null); builder.validate((SchemaBuilder) null);
final Result<Scenario, String> result = builder.build(Simple.createContentRepository()); final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
@ -59,7 +58,7 @@ public class ScenarioBuilderTest {
} }
@Test @Test
public void testNoMatch() { void noMatch() {
final ScenarioBuilder builder = createScenario(); final ScenarioBuilder builder = createScenario();
builder.match((String) null); builder.match((String) null);
final Result<Scenario, String> result = builder.build(Simple.createContentRepository()); final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
@ -68,7 +67,7 @@ public class ScenarioBuilderTest {
} }
@Test @Test
public void testInvalidMatch() { void invalidMatch() {
final ScenarioBuilder builder = createScenario(); final ScenarioBuilder builder = createScenario();
builder.match("/////"); builder.match("/////");
final Result<Scenario, String> result = builder.build(Simple.createContentRepository()); final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
@ -77,7 +76,7 @@ public class ScenarioBuilderTest {
} }
@Test @Test
public void testNoAccept() { void noAccept() {
final ScenarioBuilder builder = createScenario(); final ScenarioBuilder builder = createScenario();
builder.acceptWith((String) null); builder.acceptWith((String) null);
final Result<Scenario, String> result = builder.build(Simple.createContentRepository()); final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
@ -85,7 +84,7 @@ public class ScenarioBuilderTest {
} }
@Test @Test
public void testInvalidAccept() { void invalidAccept() {
final ScenarioBuilder builder = createScenario(); final ScenarioBuilder builder = createScenario();
builder.acceptWith("/////"); builder.acceptWith("/////");
final Result<Scenario, String> result = builder.build(Simple.createContentRepository()); final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
@ -94,7 +93,7 @@ public class ScenarioBuilderTest {
} }
@Test @Test
public void testCombinedNamespaces() { void combinedNamespaces() {
final ContentRepository repository = Simple.createContentRepository(); final ContentRepository repository = Simple.createContentRepository();
final Map<String, String> ns1 = new HashMap<>(); final Map<String, String> ns1 = new HashMap<>();
ns1.put("n1", "http://n1.org"); ns1.put("n1", "http://n1.org");
@ -118,7 +117,7 @@ public class ScenarioBuilderTest {
} }
@Test @Test
public void testConfigureWithExecutable() { void configureWithExecutable() {
final ContentRepository repository = Simple.createContentRepository(); final ContentRepository repository = Simple.createContentRepository();
final XPathExecutable match = repository.createXPath("//*", null); final XPathExecutable match = repository.createXPath("//*", null);
final XPathExecutable accept = repository.createXPath("//*", null); final XPathExecutable accept = repository.createXPath("//*", null);
@ -136,7 +135,7 @@ public class ScenarioBuilderTest {
} }
@Test @Test
public void testBasicAttributes() { void basicAttributes() {
final ContentRepository repository = Simple.createContentRepository(); final ContentRepository repository = Simple.createContentRepository();
final String random = getRandomString(5); final String random = getRandomString(5);
final ScenarioBuilder builder = createScenario(); final ScenarioBuilder builder = createScenario();
@ -150,7 +149,7 @@ public class ScenarioBuilderTest {
} }
@Test @Test
public void testNoBasicAttributes() { void noBasicAttributes() {
final ContentRepository repository = Simple.createContentRepository(); final ContentRepository repository = Simple.createContentRepository();
final ScenarioBuilder builder = createScenario(); final ScenarioBuilder builder = createScenario();
builder.name(null); builder.name(null);

View file

@ -24,8 +24,7 @@ import java.nio.file.Paths;
import javax.xml.validation.Schema; import javax.xml.validation.Schema;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.junit.Test; import org.junit.jupiter.api.Test;
import de.kosit.validationtool.impl.ContentRepository; import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.model.Result; import de.kosit.validationtool.impl.model.Result;
@ -37,10 +36,10 @@ import de.kosit.validationtool.model.scenarios.ValidateWithXmlSchema;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class SchemaBuilderTest { class SchemaBuilderTest {
@Test @Test
public void testBuildSchema() { void buildSchema() {
final SchemaBuilder builder = schema(Simple.SCHEMA); final SchemaBuilder builder = schema(Simple.SCHEMA);
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository()); final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull(); assertThat(result).isNotNull();
@ -48,7 +47,7 @@ public class SchemaBuilderTest {
} }
@Test @Test
public void testNoConfiguration() { void noConfiguration() {
final SchemaBuilder builder = schema("no-config"); final SchemaBuilder builder = schema("no-config");
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository()); final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull(); assertThat(result).isNotNull();
@ -56,7 +55,7 @@ public class SchemaBuilderTest {
} }
@Test @Test
public void testBuildNamedSchema() { void buildNamedSchema() {
final SchemaBuilder builder = schema("myname").schemaLocation(Simple.SCHEMA); final SchemaBuilder builder = schema("myname").schemaLocation(Simple.SCHEMA);
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository()); final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull(); assertThat(result).isNotNull();
@ -66,7 +65,7 @@ public class SchemaBuilderTest {
} }
@Test @Test
public void testInvalidSchema() { void invalidSchema() {
final SchemaBuilder builder = schema("myname").schemaLocation(Simple.SCHEMA_INVALID); final SchemaBuilder builder = schema("myname").schemaLocation(Simple.SCHEMA_INVALID);
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository()); final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull(); assertThat(result).isNotNull();
@ -74,7 +73,7 @@ public class SchemaBuilderTest {
} }
@Test @Test
public void testNonExisting() { void nonExisting() {
final SchemaBuilder builder = schema("myname").schemaLocation(Simple.REPOSITORY_URI.resolve("doesNotExist.xsd")); final SchemaBuilder builder = schema("myname").schemaLocation(Simple.REPOSITORY_URI.resolve("doesNotExist.xsd"));
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository()); final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull(); assertThat(result).isNotNull();
@ -82,7 +81,7 @@ public class SchemaBuilderTest {
} }
@Test @Test
public void testPath() { void path() {
final SchemaBuilder builder = schema("myname").schemaLocation(Paths.get(Simple.SCHEMA)); final SchemaBuilder builder = schema("myname").schemaLocation(Paths.get(Simple.SCHEMA));
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository()); final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull(); assertThat(result).isNotNull();
@ -90,7 +89,7 @@ public class SchemaBuilderTest {
} }
@Test @Test
public void testStringLocation() { void stringLocation() {
final SchemaBuilder builder = schema("myname").schemaLocation("simple.xsd"); final SchemaBuilder builder = schema("myname").schemaLocation("simple.xsd");
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository()); final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull(); assertThat(result).isNotNull();
@ -98,7 +97,7 @@ public class SchemaBuilderTest {
} }
@Test @Test
public void testPrecompiled() { void precompiled() {
final ContentRepository repository = Simple.createContentRepository(); final ContentRepository repository = Simple.createContentRepository();
final Schema schema = repository.createSchema(Simple.SCHEMA); final Schema schema = repository.createSchema(Simple.SCHEMA);

View file

@ -19,25 +19,24 @@ package de.kosit.validationtool.config;
import static de.kosit.validationtool.config.TestConfigurationFactory.createSimpleConfiguration; import static de.kosit.validationtool.config.TestConfigurationFactory.createSimpleConfiguration;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import de.kosit.validationtool.api.Configuration; import de.kosit.validationtool.api.Configuration;
import de.kosit.validationtool.api.InputFactory; import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.api.Result; import de.kosit.validationtool.api.Result;
import de.kosit.validationtool.impl.DefaultCheck; import de.kosit.validationtool.impl.DefaultCheck;
import de.kosit.validationtool.impl.Helper; import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import org.junit.jupiter.api.Test;
/** /**
* @author Andreas Penski * @author Andreas Penski
*/ */
public class SimpleConfigTest { class SimpleConfigTest {
@Test @Test
public void testSimpleWithApi() { void simpleWithApi() {
//@formatter:off // @formatter:off
final Configuration config = createSimpleConfiguration().build(Helper.getTestProcessor()); final Configuration config = createSimpleConfiguration().build(Helper.getTestProcessor());
//@formatter:on // @formatter:on
final DefaultCheck check = new DefaultCheck(config); final DefaultCheck check = new DefaultCheck(config);
final Result result = check.checkInput(InputFactory.read(Simple.SIMPLE_VALID)); final Result result = check.checkInput(InputFactory.read(Simple.SIMPLE_VALID));
assertThat(result).isNotNull(); assertThat(result).isNotNull();

View file

@ -51,4 +51,7 @@ public class TestConfigurationFactory {
.declareNamespace("rpt", "http://validator.kosit.de/test-report") .declareNamespace("rpt", "http://validator.kosit.de/test-report")
.declareNamespace("test", "http://validator.kosit.de/test-sample").match("/test:simple"); .declareNamespace("test", "http://validator.kosit.de/test-sample").match("/test:simple");
} }
private TestConfigurationFactory() {
}
} }

View file

@ -23,8 +23,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.commons.text.RandomStringGenerator; import org.apache.commons.text.RandomStringGenerator;
import org.junit.Test; import org.junit.jupiter.api.Test;
import de.kosit.validationtool.impl.ContentRepository; import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.model.Result; import de.kosit.validationtool.impl.model.Result;
@ -36,10 +35,10 @@ import net.sf.saxon.s9api.XPathExecutable;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class XPathBuilderTest { class XPathBuilderTest {
@Test @Test
public void testSimpleString() { void simpleString() {
final String name = getRandomString(5); final String name = getRandomString(5);
final XPathBuilder b = new XPathBuilder(name); final XPathBuilder b = new XPathBuilder(name);
b.setXpath("//*"); b.setXpath("//*");
@ -53,7 +52,7 @@ public class XPathBuilderTest {
} }
@Test @Test
public void testStringWithNamespace() { void stringWithNamespace() {
final String name = getRandomString(5); final String name = getRandomString(5);
final XPathBuilder b = new XPathBuilder(name); final XPathBuilder b = new XPathBuilder(name);
final Map<String, String> ns = new HashMap<>(); final Map<String, String> ns = new HashMap<>();
@ -68,7 +67,7 @@ public class XPathBuilderTest {
} }
@Test @Test
public void testStringWithUnknownNamespace() { void stringWithUnknownNamespace() {
final String name = getRandomString(5); final String name = getRandomString(5);
final XPathBuilder b = new XPathBuilder(name); final XPathBuilder b = new XPathBuilder(name);
final Map<String, String> ns = new HashMap<>(); final Map<String, String> ns = new HashMap<>();
@ -81,7 +80,7 @@ public class XPathBuilderTest {
} }
@Test @Test
public void testExecutable() { void executable() {
final String name = getRandomString(5); final String name = getRandomString(5);
final ContentRepository repository = Simple.createContentRepository(); final ContentRepository repository = Simple.createContentRepository();
final XPathExecutable xpath = repository.createXPath("//*", Collections.emptyMap()); final XPathExecutable xpath = repository.createXPath("//*", Collections.emptyMap());
@ -95,7 +94,7 @@ public class XPathBuilderTest {
} }
@Test @Test
public void testExecutableWithNamespace() { void executableWithNamespace() {
final String name = getRandomString(5); final String name = getRandomString(5);
final ContentRepository repository = Simple.createContentRepository(); final ContentRepository repository = Simple.createContentRepository();
final Map<String, String> ns = new HashMap<>(); final Map<String, String> ns = new HashMap<>();
@ -112,7 +111,7 @@ public class XPathBuilderTest {
} }
@Test @Test
public void testNoName() { void noName() {
final XPathBuilder b = new XPathBuilder(null); final XPathBuilder b = new XPathBuilder(null);
b.setXpath("//*"); b.setXpath("//*");
final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository()); final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository());
@ -122,7 +121,7 @@ public class XPathBuilderTest {
} }
@Test @Test
public void testNoConfig() { void noConfig() {
final String name = getRandomString(5); final String name = getRandomString(5);
final XPathBuilder b = new XPathBuilder(name); final XPathBuilder b = new XPathBuilder(name);
final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository()); final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository());

View file

@ -16,9 +16,8 @@
package de.kosit.validationtool.daemon; package de.kosit.validationtool.daemon;
import org.junit.Before;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import org.junit.jupiter.api.BeforeEach;
/** /**
* Base for integration tests. * Base for integration tests.
@ -27,7 +26,7 @@ import io.restassured.RestAssured;
*/ */
public abstract class BaseIT { public abstract class BaseIT {
@Before @BeforeEach
public void setup() { public void setup() {
final String port = System.getProperty("daemon.port"); final String port = System.getProperty("daemon.port");
if (port != null) { if (port != null) {

View file

@ -25,8 +25,7 @@ import java.io.InputStream;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.junit.Test; import org.junit.jupiter.api.Test;
import de.kosit.validationtool.impl.Helper; import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
@ -40,24 +39,24 @@ import io.restassured.specification.MultiPartSpecification;
* @author Roula Antoun * @author Roula Antoun
* @author Andreas Penski * @author Andreas Penski
*/ */
public class CheckHandlerIT extends BaseIT { class CheckHandlerIT extends BaseIT {
private static final String APPLICATION_XML = "application/xml"; private static final String APPLICATION_XML = "application/xml";
@Test @Test
public void simpleTest() throws IOException { void simpleTest() throws IOException {
try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) { try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) {
given().contentType(ContentType.XML).body(toContent(io)).when().post("/").then().statusCode(SC_OK); given().contentType(ContentType.XML).body(toContent(io)).when().post("/").then().statusCode(SC_OK);
} }
} }
@Test @Test
public void noInputTest() { void noInputTest() {
given().body("").contentType(APPLICATION_XML).when().post("/").then().statusCode(HttpStatus.SC_BAD_REQUEST); given().body("").contentType(APPLICATION_XML).when().post("/").then().statusCode(HttpStatus.SC_BAD_REQUEST);
} }
@Test @Test
public void testUnknown() throws IOException { void unknown() throws IOException {
try ( final InputStream io = Simple.UNKNOWN.toURL().openStream() ) { try ( final InputStream io = Simple.UNKNOWN.toURL().openStream() ) {
given().contentType(APPLICATION_XML).body(toContent(io)).when().post("/").then().statusCode(SC_NOT_ACCEPTABLE); given().contentType(APPLICATION_XML).body(toContent(io)).when().post("/").then().statusCode(SC_NOT_ACCEPTABLE);
} }
@ -68,14 +67,14 @@ public class CheckHandlerIT extends BaseIT {
} }
@Test @Test
public void xmlResultTest() throws IOException { void xmlResultTest() throws IOException {
try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) { try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) {
given().body(toContent(io)).when().post("/").then().contentType(APPLICATION_XML).and().statusCode(SC_OK); given().body(toContent(io)).when().post("/").then().contentType(APPLICATION_XML).and().statusCode(SC_OK);
} }
} }
@Test @Test
public void testMultipart() throws IOException { void multipart() throws IOException {
try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) { try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) {
final MultiPartSpecification spec = new MultiPartSpecBuilder(io).fileName("file").controlName("file").build(); final MultiPartSpecification spec = new MultiPartSpecBuilder(io).fileName("file").controlName("file").build();
given().multiPart(spec).when().post("/").then().statusCode(HttpStatus.SC_BAD_REQUEST); given().multiPart(spec).when().post("/").then().statusCode(HttpStatus.SC_BAD_REQUEST);
@ -83,7 +82,7 @@ public class CheckHandlerIT extends BaseIT {
} }
@Test @Test
public void testLarge() throws IOException { void large() throws IOException {
try ( final InputStream io = Helper.LARGE_XML.toURL().openStream() ) { try ( final InputStream io = Helper.LARGE_XML.toURL().openStream() ) {
given().contentType(APPLICATION_XML).body(toContent(io)).when().post("/").then().statusCode(SC_NOT_ACCEPTABLE); given().contentType(APPLICATION_XML).body(toContent(io)).when().post("/").then().statusCode(SC_NOT_ACCEPTABLE);
} }

View file

@ -18,19 +18,18 @@ package de.kosit.validationtool.daemon;
import static io.restassured.RestAssured.given; import static io.restassured.RestAssured.given;
import org.junit.Test;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
/** /**
* Integration test for the {@link ConfigHandler}. * Integration test for the {@link ConfigHandler}.
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class ConfigHandlerIT extends BaseIT { class ConfigHandlerIT extends BaseIT {
@Test @Test
public void checkHealth() { void checkHealth() {
given().when().get("/server/config").then().statusCode(200).and().contentType(ContentType.XML); given().when().get("/server/config").then().statusCode(200).and().contentType(ContentType.XML);
} }
} }

View file

@ -29,8 +29,7 @@ import static org.mockito.Mockito.when;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Collections; import java.util.Collections;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import com.sun.net.httpserver.Headers; import com.sun.net.httpserver.Headers;
@ -44,10 +43,10 @@ import de.kosit.validationtool.impl.Helper;
/** /**
* @author Andreas Penski * @author Andreas Penski
*/ */
public class ConfigHandlerTest { class ConfigHandlerTest {
@Test @Test
public void testApiConfiguration() throws IOException { void apiConfiguration() throws IOException {
final HttpExchange exchange = mock(HttpExchange.class); final HttpExchange exchange = mock(HttpExchange.class);
final Headers headers = mock(Headers.class); final Headers headers = mock(Headers.class);
final OutputStream stream = mock(OutputStream.class); final OutputStream stream = mock(OutputStream.class);
@ -61,7 +60,7 @@ public class ConfigHandlerTest {
} }
@Test @Test
public void testError() throws IOException { void error() throws IOException {
final HttpExchange exchange = mock(HttpExchange.class); final HttpExchange exchange = mock(HttpExchange.class);
final Headers headers = mock(Headers.class); final Headers headers = mock(Headers.class);
final OutputStream stream = mock(OutputStream.class); final OutputStream stream = mock(OutputStream.class);

View file

@ -18,14 +18,13 @@ package de.kosit.validationtool.daemon;
import static io.restassured.RestAssured.given; import static io.restassured.RestAssured.given;
import org.junit.Test;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
public class GuiHandlerIT extends BaseIT { class GuiHandlerIT extends BaseIT {
@Test @Test
public void checkGui() { void checkGui() {
given().when().get("/").then().statusCode(200).and().contentType(ContentType.HTML); given().when().get("/").then().statusCode(200).and().contentType(ContentType.HTML);
given().when().get("/index.html").then().statusCode(200).and().contentType("text/html"); given().when().get("/index.html").then().statusCode(200).and().contentType("text/html");
given().when().get("/unknown.md").then().statusCode(404).and().contentType(ContentType.TEXT); given().when().get("/unknown.md").then().statusCode(404).and().contentType(ContentType.TEXT);

View file

@ -18,19 +18,18 @@ package de.kosit.validationtool.daemon;
import static io.restassured.RestAssured.given; import static io.restassured.RestAssured.given;
import org.junit.Test;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
/** /**
* Checks the health endpoint. * Checks the health endpoint.
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class HealthHandlerIT extends BaseIT { class HealthHandlerIT extends BaseIT {
@Test @Test
public void checkHealth() { void checkHealth() {
given().when().get("/server/health").then().statusCode(200).and().contentType(ContentType.XML); given().when().get("/server/health").then().statusCode(200).and().contentType(ContentType.XML);
} }
} }

View file

@ -17,7 +17,7 @@
package de.kosit.validationtool.impl; package de.kosit.validationtool.impl;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
@ -28,9 +28,8 @@ import java.util.Map;
import javax.xml.validation.Schema; import javax.xml.validation.Schema;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import net.sf.saxon.s9api.XPathExecutable; import net.sf.saxon.s9api.XPathExecutable;
@ -41,39 +40,39 @@ import net.sf.saxon.s9api.XsltExecutable;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class ContentRepositoryTest { class ContentRepositoryTest {
private ContentRepository repository; private ContentRepository repository;
@Before @BeforeEach
public void setup() { void setup() {
this.repository = Simple.createContentRepository(); this.repository = Simple.createContentRepository();
} }
@Test @Test
public void testCreateSchema() throws MalformedURLException { void createSchema() throws MalformedURLException {
final Schema schema = this.repository.createSchema(Helper.ASSERTION_SCHEMA.toURL()); final Schema schema = this.repository.createSchema(Helper.ASSERTION_SCHEMA.toURL());
assertThat(schema).isNotNull(); assertThat(schema).isNotNull();
} }
@Test @Test
public void testCreateSchemaNotExisting() { void createSchemaNotExisting() {
assertThrows(IllegalStateException.class, () -> this.repository.createSchema(Simple.NOT_EXISTING.toURL())); assertThrows(IllegalStateException.class, () -> this.repository.createSchema(Simple.NOT_EXISTING.toURL()));
} }
@Test @Test
public void testLoadXSLT() { void loadXSLT() {
final XsltExecutable executable = this.repository.loadXsltScript(Simple.REPORT_XSL); final XsltExecutable executable = this.repository.loadXsltScript(Simple.REPORT_XSL);
assertThat(executable).isNotNull(); assertThat(executable).isNotNull();
} }
@Test @Test
public void testLoadXSLTNotExisting() { void loadXSLTNotExisting() {
assertThrows(IllegalStateException.class, () -> this.repository.loadXsltScript(Simple.NOT_EXISTING)); assertThrows(IllegalStateException.class, () -> this.repository.loadXsltScript(Simple.NOT_EXISTING));
} }
@Test @Test
public void testXpathCreation() { void xpathCreation() {
XPathExecutable xPath = this.repository.createXPath("//html", null); XPathExecutable xPath = this.repository.createXPath("//html", null);
assertThat(xPath).isNotNull(); assertThat(xPath).isNotNull();
xPath = this.repository.createXPath("//html", Collections.emptyMap()); xPath = this.repository.createXPath("//html", Collections.emptyMap());
@ -85,17 +84,17 @@ public class ContentRepositoryTest {
} }
@Test @Test
public void testXpathCreationWithoutNamespace() { void xpathCreationWithoutNamespace() {
assertThrows(IllegalStateException.class, () -> this.repository.createXPath("//html:html", null)); assertThrows(IllegalStateException.class, () -> this.repository.createXPath("//html:html", null));
} }
@Test @Test
public void testIllegalXpath() { void illegalXpath() {
assertThrows(IllegalStateException.class, () -> this.repository.createXPath("kein Xpath Ausdruck", null)); assertThrows(IllegalStateException.class, () -> this.repository.createXPath("kein Xpath Ausdruck", null));
} }
@Test @Test
public void loadFromJar() throws URISyntaxException { void loadFromJar() throws URISyntaxException {
assert Helper.JAR_REPOSITORY != null; assert Helper.JAR_REPOSITORY != null;
this.repository = new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(), this.repository = new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(),
Helper.JAR_REPOSITORY.toURI()); Helper.JAR_REPOSITORY.toURI());

View file

@ -17,14 +17,13 @@
package de.kosit.validationtool.impl; package de.kosit.validationtool.impl;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.Serializable; import java.io.Serializable;
import java.net.URL; import java.net.URL;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import de.kosit.validationtool.impl.Helper.Invalid; import de.kosit.validationtool.impl.Helper.Invalid;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.model.scenarios.Scenarios; import de.kosit.validationtool.model.scenarios.Scenarios;
@ -34,7 +33,7 @@ import de.kosit.validationtool.model.scenarios.Scenarios;
* *
* @author apenski * @author apenski
*/ */
public class ConversionServiceTest { class ConversionServiceTest {
private static final URL SCHEMA = ConversionServiceTest.class.getResource("/xsd/scenarios.xsd"); private static final URL SCHEMA = ConversionServiceTest.class.getResource("/xsd/scenarios.xsd");
@ -42,19 +41,19 @@ public class ConversionServiceTest {
private ContentRepository repository; private ContentRepository repository;
@Before @BeforeEach
public void setup() { void setup() {
this.service = new ConversionService(); this.service = new ConversionService();
this.repository = Simple.createContentRepository(); this.repository = Simple.createContentRepository();
} }
@Test @Test
public void testMarshalNull() { void marshalNull() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.writeXml(null)); assertThrows(ConversionService.ConversionException.class, () -> this.service.writeXml(null));
} }
@Test @Test
public void testMarshalUnknown() { void marshalUnknown() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.writeXml(new Serializable() { assertThrows(ConversionService.ConversionException.class, () -> this.service.writeXml(new Serializable() {
private static final long serialVersionUID = 8745690876369610705L; private static final long serialVersionUID = 8745690876369610705L;
@ -62,43 +61,43 @@ public class ConversionServiceTest {
} }
@Test @Test
public void testUnmarshal() { void unmarshal() {
final Scenarios s = this.service.readXml(Simple.SCENARIOS, Scenarios.class); final Scenarios s = this.service.readXml(Simple.SCENARIOS, Scenarios.class);
assertThat(s).isNotNull(); assertThat(s).isNotNull();
assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite"); assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite");
} }
@Test @Test
public void testUnmarshalWithSchema() { void unmarshalWithSchema() {
final Scenarios s = this.service.readXml(Simple.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA)); final Scenarios s = this.service.readXml(Simple.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA));
assertThat(s).isNotNull(); assertThat(s).isNotNull();
assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite"); assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite");
} }
@Test @Test
public void testUnmarshalInvalidXml() { void unmarshalInvalidXml() {
assertThrows(ConversionService.ConversionException.class, assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(Invalid.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA))); () -> this.service.readXml(Invalid.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA)));
} }
@Test @Test
public void testUnmarshalIllFormed() { void unmarshalIllFormed() {
assertThrows(ConversionService.ConversionException.class, assertThrows(ConversionService.ConversionException.class,
() -> this.service.readXml(Invalid.SCENARIOS_ILL_FORMED, Scenarios.class, this.repository.createSchema(SCHEMA))); () -> this.service.readXml(Invalid.SCENARIOS_ILL_FORMED, Scenarios.class, this.repository.createSchema(SCHEMA)));
} }
@Test @Test
public void testUnmarshalEmpty() { void unmarshalEmpty() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(null, Scenarios.class)); assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(null, Scenarios.class));
} }
@Test @Test
public void testUnmarshalUnknownType() { void unmarshalUnknownType() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(Simple.SCENARIOS, ConversionService.class)); assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(Simple.SCENARIOS, ConversionService.class));
} }
@Test @Test
public void testUnmarshalWithoutType() { void unmarshalWithoutType() {
assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(Simple.SCENARIOS, null)); assertThrows(ConversionService.ConversionException.class, () -> this.service.readXml(Simple.SCENARIOS, null));
} }

View file

@ -23,8 +23,8 @@ import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.api.Result; import de.kosit.validationtool.api.Result;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import net.sf.saxon.s9api.XdmNode; import net.sf.saxon.s9api.XdmNode;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
@ -54,8 +54,8 @@ public class DefaultCheckTest {
private DefaultCheck jarScenarioCheck; private DefaultCheck jarScenarioCheck;
@Before @BeforeEach
public void setup() throws URISyntaxException { void setup() throws URISyntaxException {
final Configuration validConfig = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build(Helper.getTestProcessor()); final Configuration validConfig = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build(Helper.getTestProcessor());
this.validCheck = new DefaultCheck(validConfig); this.validCheck = new DefaultCheck(validConfig);
@ -72,7 +72,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testHappyCase() { void happyCase() {
final Result doc = this.validCheck.checkInput(read(SIMPLE_VALID)); final Result doc = this.validCheck.checkInput(read(SIMPLE_VALID));
assertThat(doc).isNotNull(); assertThat(doc).isNotNull();
assertThat(doc.getReport()).isNotNull(); assertThat(doc.getReport()).isNotNull();
@ -90,7 +90,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testJarCase() { void jarCase() {
final Result doc = this.jarScenarioCheck.checkInput(read(SIMPLE_VALID)); final Result doc = this.jarScenarioCheck.checkInput(read(SIMPLE_VALID));
assertThat(doc).isNotNull(); assertThat(doc).isNotNull();
assertThat(doc.getReport()).isNotNull(); assertThat(doc.getReport()).isNotNull();
@ -101,7 +101,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testWithoutAcceptMatch() { void withoutAcceptMatch() {
final Result doc = this.validCheck.checkInput(read(Simple.FOO)); final Result doc = this.validCheck.checkInput(read(Simple.FOO));
assertThat(doc).isNotNull(); assertThat(doc).isNotNull();
assertThat(doc.getReport()).isNotNull(); assertThat(doc.getReport()).isNotNull();
@ -110,27 +110,27 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testHappyCaseDocument() { void happyCaseDocument() {
final Document doc = this.validCheck.check(read(SIMPLE_VALID)); final Document doc = this.validCheck.check(read(SIMPLE_VALID));
assertThat(doc).isNotNull(); assertThat(doc).isNotNull();
} }
@Test @Test
public void testMultipleCase() { void multipleCase() {
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(SIMPLE_VALID)).collect(Collectors.toList()); final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(SIMPLE_VALID)).collect(Collectors.toList());
final List<Result> docs = this.validCheck.checkInput(input); final List<Result> docs = this.validCheck.checkInput(input);
assertThat(docs).hasSize(MULTI_COUNT); assertThat(docs).hasSize(MULTI_COUNT);
} }
@Test @Test
public void testMultipleCaseDocument() { void multipleCaseDocument() {
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(SIMPLE_VALID)).collect(Collectors.toList()); final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(SIMPLE_VALID)).collect(Collectors.toList());
final List<Document> docs = this.validCheck.check(input); final List<Document> docs = this.validCheck.check(input);
assertThat(docs).hasSize(MULTI_COUNT); assertThat(docs).hasSize(MULTI_COUNT);
} }
@Test @Test
public void testExtractHtml() { void extractHtml() {
final DefaultResult doc = (DefaultResult) this.validCheck.checkInput(read(SIMPLE_VALID)); final DefaultResult doc = (DefaultResult) this.validCheck.checkInput(read(SIMPLE_VALID));
assertThat(doc).isNotNull(); assertThat(doc).isNotNull();
assertThat(doc.getReport()).isNotNull(); assertThat(doc.getReport()).isNotNull();
@ -141,7 +141,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testGarbage() { void garbage() {
final Result result = this.validCheck.checkInput(read(GARBAGE)); final Result result = this.validCheck.checkInput(read(GARBAGE));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.isWellFormed()).isFalse(); assertThat(result.isWellFormed()).isFalse();
@ -150,7 +150,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testNoScenario() { void noScenario() {
final Result result = this.validCheck.checkInput(read(UNKNOWN)); final Result result = this.validCheck.checkInput(read(UNKNOWN));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.isWellFormed()).isTrue(); assertThat(result.isWellFormed()).isTrue();
@ -161,7 +161,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testNotWellFormed() { void notWellFormed() {
final Result result = this.validCheck.checkInput(read(NOT_WELL_FORMED)); final Result result = this.validCheck.checkInput(read(NOT_WELL_FORMED));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.isWellFormed()).isFalse(); assertThat(result.isWellFormed()).isFalse();
@ -173,7 +173,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testRejectAcceptMatch() { void rejectAcceptMatch() {
final Result result = this.validCheck.checkInput(read(REJECTED)); final Result result = this.validCheck.checkInput(read(REJECTED));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.isWellFormed()).isTrue(); assertThat(result.isWellFormed()).isTrue();
@ -186,7 +186,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testSchematronFailed() { void schematronFailed() {
final Result result = this.validCheck.checkInput(read(SCHEMATRON_INVALID)); final Result result = this.validCheck.checkInput(read(SCHEMATRON_INVALID));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.isWellFormed()).isTrue(); assertThat(result.isWellFormed()).isTrue();
@ -204,7 +204,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testSchematronFailedWithoutAcceptMatch() { void schematronFailedWithoutAcceptMatch() {
final Result result = this.validCheck.checkInput(read(FOO_SCHEMATRON_INVALID)); final Result result = this.validCheck.checkInput(read(FOO_SCHEMATRON_INVALID));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.isWellFormed()).isTrue(); assertThat(result.isWellFormed()).isTrue();
@ -220,7 +220,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testSchematronExecutionError() { void schematronExecutionError() {
final Result result = this.errorCheck.checkInput(read(SIMPLE_VALID)); final Result result = this.errorCheck.checkInput(read(SIMPLE_VALID));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.isProcessingSuccessful()).isFalse(); assertThat(result.isProcessingSuccessful()).isFalse();
@ -233,7 +233,7 @@ public class DefaultCheckTest {
} }
@Test @Test
public void testXdmNode() throws Exception { void xdmNode() throws Exception {
XdmNode node = TestObjectFactory.createProcessor().newDocumentBuilder().build(new StreamSource(SIMPLE_VALID.toASCIIString())); XdmNode node = TestObjectFactory.createProcessor().newDocumentBuilder().build(new StreamSource(SIMPLE_VALID.toASCIIString()));
Input domInput = InputFactory.read(node, "node test"); Input domInput = InputFactory.read(node, "node test");
Result result = this.validCheck.checkInput(domInput); Result result = this.validCheck.checkInput(domInput);

View file

@ -21,6 +21,7 @@ import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
import de.kosit.validationtool.impl.model.Result; import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.impl.tasks.DocumentParseAction; import de.kosit.validationtool.impl.tasks.DocumentParseAction;
import de.kosit.validationtool.impl.xml.ProcessorProvider; import de.kosit.validationtool.impl.xml.ProcessorProvider;
import de.kosit.validationtool.model.reportInput.ObjectFactory;
import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import net.sf.saxon.s9api.Processor; import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.SaxonApiException;
@ -91,6 +92,9 @@ public class Helper {
public static URI getSchemaLocation() { public static URI getSchemaLocation() {
return SCHEMA; return SCHEMA;
} }
private Simple() {
}
} }
public static class Invalid { public static class Invalid {
@ -101,6 +105,9 @@ public class Helper {
public static final URI SCENARIOS_ILL_FORMED = ROOT.resolve("scenarios-illformed.xml"); public static final URI SCENARIOS_ILL_FORMED = ROOT.resolve("scenarios-illformed.xml");
private Invalid() {
}
} }
public static class Resolving { public static class Resolving {
@ -110,6 +117,9 @@ public class Helper {
public static final URI SCHEMA_WITH_REMOTE_REFERENCE = ROOT.resolve("withRemote.xsd"); public static final URI SCHEMA_WITH_REMOTE_REFERENCE = ROOT.resolve("withRemote.xsd");
public static final URI SCHEMA_WITH_REFERENCE = ROOT.resolve("main.xsd"); public static final URI SCHEMA_WITH_REFERENCE = ROOT.resolve("main.xsd");
private Resolving() {
}
} }
public static final URI MODEL_ROOT = Paths.get("src/main/model").toUri(); public static final URI MODEL_ROOT = Paths.get("src/main/model").toUri();
@ -144,8 +154,7 @@ public class Helper {
public static <T> T load(final URL url, final Class<T> type) throws URISyntaxException { public static <T> T load(final URL url, final Class<T> type) throws URISyntaxException {
final ConversionService c = new ConversionService(); final ConversionService c = new ConversionService();
c.initialize(de.kosit.validationtool.model.reportInput.ObjectFactory.class.getPackage(), c.initialize(ObjectFactory.class.getPackage(), de.kosit.validationtool.cmd.assertions.ObjectFactory.class.getPackage(),
de.kosit.validationtool.cmd.assertions.ObjectFactory.class.getPackage(),
de.kosit.validationtool.model.scenarios.ObjectFactory.class.getPackage()); de.kosit.validationtool.model.scenarios.ObjectFactory.class.getPackage());
return c.readXml(url.toURI(), type); return c.readXml(url.toURI(), type);
} }
@ -177,4 +186,7 @@ public class Helper {
public static Processor createProcessor() { public static Processor createProcessor() {
return ProcessorProvider.getProcessor(); return ProcessorProvider.getProcessor();
} }
private Helper() {
}
} }

View file

@ -17,7 +17,7 @@
package de.kosit.validationtool.impl; package de.kosit.validationtool.impl;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -28,16 +28,15 @@ import javax.xml.transform.Source;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver; import javax.xml.transform.URIResolver;
import org.junit.Test;
import de.kosit.validationtool.impl.xml.RelativeUriResolver; import de.kosit.validationtool.impl.xml.RelativeUriResolver;
import org.junit.jupiter.api.Test;
/** /**
* Testet den Uri-Resolver der relative auflösen soll * Testet den Uri-Resolver der relative auflösen soll
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class RelativeUriResolverTest { class RelativeUriResolverTest {
private static final URI BASE; private static final URI BASE;
@ -52,23 +51,23 @@ public class RelativeUriResolverTest {
private URIResolver resolver = new RelativeUriResolver(BASE); private URIResolver resolver = new RelativeUriResolver(BASE);
@Test @Test
public void testSuccess() throws TransformerException { void success() throws TransformerException {
final Source resource = this.resolver.resolve("ubl-0001.xml", BASE.toASCIIString()); final Source resource = this.resolver.resolve("ubl-0001.xml", BASE.toASCIIString());
assertThat(resource).isNotNull(); assertThat(resource).isNotNull();
} }
@Test @Test
public void testNotExisting() { void notExisting() {
assertThrows(TransformerException.class, () -> this.resolver.resolve("ubl-0001", BASE.toASCIIString())); assertThrows(TransformerException.class, () -> this.resolver.resolve("ubl-0001", BASE.toASCIIString()));
} }
@Test @Test
public void testOutOfPath() { void outOfPath() {
assertThrows(TransformerException.class, () -> this.resolver.resolve("../results/report.xml", BASE.toASCIIString())); assertThrows(TransformerException.class, () -> this.resolver.resolve("../results/report.xml", BASE.toASCIIString()));
} }
@Test @Test
public void testClasspathLocal() throws URISyntaxException, TransformerException { void classpathLocal() throws URISyntaxException, TransformerException {
this.resolver = new RelativeUriResolver( this.resolver = new RelativeUriResolver(
Objects.requireNonNull(RelativeUriResolver.class.getClassLoader().getResource("loading")).toURI()); Objects.requireNonNull(RelativeUriResolver.class.getClassLoader().getResource("loading")).toURI());
final URL moz = RelativeUriResolverTest.class.getClassLoader().getResource("loading/main.xsd"); final URL moz = RelativeUriResolverTest.class.getClassLoader().getResource("loading/main.xsd");
@ -78,7 +77,7 @@ public class RelativeUriResolverTest {
} }
@Test @Test
public void testClasspathJAR() throws URISyntaxException, TransformerException { void classpathJAR() throws URISyntaxException, TransformerException {
this.resolver = new RelativeUriResolver( this.resolver = new RelativeUriResolver(
Objects.requireNonNull(RelativeUriResolver.class.getClassLoader().getResource("packaged")).toURI()); Objects.requireNonNull(RelativeUriResolver.class.getClassLoader().getResource("packaged")).toURI());
final URL moz = RelativeUriResolverTest.class.getClassLoader().getResource("packaged/main.xsd"); final URL moz = RelativeUriResolverTest.class.getClassLoader().getResource("packaged/main.xsd");

View file

@ -18,16 +18,15 @@ package de.kosit.validationtool.impl;
import static de.kosit.validationtool.api.InputFactory.read; import static de.kosit.validationtool.api.InputFactory.read;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import de.kosit.validationtool.config.TestConfiguration; import de.kosit.validationtool.config.TestConfiguration;
import de.kosit.validationtool.impl.Helper.Simple; import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.model.Result; import de.kosit.validationtool.impl.model.Result;
@ -42,14 +41,14 @@ import net.sf.saxon.s9api.XdmNode;
* @author Andreas Penski * @author Andreas Penski
*/ */
public class ScenarioRepositoryTest { class ScenarioRepositoryTest {
private ScenarioRepository repository; private ScenarioRepository repository;
private TestConfiguration configInstance; private TestConfiguration configInstance;
@Before @BeforeEach
public void setup() { void setup() {
this.configInstance = new TestConfiguration(); this.configInstance = new TestConfiguration();
this.configInstance this.configInstance
.setContentRepository(new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(), null)); .setContentRepository(new ContentRepository(Helper.getTestProcessor(), ResolvingMode.STRICT_RELATIVE.getStrategy(), null));
@ -67,14 +66,14 @@ public class ScenarioRepositoryTest {
} }
@Test @Test
public void testHappyCase() throws Exception { void happyCase() throws Exception {
final Result<Scenario, String> scenario = this.repository.selectScenario(load(Simple.SCENARIOS)); final Result<Scenario, String> scenario = this.repository.selectScenario(load(Simple.SCENARIOS));
assertThat(scenario).isNotNull(); assertThat(scenario).isNotNull();
assertThat(scenario.isValid()).isTrue(); assertThat(scenario.isValid()).isTrue();
} }
@Test @Test
public void testNonMatch() throws Exception { void nonMatch() throws Exception {
this.configInstance.setScenarios(new ArrayList<>()); this.configInstance.setScenarios(new ArrayList<>());
final Scenario fallback = createFallback(); final Scenario fallback = createFallback();
this.configInstance.setFallbackScenario(fallback); this.configInstance.setFallbackScenario(fallback);
@ -94,7 +93,7 @@ public class ScenarioRepositoryTest {
} }
@Test @Test
public void testMultiMatch() throws Exception { void multiMatch() throws Exception {
this.configInstance.getScenarios().add(createScenario()); this.configInstance.getScenarios().add(createScenario());
this.configInstance.setFallbackScenario(createFallback()); this.configInstance.setFallbackScenario(createFallback());
final Result<Scenario, String> scenario = this.repository.selectScenario(load(Simple.SCENARIOS)); final Result<Scenario, String> scenario = this.repository.selectScenario(load(Simple.SCENARIOS));
@ -104,12 +103,12 @@ public class ScenarioRepositoryTest {
} }
@Test @Test
public void testNoConfiguration() { void noConfiguration() {
assertThrows(IllegalArgumentException.class, () -> this.repository = new ScenarioRepository()); assertThrows(IllegalArgumentException.class, () -> this.repository = new ScenarioRepository());
} }
@Test @Test
public void testFallbackOnMultipleConfigurations() { void fallbackOnMultipleConfigurations() {
final TestConfiguration first = this.configInstance; final TestConfiguration first = this.configInstance;
first.setFallbackScenario(createFallback()); first.setFallbackScenario(createFallback());
setup();// create new one; setup();// create new one;

View file

@ -20,9 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import de.kosit.validationtool.api.AcceptRecommendation; import de.kosit.validationtool.api.AcceptRecommendation;
import de.kosit.validationtool.api.Configuration; import de.kosit.validationtool.api.Configuration;
import de.kosit.validationtool.api.InputFactory; import de.kosit.validationtool.api.InputFactory;
@ -34,25 +33,25 @@ import de.kosit.validationtool.impl.Helper.Simple;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class SimpleScenarioCheckTest { class SimpleScenarioCheckTest {
private DefaultCheck implementation; private DefaultCheck implementation;
@Before @BeforeEach
public void setup() { void setup() {
final Configuration d = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build(Helper.getTestProcessor()); final Configuration d = Configuration.load(Simple.SCENARIOS, Simple.REPOSITORY_URI).build(Helper.getTestProcessor());
this.implementation = new DefaultCheck(d); this.implementation = new DefaultCheck(d);
} }
@Test @Test
public void testSimple() throws MalformedURLException { void simple() throws MalformedURLException {
final Result result = this.implementation.checkInput(InputFactory.read(Simple.SIMPLE_VALID.toURL())); final Result result = this.implementation.checkInput(InputFactory.read(Simple.SIMPLE_VALID.toURL()));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE); assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
} }
@Test @Test
public void testInvalid() throws MalformedURLException { void invalid() throws MalformedURLException {
final Result result = this.implementation.checkInput(InputFactory.read(Simple.SCHEMA_INVALID.toURL())); final Result result = this.implementation.checkInput(InputFactory.read(Simple.SCHEMA_INVALID.toURL()));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT); assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
@ -60,7 +59,7 @@ public class SimpleScenarioCheckTest {
} }
@Test @Test
public void testUnknown() throws MalformedURLException { void unknown() throws MalformedURLException {
final Result result = this.implementation.checkInput(InputFactory.read(Simple.UNKNOWN.toURL())); final Result result = this.implementation.checkInput(InputFactory.read(Simple.UNKNOWN.toURL()));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.isProcessingSuccessful()).isTrue(); assertThat(result.isProcessingSuccessful()).isTrue();
@ -70,7 +69,7 @@ public class SimpleScenarioCheckTest {
} }
@Test @Test
public void testWithoutAcceptMatch() throws MalformedURLException { void withoutAcceptMatch() throws MalformedURLException {
final Result result = this.implementation.checkInput(InputFactory.read(Simple.FOO.toURL())); final Result result = this.implementation.checkInput(InputFactory.read(Simple.FOO.toURL()));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE); assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE);

View file

@ -31,4 +31,7 @@ public class TestObjectFactory {
} }
return processor; return processor;
} }
private TestObjectFactory() {
}
} }

View file

@ -17,21 +17,21 @@
package de.kosit.validationtool.impl; package de.kosit.validationtool.impl;
import de.kosit.validationtool.model.scenarios.Scenarios; import de.kosit.validationtool.model.scenarios.Scenarios;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Testet die Versionierung von Scenario-Dateien aka Konfigurationsdaten. * Testet die Versionierung von Scenario-Dateien aka Konfigurationsdaten.
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class VersioningTest { class VersioningTest {
private static final URL BASE = VersioningTest.class.getResource("/examples/versioning/scenarios-base.xml"); private static final URL BASE = VersioningTest.class.getResource("/examples/versioning/scenarios-base.xml");
@ -43,38 +43,36 @@ public class VersioningTest {
private ConversionService service; private ConversionService service;
@Before @BeforeEach
public void setup() { void setup() {
this.service = new ConversionService(); this.service = new ConversionService();
} }
@Test @Test
public void testBase() throws URISyntaxException { void base() throws URISyntaxException {
assert BASE != null; assert BASE != null;
final Scenarios result = this.service.readXml(BASE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()); final Scenarios result = this.service.readXml(BASE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
assertThat(result).isNotNull(); assertThat(result).isNotNull();
} }
@Test @Test
public void testFrameworkIncrement() throws URISyntaxException { void frameworkIncrement() throws URISyntaxException {
assert INCREMENT != null; assert INCREMENT != null;
final Scenarios result = this.service.readXml(INCREMENT.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()); final Scenarios result = this.service.readXml(INCREMENT.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
assertThat(result).isNotNull(); assertThat(result).isNotNull();
} }
@Test @Test
public void testNewFeature() { void newFeature() {
assertThrows(ConversionService.ConversionException.class, () -> { assert NEW_FEATURE != null;
assert NEW_FEATURE != null; assertThrows(ConversionService.ConversionException.class,
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()); () -> this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()));
});
} }
@Test @Test
public void testNewVersion() { void newVersion() {
assertThrows(ConversionService.ConversionException.class, () -> { assert NEW_VERSION != null;
assert NEW_VERSION != null; assertThrows(ConversionService.ConversionException.class,
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()); () -> this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()));
});
} }
} }

View file

@ -17,7 +17,7 @@
package de.kosit.validationtool.impl.input; package de.kosit.validationtool.impl.input;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Andreas Penski * @author Andreas Penski
*/ */
public class StreamHelperTest { class StreamHelperTest {
/** /**
* Simulates a stream that is return 0 for {@link InputStream#available()} even though content is supplied. * Simulates a stream that is return 0 for {@link InputStream#available()} even though content is supplied.
@ -49,7 +49,7 @@ public class StreamHelperTest {
} }
@Test @Test
public void testLazyStream() throws IOException { void lazyStream() throws IOException {
final String myContent = "SomeBytes"; final String myContent = "SomeBytes";
try ( final InputStream in = new MyLazyStream(new ByteArrayInputStream(myContent.getBytes())) ) { try ( final InputStream in = new MyLazyStream(new ByteArrayInputStream(myContent.getBytes())) ) {
final BufferedInputStream peekable = StreamHelper.wrapPeekable(in); final BufferedInputStream peekable = StreamHelper.wrapPeekable(in);

View file

@ -22,7 +22,7 @@ import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.ResolvingMode; import de.kosit.validationtool.impl.ResolvingMode;
import de.kosit.validationtool.impl.tasks.CheckAction.Bag; import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
import net.sf.saxon.s9api.XPathExecutable; import net.sf.saxon.s9api.XPathExecutable;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -35,14 +35,14 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class ComputeAcceptanceActionTest { class ComputeAcceptanceActionTest {
private static final String DOES_NOT_EXIST = "count(//doesnotExist) = 0"; private static final String DOES_NOT_EXIST = "count(//doesnotExist) = 0";
private final ComputeAcceptanceAction action = new ComputeAcceptanceAction(); private final ComputeAcceptanceAction action = new ComputeAcceptanceAction();
@Test @Test
public void simpleTest() { void simpleTest() {
final Bag bag = createBag(true, true); final Bag bag = createBag(true, true);
assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.UNDEFINED); assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.UNDEFINED);
this.action.check(bag); this.action.check(bag);
@ -50,21 +50,21 @@ public class ComputeAcceptanceActionTest {
} }
@Test @Test
public void testSchemaFailed() { void schemaFailed() {
final Bag bag = createBag(false, true); final Bag bag = createBag(false, true);
this.action.check(bag); this.action.check(bag);
assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT); assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
} }
@Test @Test
public void testSchematronFailed() { void schematronFailed() {
final Bag bag = createBag(true, false); final Bag bag = createBag(true, false);
this.action.check(bag); this.action.check(bag);
assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT); assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
} }
@Test @Test
public void testValidAcceptMatch() { void validAcceptMatch() {
final Bag bag = createBag(true, true); final Bag bag = createBag(true, true);
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath(DOES_NOT_EXIST)); bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath(DOES_NOT_EXIST));
this.action.check(bag); this.action.check(bag);
@ -72,7 +72,7 @@ public class ComputeAcceptanceActionTest {
} }
@Test @Test
public void testAcceptMatchNotSatisfied() { void acceptMatchNotSatisfied() {
final Bag bag = createBag(true, true); final Bag bag = createBag(true, true);
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath("count(//doesnotExist) = 1")); bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath("count(//doesnotExist) = 1"));
this.action.check(bag); this.action.check(bag);
@ -80,7 +80,7 @@ public class ComputeAcceptanceActionTest {
} }
@Test @Test
public void testAcceptMatchOverridesSchematronErrors() { void acceptMatchOverridesSchematronErrors() {
final Bag bag = createBag(true, false); final Bag bag = createBag(true, false);
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath(DOES_NOT_EXIST)); bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath(DOES_NOT_EXIST));
this.action.check(bag); this.action.check(bag);
@ -88,7 +88,7 @@ public class ComputeAcceptanceActionTest {
} }
@Test @Test
public void testValidAcceptMatchOnSchemaFailed() { void validAcceptMatchOnSchemaFailed() {
final Bag bag = createBag(false, true); final Bag bag = createBag(false, true);
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath(DOES_NOT_EXIST)); bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath(DOES_NOT_EXIST));
this.action.check(bag); this.action.check(bag);
@ -96,14 +96,14 @@ public class ComputeAcceptanceActionTest {
} }
@Test @Test
public void testMissingSchemaCheck() { void missingSchemaCheck() {
final Bag bag = createBag(null, Collections.emptyList()); final Bag bag = createBag(null, Collections.emptyList());
this.action.check(bag); this.action.check(bag);
assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT); assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
} }
@Test @Test
public void testNoSchematronCheck() { void noSchematronCheck() {
final Bag bag = createBag(true, true); final Bag bag = createBag(true, true);
// remove schematron results // remove schematron results
bag.getReportInput().getValidationResultsSchematron().clear(); bag.getReportInput().getValidationResultsSchematron().clear();
@ -112,7 +112,7 @@ public class ComputeAcceptanceActionTest {
} }
@Test @Test
public void testMissingReport() { void missingReport() {
final Bag bag = createBag(false, true); final Bag bag = createBag(false, true);
bag.setReport(null); bag.setReport(null);
this.action.check(bag); this.action.check(bag);

View file

@ -26,8 +26,8 @@ import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
import net.sf.saxon.s9api.DocumentBuilder; import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.Processor; import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.SaxonApiException;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import javax.xml.transform.Source; import javax.xml.transform.Source;
@ -43,20 +43,20 @@ import static org.mockito.Mockito.when;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class CreateReportActionTest { class CreateReportActionTest {
private CreateReportAction action; private CreateReportAction action;
private ContentRepository repository; private ContentRepository repository;
@Before @BeforeEach
public void setup() { void setup() {
this.repository = Simple.createContentRepository(); this.repository = Simple.createContentRepository();
this.action = new CreateReportAction(this.repository.getProcessor(), new ConversionService()); this.action = new CreateReportAction(this.repository.getProcessor(), new ConversionService());
} }
@Test @Test
public void testSimpleCreate() { void simpleCreate() {
final Bag bag = TestBagBuilder.createBag(true, true); final Bag bag = TestBagBuilder.createBag(true, true);
final Scenario scenario = createScenario().build(this.repository).getObject(); final Scenario scenario = createScenario().build(this.repository).getObject();
bag.setScenarioSelectionResult(new Result<>(scenario)); bag.setScenarioSelectionResult(new Result<>(scenario));
@ -66,7 +66,7 @@ public class CreateReportActionTest {
} }
@Test @Test
public void testNoValidParseResult() { void noValidParseResult() {
// e.g. no valid xml file specified // e.g. no valid xml file specified
final Bag bag = TestBagBuilder.createBag(InputFactory.read("someBytes".getBytes(), "invalid"), true); final Bag bag = TestBagBuilder.createBag(InputFactory.read("someBytes".getBytes(), "invalid"), true);
final Scenario scenario = createScenario().build(this.repository).getObject(); final Scenario scenario = createScenario().build(this.repository).getObject();
@ -79,7 +79,7 @@ public class CreateReportActionTest {
} }
@Test @Test
public void testExecutionException() throws SaxonApiException { void executionException() throws SaxonApiException {
final Processor p = mock(Processor.class); final Processor p = mock(Processor.class);
final DocumentBuilder documentBuilder = mock(DocumentBuilder.class); final DocumentBuilder documentBuilder = mock(DocumentBuilder.class);
this.action = new CreateReportAction(p, new ConversionService()); this.action = new CreateReportAction(p, new ConversionService());

View file

@ -21,29 +21,29 @@ import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.model.Result; import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.model.reportInput.XMLSyntaxError; import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import net.sf.saxon.s9api.XdmNode; import net.sf.saxon.s9api.XdmNode;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import static de.kosit.validationtool.api.InputFactory.read; import static de.kosit.validationtool.api.InputFactory.read;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Testet die Document Parsing-Funktionalitäten. * Testet die Document Parsing-Funktionalitäten.
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class DocumentParseActionTest { class DocumentParseActionTest {
private DocumentParseAction action; private DocumentParseAction action;
@Before @BeforeEach
public void setup() { void setup() {
this.action = new DocumentParseAction(Helper.createProcessor()); this.action = new DocumentParseAction(Helper.createProcessor());
} }
@Test @Test
public void testSimple() { void simple() {
final Result<XdmNode, XMLSyntaxError> result = this.action.parseDocument(read(Simple.SIMPLE_VALID)); final Result<XdmNode, XMLSyntaxError> result = this.action.parseDocument(read(Simple.SIMPLE_VALID));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.getObject()).isNotNull(); assertThat(result.getObject()).isNotNull();
@ -52,7 +52,7 @@ public class DocumentParseActionTest {
} }
@Test @Test
public void testIllFormed() { void illFormed() {
final Result<XdmNode, XMLSyntaxError> result = this.action.parseDocument(read(Simple.NOT_WELL_FORMED)); final Result<XdmNode, XMLSyntaxError> result = this.action.parseDocument(read(Simple.NOT_WELL_FORMED));
assertThat(result).isNotNull(); assertThat(result).isNotNull();
assertThat(result.getErrors()).isNotEmpty(); assertThat(result.getErrors()).isNotEmpty();
@ -61,7 +61,7 @@ public class DocumentParseActionTest {
} }
@Test @Test
public void testNullInput() { void nullInput() {
assertThrows(IllegalArgumentException.class, () -> this.action.parseDocument(null)); assertThrows(IllegalArgumentException.class, () -> this.action.parseDocument(null));
} }
} }

View file

@ -26,8 +26,8 @@ import de.kosit.validationtool.impl.SchemaProvider;
import de.kosit.validationtool.impl.TestObjectFactory; import de.kosit.validationtool.impl.TestObjectFactory;
import de.kosit.validationtool.impl.input.SourceInput; import de.kosit.validationtool.impl.input.SourceInput;
import de.kosit.validationtool.impl.tasks.CheckAction.Bag; import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
@ -48,17 +48,17 @@ import static org.mockito.Mockito.*;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class SchemaValidatorActionTest { class SchemaValidatorActionTest {
private SchemaValidationAction service; private SchemaValidationAction service;
@Before @BeforeEach
public void setup() { void setup() {
this.service = new SchemaValidationAction(TestObjectFactory.createProcessor()); this.service = new SchemaValidationAction(TestObjectFactory.createProcessor());
} }
@Test @Test
public void testSimple() throws MalformedURLException { void simple() throws MalformedURLException {
final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL())); final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()));
this.service.check(bag); this.service.check(bag);
assertThat(bag.getSchemaValidationResult().isValid()).isTrue(); assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
@ -67,7 +67,7 @@ public class SchemaValidatorActionTest {
} }
@Test @Test
public void testValidationFailure() throws MalformedURLException { void validationFailure() throws MalformedURLException {
final Input input = InputFactory.read(Simple.SCHEMA_INVALID.toURL()); final Input input = InputFactory.read(Simple.SCHEMA_INVALID.toURL());
final CheckAction.Bag bag = createBag(input); final CheckAction.Bag bag = createBag(input);
this.service.check(bag); this.service.check(bag);
@ -80,13 +80,13 @@ public class SchemaValidatorActionTest {
} }
@Test @Test
public void testSchemaReferences() { void schemaReferences() {
final Schema reportInputSchema = SchemaProvider.getReportInputSchema(); final Schema reportInputSchema = SchemaProvider.getReportInputSchema();
assertThat(reportInputSchema).isNotNull(); assertThat(reportInputSchema).isNotNull();
} }
@Test @Test
public void testNoRepeatableRead() throws Exception { void noRepeatableRead() throws Exception {
try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream() ) { try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream() ) {
final Bag bag = createBag(InputFactory.read(new StreamSource(inputStream))); final Bag bag = createBag(InputFactory.read(new StreamSource(inputStream)));
// don't read the real input stream here! // don't read the real input stream here!
@ -98,7 +98,7 @@ public class SchemaValidatorActionTest {
} }
@Test @Test
public void testNoRepeatableReadBigFile() throws Exception { void noRepeatableReadBigFile() throws Exception {
try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream() ) { try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream() ) {
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(inputStream)); final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(inputStream));
final Bag bag = createBag(input); final Bag bag = createBag(input);
@ -114,7 +114,7 @@ public class SchemaValidatorActionTest {
} }
@Test @Test
public void testNoRepeatableReaderInput() throws Exception { void noRepeatableReaderInput() throws Exception {
try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream(); try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream();
final Reader reader = new InputStreamReader(inputStream) ) { final Reader reader = new InputStreamReader(inputStream) ) {
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader)); final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader));
@ -128,7 +128,7 @@ public class SchemaValidatorActionTest {
} }
@Test @Test
public void testNoRepeatableReaderInputBigFile() throws Exception { void noRepeatableReaderInputBigFile() throws Exception {
try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream(); try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream();
final Reader reader = new InputStreamReader(inputStream) ) { final Reader reader = new InputStreamReader(inputStream) ) {
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader)); final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader));
@ -144,7 +144,7 @@ public class SchemaValidatorActionTest {
} }
@Test @Test
public void testProcessingError() throws IOException, SAXException { void processingError() throws IOException, SAXException {
final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL())); final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()));
final Scenario scenario = bag.getScenarioSelectionResult().getObject(); final Scenario scenario = bag.getScenarioSelectionResult().getObject();
final Schema schema = mock(Schema.class); final Schema schema = mock(Schema.class);

View file

@ -25,8 +25,8 @@ import de.kosit.validationtool.model.scenarios.ResourceType;
import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XsltExecutable; import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer; import net.sf.saxon.s9api.XsltTransformer;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
@ -40,17 +40,17 @@ import static org.mockito.Mockito.*;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class SchematronValidationActionTest { class SchematronValidationActionTest {
private SchematronValidationAction action; private SchematronValidationAction action;
@Before @BeforeEach
public void setup() { void setup() {
this.action = new SchematronValidationAction(new ConversionService()); this.action = new SchematronValidationAction(new ConversionService());
} }
@Test @Test
public void testProcessingError() throws IOException, SaxonApiException { void processingError() throws IOException, SaxonApiException {
final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()), true); final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()), true);
final Scenario scenario = bag.getScenarioSelectionResult().getObject(); final Scenario scenario = bag.getScenarioSelectionResult().getObject();

View file

@ -125,4 +125,7 @@ public class TestBagBuilder {
b.setReport(createReport()); b.setReport(createReport());
return b; return b;
} }
private TestBagBuilder() {
}
} }

View file

@ -17,14 +17,14 @@
package de.kosit.validationtool.impl.xml; package de.kosit.validationtool.impl.xml;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException; import org.xml.sax.SAXNotSupportedException;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
import javax.xml.validation.SchemaFactory; import javax.xml.validation.SchemaFactory;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
/** /**
@ -46,7 +46,7 @@ public class BaseResolverConfigurationTest {
public static final String NOT_EXISTING_SCHEME = "not-existing-scheme"; public static final String NOT_EXISTING_SCHEME = "not-existing-scheme";
@Test @Test
public void testIgnoreUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException { void ignoreUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
final SchemaFactory sf = mock(SchemaFactory.class); final SchemaFactory sf = mock(SchemaFactory.class);
final TestResolvingStrategy s = new TestResolvingStrategy(); final TestResolvingStrategy s = new TestResolvingStrategy();
doThrow(new SAXNotRecognizedException("not supported")).when(sf).setProperty(any(), any()); doThrow(new SAXNotRecognizedException("not supported")).when(sf).setProperty(any(), any());
@ -54,7 +54,7 @@ public class BaseResolverConfigurationTest {
} }
@Test @Test
public void testFailOnUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException { void failOnUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
final SchemaFactory sf = mock(SchemaFactory.class); final SchemaFactory sf = mock(SchemaFactory.class);
final TestResolvingStrategy s = new TestResolvingStrategy(); final TestResolvingStrategy s = new TestResolvingStrategy();
doThrow(new SAXNotRecognizedException("not supported")).when(sf).setProperty(any(), any()); doThrow(new SAXNotRecognizedException("not supported")).when(sf).setProperty(any(), any());
@ -62,7 +62,7 @@ public class BaseResolverConfigurationTest {
} }
@Test @Test
public void testSimpleSuccess() throws SAXNotRecognizedException, SAXNotSupportedException { void simpleSuccess() throws SAXNotRecognizedException, SAXNotSupportedException {
final SchemaFactory sf = mock(SchemaFactory.class); final SchemaFactory sf = mock(SchemaFactory.class);
final TestResolvingStrategy s = new TestResolvingStrategy(); final TestResolvingStrategy s = new TestResolvingStrategy();
s.setInternalProperty(sf, true); s.setInternalProperty(sf, true);

View file

@ -18,7 +18,7 @@ package de.kosit.validationtool.impl.xml;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy; import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
import de.kosit.validationtool.impl.Helper.Resolving; import de.kosit.validationtool.impl.Helper.Resolving;
import org.junit.Test; import org.junit.jupiter.api.Test;
import javax.xml.validation.Schema; import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory; import javax.xml.validation.SchemaFactory;
@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class RemoteResolvingStrategyTest { class RemoteResolvingStrategyTest {
@Test @Test
public void testRemoteSchemaResolving() throws Exception { void remoteSchemaResolving() throws Exception {
final ResolvingConfigurationStrategy s = new RemoteResolvingStrategy(); final ResolvingConfigurationStrategy s = new RemoteResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory(); final SchemaFactory schemaFactory = s.createSchemaFactory();
final Schema schema = schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL()); final Schema schema = schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL());
@ -41,7 +41,7 @@ public class RemoteResolvingStrategyTest {
} }
@Test @Test
public void testLocalSchemaResolving() throws Exception { void localSchemaResolving() throws Exception {
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy(); final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory(); final SchemaFactory schemaFactory = s.createSchemaFactory();
final Schema schema = schemaFactory.newSchema(Resolving.SCHEMA_WITH_REFERENCE.toURL()); final Schema schema = schemaFactory.newSchema(Resolving.SCHEMA_WITH_REFERENCE.toURL());

View file

@ -31,7 +31,7 @@ import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable; import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer; import net.sf.saxon.s9api.XsltTransformer;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.Test; import org.junit.jupiter.api.Test;
import javax.xml.transform.Source; import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
@ -40,7 +40,7 @@ import java.net.URL;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
/** /**
* Testet verschiedene Saxon Security Einstellungen. * Testet verschiedene Saxon Security Einstellungen.
@ -48,11 +48,11 @@ import static org.junit.Assert.fail;
* @author Andreas Penski * @author Andreas Penski
*/ */
@Slf4j @Slf4j
public class SaxonSecurityTest { class SaxonSecurityTest {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Test @Test
public void testEvilStylesheets() throws IOException { void evilStylesheets() throws IOException {
final Processor p = TestObjectFactory.createProcessor(); final Processor p = TestObjectFactory.createProcessor();
for (int i = 1; i <= 5; i++) { for (int i = 1; i <= 5; i++) {
try { try {
@ -80,13 +80,13 @@ public class SaxonSecurityTest {
} }
} catch (final SaxonApiException | RuntimeException e) { } catch (final SaxonApiException | RuntimeException e) {
log.info("Expected exception detected {}", e.getMessage(), e); log.error("Expected exception detected {}", e.getMessage(), e);
} }
} }
} }
@Test @Test
public void testXxe() { void xxe() {
final URL resource = SaxonSecurityTest.class.getResource("/evil/xxe.xml"); final URL resource = SaxonSecurityTest.class.getResource("/evil/xxe.xml");
final Result<XdmNode, XMLSyntaxError> result = Helper.parseDocument(InputFactory.read(resource)); final Result<XdmNode, XMLSyntaxError> result = Helper.parseDocument(InputFactory.read(resource));
assertThat(result.isValid()).isFalse(); assertThat(result.isValid()).isFalse();

View file

@ -18,24 +18,24 @@ package de.kosit.validationtool.impl.xml;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy; import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
import de.kosit.validationtool.impl.Helper.Resolving; import de.kosit.validationtool.impl.Helper.Resolving;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
import javax.xml.validation.Schema; import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory; import javax.xml.validation.SchemaFactory;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Tests {@link StrictLocalResolvingStrategy} * Tests {@link StrictLocalResolvingStrategy}
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class StrictLocalResolvingTest { class StrictLocalResolvingTest {
@Test @Test
public void testRemoteSchemaResolving() { void remoteSchemaResolving() {
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy(); final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory(); final SchemaFactory schemaFactory = s.createSchemaFactory();
Throwable e = assertThrows(SAXParseException.class, () -> schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL())); Throwable e = assertThrows(SAXParseException.class, () -> schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL()));
@ -43,7 +43,7 @@ public class StrictLocalResolvingTest {
} }
@Test @Test
public void testLocalSchemaResolving() throws Exception { void localSchemaResolving() throws Exception {
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy(); final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory(); final SchemaFactory schemaFactory = s.createSchemaFactory();
final Schema schema = schemaFactory.newSchema(Resolving.SCHEMA_WITH_REFERENCE.toURL()); final Schema schema = schemaFactory.newSchema(Resolving.SCHEMA_WITH_REFERENCE.toURL());

View file

@ -18,24 +18,24 @@ package de.kosit.validationtool.impl.xml;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy; import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
import de.kosit.validationtool.impl.Helper.Resolving; import de.kosit.validationtool.impl.Helper.Resolving;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
import javax.xml.validation.Schema; import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory; import javax.xml.validation.SchemaFactory;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Tests {@link StrictRelativeResolvingStrategy}. * Tests {@link StrictRelativeResolvingStrategy}.
* *
* @author Andreas Penski * @author Andreas Penski
*/ */
public class StrictRelativeResolvingTest { class StrictRelativeResolvingTest {
@Test @Test
public void testRemoteSchemaResolving() { void remoteSchemaResolving() {
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy(); final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory(); final SchemaFactory schemaFactory = s.createSchemaFactory();
Throwable e = assertThrows(SAXParseException.class, () -> schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL())); Throwable e = assertThrows(SAXParseException.class, () -> schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL()));
@ -43,7 +43,7 @@ public class StrictRelativeResolvingTest {
} }
@Test @Test
public void testLocalSchemaResolving() throws Exception { void localSchemaResolving() throws Exception {
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy(); final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory(); final SchemaFactory schemaFactory = s.createSchemaFactory();
final Schema schema = schemaFactory.newSchema(Resolving.SCHEMA_WITH_REFERENCE.toURL()); final Schema schema = schemaFactory.newSchema(Resolving.SCHEMA_WITH_REFERENCE.toURL());

View file

@ -59,8 +59,8 @@
<scenario> <scenario>
<name>NoAcceptMatch</name> <name>NoAcceptMatch</name>
<description> <description>
<p>Nur Schemaprüfung. Keine AcceptMatch deklaration</p> <p>Nur Schemaprüfung. Keine AcceptMatch Deklaration</p>
<p>Testen, ob auch alte Konfiguration funktionioeren</p> <p>Testen, ob auch alte Konfiguration funktionieren</p>
</description> </description>
<namespace prefix="test">http://validator.kosit.de/test-sample</namespace> <namespace prefix="test">http://validator.kosit.de/test-sample</namespace>
<match>/test:DoesNotMatchfoo</match> <match>/test:DoesNotMatchfoo</match>

View file

@ -60,7 +60,7 @@
<name>NoAcceptMatch</name> <name>NoAcceptMatch</name>
<description> <description>
<p>Nur Schemaprüfung. Keine AcceptMatch deklaration</p> <p>Nur Schemaprüfung. Keine AcceptMatch deklaration</p>
<p>Testen, ob auch alte Konfiguration funktionioeren</p> <p>Testen, ob auch alte Konfiguration funktionieren</p>
</description> </description>
<namespace prefix="test">http://validator.kosit.de/test-sample</namespace> <namespace prefix="test">http://validator.kosit.de/test-sample</namespace>
<match>/test:foo</match> <match>/test:foo</match>