From 822c57c02bdff6ba02b98295f5fb76ba8083cd8d Mon Sep 17 00:00:00 2001 From: usbharu Date: Tue, 14 May 2024 13:27:44 +0900 Subject: [PATCH] =?UTF-8?q?test:=20JsonLD=E3=81=AE=E3=82=B7=E3=83=AA?= =?UTF-8?q?=E3=82=A2=E3=83=A9=E3=82=A4=E3=82=BA=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/model/JsonLdSerializeTest.kt | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/JsonLdSerializeTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/JsonLdSerializeTest.kt index 3056cc17..9c9530cc 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/JsonLdSerializeTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/JsonLdSerializeTest.kt @@ -176,4 +176,74 @@ class JsonLdSerializeTest { assertEquals("""{"@context":["https://example.com","https://www.w3.org/ns/activitystreams"]}""", actual) } + + @Test + fun contextがオブジェクトのときシリアライズできる() { + val jsonLd = JsonLd( + listOf( + StringOrObject(mapOf("hoge" to "fuga")) + ) + ) + + val objectMapper = ActivityPubConfig().objectMapper() + + val actual = objectMapper.writeValueAsString(jsonLd) + + assertEquals("""{"@context":{"hoge":"fuga"}}""", actual) + + } + + @Test + fun contextが複数のオブジェクトのときシリアライズできる() { + val jsonLd = JsonLd( + listOf( + StringOrObject(mapOf("hoge" to "fuga")), + StringOrObject(mapOf("foo" to "bar")) + ) + ) + + val objectMapper = ActivityPubConfig().objectMapper() + + val actual = objectMapper.writeValueAsString(jsonLd) + + assertEquals("""{"@context":[{"hoge":"fuga"},{"foo":"bar"}]}""", actual) + } + + @Test + fun contextが複数のオブジェクトのときデシリアライズできる() { + //language=JSON + val json = """{"@context":["https://example.com",{"hoge": "fuga"},{"foo": "bar"}]}""" + + val objectMapper = ActivityPubConfig().objectMapper() + + val readValue = objectMapper.readValue(json) + + assertEquals( + JsonLd( + listOf( + StringOrObject("https://example.com"), + StringOrObject(mapOf("hoge" to "fuga")), + StringOrObject(mapOf("foo" to "bar")) + ) + ), readValue + ) + } + + @Test + fun contextがオブジェクトのときデシリアライズできる() { + //language=JSON + val json = """{"@context":{"hoge": "fuga"}}""" + + val objectMapper = ActivityPubConfig().objectMapper() + + val readValue = objectMapper.readValue(json) + + assertEquals( + JsonLd( + listOf( + StringOrObject(mapOf("hoge" to "fuga")) + ) + ), readValue + ) + } }