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 + ) + } }