Replaced deprecated methods etc.

This commit is contained in:
Philip Helger 2025-10-24 12:27:20 +02:00 committed by Renzo Kottmann
parent c030aaff02
commit 0b22c3ea91
37 changed files with 204 additions and 288 deletions

View file

@ -23,16 +23,14 @@ import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.cmd.assertions.AssertionType;
import de.kosit.validationtool.cmd.assertions.Assertions;
import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.impl.tasks.CheckAction;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XPathCompiler;
@ -56,12 +54,12 @@ class CheckAssertionAction implements CheckAction {
private Map<String, List<AssertionType>> mappedAssertions;
private static boolean matches(String key, String name) {
private static boolean matches(final String key, final String name) {
return key.startsWith(name) || (name + ".xml").endsWith(key);
}
@Override
public void check(Bag results) {
public void check(final Bag results) {
log.info("Checking assertions for {}", results.getInput().getName());
final List<AssertionType> toCheck = findAssertions(results.getName());
final List<String> errors = new ArrayList<>();
@ -84,28 +82,28 @@ class CheckAssertionAction implements CheckAction {
}
}
private List<AssertionType> findAssertions(String name) {
private List<AssertionType> findAssertions(final String name) {
return getMapped().entrySet().stream().filter(e -> matches(e.getKey(), name)).map(Map.Entry::getValue).findFirst().orElse(null);
}
private boolean check(XdmNode document, AssertionType assertion) {
private boolean check(final XdmNode document, final AssertionType assertion) {
try {
final XPathSelector selector = createSelector(assertion);
selector.setContextItem(document);
return selector.effectiveBooleanValue();
} catch (SaxonApiException e) {
} catch (final SaxonApiException e) {
log.error("Error evaluating assertion {} for {}", assertion.getTest(), assertion.getReportDoc(), e);
}
return false;
}
private XPathSelector createSelector(AssertionType assertion) throws SaxonApiException {
private XPathSelector createSelector(final AssertionType assertion) {
try {
final XPathCompiler compiler = getProcessor().newXPathCompiler();
assertions.getNamespace().forEach(ns -> compiler.declareNamespace(ns.getPrefix(), ns.getValue()));
return compiler.compile(assertion.getTest()).load();
} catch (SaxonApiException e) {
} catch (final SaxonApiException e) {
throw new IllegalStateException(String.format("Can not compile xpath match expression '%s'",
StringUtils.isNotBlank(assertion.getTest()) ? assertion.getTest() : "EMPTY EXPRESSION"), e);
}
@ -114,8 +112,8 @@ class CheckAssertionAction implements CheckAction {
private Map<String, List<AssertionType>> getMapped() {
if (mappedAssertions == null) {
mappedAssertions = new HashMap<>();
for (AssertionType assertionType : assertions.getAssertion()) {
List<AssertionType> list = mappedAssertions.computeIfAbsent(assertionType.getReportDoc(), k -> new ArrayList<>());
for (final AssertionType assertionType : assertions.getAssertion()) {
final List<AssertionType> list = mappedAssertions.computeIfAbsent(assertionType.getReportDoc(), k -> new ArrayList<>());
list.add(assertionType);
}
}

View file

@ -95,6 +95,8 @@ public class CommandLineApplication {
return resultStatus;
}
// The signature is required, because the method is used a lambda
@SuppressWarnings("unused")
private static int logExecutionException(final Exception ex, final CommandLine cli, final ParseResult parseResult) {
final String message = isNotEmpty(ex.getMessage()) ? ex.getMessage() : "Es ist eine Fehler aufgetreten";
Printer.writeErr(ex, message);

View file

@ -321,10 +321,8 @@ public class Validator {
private static URI determineRepository(final Path d) {
if (Files.isDirectory(d)) {
return d.toUri();
} else {
throw new IllegalArgumentException(
String.format("Not a valid path for repository definition specified: '%s'", d.toAbsolutePath()));
}
throw new IllegalArgumentException(String.format("Not a valid path for repository definition specified: '%s'", d.toAbsolutePath()));
}

View file

@ -82,6 +82,7 @@ public class Grid {
*
* @param name the name of the column
* @param maxLength the max length of the column
* @param minLength the minimum length of the column
*/
public ColumnDefinition(final String name, final int maxLength, final int minLength) {
this(name, maxLength, minLength, 1);
@ -91,7 +92,8 @@ public class Grid {
* Constructor.
*
* @param name the name of the column
* @param minLength the max length of the column
* @param maxLength the max length of the column
* @param minLength the minimum length of the column
* @param maxLines the max lines per cell
*/
public ColumnDefinition(final String name, final int maxLength, final int minLength, final int maxLines) {
@ -149,10 +151,6 @@ public class Grid {
this.text.add(txt);
}
public Cell(final Object object, final Code... codes) {
this(new Text(object, codes));
}
protected Line getFormattedLine(final int lineNumber, final ColumnDefinition def) {
final Line line = new Line();
int startSubstring = lineNumber * def.getLength();
@ -194,11 +192,6 @@ public class Grid {
}
public Cell add(final Object object, final Code... codes) {
this.text.add(new Text(object, codes));
return this;
}
}
private static final Format DEFAULT_FORMAT = new Format();
@ -321,7 +314,7 @@ public class Grid {
}
private static boolean isEmpty(final StringBuilder current) {
return current.toString().replaceAll("\\|", "").trim().length() == 0;
return current.toString().replace("|", "").trim().length() == 0;
}
private int getMaxVirtualLine() {

View file

@ -16,8 +16,6 @@
package de.kosit.validationtool.config;
import static org.apache.commons.lang3.StringUtils.startsWith;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.HashMap;
@ -27,10 +25,7 @@ import java.util.stream.Collectors;
import javax.xml.validation.Schema;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.Strings;
import de.kosit.validationtool.api.Check;
import de.kosit.validationtool.api.Configuration;
@ -49,7 +44,10 @@ import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import de.kosit.validationtool.model.scenarios.ResourceType;
import de.kosit.validationtool.model.scenarios.ScenarioType;
import de.kosit.validationtool.model.scenarios.Scenarios;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.XdmNode;
@ -113,8 +111,8 @@ public class ConfigurationLoader {
private static boolean isSupportedDocument(final XdmNode doc) {
final XdmNode root = findRoot(doc);
final String frameworkVersion = root.getAttributeValue(new QName("frameworkVersion"));
return startsWith(frameworkVersion, SUPPORTED_MAJOR_VERSION)
&& root.getNodeName().getNamespaceURI().equals(SUPPORTED_MAJOR_VERSION_SCHEMA);
return Strings.CS.startsWith(frameworkVersion, SUPPORTED_MAJOR_VERSION)
&& root.getNodeName().getNamespace().equals(SUPPORTED_MAJOR_VERSION_SCHEMA);
}
private static Scenario createFallback(final Scenarios scenarios, final ContentRepository repository) {

View file

@ -44,18 +44,18 @@ abstract class BaseHandler implements HttpHandler {
throws IOException {
exchange.getResponseHeaders().add("Content-Type", contentType);
exchange.sendResponseHeaders(statusCode, 0);
final OutputStream os = exchange.getResponseBody();
write.write(os);
os.close();
try ( final OutputStream os = exchange.getResponseBody() ) {
write.write(os);
}
}
protected static void error(final HttpExchange exchange, final int statusCode, final String message) throws IOException {
final byte[] bytes = message.getBytes();
exchange.getResponseHeaders().add("Content-Type", "text/plain");
exchange.sendResponseHeaders(statusCode, bytes.length);
final OutputStream os = exchange.getResponseBody();
os.write(bytes);
os.close();
try ( final OutputStream os = exchange.getResponseBody() ) {
os.write(bytes);
}
}
@FunctionalInterface

View file

@ -37,10 +37,6 @@ import javax.xml.validation.SchemaFactory;
import org.apache.commons.lang3.StringUtils;
import org.xml.sax.SAXException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
import de.kosit.validationtool.impl.Scenario.Transformation;
import de.kosit.validationtool.impl.xml.RelativeUriResolver;
@ -49,7 +45,9 @@ import de.kosit.validationtool.model.scenarios.NamespaceType;
import de.kosit.validationtool.model.scenarios.ResourceType;
import de.kosit.validationtool.model.scenarios.ScenarioType;
import de.kosit.validationtool.model.scenarios.ValidateWithSchematron;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.saxon.lib.UnparsedTextURIResolver;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;

View file

@ -24,14 +24,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.StringJoiner;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.JAXBIntrospector;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;
import jakarta.xml.bind.ValidationEventHandler;
import jakarta.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
@ -44,6 +36,14 @@ import javax.xml.validation.Schema;
import org.apache.commons.lang3.StringUtils;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.JAXBIntrospector;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.Unmarshaller;
import jakarta.xml.bind.ValidationEventHandler;
import jakarta.xml.bind.annotation.XmlRegistry;
import lombok.extern.slf4j.Slf4j;
/**
@ -219,6 +219,7 @@ public class ConversionService {
final XMLOutputFactory xof = XMLOutputFactory.newFactory();
final XMLStreamWriter xmlStreamWriter = xof.createXMLStreamWriter(w);
if (null == introspector.getElementName(model)) {
@SuppressWarnings({ "rawtypes", "unchecked" })
final JAXBElement jaxbElement = new JAXBElement(createQName(model), model.getClass(), model);
marshaller.marshal(jaxbElement, xmlStreamWriter);
} else {

View file

@ -169,6 +169,7 @@ public class DefaultCheck implements Check {
.map(fa -> new CustomFailedAssert(fa, customLevels.get(fa.getId()))).collect(Collectors.toList());
}
@SuppressWarnings("unchecked")
private static List<XmlError> convertErrors(final List<XMLSyntaxError> errors) {
// noinspection unchecked
return (List<XmlError>) (List<?>) errors;

View file

@ -19,18 +19,18 @@ package de.kosit.validationtool.impl.input;
import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import jakarta.xml.bind.util.JAXBSource;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.io.input.ReaderInputStream;
import jakarta.xml.bind.util.JAXBSource;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.sf.saxon.om.TreeInfo;
/**
@ -102,7 +102,7 @@ public class SourceInput extends AbstractInput {
return isStreamSource();
}
private boolean isConsumed() throws IOException {
private boolean isConsumed() {
if (isStreamSource()) {
final StreamSource ss = (StreamSource) this.source;
@ -140,7 +140,13 @@ public class SourceInput extends AbstractInput {
if (ss.getInputStream() != null) {
result = new StreamSource(wrap(ss.getInputStream()), this.source.getSystemId());
} else if (ss.getReader() != null) {
result = new StreamSource(wrap(new ReaderInputStream(ss.getReader(), Charset.defaultCharset())), this.source.getSystemId());
try {
result = new StreamSource(
wrap(ReaderInputStream.builder().setReader(ss.getReader()).setCharset(Charset.defaultCharset()).get()),
this.source.getSystemId());
} catch (final IOException ex) {
throw new UncheckedIOException(ex);
}
}
}
return result;

View file

@ -20,13 +20,14 @@ import java.io.BufferedInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.io.input.CountingInputStream;
import org.apache.commons.io.input.BoundedInputStream;
import de.kosit.validationtool.api.Input;
@ -39,7 +40,7 @@ public class StreamHelper {
/**
* Helper class, which generates the hashcode while reading the stream e.g. for parsing the document. This allows
* generating the hashcode without an aditional reading step.
* generating the hashcode without an additional reading step.
*/
@SuppressWarnings("squid:S4929") // efficient read is done by internally used stream
private static class DigestingInputStream extends FilterInputStream {
@ -96,15 +97,15 @@ public class StreamHelper {
private final LazyReadInput reference;
public CountInputStream(final LazyReadInput input, final InputStream stream) {
super(new org.apache.commons.io.input.CountingInputStream(stream));
public CountInputStream(final LazyReadInput input, final InputStream stream) throws IOException {
super(BoundedInputStream.builder().setInputStream(stream).get());
this.reference = input;
}
@Override
public void close() throws IOException {
super.close();
this.reference.setLength(((CountingInputStream) this.in).getByteCount());
this.reference.setLength(((BoundedInputStream) this.in).getCount());
}
}
@ -130,19 +131,24 @@ public class StreamHelper {
/**
* Wraps the {@link InputStream} with a counting length implementation.
*
* @param input the {@link LazyReadInput input}
* @param input the lazy read input
* @param stream the stream
* @return a wrapped stream
*/
public static InputStream wrapCount(final LazyReadInput input, final InputStream stream) {
return new CountInputStream(input, stream);
try {
return new CountInputStream(input, stream);
} catch (final IOException ex) {
throw new UncheckedIOException(ex);
}
}
/**
* Wraps the {@link InputStream} with an implementation the generates a hash sum over the stream data.
*
* @param input the {@link LazyReadInput input}
* @param input the lazy read input
* @param stream the stream
* @param digestAlgorithm the message digest algorithm to use
* @return a wrapped stream
*/
public static InputStream wrapDigesting(final LazyReadInput input, final InputStream stream, final String digestAlgorithm) {
@ -175,7 +181,7 @@ public class StreamHelper {
* @param input the input
* @throws IOException on I/O errors
*/
@SuppressWarnings("squid:S1854")
@SuppressWarnings({ "squid:S1854", "unused" })
public static void drain(final InputStream input) throws IOException {
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];

View file

@ -31,12 +31,6 @@ import javax.xml.validation.Validator;
import org.apache.commons.io.FileUtils;
import org.xml.sax.SAXException;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.api.Input;
import de.kosit.validationtool.impl.CollectingErrorEventHandler;
import de.kosit.validationtool.impl.Scenario;
@ -45,7 +39,11 @@ import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.model.reportInput.CreateReportInput;
import de.kosit.validationtool.model.reportInput.ValidationResultsXmlSchema;
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.Serializer;
@ -216,7 +214,7 @@ public class SchemaValidationAction implements CheckAction {
}
}
private interface SerializedDocument extends AutoCloseable, SourceProvider {
private interface SerializedDocument extends SourceProvider {
void serialize(XdmNode node) throws SaxonApiException, IOException;

View file

@ -22,7 +22,7 @@ import java.io.Reader;
import java.net.URI;
import java.net.URL;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
@ -90,7 +90,7 @@ public class ClassPathResourceResolver implements LSResourceResolver {
* @param basePath der Basispfad
*/
public ClassPathResourceResolver(final String basePath) {
if (!StringUtils.startsWith(basePath, "/")) {
if (!Strings.CS.startsWith(basePath, "/")) {
throw new IllegalArgumentException("Base path must start with a slash");
}
this.base = URI.create(basePath + (basePath.endsWith("/") == basePath.length() > 1 ? "" : "/"));

View file

@ -26,7 +26,6 @@ import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource;
import lombok.RequiredArgsConstructor;
import net.sf.saxon.Configuration;
import net.sf.saxon.lib.StandardUnparsedTextResolver;
import net.sf.saxon.lib.UnparsedTextURIResolver;
@ -54,10 +53,9 @@ public class RelativeUriResolver implements URIResolver, UnparsedTextURIResolver
throw new TransformerException(String.format("Can not resolve required %s", href), e);
}
} else {
throw new TransformerException(String
.format("The resolved transformation artifact %s is not within the configured repository %s", resolved, this.baseUri));
}
throw new TransformerException(String.format("The resolved transformation artifact %s is not within the configured repository %s",
resolved, this.baseUri));
}
/**
@ -96,10 +94,9 @@ public class RelativeUriResolver implements URIResolver, UnparsedTextURIResolver
public Reader resolve(final URI absoluteURI, final String encoding, final Configuration config) throws XPathException {
if (isUnderBaseUri(absoluteURI, this.baseUri)) {
return new StandardUnparsedTextResolver().resolve(absoluteURI, encoding, config);
} else {
throw new XPathException(String.format("The resolved transformation artifact %s is not within the configured repository %s",
absoluteURI, this.baseUri));
}
throw new XPathException(String.format("The resolved transformation artifact %s is not within the configured repository %s",
absoluteURI, this.baseUri));
}
}

View file

@ -25,16 +25,13 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -45,7 +42,6 @@ import de.kosit.validationtool.impl.TestObjectFactory;
import de.kosit.validationtool.impl.input.SourceInput;
import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import net.sf.saxon.dom.NodeOverNodeInfo;
import net.sf.saxon.s9api.BuildingContentHandler;
import net.sf.saxon.s9api.DocumentBuilder;
@ -61,9 +57,6 @@ public class InputFactoryTest {
public static final String SOME_VALUE = "some value";
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testDefaultDigestAlgorithm() {
assertThat(new InputFactory().getAlgorithm()).isEqualTo(InputFactory.DEFAULT_ALGORITH);
@ -81,15 +74,13 @@ public class InputFactoryTest {
assertThat(s1).isNotEqualTo(s3);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testWrongAlgorithm() {
this.expectedException.expect(IllegalArgumentException.class);
new InputFactory("unknown");
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullInputURL() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read((URL) null);
}
@ -105,44 +96,40 @@ public class InputFactoryTest {
assertThat(input).isNotNull();
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullStream() {
this.expectedException.expect(IllegalArgumentException.class);
final Input input = InputFactory.read((InputStream) null, SOME_VALUE);
InputFactory.read((InputStream) null, SOME_VALUE);
}
@Test
public void testInputFile() throws URISyntaxException {
public void testInputFile() {
final Input input = InputFactory.read(new File(Simple.SIMPLE_VALID));
assertThat(input).isNotNull();
}
@Test
public void testInputPath() throws URISyntaxException {
public void testInputPath() {
final Input input = InputFactory.read(Paths.get(Simple.SIMPLE_VALID));
assertThat(input).isNotNull();
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullInput() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read((byte[]) null, SOME_VALUE);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullInputName() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read(SOME_VALUE.getBytes(), null);
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testEmptyInputName() throws IOException {
this.expectedException.expect(IllegalArgumentException.class);
final Input input = InputFactory.read(SOME_VALUE.getBytes(), "");
drain(input);
}
@Test
@Test(expected = IllegalStateException.class)
public void testSourceInput() throws IOException {
try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream() ) {
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(s));
@ -150,12 +137,11 @@ public class InputFactoryTest {
drain(input);
assertThat(input.getHashCode()).isNotNull();
assertThat(input.getLength()).isGreaterThan(0L);
this.expectedException.expect(IllegalStateException.class);
input.getSource();
}
}
@Test
@Test(expected = IllegalStateException.class)
public void testSourceInputReader() throws IOException {
try ( final InputStream s = Simple.SIMPLE_VALID.toURL().openStream();
final InputStreamReader reader = new InputStreamReader(s) ) {
@ -164,14 +150,12 @@ public class InputFactoryTest {
drain(input);
assertThat(input.getHashCode()).isNotNull();
assertThat(input.getLength()).isGreaterThan(0L);
this.expectedException.expect(IllegalStateException.class);
input.getSource();
}
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testUnexistingInput() {
this.expectedException.expect(IllegalArgumentException.class);
InputFactory.read(Simple.NOT_EXISTING);
}

View file

@ -18,7 +18,6 @@ package de.kosit.validationtool.cmd;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
@ -45,11 +44,8 @@ public class CheckAssertionActionTest {
private static final URL SAMPLE_ASSERTIONS = CheckAssertionActionTest.class.getResource("/examples/assertions/tests-xrechnung.xml");
private CommandLine commandLine;
@Before
public void setup() throws IOException {
this.commandLine = new CommandLine();
public void setup() {
CommandLine.activate();
}

View file

@ -46,6 +46,7 @@ public class CommandLine {
*/
private static class ReplaceableOutputStream<O extends OutputStream> extends OutputStream {
@SuppressWarnings("hiding")
@Getter
@Setter
private O out;

View file

@ -26,7 +26,7 @@ import java.nio.file.Paths;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.assertj.core.api.Condition;
import org.junit.After;
import org.junit.Before;
@ -45,13 +45,10 @@ public class CommandlineApplicationTest {
public static final String RESULT_OUTPUT = "Processing 1 object(s) completed";
private CommandLine commandLine;
private final Path output = Paths.get("target/test-output");
@Before
public void setup() throws IOException {
this.commandLine = new CommandLine();
CommandLine.activate();
if (Files.exists(this.output)) {
FileUtils.deleteDirectory(this.output.toFile());
@ -194,7 +191,7 @@ public class CommandlineApplicationTest {
CommandLineApplication.mainProgram(args);
assertThat(CommandLine.getErrorOutput()).contains(RESULT_OUTPUT);
assertThat(CommandLine.getOutputLines()).haveAtLeastOne(new Condition<>(
s -> StringUtils.contains(s, "<?xml version=\"1.0\" " + "encoding=\"UTF-8\"?>"), "Must " + "contain xml preambel"));
s -> Strings.CS.contains(s, "<?xml version=\"1.0\" " + "encoding=\"UTF-8\"?>"), "Must " + "contain xml preambel"));
}
@Test
@ -242,7 +239,7 @@ public class CommandlineApplicationTest {
}
@Test
public void testAndre() throws IOException {
public void testAndre() {
final String[] args = { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY_URI).toString(),
Paths.get(Simple.SIMPLE_VALID).toString(), "--report-prefix", "andre1" };
CommandLineApplication.mainProgram(args);

View file

@ -35,13 +35,10 @@ import de.kosit.validationtool.impl.tasks.CheckAction;
*/
public class PrintReportActionTest {
private CommandLine commandLine;
private PrintReportAction action;
@Before
public void setup() {
this.commandLine = new CommandLine();
CommandLine.activate();
this.action = new PrintReportAction(TestObjectFactory.createProcessor());
}

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.TestConfigurationFactory.createSimpleConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URI;
import java.time.LocalDate;
import java.util.Date;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper;
@ -41,58 +40,69 @@ public class ConfigurationBuilderTest {
public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
@Rule
public ExpectedException exceptions = ExpectedException.none();
@Test
@Test(expected = IllegalStateException.class)
public void testNoConfiguration() {
this.exceptions.expect(IllegalStateException.class);
new ConfigurationBuilder().build(Helper.getTestProcessor());
}
@Test
public void testNoFallback() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("fallback"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.with((FallbackBuilder) null);
builder.build(Helper.getTestProcessor());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.with((FallbackBuilder) null);
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("fallback"));
}
}
@Test
public void testNoSchema() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("schema"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate((SchemaBuilder) null);
builder.build(Helper.getTestProcessor());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate((SchemaBuilder) null);
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("schema"));
}
}
@Test
public void testInvalidSchematron() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("schematron"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid").source(URI.create("DoesNotExist")));
builder.build(Helper.getTestProcessor());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid").source(URI.create("DoesNotExist")));
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("schematron"));
}
}
@Test
public void testInsufficientSchematron() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("schematron"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid"));
builder.build(Helper.getTestProcessor());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).validate(schematron("invalid"));
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("schematron"));
}
}
@Test
public void testNoReport() {
this.exceptions.expect(IllegalStateException.class);
this.exceptions.expectMessage(Matchers.containsString("report"));
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).with(report("invalid"));
builder.build(Helper.getTestProcessor());
try {
final ConfigurationBuilder builder = createSimpleConfiguration();
builder.getScenarios().get(0).with(report("invalid"));
builder.build(Helper.getTestProcessor());
fail();
} catch (final IllegalStateException ex) {
assertTrue(ex.getMessage().contains("report"));
}
}
@Test

View file

@ -24,9 +24,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Helper.Simple;
@ -43,9 +41,6 @@ import net.sf.saxon.s9api.XPathExecutable;
*/
public class ScenarioBuilderTest {
@Rule
public ExpectedException exceptions = ExpectedException.none();
@Test
public void simpleValid() {
final Result<Scenario, String> result = createScenario().build(Simple.createContentRepository());
@ -161,7 +156,7 @@ public class ScenarioBuilderTest {
@Test
public void testBasicAttributes() {
final ContentRepository repository = Simple.createContentRepository();
final String random = RandomStringUtils.random(5);
final String random = RandomStringUtils.secure().next(5);
final ScenarioBuilder builder = createScenario();
builder.name(random).description(random);
final Result<Scenario, String> result = builder.build(repository);

View file

@ -28,7 +28,6 @@ import org.junit.Test;
import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.model.Result;
import net.sf.saxon.s9api.XPathExecutable;
/**
@ -40,7 +39,7 @@ public class XPathBuilderTest {
@Test
public void testSimpleString() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final XPathBuilder b = new XPathBuilder(name);
b.setXpath("//*");
final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository());
@ -54,7 +53,7 @@ public class XPathBuilderTest {
@Test
public void testStringWithNamespace() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final XPathBuilder b = new XPathBuilder(name);
final Map<String, String> ns = new HashMap<>();
ns.put("p", "http://somens");
@ -69,7 +68,7 @@ public class XPathBuilderTest {
@Test
public void testStringWithUnknownNamespace() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final XPathBuilder b = new XPathBuilder(name);
final Map<String, String> ns = new HashMap<>();
ns.put("p", "http://somens");
@ -82,7 +81,7 @@ public class XPathBuilderTest {
@Test
public void testExecutable() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final ContentRepository repository = Simple.createContentRepository();
final XPathExecutable xpath = repository.createXPath("//*", Collections.emptyMap());
final XPathBuilder b = new XPathBuilder(name);
@ -96,7 +95,7 @@ public class XPathBuilderTest {
@Test
public void testExecutableWithNamespace() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final ContentRepository repository = Simple.createContentRepository();
final Map<String, String> ns = new HashMap<>();
ns.put("p", "http://somens");
@ -123,7 +122,7 @@ public class XPathBuilderTest {
@Test
public void testNoConfig() {
final String name = RandomStringUtils.randomAlphanumeric(5);
final String name = RandomStringUtils.secure().nextAlphanumeric(5);
final XPathBuilder b = new XPathBuilder(name);
final Result<XPathExecutable, String> result = b.build(Simple.createContentRepository());
assertThat(result).isNotNull();

View file

@ -15,6 +15,7 @@ import net.sf.saxon.lib.UnparsedTextURIResolver;
public class MiscDocExampleCodes {
@SuppressWarnings("unused")
void m1() {
final Configuration config = Configuration.load(URI.create("myscenarios.xml")).setResolvingMode(ResolvingMode.STRICT_LOCAL)
.build(ProcessorProvider.getProcessor());
@ -43,6 +44,7 @@ public class MiscDocExampleCodes {
}
}
@SuppressWarnings("unused")
void m2() {
final Configuration config = Configuration.load(URI.create("myscenarios.xml"))
.setResolvingStrategy(new MyCustomResolvingConfigurationStrategy()).build(ProcessorProvider.getProcessor());

View file

@ -19,6 +19,7 @@ import de.kosit.validationtool.impl.xml.ProcessorProvider;
*/
public class MyValidator {
@SuppressWarnings("unused")
public static void main(final String[] args) {
final Configuration config = Configuration.create().name("myconfiguration")
.with(scenario("firstScenario").match("//myNode").validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))

View file

@ -20,6 +20,7 @@ import de.kosit.validationtool.impl.xml.ProcessorProvider;
*/
public class StandardExample {
@SuppressWarnings("unused")
public void run(final Path testDocument) throws URISyntaxException {
// Load scenarios.xml from classpath
final URL scenarios = this.getClass().getClassLoader().getResource("examples/simple/scenarios-with-relative-paths.xml");

View file

@ -28,12 +28,9 @@ import java.util.Map;
import javax.xml.validation.Schema;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper.Simple;
import net.sf.saxon.s9api.XPathExecutable;
import net.sf.saxon.s9api.XsltExecutable;
@ -46,9 +43,6 @@ public class ContentRepositoryTest {
private ContentRepository repository;
@Rule
public ExpectedException exception = ExpectedException.none();
@Before
public void setup() {
this.repository = Simple.createContentRepository();
@ -60,9 +54,8 @@ public class ContentRepositoryTest {
assertThat(schema).isNotNull();
}
@Test
@Test(expected = IllegalStateException.class)
public void testCreateSchemaNotExisting() throws Exception {
this.exception.expect(IllegalStateException.class);
this.repository.createSchema(Simple.NOT_EXISTING.toURL());
}
@ -72,9 +65,8 @@ public class ContentRepositoryTest {
assertThat(executable).isNotNull();
}
@Test
@Test(expected = IllegalStateException.class)
public void testLoadXSLTNotExisting() {
this.exception.expect(IllegalStateException.class);
this.repository.loadXsltScript(Simple.NOT_EXISTING);
}
@ -90,15 +82,13 @@ public class ContentRepositoryTest {
assertThat(xPath).isNotNull();
}
@Test
@Test(expected = IllegalStateException.class)
public void testXpathCreationWithoutNamespace() {
this.exception.expect(IllegalStateException.class);
this.repository.createXPath("//html:html", null);
}
@Test
@Test(expected = IllegalStateException.class)
public void testIllegalXpath() {
this.exception.expect(IllegalStateException.class);
this.repository.createXPath("kein Xpath Ausdruck", null);
}

View file

@ -16,16 +16,13 @@
package de.kosit.validationtool.impl;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.Serializable;
import java.net.URISyntaxException;
import java.net.URL;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper.Invalid;
import de.kosit.validationtool.impl.Helper.Simple;
@ -40,9 +37,6 @@ public class ConversionServiceTest {
private static final URL SCHEMA = ConversionServiceTest.class.getResource("/xsd/scenarios.xsd");
@Rule
public ExpectedException exception = ExpectedException.none();
private ConversionService service;
private ContentRepository repository;
@ -53,15 +47,13 @@ public class ConversionServiceTest {
this.repository = Simple.createContentRepository();
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testMarshalNull() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.writeXml(null);
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testMarshalUnknown() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.writeXml(new Serializable() {
});
}
@ -80,33 +72,28 @@ public class ConversionServiceTest {
assertThat(s.getName()).isEqualToIgnoringCase("HTML-TestSuite");
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalInvalidXml() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(Invalid.SCENARIOS, Scenarios.class, this.repository.createSchema(SCHEMA));
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalIllFormed() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(Invalid.SCENARIOS_ILLFORMED, Scenarios.class, this.repository.createSchema(SCHEMA));
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalEmpty() {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(null, Scenarios.class);
}
@Test
public void testUnmarshalUnknownType() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionExeption.class);
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalUnknownType() {
this.service.readXml(Simple.SCENARIOS, ConversionService.class);
}
@Test
public void testUnmarshalWithoutType() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionExeption.class);
@Test(expected = ConversionService.ConversionExeption.class)
public void testUnmarshalWithoutType() {
this.service.readXml(Simple.SCENARIOS, null);
}

View file

@ -26,9 +26,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.xml.RelativeUriResolver;
@ -49,9 +47,6 @@ public class RelativeUriResolverTest {
}
}
@Rule
public ExpectedException exception = ExpectedException.none();
private URIResolver resolver = new RelativeUriResolver(BASE);
@Test
@ -60,15 +55,13 @@ public class RelativeUriResolverTest {
assertThat(resource).isNotNull();
}
@Test
@Test(expected = TransformerException.class)
public void testNotExisting() throws TransformerException {
this.exception.expect(TransformerException.class);
this.resolver.resolve("ubl-0001", BASE.toASCIIString());
}
@Test
@Test(expected = TransformerException.class)
public void testOutOfPath() throws TransformerException {
this.exception.expect(TransformerException.class);
this.resolver.resolve("../results/report.xml", BASE.toASCIIString());
}

View file

@ -25,15 +25,12 @@ import java.util.ArrayList;
import java.util.HashMap;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.config.TestConfiguration;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.model.scenarios.ScenarioType;
import net.sf.saxon.s9api.XPathExecutable;
import net.sf.saxon.s9api.XdmNode;
@ -45,9 +42,6 @@ import net.sf.saxon.s9api.XdmNode;
public class ScenarioRepositoryTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private ScenarioRepository repository;
private TestConfiguration configInstance;
@ -107,9 +101,8 @@ public class ScenarioRepositoryTest {
assertThat(scenario.getObject().getName()).isEqualTo("fallback");
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNoConfiguration() {
this.expectedException.expect(IllegalArgumentException.class);
this.repository = new ScenarioRepository();
}

View file

@ -22,11 +22,8 @@ import java.net.URISyntaxException;
import java.net.URL;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.model.scenarios.Scenarios;
/**
@ -44,16 +41,10 @@ public class VersioningTest {
private static final URL NEW_VERSION = VersioningTest.class.getResource("/examples/versioning/scenarios-newversion.xml");
@Rule
public ExpectedException exception = ExpectedException.none();
private ConversionService service;
private ContentRepository repository;
@Before
public void setup() {
this.repository = Simple.createContentRepository();
this.service = new ConversionService();
}
@ -69,15 +60,13 @@ public class VersioningTest {
assertThat(result).isNotNull();
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testNewFeature() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
}
@Test
@Test(expected = ConversionService.ConversionExeption.class)
public void testNewVersion() throws URISyntaxException {
this.exception.expect(ConversionService.ConversionExeption.class);
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
}
}

View file

@ -20,15 +20,12 @@ import static de.kosit.validationtool.api.InputFactory.read;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import net.sf.saxon.s9api.XdmNode;
/**
@ -38,9 +35,6 @@ import net.sf.saxon.s9api.XdmNode;
*/
public class DocumentParseActionTest {
@Rule
public ExpectedException exception = ExpectedException.none();
private DocumentParseAction action;
@Before
@ -66,9 +60,8 @@ public class DocumentParseActionTest {
assertThat(result.isValid()).isFalse();
}
@Test
@Test(expected = IllegalArgumentException.class)
public void testNullInput() {
this.exception.expect(IllegalArgumentException.class);
this.action.parseDocument(null);
}

View file

@ -35,7 +35,6 @@ import javax.xml.validation.Validator;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXException;
import de.kosit.validationtool.api.Input;
@ -56,8 +55,6 @@ import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
*/
public class SchemaValidatorActionTest {
public ExpectedException expectedException = ExpectedException.none();
private SchemaValidationAction service;
@Before

View file

@ -25,9 +25,7 @@ import static org.mockito.Mockito.verify;
import javax.xml.XMLConstants;
import javax.xml.validation.SchemaFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
@ -51,9 +49,6 @@ public class BaseResolverConfigurationTest {
public static final String NOT_EXISTING_SCHEME = "not-existing-scheme";
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testIgnoreUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
final SchemaFactory sf = mock(SchemaFactory.class);
@ -62,9 +57,8 @@ public class BaseResolverConfigurationTest {
s.setInternalProperty(sf, true);
}
@Test
@Test(expected = IllegalStateException.class)
public void testFailOnUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
this.expectedException.expect(IllegalStateException.class);
final SchemaFactory sf = mock(SchemaFactory.class);
final TestResolvingStrategy s = new TestResolvingStrategy();
doThrow(new SAXNotRecognizedException("not supported")).when(sf).setProperty(any(), any());

View file

@ -21,9 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
import de.kosit.validationtool.impl.Helper.Resolving;
@ -35,9 +33,6 @@ import de.kosit.validationtool.impl.Helper.Resolving;
*/
public class RemoteResolvingStrategyTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testRemoteSchemaResolving() throws Exception {
final ResolvingConfigurationStrategy s = new RemoteResolvingStrategy();

View file

@ -16,8 +16,12 @@
package de.kosit.validationtool.impl.xml;
import static org.junit.Assert.assertNotNull;
import javax.xml.validation.SchemaFactory;
import org.junit.Test;
import de.kosit.validationtool.impl.ResolvingMode;
/**
@ -25,6 +29,10 @@ import de.kosit.validationtool.impl.ResolvingMode;
*/
public class SchemaProviderTest {
private final SchemaFactory schemaFactory = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
@Test
public void testBasic() {
final SchemaFactory schemaFactory = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
assertNotNull(schemaFactory);
}
}

View file

@ -17,14 +17,13 @@
package de.kosit.validationtool.impl.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.Assert.assertTrue;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXParseException;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
@ -37,16 +36,16 @@ import de.kosit.validationtool.impl.Helper.Resolving;
*/
public class StrictLocalResolvingTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testRemoteSchemaResolving() throws Exception {
this.expectedException.expect(SAXParseException.class);
this.expectedException.expectMessage(Matchers.containsString("schema_reference"));
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory();
schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL());
try {
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory();
schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL());
fail();
} catch (SAXParseException ex) {
assertTrue(ex.getMessage().contains("schema_reference"));
}
}
@Test

View file

@ -17,14 +17,13 @@
package de.kosit.validationtool.impl.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.Assert.assertTrue;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.xml.sax.SAXParseException;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
@ -37,16 +36,16 @@ import de.kosit.validationtool.impl.Helper.Resolving;
*/
public class StrictRelativeResolvingTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testRemoteSchemaResolving() throws Exception {
this.expectedException.expect(SAXParseException.class);
this.expectedException.expectMessage(Matchers.containsString("schema_reference"));
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory();
schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL());
try {
final ResolvingConfigurationStrategy s = new StrictLocalResolvingStrategy();
final SchemaFactory schemaFactory = s.createSchemaFactory();
schemaFactory.newSchema(Resolving.SCHEMA_WITH_REMOTE_REFERENCE.toURL());
fail();
} catch (SAXParseException ex) {
assertTrue(ex.getMessage().contains("schema_reference"));
}
}
@Test