From 1a001a1af46addbc91f2854b5351f798f5e16dd6 Mon Sep 17 00:00:00 2001 From: "Andreas Penski (init)" Date: Fri, 1 May 2020 13:47:40 +0200 Subject: [PATCH] more tests --- .../validationtool/config/SchemaBuilder.java | 2 +- .../impl/xml/RelativeUriResolver.java | 9 +- .../cmd/CommandlineApplicationTest.java | 9 ++ .../config/SchemaBuilderTest.java | 93 +++++++++++++++++++ .../de/kosit/validationtool/impl/Helper.java | 4 +- .../impl/RelativeUriResolverTest.java | 2 +- 6 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 src/test/java/de/kosit/validationtool/config/SchemaBuilderTest.java diff --git a/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java b/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java index ca51060..3c7aa1d 100644 --- a/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java +++ b/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java @@ -57,7 +57,7 @@ public class SchemaBuilder implements Builder, 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, 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, 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, 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, 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, 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, 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, String> result = builder.build(repository); + assertThat(result).isNotNull(); + assertThat(result.isValid()).isTrue(); + } +} diff --git a/src/test/java/de/kosit/validationtool/impl/Helper.java b/src/test/java/de/kosit/validationtool/impl/Helper.java index a19a61c..d0ca817 100644 --- a/src/test/java/de/kosit/validationtool/impl/Helper.java +++ b/src/test/java/de/kosit/validationtool/impl/Helper.java @@ -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; } } diff --git a/src/test/java/de/kosit/validationtool/impl/RelativeUriResolverTest.java b/src/test/java/de/kosit/validationtool/impl/RelativeUriResolverTest.java index 2106f65..925fa26 100644 --- a/src/test/java/de/kosit/validationtool/impl/RelativeUriResolverTest.java +++ b/src/test/java/de/kosit/validationtool/impl/RelativeUriResolverTest.java @@ -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(); }