Skip to content

Commit

Permalink
Oppdatert etter flytting av kotlin-clients
Browse files Browse the repository at this point in the history
  • Loading branch information
naviktthomas committed Oct 25, 2024
1 parent 247777d commit 3b594a2
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 227 deletions.
6 changes: 3 additions & 3 deletions apps/api-start-stopp-perioder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ jib {
environment = mapOf(
"IMAGE_WITH_VERSION" to "${image ?: project.name}:${project.version}",
"OTEL_INSTRUMENTATION_METHODS_INCLUDE" to ("io.ktor.server.routing.Routing[interceptor,executeResult];" +
"io.ktor.server.netty.NettyApplicationCallHandler[handleRequest,exceptionCaught];") +
"io.ktor.serialization.jackson.JacksonConverter[deserialize,serializeNullable]"
"io.ktor.server.netty.NettyApplicationCallHandler[handleRequest,exceptionCaught];") +
"io.ktor.serialization.jackson.JacksonConverter[deserialize,serializeNullable]"
)
jvmFlags = listOf("-XX:ActiveProcessorCount=4", "-XX:+UseZGC", "-XX:+ZGenerational")
}
Expand All @@ -107,7 +107,7 @@ mapOf(
"${layout.projectDirectory}/src/main/resources/openapi/opplysninger.yaml" to "${generatedCodePackageName}.opplysningermottatt",
"${layout.projectDirectory}/src/main/resources/openapi/startstopp.yaml" to "${generatedCodePackageName}.startstopp"
).map { (openApiDocFile, pkgName) ->
val taskName = "generate${pkgName.capitalized()}"
val taskName = "generate${pkgName.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }}"
tasks.register(taskName, GenerateTask::class) {
generatorName.set("kotlin-server")
library = "ktor"
Expand Down
2 changes: 1 addition & 1 deletion apps/bekreftelse-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {

// Serialization
implementation(libs.ktor.serialization.jackson)
implementation(libs.ktor.serialization.json)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.jackson.datatypeJsr310)

// Authentication
Expand Down
2 changes: 1 addition & 1 deletion apps/bekreftelse-tjeneste/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {

// Serialization
implementation(libs.ktor.serialization.jackson)
implementation(libs.ktor.serialization.json)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.jackson.datatypeJsr310)

// Tooling
Expand Down
2 changes: 1 addition & 1 deletion apps/bekreftelse-utgang/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {

// Serialization
implementation(libs.ktor.serialization.jackson)
implementation(libs.ktor.serialization.json)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.jackson.datatypeJsr310)

// Tooling
Expand Down
5 changes: 2 additions & 3 deletions apps/hendelselogg-backup/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.gradle.configurationcache.extensions.capitalized
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
Expand Down Expand Up @@ -107,7 +106,7 @@ val generatedCodeOutputDir = "${layout.buildDirectory.get()}/generated/"
mapOf(
"${layout.projectDirectory}/src/main/resources/openapi/Brukerstoette.yaml" to "${generatedCodePackageName}.brukerstoette"
).map { (openApiDocFile, pkgName) ->
val taskName = "generate${pkgName.capitalized()}"
val taskName = "generate${pkgName.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }}"
tasks.register(taskName, GenerateTask::class) {
generatorName.set("kotlin-server")
library = "ktor"
Expand Down Expand Up @@ -142,7 +141,7 @@ mapOf(
mapOf(
"${layout.projectDirectory}/src/main/resources/openapi/oppslags-api.yaml" to "${generatedCodePackageName}.oppslagsapi"
).map { (openApiDocFile, pkgName) ->
val taskName = "generate${pkgName.capitalized()}"
val taskName = "generate${pkgName.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }}"
tasks.register(taskName, GenerateTask::class) {
generatorName.set("kotlin")
library = "jvm-ktor"
Expand Down
13 changes: 10 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[versions]
pawPdlClientVersion = "24.10.18.41-1"
pawAaregClientVersion = "24.07.04.18-1"
noNavSecurityVersion = "5.0.5"
noNavCommonVersion = "3.2024.05.23_05.46-2b29fa343e8e"
arbeidssokerregisteretVersion = "1.9348086045.48-1"
bekreftelseSchemaVersion = "24.10.21.12-1"
arrowVersion = "1.2.4"
arrowJacksonIntegrationVersion = "0.14.1"
noNavCommonVersion = "3.2024.05.23_05.46-2b29fa343e8e"
noNavSecurityVersion = "5.0.5"
comSksamuelHopliteVersion = "2.8.2"
graphqlClientVersion = "7.1.1"
orgApacheKafkaVersion = "3.7.0"
ioConfluentKafkaVersion = "7.7.1"
orgApacheAvroVersion = "1.12.0"
Expand All @@ -27,6 +28,8 @@ coroutinesVersion = "1.9.0"
postgresDriverVersion = "42.7.4"
flywayVersion = "10.20.0"
hikariVersion = "6.0.0"
kotlinxCoroutinesVersion = "1.8.1"
kotlinxSerializationJsonVersion = "1.7.3"
ktorVersion = "2.3.12"

[libraries]
Expand All @@ -36,6 +39,8 @@ arrow-core-serialization = { group = "io.arrow-kt", name = "arrow-core-serializa
arrow-integration-jackson = { group = "io.arrow-kt", name = "arrow-integrations-jackson-module", version.ref = "arrowJacksonIntegrationVersion" }
logbackClassic = { group = "ch.qos.logback", name = "logback-classic", version.ref = "logbackVersion" }
logstashLogbackEncoder = { group = "net.logstash.logback", name = "logstash-logback-encoder", version.ref = "logstashVersion" }
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesVersion" }
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerializationJsonVersion" }
ktor-client-contentNegotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktorVersion" }
ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktorVersion" }
ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktorVersion" }
Expand All @@ -57,7 +62,7 @@ ktor-server-testJvm = { group = "io.ktor", name = "ktor-server-tests-jvm", versi
ktor-serialization-core = { group = "io.ktor", name = "ktor-serialization", version.ref = "ktorVersion" }
ktor-serialization-jvm = { group = "io.ktor", name = "ktor-serialization-jvm", version.ref = "ktorVersion" }
ktor-serialization-jackson = { group = "io.ktor", name = "ktor-serialization-jackson", version.ref = "ktorVersion" }
ktor-serialization-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktorVersion" }
ktor-serialization-kotlinx-json = { group = "io.ktor", name = "ktor-serialization-kotlinx-json", version.ref = "ktorVersion" }
opentelemetry-api = { group = "io.opentelemetry", name = "opentelemetry-api", version.ref = "otelTargetSdkVersion" }
opentelemetry-ktor = { group = "io.opentelemetry.instrumentation", name = "opentelemetry-ktor-2.0", version.ref = "otelInstrumentationKtorVersion" }
opentelemetry-annotations = { group = "io.opentelemetry.instrumentation", name = "opentelemetry-instrumentation-annotations", version.ref = "otelInstrumentationVersion" }
Expand All @@ -80,6 +85,8 @@ nav-common-log = { group = "no.nav.common", name = "log", version.ref = "noNavCo
nav-common-auditLog = { group = "no.nav.common", name = "audit-log", version.ref = "noNavCommonVersion" }
nav-security-tokenValidationKtorV2 = { group = "no.nav.security", name = "token-validation-ktor-v2", version.ref = "noNavSecurityVersion" }
nav-security-tokenClientCore = { group = "no.nav.security", name = "token-client-core", version.ref = "noNavSecurityVersion" }
graphql-client = { group = "com.expediagroup", name = "graphql-kotlin-client", version.ref = "graphqlClientVersion" }
graphql-ktor-client = { group = "com.expediagroup", name = "graphql-kotlin-ktor-client", version.ref = "graphqlClientVersion" }
hoplite-core = { group = "com.sksamuel.hoplite", name = "hoplite-core", version.ref = "comSksamuelHopliteVersion" }
hoplite-toml = { group = "com.sksamuel.hoplite", name = "hoplite-toml", version.ref = "comSksamuelHopliteVersion" }
hoplite-yaml = { group = "com.sksamuel.hoplite", name = "hoplite-yaml", version.ref = "comSksamuelHopliteVersion" }
Expand Down
77 changes: 14 additions & 63 deletions lib/aareg-client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,77 +1,28 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("org.jmailen.kotlinter")
id("maven-publish")
java
}

group = "no.nav.paw"

tasks {
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
test {
useJUnitPlatform()
}
}

val jvmMajorVersion: String by project

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
dependencies {
api(libs.kotlinx.serialization.json)

withSourcesJar()
}
implementation(libs.ktor.client.contentNegotiation)
implementation(libs.ktor.client.okhttp)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.ktor.client.logging)

repositories {
mavenCentral()
mavenNav("*")
testImplementation(libs.bundles.testLibsWithUnitTesting)
testImplementation(libs.ktor.client.mock)
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
repositories {
mavenNav("paw-kotlin-clients")
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(jvmMajorVersion))
}
}

dependencies {
val ktorVersion: String by project
val mockkVersion: String by project
val kotlinSerializationVersion: String by project
val junitJupiterVersion: String by project
val slf4jVersion: String by project

api("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializationVersion")

implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")

testImplementation("org.junit.jupiter:junit-jupiter:$junitJupiterVersion")
testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("org.slf4j:slf4j-simple:$slf4jVersion")
}

fun RepositoryHandler.mavenNav(repo: String): MavenArtifactRepository {
val githubPassword: String by project

return maven {
setUrl("https://maven.pkg.github.com/navikt/$repo")
credentials {
username = "x-access-token"
password = githubPassword
}
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,21 @@
package no.nav.paw.aareg

import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.collections.shouldContain
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class AaregClientTest {
class AaregClientTest : FreeSpec({

/*
API Description:
https://navikt.github.io/aareg/tjenester/integrasjon/api/
*/
@Test
fun `Returnerer gyldig objekt når alt er oK`() {
"Returnerer gyldig objekt når alt er ok" {
val response = runBlocking {
mockAaregClient(MockResponse.arbeidsforhold)
.hentArbeidsforhold("ident", "call-id")
}
assertTrue(response.any { it.arbeidsgiver.organisasjonsnummer == "896929119" })

response.map { it.arbeidsgiver.organisasjonsnummer } shouldContain "896929119"
}
//
// @Test
// fun test_OK_svar_Med_Uventet_JSON() {
// val response = runBlocking {
// mockAaregClient(MockResponse.error)
// .hentArbeidsforhold("hei", "54-56 That's My Number")
// }
// val empty = emptyList<Arbeidsforhold>()
// assertEquals(empty, response)
// }
//
// @Test
// fun test_Server_Error() {
// val response = runBlocking {
// mockAaregClient("blablabla", HttpStatusCode.InternalServerError)
// .hentArbeidsforhold("hei", "123456")
// }
// val empty = emptyList<Arbeidsforhold>()
// assertEquals(empty, response)
// }
//
// @Test
// fun realDeal() {
// val client = AaregClient(url = "blah") { "tja" }
// val response = runBlocking { client.hentArbeidsforhold("hei", "Number 2") }
// assertEquals(emptyList<Arbeidsforhold>(), response)
// }
}
})
81 changes: 16 additions & 65 deletions lib/pdl-client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "no.nav.paw"

plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("com.expediagroup.graphql")
id("org.jmailen.kotlinter")
id("maven-publish")
}

tasks {
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "21"
}
test {
useJUnitPlatform()
}
lintKotlinMain {
exclude("no/nav/paw/pdl/graphql/generated/**/*.kt")
}
formatKotlinMain {
exclude("no/nav/paw/pdl/graphql/generated/**/*.kt")
}
val jvmMajorVersion: String by project

dependencies {
api(libs.kotlinx.serialization.json)

implementation(libs.ktor.client.contentNegotiation)
implementation(libs.ktor.client.okhttp)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.ktor.client.logging)
api(libs.graphql.ktor.client)

testImplementation(libs.bundles.testLibsWithUnitTesting)
testImplementation(libs.ktor.client.mock)
testImplementation(libs.kotlinx.coroutines.core)
}

java {
Expand All @@ -32,21 +27,6 @@ java {
}
}

repositories {
mavenCentral()
mavenNav("*")
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
repositories {
mavenNav("paw-kotlin-clients")
}
}

graphql {
client {
Expand All @@ -57,35 +37,6 @@ graphql {
}
}

dependencies {
val coroutinesVersion: String by project
val kotlinSerializationVersion: String by project
val ktorVersion: String by project
val mockkVersion: String by project
val graphQLKotlinVersion: String by project

api("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinSerializationVersion")

implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
api("com.expediagroup:graphql-kotlin-ktor-client:$graphQLKotlinVersion")

testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
testImplementation(kotlin("test"))
}

fun RepositoryHandler.mavenNav(repo: String): MavenArtifactRepository {
val githubPassword: String by project

return maven {
setUrl("https://maven.pkg.github.com/navikt/$repo")
credentials {
username = "x-access-token"
password = githubPassword
}
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.paw
package no.nav.paw.pdl

import io.ktor.client.HttpClient
import io.ktor.client.engine.mock.MockEngine
Expand All @@ -7,7 +7,6 @@ import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
import io.ktor.http.headersOf
import no.nav.paw.pdl.PdlClient

fun mockPdlClient(content: String): PdlClient {
val mockEngine =
Expand Down
Loading

0 comments on commit 3b594a2

Please sign in to comment.