mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
some more tests
This commit is contained in:
parent
fcf3ff2bf1
commit
16dc45ab46
11 changed files with 257 additions and 46 deletions
|
|
@ -0,0 +1,88 @@
|
|||
package de.kosit.validationtool.config;
|
||||
|
||||
import static de.kosit.validationtool.config.ConfigurationBuilder.report;
|
||||
import static de.kosit.validationtool.config.ConfigurationBuilder.schematron;
|
||||
import static de.kosit.validationtool.config.SimpleConfigTest.createSimpleConfiguration;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test {@link ConfigurationBuilder}.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class ConfigurationBuilderTest {
|
||||
|
||||
public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
|
||||
|
||||
@Rule
|
||||
public ExpectedException exceptions = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testNoConfiguration() {
|
||||
this.exceptions.expect(IllegalStateException.class);
|
||||
new ConfigurationBuilder().build();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDate() {
|
||||
assertThat(createSimpleConfiguration().date(EPOCH).build().getDate()).isEqualTo("1970-01-01");
|
||||
assertThat(createSimpleConfiguration().date(new Date(EPOCH.toEpochDay())).build().getDate()).isEqualTo("1970-01-01");
|
||||
assertThat(createSimpleConfiguration().date((Date) null).build().getDate()).isEqualTo(LocalDate.now().toString());
|
||||
assertThat(createSimpleConfiguration().date((LocalDate) null).build().getDate()).isEqualTo(LocalDate.now().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package de.kosit.validationtool.config;
|
||||
|
||||
import static de.kosit.validationtool.config.SimpleConfigTest.createScenarioConfiguration;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.Scenario;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
|
||||
/**
|
||||
* Test {@link ScenarioBuilder}.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class ScenarioBuilderTest {
|
||||
|
||||
@Rule
|
||||
public ExpectedException exceptions = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void simpleValid() {
|
||||
final Result<Scenario, String> result = createScenarioConfiguration().build(Simple.createContentRepository());
|
||||
assertThat(result.isValid()).isTrue();
|
||||
assertThat(result.getObject().getConfiguration()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSchema() {
|
||||
final ScenarioBuilder builder = createScenarioConfiguration();
|
||||
builder.validate((SchemaBuilder) null);
|
||||
final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
|
||||
assertThat(result.isValid()).isFalse();
|
||||
assertThat(result.getErrors()).anyMatch(e -> e.contains("schema"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoMatch() {
|
||||
final ScenarioBuilder builder = createScenarioConfiguration();
|
||||
builder.match((String) null);
|
||||
final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
|
||||
assertThat(result.isValid()).isFalse();
|
||||
assertThat(result.getErrors()).anyMatch(e -> e.contains("match"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidMatch() {
|
||||
final ScenarioBuilder builder = createScenarioConfiguration();
|
||||
builder.match("/////");
|
||||
final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
|
||||
assertThat(result.isValid()).isFalse();
|
||||
assertThat(result.getErrors()).anyMatch(e -> e.contains("match"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoAccept() {
|
||||
final ScenarioBuilder builder = createScenarioConfiguration();
|
||||
builder.acceptWith((String) null);
|
||||
final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
|
||||
assertThat(result.isValid()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidAccept() {
|
||||
final ScenarioBuilder builder = createScenarioConfiguration();
|
||||
builder.acceptWith("/////");
|
||||
final Result<Scenario, String> result = builder.build(Simple.createContentRepository());
|
||||
assertThat(result.isValid()).isFalse();
|
||||
assertThat(result.getErrors()).anyMatch(e -> e.contains("accept"));
|
||||
}
|
||||
}
|
||||
|
|
@ -25,25 +25,26 @@ public class SimpleConfigTest {
|
|||
@Test
|
||||
public void testSimpleWithApi() {
|
||||
//@formatter:off
|
||||
final Configuration config =
|
||||
Configuration.create().name("Simple-API")
|
||||
.with(scenario("simple")
|
||||
.validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
|
||||
.with(report("Report für eRechnung").source("report.xsl"))
|
||||
.acceptWith("count(//test:rejected) = 0")
|
||||
.declareNamespace("cri", "http://www.xoev.de/de/validator/framework/1/createreportinput")
|
||||
.declareNamespace("rpt", "http://validator.kosit.de/test-report")
|
||||
.declareNamespace("test", "http://validator.kosit.de/test-sample")
|
||||
.match("/test:simple")
|
||||
// .description("awesome api")
|
||||
)
|
||||
.with(fallback().name("default").source("report.xsl"))
|
||||
|
||||
.resolvingMode(ResolvingMode.STRICT_RELATIVE)
|
||||
.useRepository(Simple.REPOSITORY_URI).build();
|
||||
final Configuration config = createSimpleConfiguration().build();
|
||||
//@formatter:on
|
||||
final DefaultCheck check = new DefaultCheck(config);
|
||||
final Result result = check.checkInput(InputFactory.read(Simple.SIMPLE_VALID));
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
static ConfigurationBuilder createSimpleConfiguration() {
|
||||
return Configuration.create().name("Simple-API").with(createScenarioConfiguration()
|
||||
// .description("awesome api")
|
||||
).with(fallback().name("default").source("report.xsl"))
|
||||
|
||||
.resolvingMode(ResolvingMode.STRICT_RELATIVE).useRepository(Simple.REPOSITORY_URI);
|
||||
}
|
||||
|
||||
static ScenarioBuilder createScenarioConfiguration() {
|
||||
return scenario("simple").validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
|
||||
.with(report("Report für eRechnung").source("report.xsl")).acceptWith("count(//test:rejected) = 0")
|
||||
.declareNamespace("cri", "http://www.xoev.de/de/validator/framework/1/createreportinput")
|
||||
.declareNamespace("rpt", "http://validator.kosit.de/test-report")
|
||||
.declareNamespace("test", "http://validator.kosit.de/test-sample").match("/test:simple");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue