1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-16 17:21:08 +01:00

Implement lookup mechanism using sqlite

This commit is contained in:
Paul Schaub 2022-02-14 15:00:15 +01:00
parent c4898ed26a
commit 0e4cf1c166
12 changed files with 419 additions and 8 deletions

View file

@ -20,6 +20,8 @@ dependencies {
// Logging
testImplementation "ch.qos.logback:logback-classic:$logbackVersion"
testImplementation project(":pgp-cert-d-java-jdbc-sqlite-lookup")
api project(":pgp-certificate-store")
}

View file

@ -4,6 +4,10 @@
package pgp.cert_d;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
@ -12,6 +16,7 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import pgp.cert_d.jdbc.sqlite.SqliteSubkeyLookup;
import pgp.certificate_store.SubkeyLookup;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -22,8 +27,15 @@ public class SubkeyLookupTest {
private static final List<SubkeyLookup> testSubjects = new ArrayList<>();
@BeforeAll
public static void setupLookupTestSubjects() {
testSubjects.add(new InMemorySubkeyLookup());
public static void setupLookupTestSubjects() throws IOException, SQLException {
InMemorySubkeyLookup inMemorySubkeyLookup = new InMemorySubkeyLookup();
testSubjects.add(inMemorySubkeyLookup);
File sqliteDatabase = Files.createTempFile("subkeyLookupTest", ".db").toFile();
sqliteDatabase.createNewFile();
sqliteDatabase.deleteOnExit();
SqliteSubkeyLookup sqliteSubkeyLookup = SqliteSubkeyLookup.forDatabaseFile(sqliteDatabase);
testSubjects.add(sqliteSubkeyLookup);
}
@AfterAll
@ -37,7 +49,7 @@ public class SubkeyLookupTest {
@ParameterizedTest
@MethodSource("provideSubkeyLookupsForTest")
public void testInsertGet(SubkeyLookup subject) {
public void testInsertGet(SubkeyLookup subject) throws IOException {
// Initially all null
assertNull(subject.getIdentifierForSubkeyId(123));
@ -65,6 +77,7 @@ public class SubkeyLookupTest {
subject.storeIdentifierForSubkeyId(123, "d1a66e1a23b182c9980f788cfbfcc82a015e7330");
assertEquals("d1a66e1a23b182c9980f788cfbfcc82a015e7330", subject.getIdentifierForSubkeyId(123));
// TODO: Decide on expected result and fix test
// assertEquals("d1a66e1a23b182c9980f788cfbfcc82a015e7330", subject.getIdentifierForSubkeyId(123));
}
}