more tests

This commit is contained in:
Andreas Penski (init) 2020-05-01 13:47:40 +02:00
parent 7abc072911
commit 1a001a1af4
6 changed files with 115 additions and 4 deletions

View file

@ -57,7 +57,7 @@ public class SchemaBuilder implements Builder<Pair<ValidateWithXmlSchema, Schema
final ValidateWithXmlSchema o = new ValidateWithXmlSchema();
final ResourceType r = new ResourceType();
r.setName(isNotEmpty(this.name) ? this.name : DEFAULT_NAME);
r.setLocation(this.schemaLocation.toASCIIString());
r.setLocation(this.schemaLocation != null ? this.schemaLocation.toASCIIString() : "manuelly configured");
o.getResource().add(r);
return o;
}

View file

@ -81,7 +81,14 @@ public class RelativeUriResolver implements URIResolver {
}
private boolean isUnderBaseUri(final URI resolved) {
final String base = this.baseUri.toASCIIString().replaceAll("file:/+", "");
return isUnderBaseUri(resolved, this.baseUri);
}
private static boolean isUnderBaseUri(final URI resolved, final URI baseUri) {
if (resolved == null || baseUri == null) {
return false;
}
final String base = baseUri.toASCIIString().replaceAll("file:/+", "");
final String r = resolved.toASCIIString().replaceAll("file:/+", "");
return r.startsWith(base);
}

View file

@ -51,6 +51,7 @@ public class CommandlineApplicationTest {
private final Path output = Paths.get("target/test-output");
@Before
public void setup() throws IOException {
this.commandLine = new CommandLine();
@ -203,4 +204,12 @@ public class CommandlineApplicationTest {
assertThat(this.commandLine.getErrorOutput()).contains("at de.kosit.validationtool");
}
@Test
public void testPrintMemoryStats() {
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() };
CommandLineApplication.mainProgram(args);
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
assertThat(this.commandLine.getErrorOutput()).contains("total");
}
}

View file

@ -0,0 +1,93 @@
package de.kosit.validationtool.config;
import static de.kosit.validationtool.config.ConfigurationBuilder.schema;
import static org.assertj.core.api.Assertions.assertThat;
import java.nio.file.Paths;
import javax.xml.validation.Schema;
import org.apache.commons.lang3.tuple.Pair;
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 de.kosit.validationtool.model.scenarios.ResourceType;
import de.kosit.validationtool.model.scenarios.ValidateWithXmlSchema;
/**
* Tests {@link SchemaBuilder}.
*
* @author Andreas Penski
*/
public class SchemaBuilderTest {
@Test
public void testBuildSchema() {
final SchemaBuilder builder = schema(Simple.SCHEMA);
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isTrue();
}
@Test
public void testNoConfiguration() {
final SchemaBuilder builder = schema("no-config");
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isFalse();
}
@Test
public void testBuildNamedSchema() {
final SchemaBuilder builder = schema("myname").schemaLocation(Simple.SCHEMA);
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isTrue();
assertThat(result.getObject().getKey().getResource().stream().map(ResourceType::getName).findFirst().get()).isEqualTo("myname");
}
@Test
public void testInvalidSchema() {
final SchemaBuilder builder = schema("myname").schemaLocation(Simple.INVALID);
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isFalse();
}
@Test
public void testNonExisting() {
final SchemaBuilder builder = schema("myname").schemaLocation(Simple.REPOSITORY_URI.resolve("doesNotExist.xsd"));
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isFalse();
}
@Test
public void testPath() {
final SchemaBuilder builder = schema("myname").schemaLocation(Paths.get(Simple.SCHEMA));
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isTrue();
}
@Test
public void testStringLocation() {
final SchemaBuilder builder = schema("myname").schemaLocation("simple.xsd");
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isTrue();
}
@Test
public void testPrecompiled() {
final ContentRepository repository = Simple.createContentRepository();
final Schema schema = repository.createSchema(Simple.SCHEMA);
final SchemaBuilder builder = schema("myname").schema(schema);
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(repository);
assertThat(result).isNotNull();
assertThat(result.isValid()).isTrue();
}
}

View file

@ -77,6 +77,8 @@ public class Helper {
public static final URI REPORT_XSL = REPOSITORY_URI.resolve("report.xsl");
public static final URI SCHEMA = REPOSITORY_URI.resolve("simple.xsd");
public static final ContentRepository createContentRepository() {
final ResolvingConfigurationStrategy strategy = ResolvingMode.STRICT_RELATIVE.getStrategy();
return new ContentRepository(strategy, Simple.REPOSITORY_URI);
@ -84,7 +86,7 @@ public class Helper {
public static URI getSchemaLocation() {
return ROOT.resolve("repository/simple.xsd");
return SCHEMA;
}
}

View file

@ -58,7 +58,7 @@ public class RelativeUriResolverTest {
private URIResolver resolver = new RelativeUriResolver(BASE);
@Test
public void testSucces() throws TransformerException {
public void testSuccess() throws TransformerException {
final Source resource = this.resolver.resolve("ubl-0001.xml", BASE.toASCIIString());
assertThat(resource).isNotNull();
}