diff --git a/.editorconfig b/.editorconfig index 40e3f9b5..30c675e0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,20 +5,20 @@ root = true # Unix-style newlines with a newline ending every file [*] +end_of_line = lf insert_final_newline = true +charset = utf-8 indent_style = space -indent_size = 2 -trim_trailing_whitespace = true +indent_size = 4 -# Markdown -[*.md] -trim_trailing_whitespace = false +[{*.yml, *.yaml}] +indent_size = 2 -# Gradle [*.gradle] indent_size = 4 -# Java -[*.{java,kt,kts}] -indent_size = 4 -continuation_indent_size = 8 +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma_on_call_site = true +ij_kotlin_allow_trailing_comma = true +# To satisfy ktlint rules, see: https://stackoverflow.com/questions/59849619/intellij-does-not-sort-kotlin-imports-according-to-ktlints-expectations +ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^ \ No newline at end of file diff --git a/java-sdk/buildSrc/src/main/kotlin/Versions.kt b/java-sdk/buildSrc/src/main/kotlin/Versions.kt index fcbb114c..a46e36c5 100644 --- a/java-sdk/buildSrc/src/main/kotlin/Versions.kt +++ b/java-sdk/buildSrc/src/main/kotlin/Versions.kt @@ -5,7 +5,7 @@ object Versions { const val java = 17 const val avroGenerator = "1.9.1" - const val radarCommons = "1.1.3-SNAPSHOT" + const val radarCommons = "1.1.2" const val avro = "1.11.3" const val jackson = "2.16.1" const val argparse = "0.9.0" diff --git a/java-sdk/radar-schemas-registration/build.gradle.kts b/java-sdk/radar-schemas-registration/build.gradle.kts index 8d398e6a..146785eb 100644 --- a/java-sdk/radar-schemas-registration/build.gradle.kts +++ b/java-sdk/radar-schemas-registration/build.gradle.kts @@ -13,4 +13,5 @@ dependencies { implementation("org.apache.kafka:connect-json:${Versions.kafka}") implementation("io.ktor:ktor-client-auth:${Versions.ktor}") + testImplementation("com.squareup.okhttp3:mockwebserver:${Versions.okHttp}") } diff --git a/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt b/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt index ede1c83a..bdc1f549 100644 --- a/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt +++ b/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt @@ -46,7 +46,6 @@ import org.radarcns.kafka.ObservationKey import org.slf4j.LoggerFactory import java.io.IOException import java.net.MalformedURLException -import java.net.URI import java.time.Duration import kotlin.streams.asSequence import kotlin.time.Duration.Companion.seconds @@ -97,7 +96,7 @@ class SchemaRegistry( .mapNotNull { try { httpClient.request> { - url(URI(baseUrl).resolve("subjects").toString()) + url("subjects") if (apiKey != null && apiSecret != null) { basicAuth(apiKey, apiSecret) } @@ -227,7 +226,7 @@ class SchemaRegistry( logger.info("Setting compatibility to {}", compatibility) return try { httpClient.requestEmpty { - url(URI(baseUrl).resolve("config").toString()) + url("config") method = HttpMethod.Put contentType(ContentType("application", "vnd.schemaregistry.v1+json")) setBody("{\"compatibility\": \"${compatibility.name}\"}") diff --git a/java-sdk/radar-schemas-registration/src/test/java/org/radarbase/schema/registration/SchemaRegistryTest.kt b/java-sdk/radar-schemas-registration/src/test/java/org/radarbase/schema/registration/SchemaRegistryTest.kt new file mode 100644 index 00000000..7c4d55a4 --- /dev/null +++ b/java-sdk/radar-schemas-registration/src/test/java/org/radarbase/schema/registration/SchemaRegistryTest.kt @@ -0,0 +1,87 @@ +package org.radarbase.schema.registration + +import io.ktor.http.HttpHeaders +import kotlinx.coroutines.runBlocking +import okhttp3.mockwebserver.MockResponse +import okhttp3.mockwebserver.MockWebServer +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.radarbase.schema.registration.SchemaRegistry.Compatibility.FORWARD +import org.radarbase.topic.AvroTopic +import org.radarcns.kafka.ObservationKey +import org.radarcns.passive.phone.PhoneAcceleration + +class SchemaRegistryTest { + private var server = MockWebServer() + private val expectedAuthHeader = "Basic dXNlcm5hbWU6cGFzc3dvcmQ=" + lateinit var schemaRegistry: SchemaRegistry + + @BeforeEach + fun setUpClass() { + schemaRegistry = SchemaRegistry( + server.url("/").toString(), + "username", + "password", + ) + + val mockresponse = + MockResponse() + .setHeader(HttpHeaders.ContentType, "application/json") + .setBody( + """ + { + "id": 1 + } + """.trimIndent(), + ) + + server.enqueue(mockresponse) + server.enqueue(mockresponse) + } + + @AfterEach + fun tearDown() { + server.shutdown() + } + + @Test + fun registerSchema() { + // Create an instance of AvroTopic + val avroTopic = AvroTopic( + "test", + ObservationKey.getClassSchema(), + PhoneAcceleration.getClassSchema(), + ObservationKey::class.java, + PhoneAcceleration::class.java, + ) + + runBlocking { + // Register the schema + schemaRegistry.registerSchema(avroTopic) + + // Get the request that was received by the MockWebServer + val request = server.takeRequest() + + // Verify the Basic Auth credentials + val authHeader = request.getHeader("Authorization") + assertEquals(expectedAuthHeader, authHeader) + } + } + + @Test + fun putCompatibility() { + runBlocking { + // Register the schema + schemaRegistry.putCompatibility(compatibility = FORWARD) + + // Get the request that was received by the MockWebServer + val request = server.takeRequest() + + // Verify the Basic Auth credentials + val authHeader = request.getHeader("Authorization") + assertEquals(expectedAuthHeader, authHeader) + } + } +}