test: JsonLDのシリアライズのテストを追加

This commit is contained in:
usbharu 2024-05-14 13:27:44 +09:00
parent 4ee71416d9
commit 822c57c02b
1 changed files with 70 additions and 0 deletions

View File

@ -176,4 +176,74 @@ class JsonLdSerializeTest {
assertEquals("""{"@context":["https://example.com","https://www.w3.org/ns/activitystreams"]}""", actual) 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<JsonLd>(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<JsonLd>(json)
assertEquals(
JsonLd(
listOf(
StringOrObject(mapOf("hoge" to "fuga"))
)
), readValue
)
}
} }