Skip to content

Commit

Permalink
erstattet JSONAssert med JsonUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
jankroken-nav committed Nov 27, 2024
1 parent d08fb26 commit 1d2e4cd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ val wiremockVersion = "3.9.2"
val micrometerRegistryPrometheusVersion = "1.14.1"
val mockitoKotlinVersion = "5.4.0"
val unleashVersion = "9.2.5"
val jsonAssertVersion = "1.5.2"
val jsonUnitVersion = "4.0.0"
val guavaVersion = "33.3.1-jre"

Expand Down Expand Up @@ -94,7 +93,6 @@ dependencies {
testImplementation("org.assertj:assertj-core:$assertjVersion")
testImplementation("org.awaitility:awaitility:$awaitilityVersion")
testImplementation("org.wiremock:wiremock-jetty12:$wiremockVersion")
testImplementation("org.skyscreamer:jsonassert:$jsonAssertVersion")
testImplementation("net.javacrumbs.json-unit:json-unit-assertj:$jsonUnitVersion")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.junit5.WireMockExtension
import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
import net.javacrumbs.jsonunit.assertj.whenever
import net.javacrumbs.jsonunit.core.Option
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.deserialize
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.domene.kafka.messages.domene.Kilde
Expand All @@ -22,7 +23,6 @@ import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.external.pdl
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import org.skyscreamer.jsonassert.JSONAssert
import org.springframework.beans.factory.annotation.Autowired
import java.time.Month
import java.time.YearMonth
Expand Down Expand Up @@ -90,11 +90,12 @@ class EndToEndTest : SpringContextTest.WithKafka() {
sendTilBestemService.sendTilBestem()

listener.removeFirstRecord(3).let { consumerRecord ->
assertThatJson(consumerRecord.key()).isEqualTo(
"""
assertThatJson(consumerRecord.key())
.isEqualTo(
"""
{"ident":"12345678910"}
""".trimIndent()
)
)

deserialize<PersongrunnlagMelding>(consumerRecord.value()).also {
assertThat(it.omsorgsyter).isEqualTo("12345678910")
Expand Down Expand Up @@ -131,7 +132,7 @@ class EndToEndTest : SpringContextTest.WithKafka() {
assertThat(it.rådata[0]["fnr"]).isEqualTo("12345678910")
assertThat(it.rådata[0]["fom"]).isEqualTo("2020-01-01")
assertThatJson(it.rådata[0]["barnetrygd"] as String)
.`when`(Option.IGNORING_EXTRA_FIELDS)
.whenever(Option.IGNORING_EXTRA_FIELDS)
.isEqualTo(
"""
{
Expand Down Expand Up @@ -161,8 +162,10 @@ class EndToEndTest : SpringContextTest.WithKafka() {
assertThat(hjelpestønadRådata["fnr"]).isEqualTo("09876543210")
assertThat(hjelpestønadRådata["fom"]).isEqualTo("2020-01-01")
assertThat(hjelpestønadRådata["tom"]).isEqualTo("2021-12-31")
JSONAssert.assertEquals(
"""
assertThatJson(hjelpestønadRådata["hjelpestønad"] as String)
.whenever(Option.IGNORING_EXTRA_FIELDS)
.isEqualTo(
"""
[
{
"id":"101",
Expand All @@ -173,9 +176,7 @@ class EndToEndTest : SpringContextTest.WithKafka() {
}
]
""".trimIndent(),
hjelpestønadRådata["hjelpestønad"] as String,
false,
)
)
assertThat(it.innlesingId.toString()).isEqualTo(innlesingId.toString())
assertThat(it.correlationId).isNotNull() //opprettes internt
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning

import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.OutputStreamAppender
import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
import net.javacrumbs.jsonunit.assertj.whenever
import net.javacrumbs.jsonunit.core.Option
import net.logstash.logback.encoder.LogstashEncoder
import org.junit.jupiter.api.Test
import org.skyscreamer.jsonassert.JSONAssert
import org.slf4j.LoggerFactory
import org.testcontainers.shaded.org.apache.commons.io.output.ByteArrayOutputStream

Expand Down Expand Up @@ -34,16 +36,16 @@ class LogbackVerificationTest {
log.detachAndStopAllAppenders()
val string = String(os.toByteArray())

JSONAssert.assertEquals(
"""
assertThatJson(string)
.whenever(Option.IGNORING_EXTRA_FIELDS)
.isEqualTo(
"""
{
"@version" : "1",
"message" : "hello",
"level" : "INFO"
}
""",
string,
false
)
"""
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.external.ba

import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.junit5.WireMockExtension
import net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson
import net.javacrumbs.jsonunit.assertj.whenever
import net.javacrumbs.jsonunit.core.Option
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.CorrelationId
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.InnlesingId
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.domene.kafka.messages.domene.Kilde
Expand All @@ -23,7 +26,6 @@ import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.RegisterExtension
import org.skyscreamer.jsonassert.JSONAssert
import org.springframework.beans.factory.annotation.Autowired
import java.time.Month
import java.time.YearMonth
Expand Down Expand Up @@ -106,8 +108,9 @@ class BarnetrygdClientTest : SpringContextTest.NoKafka() {

assertThat(it.rådataFraKilde["fnr"]).isEqualTo("123")
assertThat(it.rådataFraKilde["fom"]).isEqualTo("2020-01-01")
JSONAssert.assertEquals(
it.rådataFraKilde["barnetrygd"],
assertThatJson(it.rådataFraKilde["barnetrygd"])
.whenever(Option.IGNORING_EXTRA_FIELDS)
.isEqualTo(
"""{
"fagsaker": [
{
Expand All @@ -129,7 +132,6 @@ class BarnetrygdClientTest : SpringContextTest.NoKafka() {
}
]
}""".trimIndent(),
false,
)
}
}
Expand Down

0 comments on commit 1d2e4cd

Please sign in to comment.