Skip to content

Commit

Permalink
Use first xtf file in testbed as base data
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Dec 6, 2023
1 parent 3ec9be1 commit 9df5f36
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
25 changes: 20 additions & 5 deletions src/main/java/ch/geowerkstatt/interlis/testbed/runner/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;

public final class Runner {
private static final Logger LOGGER = LogManager.getLogger();

Expand All @@ -28,7 +32,7 @@ public boolean run() {
LOGGER.info("Starting validation of testbed at " + options.basePath());

try {
if (!validateSuccessfulData()) {
if (!validateBaseData()) {
LOGGER.error("Validation of base data failed.");
return false;
}
Expand All @@ -41,9 +45,20 @@ public boolean run() {
return true;
}

private boolean validateSuccessfulData() throws ValidatorException {
var filePath = options.baseDataFilePath();
LOGGER.info("Validating base data file " + filePath);
return validator.validate(filePath);
private boolean validateBaseData() throws ValidatorException {
Optional<Path> filePath;
try {
filePath = options.baseDataFilePath();
} catch (IOException e) {
throw new ValidatorException(e);
}

if (filePath.isEmpty()) {
LOGGER.error("No base data file found.");
return false;
}

LOGGER.info("Validating base data file " + filePath.get());
return validator.validate(filePath.get());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package ch.geowerkstatt.interlis.testbed.runner;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.stream.Stream;

public record TestOptions(Path basePath, Path ilivalidatorPath) {
private static final String BASE_DATA_FILENAME = "Successful_Data.xtf";
private static final String DATA_FILE_EXTENSION = ".xtf";
private static final String OUTPUT_DIR_NAME = "output";

/**
Expand All @@ -21,8 +25,10 @@ public record TestOptions(Path basePath, Path ilivalidatorPath) {
*
* @return the path to the base data file.
*/
public Path baseDataFilePath() {
return basePath.resolve(BASE_DATA_FILENAME);
public Optional<Path> baseDataFilePath() throws IOException {
try (var dataFiles = findDataFiles(basePath)) {
return dataFiles.findFirst();
}
}

/**
Expand All @@ -33,4 +39,8 @@ public Path baseDataFilePath() {
public Path outputPath() {
return basePath.resolve(OUTPUT_DIR_NAME);
}

private static Stream<Path> findDataFiles(Path basePath) throws IOException {
return Files.find(basePath, 1, (path, attributes) -> path.getFileName().toString().toLowerCase().endsWith(DATA_FILE_EXTENSION));
}
}
10 changes: 10 additions & 0 deletions src/test/data/testbed/data.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<ili:transfer xmlns:ili="http://www.interlis.ch/xtf/2.4/INTERLIS">
<ili:headersection>
<ili:models>
</ili:models>
<ili:sender>interlis-testbed-runner</ili:sender>
</ili:headersection>
<ili:datasection>
</ili:datasection>
</ili:transfer>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -33,7 +34,7 @@ public void teardown() {
}

@Test
public void runValidatesBaseData() {
public void runValidatesBaseData() throws IOException {
var validatedFiles = new ArrayList<Path>();

var runner = new Runner(options, file -> {
Expand All @@ -45,10 +46,12 @@ public void runValidatesBaseData() {

assertTrue(runResult, "Testbed run should have been successful.");

var baseDataFile = Path.of(BASE_PATH, "Successful_Data.xtf").toAbsolutePath().normalize();
assertEquals(baseDataFile, options.baseDataFilePath());
var expectedBaseDataFile = Path.of(BASE_PATH, "data.xtf").toAbsolutePath().normalize();
var baseDataFile = options.baseDataFilePath();
assertFalse(baseDataFile.isEmpty(), "Base data file should have been found.");
assertEquals(expectedBaseDataFile, baseDataFile.get());

var expectedFiles = List.of(baseDataFile);
var expectedFiles = List.of(expectedBaseDataFile);
assertIterableEquals(expectedFiles, validatedFiles);

var errors = appender.getMessages()
Expand Down

0 comments on commit 9df5f36

Please sign in to comment.