mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
19-FixProbableBugs
This commit is contained in:
parent
b5bd901b12
commit
64b84508ed
10 changed files with 38 additions and 19 deletions
|
|
@ -76,7 +76,7 @@ public class Daemon {
|
||||||
* @param config the configuration to use
|
* @param config the configuration to use
|
||||||
*/
|
*/
|
||||||
public void startServer(final Processor processor, final Configuration... config) {
|
public void startServer(final Processor processor, final Configuration... config) {
|
||||||
HttpServer server = null;
|
HttpServer server;
|
||||||
try {
|
try {
|
||||||
final ConversionService healthConverter = new ConversionService();
|
final ConversionService healthConverter = new ConversionService();
|
||||||
healthConverter.initialize(HealthType.class.getPackage());
|
healthConverter.initialize(HealthType.class.getPackage());
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class RoutingHandler extends BaseHandler {
|
||||||
} else if (requestMethod.equals("GET")) {
|
} else if (requestMethod.equals("GET")) {
|
||||||
this.guiHandler.handle(exchange);
|
this.guiHandler.handle(exchange);
|
||||||
} else {
|
} else {
|
||||||
error(exchange, 405, String.format("Method % not supported", requestMethod));
|
error(exchange, 405, String.format("Method %s not supported", requestMethod));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,8 @@ public class ContentRepository {
|
||||||
|
|
||||||
public Transformation createIdentityTransformation() {
|
public Transformation createIdentityTransformation() {
|
||||||
final URL url = ContentRepository.class.getClassLoader().getResource("transform/identity.xsl");
|
final URL url = ContentRepository.class.getClassLoader().getResource("transform/identity.xsl");
|
||||||
|
try {
|
||||||
|
assert url != null;
|
||||||
try ( final InputStream input = url.openStream() ) {
|
try ( final InputStream input = url.openStream() ) {
|
||||||
final XsltCompiler xsltCompiler = getProcessor().newXsltCompiler();
|
final XsltCompiler xsltCompiler = getProcessor().newXsltCompiler();
|
||||||
final XsltExecutable executable = xsltCompiler.compile(new StreamSource(input));
|
final XsltExecutable executable = xsltCompiler.compile(new StreamSource(input));
|
||||||
|
|
@ -274,6 +276,7 @@ public class ContentRepository {
|
||||||
resource.setName("identity");
|
resource.setName("identity");
|
||||||
resource.setLocation(url.toString());
|
resource.setLocation(url.toString());
|
||||||
return new Transformation(executable, resource);
|
return new Transformation(executable, resource);
|
||||||
|
}
|
||||||
} catch (final IOException | SaxonApiException e) {
|
} catch (final IOException | SaxonApiException e) {
|
||||||
throw new IllegalStateException("Error creating identity transformation", e);
|
throw new IllegalStateException("Error creating identity transformation", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import javax.xml.validation.SchemaFactory;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andreas Penski
|
* @author Andreas Penski
|
||||||
|
|
@ -43,7 +44,7 @@ public class SchemaProvider {
|
||||||
public static Schema getReportInputSchema() {
|
public static Schema getReportInputSchema() {
|
||||||
if (reportInputSchema == null) {
|
if (reportInputSchema == null) {
|
||||||
final SchemaFactory sf = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
|
final SchemaFactory sf = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
|
||||||
final Source source = resolve(SchemaProvider.class.getResource("/xsd/createReportInput.xsd"));
|
final Source source = resolve(Objects.requireNonNull(SchemaProvider.class.getResource("/xsd/createReportInput.xsd")));
|
||||||
reportInputSchema = createSchema(sf, new Source[] { source }, new ClassPathResourceResolver("/xsd"));
|
reportInputSchema = createSchema(sf, new Source[] { source }, new ClassPathResourceResolver("/xsd"));
|
||||||
}
|
}
|
||||||
return reportInputSchema;
|
return reportInputSchema;
|
||||||
|
|
@ -79,7 +80,7 @@ public class SchemaProvider {
|
||||||
*/
|
*/
|
||||||
public static Schema getScenarioSchema() {
|
public static Schema getScenarioSchema() {
|
||||||
final SchemaFactory sf = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
|
final SchemaFactory sf = ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory();
|
||||||
return createSchema(sf, resolve(SchemaProvider.class.getResource("/xsd/scenarios.xsd")));
|
return createSchema(sf, resolve(Objects.requireNonNull(SchemaProvider.class.getResource("/xsd/scenarios.xsd"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ public class ClassPathResourceResolver implements LSResourceResolver {
|
||||||
: ClassPathResourceResolver.class.getResource(resolved.toASCIIString());
|
: ClassPathResourceResolver.class.getResource(resolved.toASCIIString());
|
||||||
final LSInputImpl input = new LSInputImpl(publicId, systemId, resolved.toASCIIString());
|
final LSInputImpl input = new LSInputImpl(publicId, systemId, resolved.toASCIIString());
|
||||||
// intentionally not closed, since xml stack wants it open upon return
|
// intentionally not closed, since xml stack wants it open upon return
|
||||||
|
assert resource != null;
|
||||||
final InputStream in = resource.openStream();
|
final InputStream in = resource.openStream();
|
||||||
input.setByteStream(in);
|
input.setByteStream(in);
|
||||||
return input;
|
return input;
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ public class CheckAssertionActionTest {
|
||||||
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));
|
||||||
|
|
||||||
|
assert SAMPLE_ASSERTIONS != null;
|
||||||
final Assertions assertions = Helper.load(SAMPLE_ASSERTIONS, Assertions.class);
|
final Assertions assertions = Helper.load(SAMPLE_ASSERTIONS, Assertions.class);
|
||||||
final CheckAssertionAction a = new CheckAssertionAction(assertions, TestObjectFactory.createProcessor());
|
final CheckAssertionAction a = new CheckAssertionAction(assertions, TestObjectFactory.createProcessor());
|
||||||
a.check(bag);
|
a.check(bag);
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,8 @@ public class SchemaBuilderTest {
|
||||||
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();
|
||||||
assertThat(result.isValid()).isTrue();
|
assertThat(result.isValid()).isTrue();
|
||||||
assertThat(result.getObject().getKey().getResource().stream().map(ResourceType::getName).findFirst().get()).isEqualTo("myname");
|
assertThat(result.getObject().getKey().getResource().stream().map(ResourceType::getName).findFirst().orElse(null))
|
||||||
|
.isEqualTo("myname");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import static org.junit.Assert.assertThrows;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.xml.transform.Source;
|
import javax.xml.transform.Source;
|
||||||
import javax.xml.transform.TransformerException;
|
import javax.xml.transform.TransformerException;
|
||||||
|
|
@ -42,7 +43,7 @@ public class RelativeUriResolverTest {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
BASE = RelativeUriResolver.class.getResource("/examples/assertions/").toURI();
|
BASE = Objects.requireNonNull(RelativeUriResolver.class.getResource("/examples/assertions/")).toURI();
|
||||||
} catch (final URISyntaxException e) {
|
} catch (final URISyntaxException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
|
|
@ -68,16 +69,20 @@ public class RelativeUriResolverTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClasspathLocal() throws URISyntaxException, TransformerException {
|
public void testClasspathLocal() throws URISyntaxException, TransformerException {
|
||||||
this.resolver = new RelativeUriResolver(RelativeUriResolver.class.getClassLoader().getResource("loading").toURI());
|
this.resolver = new RelativeUriResolver(
|
||||||
|
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");
|
||||||
|
assert moz != null;
|
||||||
final Source resolved = this.resolver.resolve("./resources/reference.xsd", moz.toURI().toASCIIString());
|
final Source resolved = this.resolver.resolve("./resources/reference.xsd", moz.toURI().toASCIIString());
|
||||||
assertThat(resolved).isNotNull();
|
assertThat(resolved).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClasspathJAR() throws URISyntaxException, TransformerException {
|
public void testClasspathJAR() throws URISyntaxException, TransformerException {
|
||||||
this.resolver = new RelativeUriResolver(RelativeUriResolver.class.getClassLoader().getResource("packaged").toURI());
|
this.resolver = new RelativeUriResolver(
|
||||||
|
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");
|
||||||
|
assert moz != null;
|
||||||
final Source resolved = this.resolver.resolve("./resources/reference.xsd", moz.toURI().toASCIIString());
|
final Source resolved = this.resolver.resolve("./resources/reference.xsd", moz.toURI().toASCIIString());
|
||||||
assertThat(resolved).isNotNull();
|
assertThat(resolved).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,25 +50,31 @@ public class VersioningTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBase() throws URISyntaxException {
|
public void testBase() throws URISyntaxException {
|
||||||
|
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 {
|
public void testFrameworkIncrement() throws URISyntaxException {
|
||||||
|
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() {
|
public void testNewFeature() {
|
||||||
assertThrows(ConversionService.ConversionException.class,
|
assertThrows(ConversionService.ConversionException.class, () -> {
|
||||||
() -> this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()));
|
assert NEW_FEATURE != null;
|
||||||
|
this.service.readXml(NEW_FEATURE.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNewVersion() {
|
public void testNewVersion() {
|
||||||
assertThrows(ConversionService.ConversionException.class,
|
assertThrows(ConversionService.ConversionException.class, () -> {
|
||||||
() -> this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema()));
|
assert NEW_VERSION != null;
|
||||||
|
this.service.readXml(NEW_VERSION.toURI(), Scenarios.class, SchemaProvider.getScenarioSchema());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ public class SaxonSecurityTest {
|
||||||
final RelativeUriResolver resolver = new RelativeUriResolver(Simple.REPOSITORY_URI);
|
final RelativeUriResolver resolver = new RelativeUriResolver(Simple.REPOSITORY_URI);
|
||||||
// TODO: Replace call to deprecated method.
|
// TODO: Replace call to deprecated method.
|
||||||
compiler.setURIResolver(resolver);
|
compiler.setURIResolver(resolver);
|
||||||
|
assert resource != null;
|
||||||
final XsltExecutable executable = compiler.compile(new StreamSource(resource.openStream()));
|
final XsltExecutable executable = compiler.compile(new StreamSource(resource.openStream()));
|
||||||
final XsltTransformer transformer = executable.load();
|
final XsltTransformer transformer = executable.load();
|
||||||
final Source document = InputFactory.read("<root/>".getBytes(), "dummy").getSource();
|
final Source document = InputFactory.read("<root/>".getBytes(), "dummy").getSource();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue