Refactor TestSuiteTestRunner

This commit is contained in:
Paul Schaub 2022-03-13 16:23:42 +01:00
parent d50df99946
commit a99f0fef71
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 20 additions and 10 deletions

View File

@ -6,12 +6,15 @@ package pgp.wkd.cli.test_suite;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.logging.Logger;
import org.junit.platform.commons.logging.LoggerFactory;
import pgp.wkd.cli.WKDCLI;
import pgp.wkd.cli.command.Fetch;
import pgp.wkd.test_suite.TestCase;
import pgp.wkd.test_suite.TestSuite;
import pgp.wkd.test_suite.TestSuiteGenerator;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
@ -20,32 +23,39 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class TestSuiteTestRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(TestSuiteTestRunner.class);
private static TestSuite suite;
@BeforeAll
public static void setup() throws Exception {
Path tempDir = Files.createTempDirectory("wkd-test");
tempDir.toFile().deleteOnExit();
Fetch.fetcher = new DirectoryBasedWkdFetcher(tempDir);
// Temporary, directory based WKD
Path tempPath = Files.createTempDirectory("wkd-test");
File tempFile = tempPath.toFile();
tempFile.deleteOnExit();
// Generate test certificates inside the temp wkd
String domain = "example.com";
TestSuiteGenerator generator = new TestSuiteGenerator(domain);
suite = generator.generateTestSuiteInDirectory(tempDir.toFile(), TestSuiteGenerator.Method.direct);
suite = generator.generateTestSuiteInDirectory(tempFile, TestSuiteGenerator.Method.direct);
// Fetch certificates from a local directory instead of the internetzzz.
Fetch.fetcher = new DirectoryBasedWkdFetcher(tempPath);
}
@Test
public void runTestsAgainstTestSuite() {
void runTestsAgainstTestSuite() {
for (TestCase testCase : suite.getTestCases()) {
System.out.println("Executing test " + testCase.getTestTitle());
LOGGER.info(() -> "Execute Test Case '" + testCase.getTestTitle() + "'");
String mail = testCase.getLookupMailAddress();
int exitCode = WKDCLI.execute(new String[] {
"fetch", "--armor", testCase.getLookupMailAddress()
"fetch", "--armor", mail
});
if (testCase.isExpectSuccess()) {
assertEquals(0, exitCode);
assertEquals(0, exitCode, testCase.getTestDescription());
} else {
assertNotEquals(0, exitCode);
assertNotEquals(0, exitCode, testCase.getTestDescription());
}
}
}