diff --git a/build.gradle b/build.gradle index c44bd4b7..79c007f6 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,7 @@ buildscript { // https://github.com/FasterXML/jackson/wiki/Jackson-Releases jacksonVersion = '2.16.1' // https://github.com/FasterXML/jackson-databind/tags // retrofit is why we need allow-opens. context: https://stackoverflow.com/questions/60915381/retrofit2-maven-project-illegal-reflective-access-warning // https://github.com/square/retrofit/issues/3341 + // Note that after Java 14, this isn't a problem, so I'm not inclined to keep having add-opens because of retrofit retrofitVersion = "2.9.0" // https://github.com/square/retrofit/tags shadowVersion = '8.1.1' // https://github.com/johnrengelman/shadow/releases ioLibVersion = '2.3.0' // https://github.com/retrodaredevil/io-lib/releases @@ -105,11 +106,6 @@ subprojects { } test { useJUnitPlatform() - if(JavaVersion.current() >= JavaVersion.VERSION_1_9) { - // If we don't have this, we get warnings for something about retrofit2.Platform - // - likely solcast action node - jvmArgs "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED" - } } tasks.withType(JavaCompile).configureEach { options.errorprone { @@ -235,15 +231,11 @@ project(":client"){ excludeTags 'integration' } } - task integration(type: Test) { + tasks.register('integration', Test) { // In the future, we can use the Test Suite feature rather than doing this manually: https://docs.gradle.org/7.3.1/userguide/jvm_test_suite_plugin.html useJUnitPlatform { includeTags 'integration' } - if(JavaVersion.current() >= JavaVersion.VERSION_1_9) { - // If we don't have this, we get warnings for something about retrofit2.Platform - jvmArgs "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED" - } } dockerCompose { useComposeFiles = ['../testing/couchdb-compose.yml'] diff --git a/client/src/test/java/me/retrodaredevil/solarthing/integration/DatabasePermissionTest.java b/client/src/test/java/me/retrodaredevil/solarthing/integration/DatabasePermissionTest.java index e4ba6113..859ef502 100644 --- a/client/src/test/java/me/retrodaredevil/solarthing/integration/DatabasePermissionTest.java +++ b/client/src/test/java/me/retrodaredevil/solarthing/integration/DatabasePermissionTest.java @@ -15,7 +15,8 @@ import me.retrodaredevil.solarthing.packets.instance.InstanceFragmentIndicatorPackets; import me.retrodaredevil.solarthing.packets.instance.InstanceSourcePackets; import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.time.Instant; import java.time.ZoneId; @@ -41,13 +42,15 @@ private static PacketCollection createSimplePacketCollection() { ); } - @Test - void test() throws CouchDbException, SolarThingDatabaseException { - IntegrationSetup.setup(IntegrationUtil.createCouchDbInstance(IntegrationUtil.DEFAULT_ADMIN_AUTH)); + + @ParameterizedTest + @MethodSource("me.retrodaredevil.solarthing.integration.DatabaseService#all") + void test(DatabaseService databaseService) throws CouchDbException, SolarThingDatabaseException { + IntegrationSetup.setup(IntegrationUtil.createCouchDbInstance(databaseService, IntegrationUtil.DEFAULT_ADMIN_AUTH)); { // No auth - CouchDbInstance noAuthInstance = IntegrationUtil.createCouchDbInstance(CouchDbAuth.createNoAuth()); + CouchDbInstance noAuthInstance = IntegrationUtil.createCouchDbInstance(databaseService, CouchDbAuth.createNoAuth()); SolarThingDatabase database = CouchDbSolarThingDatabase.create(noAuthInstance); database.getStatusDatabase().query(new MillisQueryBuilder().startKey(System.currentTimeMillis()).build()); // anyone can query status database.getEventDatabase().query(new MillisQueryBuilder().startKey(System.currentTimeMillis()).build()); // anyone can query events @@ -69,7 +72,7 @@ void test() throws CouchDbException, SolarThingDatabaseException { } { // Uploader user - CouchDbInstance uploaderInstance = IntegrationUtil.createCouchDbInstance(IntegrationUtil.getAuthFor(SolarThingDatabaseType.UserType.UPLOADER)); + CouchDbInstance uploaderInstance = IntegrationUtil.createCouchDbInstance(databaseService, IntegrationUtil.getAuthFor(SolarThingDatabaseType.UserType.UPLOADER)); SolarThingDatabase database = CouchDbSolarThingDatabase.create(uploaderInstance); PacketCollection packetCollection = createSimplePacketCollection(); @@ -78,7 +81,7 @@ void test() throws CouchDbException, SolarThingDatabaseException { } { // Manager user - CouchDbInstance managerInstance = IntegrationUtil.createCouchDbInstance(IntegrationUtil.getAuthFor(SolarThingDatabaseType.UserType.MANAGER)); + CouchDbInstance managerInstance = IntegrationUtil.createCouchDbInstance(databaseService, IntegrationUtil.getAuthFor(SolarThingDatabaseType.UserType.MANAGER)); SolarThingDatabase database = CouchDbSolarThingDatabase.create(managerInstance); PacketCollection packetCollection = createSimplePacketCollection(); diff --git a/client/src/test/java/me/retrodaredevil/solarthing/integration/DatabaseService.java b/client/src/test/java/me/retrodaredevil/solarthing/integration/DatabaseService.java new file mode 100644 index 00000000..07b5ce0d --- /dev/null +++ b/client/src/test/java/me/retrodaredevil/solarthing/integration/DatabaseService.java @@ -0,0 +1,36 @@ +package me.retrodaredevil.solarthing.integration; + +public enum DatabaseService { + COUCHDB("couchdb"), + ; + + private final String serviceName; + DatabaseService(String serviceName) { + this.serviceName = serviceName; + } + + public String getHost() { + String key = serviceName + ".host"; + String host = System.getProperty(key); + if (host == null) { + throw new IllegalStateException("System property does not exist for key: " + key); + } + return host; + } + public int getPort() { + // The gradle compose plugin sets system properties for the services defined in the docker compose file: + // https://github.com/avast/gradle-docker-compose-plugin + String key = serviceName + ".tcp.5984"; + String portString = System.getProperty(key); + if (portString == null) { + throw new IllegalStateException("System property does not exist for key: " + key); + } + return Integer.parseInt(portString); + } + public static DatabaseService[] couchOnly() { + return new DatabaseService[]{COUCHDB}; + } + public static DatabaseService[] all() { + return values(); + } +} diff --git a/client/src/test/java/me/retrodaredevil/solarthing/integration/IntegrationUtil.java b/client/src/test/java/me/retrodaredevil/solarthing/integration/IntegrationUtil.java index d1e8b5e1..812809a5 100644 --- a/client/src/test/java/me/retrodaredevil/solarthing/integration/IntegrationUtil.java +++ b/client/src/test/java/me/retrodaredevil/solarthing/integration/IntegrationUtil.java @@ -16,14 +16,14 @@ public final class IntegrationUtil { public static final CouchDbAuth DEFAULT_ADMIN_AUTH = CouchDbAuth.create("admin", "password"); - public static CouchDbInstance createCouchDbInstance(CouchDbAuth auth) { - return createCouchDbInstance(auth, false); + public static CouchDbInstance createCouchDbInstance(DatabaseService databaseService, CouchDbAuth auth) { + return createCouchDbInstance(databaseService, auth, false); } - public static CouchDbInstance createDebugCouchDbInstance(CouchDbAuth auth) { - return createCouchDbInstance(auth, true); + public static CouchDbInstance createDebugCouchDbInstance(DatabaseService databaseService, CouchDbAuth auth) { + return createCouchDbInstance(databaseService, auth, true); } - private static CouchDbInstance createCouchDbInstance(CouchDbAuth auth, boolean debug) { + private static CouchDbInstance createCouchDbInstance(DatabaseService databaseService, CouchDbAuth auth, boolean debug) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); if (debug){ builder.addInterceptor(new HttpLoggingInterceptor(System.out::println).setLevel(HttpLoggingInterceptor.Level.BODY)); @@ -32,8 +32,8 @@ private static CouchDbInstance createCouchDbInstance(CouchDbAuth auth, boolean d builder.build(), new HttpUrl.Builder() .scheme("http") - .host("localhost") - .port(5984) + .host(databaseService.getHost()) + .port(databaseService.getPort()) .build(), new BasicAuthHandler(auth) ); diff --git a/testing/couchdb-compose.yml b/testing/couchdb-compose.yml index 6ca61bff..46ba0041 100644 --- a/testing/couchdb-compose.yml +++ b/testing/couchdb-compose.yml @@ -7,4 +7,4 @@ services: - 'COUCHDB_USER=admin' - 'COUCHDB_PASSWORD=password' ports: - - '5984:5984' + - '5984'