Skip to content

Commit

Permalink
Add tests for constraint errors in log files
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Dec 14, 2023
1 parent dea09d3 commit 293c673
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/test/data/validator/logfile.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Info: validate data...
Info: assume unknown external objects
Info: first validation pass...
Info: second validation pass...
Info: validate mandatory constraint ModelA.TopicA.ClassA.ConstraintA...
Error: line 10: ModelA.TopicA.ClassA: tid 1: Mandatory Constraint ModelA.TopicA.ClassA.ConstraintA is not true.
Info: validate mandatory constraint ModelA.TopicA.ClassA.ConstraintB...
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ch.geowerkstatt.interlis.testbed.runner;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public final class ValidatorTest {
private static final String CONSTRAINT_A_NAME = "ModelA.TopicA.ClassA.ConstraintA";
private static final String CONSTRAINT_B_NAME = "ModelA.TopicA.ClassA.ConstraintB";
private static final Path BASE_PATH = Path.of("src/test/data/validator");
private static final Path LOG_FILE = BASE_PATH.resolve("logfile.log");

private TestOptions options;

@BeforeEach
public void setup() {
options = new TestOptions(BASE_PATH, Path.of("ilivalidator.jar"));
}

@Test
public void containsConstraintError() throws ValidatorException {
var validator = new InterlisValidator(options);

var result = validator.containsConstraintError(LOG_FILE, CONSTRAINT_A_NAME);

assertTrue(result, "The log file should contain an error for constraint A.");
}

@Test
public void noErrorForValidConstraint() throws ValidatorException, IOException {
var validator = new InterlisValidator(options);

var result = validator.containsConstraintError(LOG_FILE, CONSTRAINT_B_NAME);

assertFalse(result, "The log file should not contain an error for constraint B.");

try (var lines = Files.lines(LOG_FILE)) {
var hasConstraintInfo = lines.anyMatch(line -> line.startsWith("Info:") && line.contains(CONSTRAINT_B_NAME));
assertTrue(hasConstraintInfo, "The log file should contain an info message for the constraint.");
}
}
}

0 comments on commit 293c673

Please sign in to comment.