test: テストを修正

This commit is contained in:
usbharu 2024-05-16 15:23:29 +09:00
parent 301c07c38e
commit 4151cda7b6
5 changed files with 32 additions and 56 deletions

View File

@ -17,6 +17,7 @@
package dev.usbharu.hideout.activitypub.domain.model
import com.fasterxml.jackson.module.kotlin.readValue
import dev.usbharu.hideout.activitypub.domain.Constant
import dev.usbharu.hideout.application.config.ActivityPubConfig
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Assertions.assertEquals
@ -37,14 +38,7 @@ class DeleteSerializeTest {
"discoverable" : "toot:discoverable",
"schema" : "http://schema.org#",
"PropertyValue" : "schema:PropertyValue",
"value" : "schema:value",
"misskey" : "https://misskey-hub.net/ns#",
"_misskey_content" : "misskey:_misskey_content",
"_misskey_quote" : "misskey:_misskey_quote",
"_misskey_reaction" : "misskey:_misskey_reaction",
"_misskey_votes" : "misskey:_misskey_votes",
"isCat" : "misskey:isCat",
"vcard" : "http://www.w3.org/2006/vcard/ns#"
"value" : "schema:value"
} ],
"type" : "Delete",
"actor" : "https://misskey.usbharu.dev/users/97ws8y3rj6",
@ -69,11 +63,7 @@ class DeleteSerializeTest {
),
published = "2023-11-02T15:30:34.160Z",
)
expected.context = listOf(
StringOrObject("https://www.w3.org/ns/activitystreams"),
StringOrObject("https://w3id.org/security/v1"),
StringOrObject("")
)
expected.context = Constant.context
assertEquals(expected, readValue)
}

View File

@ -17,6 +17,7 @@
package dev.usbharu.hideout.activitypub.domain.model
import com.fasterxml.jackson.module.kotlin.readValue
import dev.usbharu.hideout.activitypub.domain.Constant
import dev.usbharu.hideout.activitypub.service.objects.note.APNoteServiceImpl.Companion.public
import dev.usbharu.hideout.application.config.ActivityPubConfig
import org.assertj.core.api.Assertions.assertThat
@ -108,15 +109,7 @@ class NoteSerializeTest {
"discoverable": "toot:discoverable",
"schema": "http://schema.org#",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value",
"misskey": "https://misskey-hub.net/ns#",
"_misskey_content": "misskey:_misskey_content",
"_misskey_quote": "misskey:_misskey_quote",
"_misskey_reaction": "misskey:_misskey_reaction",
"_misskey_votes": "misskey:_misskey_votes",
"_misskey_summary": "misskey:_misskey_summary",
"isCat": "misskey:isCat",
"vcard": "http://www.w3.org/2006/vcard/ns#"
"value": "schema:value"
}
],
"id": "https://misskey.usbharu.dev/notes/9nj1omt1rn",
@ -182,10 +175,7 @@ class NoteSerializeTest {
)
)
expected.context = listOf(
StringOrObject("https://www.w3.org/ns/activitystreams"),
StringOrObject("https://w3id.org/security/v1")
)
expected.context = Constant.context
val note = objectMapper.readValue<Note>(json)

View File

@ -17,6 +17,7 @@
package dev.usbharu.hideout.activitypub.domain.model
import com.fasterxml.jackson.module.kotlin.readValue
import dev.usbharu.hideout.activitypub.domain.Constant
import dev.usbharu.hideout.application.config.ActivityPubConfig
import org.assertj.core.api.Assertions.assertThat
import org.intellij.lang.annotations.Language
@ -38,15 +39,7 @@ class RejectTest {
"discoverable" : "toot:discoverable",
"schema" : "http://schema.org#",
"PropertyValue" : "schema:PropertyValue",
"value" : "schema:value",
"misskey" : "https://misskey-hub.net/ns#",
"_misskey_content" : "misskey:_misskey_content",
"_misskey_quote" : "misskey:_misskey_quote",
"_misskey_reaction" : "misskey:_misskey_reaction",
"_misskey_votes" : "misskey:_misskey_votes",
"_misskey_summary" : "misskey:_misskey_summary",
"isCat" : "misskey:isCat",
"vcard" : "http://www.w3.org/2006/vcard/ns#"
"value" : "schema:value"
} ],
"type" : "Reject",
"actor" : "https://misskey.usbharu.dev/users/97ws8y3rj6",
@ -73,10 +66,7 @@ class RejectTest {
id = "https://misskey.usbharu.dev/follows/9mxh6mawru/97ws8y3rj6"
)
).apply {
context = listOf(
StringOrObject("https://www.w3.org/ns/activitystreams"),
StringOrObject("https://w3id.org/security/v1")
)
context = Constant.context
}
assertThat(reject).isEqualTo(expected)

View File

@ -33,6 +33,7 @@ import org.mockito.kotlin.doReturn
import org.mockito.kotlin.doThrow
import org.mockito.kotlin.eq
import org.mockito.kotlin.whenever
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.get
import org.springframework.test.web.servlet.post
@ -51,7 +52,10 @@ class ActorAPControllerImplTest {
@BeforeEach
fun setUp() {
mockMvc = MockMvcBuilders.standaloneSetup(userAPControllerImpl).build()
mockMvc = MockMvcBuilders
.standaloneSetup(userAPControllerImpl)
.setMessageConverters(MappingJackson2HttpMessageConverter(ActivityPubConfig().objectMapper()))
.build()
}
@Test
@ -85,6 +89,7 @@ class ActorAPControllerImplTest {
mockMvc
.get("/users/hoge")
.asyncDispatch()
.andDo { print() }
.andExpect { status { isOk() } }
.andExpect { content { this.json(objectMapper.writeValueAsString(person)) } }
}

View File

@ -17,8 +17,10 @@
package dev.usbharu.hideout.activitypub.service.common
import com.fasterxml.jackson.module.kotlin.readValue
import dev.usbharu.hideout.activitypub.domain.Constant
import dev.usbharu.hideout.activitypub.domain.model.Follow
import dev.usbharu.hideout.activitypub.domain.model.StringOrObject
import dev.usbharu.hideout.application.config.ActivityPubConfig
import dev.usbharu.hideout.util.Base64Util
import dev.usbharu.httpsignature.common.HttpHeaders
import dev.usbharu.httpsignature.common.HttpMethod
@ -36,7 +38,6 @@ import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import utils.JsonObjectMapper.objectMapper
import utils.UserBuilder
import java.net.URL
import java.security.MessageDigest
@ -58,7 +59,7 @@ class APRequestServiceImplTest {
}
respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""")
}),
objectMapper,
ActivityPubConfig().objectMapper(),
mock(),
dateTimeFormatter
)
@ -83,7 +84,7 @@ class APRequestServiceImplTest {
}
respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""")
}),
objectMapper,
ActivityPubConfig().objectMapper(),
mock(),
dateTimeFormatter
)
@ -123,7 +124,7 @@ class APRequestServiceImplTest {
}
respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""")
}),
objectMapper,
ActivityPubConfig().objectMapper(),
httpSignatureSigner,
dateTimeFormatter
)
@ -172,12 +173,12 @@ class APRequestServiceImplTest {
fun `apPost bodyがnullでないときcontextにactivitystreamのURLを追加する`() = runTest {
val dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
val readValue = objectMapper.readValue<Follow>(it.body.toByteArray())
val readValue = ActivityPubConfig().objectMapper().readValue<Follow>(it.body.toByteArray())
assertThat(readValue.context).contains(StringOrObject("https://www.w3.org/ns/activitystreams"))
assertThat(readValue.context).containsAll(Constant.context)
respondOk("{}")
}), objectMapper, mock(), dateTimeFormatter)
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
val body = Follow(
apObject = "https://example.com",
@ -194,7 +195,7 @@ class APRequestServiceImplTest {
assertEquals(0, it.body.toByteArray().size)
respondOk("{}")
}), objectMapper, mock(), dateTimeFormatter)
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
apRequestServiceImpl.apPost("https://example.com", null, null)
}
@ -204,7 +205,7 @@ class APRequestServiceImplTest {
val dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
val src = it.body.toByteArray()
val readValue = objectMapper.readValue<Follow>(src)
val readValue = ActivityPubConfig().objectMapper().readValue<Follow>(src)
assertThat(readValue.context).contains(StringOrObject("https://www.w3.org/ns/activitystreams"))
@ -223,7 +224,7 @@ class APRequestServiceImplTest {
assertEquals(digest, it.headers["Digest"].orEmpty().split("256=").last())
respondOk("{}")
}), objectMapper, mock(), dateTimeFormatter)
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
val body = Follow(
apObject = "https://example.com",
@ -237,7 +238,7 @@ class APRequestServiceImplTest {
val dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
val src = it.body.toByteArray()
val readValue = objectMapper.readValue<Follow>(src)
val readValue = ActivityPubConfig().objectMapper().readValue<Follow>(src)
assertThat(readValue.context).contains(StringOrObject("https://www.w3.org/ns/activitystreams"))
@ -253,7 +254,7 @@ class APRequestServiceImplTest {
assertEquals(digest, it.headers["Digest"].orEmpty().split("256=").last())
respondOk("{}")
}), objectMapper, mock(), dateTimeFormatter)
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
val body = Follow(
apObject = "https://example.com",
@ -278,7 +279,7 @@ class APRequestServiceImplTest {
}
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
val src = it.body.toByteArray()
val readValue = objectMapper.readValue<Follow>(src)
val readValue = ActivityPubConfig().objectMapper().readValue<Follow>(src)
assertThat(readValue.context).contains(StringOrObject("https://www.w3.org/ns/activitystreams"))
@ -294,7 +295,7 @@ class APRequestServiceImplTest {
assertEquals(digest, it.headers["Digest"].orEmpty().split("256=").last())
respondOk("{}")
}), objectMapper, httpSignatureSigner, dateTimeFormatter)
}), ActivityPubConfig().objectMapper(), httpSignatureSigner, dateTimeFormatter)
val body = Follow(
apObject = "https://example.com",
@ -339,12 +340,12 @@ class APRequestServiceImplTest {
val dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
val src = it.body.toByteArray()
val readValue = objectMapper.readValue<Follow>(src)
val readValue = ActivityPubConfig().objectMapper().readValue<Follow>(src)
assertThat(readValue.context).contains(StringOrObject("https://www.w3.org/ns/activitystreams"))
respondOk(src.decodeToString())
}), objectMapper, mock(), dateTimeFormatter)
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
val body = Follow(
apObject = "https://example.com",