mirror of https://github.com/usbharu/Hideout.git
test: テストを修正
This commit is contained in:
parent
301c07c38e
commit
4151cda7b6
|
@ -17,6 +17,7 @@
|
||||||
package dev.usbharu.hideout.activitypub.domain.model
|
package dev.usbharu.hideout.activitypub.domain.model
|
||||||
|
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.Constant
|
||||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
@ -37,14 +38,7 @@ class DeleteSerializeTest {
|
||||||
"discoverable" : "toot:discoverable",
|
"discoverable" : "toot:discoverable",
|
||||||
"schema" : "http://schema.org#",
|
"schema" : "http://schema.org#",
|
||||||
"PropertyValue" : "schema:PropertyValue",
|
"PropertyValue" : "schema:PropertyValue",
|
||||||
"value" : "schema:value",
|
"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#"
|
|
||||||
} ],
|
} ],
|
||||||
"type" : "Delete",
|
"type" : "Delete",
|
||||||
"actor" : "https://misskey.usbharu.dev/users/97ws8y3rj6",
|
"actor" : "https://misskey.usbharu.dev/users/97ws8y3rj6",
|
||||||
|
@ -69,11 +63,7 @@ class DeleteSerializeTest {
|
||||||
),
|
),
|
||||||
published = "2023-11-02T15:30:34.160Z",
|
published = "2023-11-02T15:30:34.160Z",
|
||||||
)
|
)
|
||||||
expected.context = listOf(
|
expected.context = Constant.context
|
||||||
StringOrObject("https://www.w3.org/ns/activitystreams"),
|
|
||||||
StringOrObject("https://w3id.org/security/v1"),
|
|
||||||
StringOrObject("")
|
|
||||||
)
|
|
||||||
assertEquals(expected, readValue)
|
assertEquals(expected, readValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package dev.usbharu.hideout.activitypub.domain.model
|
package dev.usbharu.hideout.activitypub.domain.model
|
||||||
|
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
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.activitypub.service.objects.note.APNoteServiceImpl.Companion.public
|
||||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
@ -108,15 +109,7 @@ class NoteSerializeTest {
|
||||||
"discoverable": "toot:discoverable",
|
"discoverable": "toot:discoverable",
|
||||||
"schema": "http://schema.org#",
|
"schema": "http://schema.org#",
|
||||||
"PropertyValue": "schema:PropertyValue",
|
"PropertyValue": "schema:PropertyValue",
|
||||||
"value": "schema:value",
|
"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#"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"id": "https://misskey.usbharu.dev/notes/9nj1omt1rn",
|
"id": "https://misskey.usbharu.dev/notes/9nj1omt1rn",
|
||||||
|
@ -182,10 +175,7 @@ class NoteSerializeTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
expected.context = listOf(
|
expected.context = Constant.context
|
||||||
StringOrObject("https://www.w3.org/ns/activitystreams"),
|
|
||||||
StringOrObject("https://w3id.org/security/v1")
|
|
||||||
)
|
|
||||||
|
|
||||||
val note = objectMapper.readValue<Note>(json)
|
val note = objectMapper.readValue<Note>(json)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package dev.usbharu.hideout.activitypub.domain.model
|
package dev.usbharu.hideout.activitypub.domain.model
|
||||||
|
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.Constant
|
||||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
|
@ -38,15 +39,7 @@ class RejectTest {
|
||||||
"discoverable" : "toot:discoverable",
|
"discoverable" : "toot:discoverable",
|
||||||
"schema" : "http://schema.org#",
|
"schema" : "http://schema.org#",
|
||||||
"PropertyValue" : "schema:PropertyValue",
|
"PropertyValue" : "schema:PropertyValue",
|
||||||
"value" : "schema:value",
|
"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#"
|
|
||||||
} ],
|
} ],
|
||||||
"type" : "Reject",
|
"type" : "Reject",
|
||||||
"actor" : "https://misskey.usbharu.dev/users/97ws8y3rj6",
|
"actor" : "https://misskey.usbharu.dev/users/97ws8y3rj6",
|
||||||
|
@ -73,10 +66,7 @@ class RejectTest {
|
||||||
id = "https://misskey.usbharu.dev/follows/9mxh6mawru/97ws8y3rj6"
|
id = "https://misskey.usbharu.dev/follows/9mxh6mawru/97ws8y3rj6"
|
||||||
)
|
)
|
||||||
).apply {
|
).apply {
|
||||||
context = listOf(
|
context = Constant.context
|
||||||
StringOrObject("https://www.w3.org/ns/activitystreams"),
|
|
||||||
StringOrObject("https://w3id.org/security/v1")
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(reject).isEqualTo(expected)
|
assertThat(reject).isEqualTo(expected)
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.mockito.kotlin.doReturn
|
||||||
import org.mockito.kotlin.doThrow
|
import org.mockito.kotlin.doThrow
|
||||||
import org.mockito.kotlin.eq
|
import org.mockito.kotlin.eq
|
||||||
import org.mockito.kotlin.whenever
|
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.MockMvc
|
||||||
import org.springframework.test.web.servlet.get
|
import org.springframework.test.web.servlet.get
|
||||||
import org.springframework.test.web.servlet.post
|
import org.springframework.test.web.servlet.post
|
||||||
|
@ -51,7 +52,10 @@ class ActorAPControllerImplTest {
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
mockMvc = MockMvcBuilders.standaloneSetup(userAPControllerImpl).build()
|
mockMvc = MockMvcBuilders
|
||||||
|
.standaloneSetup(userAPControllerImpl)
|
||||||
|
.setMessageConverters(MappingJackson2HttpMessageConverter(ActivityPubConfig().objectMapper()))
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -85,6 +89,7 @@ class ActorAPControllerImplTest {
|
||||||
mockMvc
|
mockMvc
|
||||||
.get("/users/hoge")
|
.get("/users/hoge")
|
||||||
.asyncDispatch()
|
.asyncDispatch()
|
||||||
|
.andDo { print() }
|
||||||
.andExpect { status { isOk() } }
|
.andExpect { status { isOk() } }
|
||||||
.andExpect { content { this.json(objectMapper.writeValueAsString(person)) } }
|
.andExpect { content { this.json(objectMapper.writeValueAsString(person)) } }
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
package dev.usbharu.hideout.activitypub.service.common
|
package dev.usbharu.hideout.activitypub.service.common
|
||||||
|
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
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.Follow
|
||||||
import dev.usbharu.hideout.activitypub.domain.model.StringOrObject
|
import dev.usbharu.hideout.activitypub.domain.model.StringOrObject
|
||||||
|
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||||
import dev.usbharu.hideout.util.Base64Util
|
import dev.usbharu.hideout.util.Base64Util
|
||||||
import dev.usbharu.httpsignature.common.HttpHeaders
|
import dev.usbharu.httpsignature.common.HttpHeaders
|
||||||
import dev.usbharu.httpsignature.common.HttpMethod
|
import dev.usbharu.httpsignature.common.HttpMethod
|
||||||
|
@ -36,7 +38,6 @@ import org.mockito.kotlin.any
|
||||||
import org.mockito.kotlin.doReturn
|
import org.mockito.kotlin.doReturn
|
||||||
import org.mockito.kotlin.eq
|
import org.mockito.kotlin.eq
|
||||||
import org.mockito.kotlin.mock
|
import org.mockito.kotlin.mock
|
||||||
import utils.JsonObjectMapper.objectMapper
|
|
||||||
import utils.UserBuilder
|
import utils.UserBuilder
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
|
@ -58,7 +59,7 @@ class APRequestServiceImplTest {
|
||||||
}
|
}
|
||||||
respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""")
|
respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""")
|
||||||
}),
|
}),
|
||||||
objectMapper,
|
ActivityPubConfig().objectMapper(),
|
||||||
mock(),
|
mock(),
|
||||||
dateTimeFormatter
|
dateTimeFormatter
|
||||||
)
|
)
|
||||||
|
@ -83,7 +84,7 @@ class APRequestServiceImplTest {
|
||||||
}
|
}
|
||||||
respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""")
|
respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""")
|
||||||
}),
|
}),
|
||||||
objectMapper,
|
ActivityPubConfig().objectMapper(),
|
||||||
mock(),
|
mock(),
|
||||||
dateTimeFormatter
|
dateTimeFormatter
|
||||||
)
|
)
|
||||||
|
@ -123,7 +124,7 @@ class APRequestServiceImplTest {
|
||||||
}
|
}
|
||||||
respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""")
|
respond("""{"type":"Follow","object": "https://example.com","actor": "https://example.com"}""")
|
||||||
}),
|
}),
|
||||||
objectMapper,
|
ActivityPubConfig().objectMapper(),
|
||||||
httpSignatureSigner,
|
httpSignatureSigner,
|
||||||
dateTimeFormatter
|
dateTimeFormatter
|
||||||
)
|
)
|
||||||
|
@ -172,12 +173,12 @@ class APRequestServiceImplTest {
|
||||||
fun `apPost bodyがnullでないときcontextにactivitystreamのURLを追加する`() = runTest {
|
fun `apPost bodyがnullでないときcontextにactivitystreamのURLを追加する`() = runTest {
|
||||||
val dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
|
val dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
|
||||||
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
|
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("{}")
|
respondOk("{}")
|
||||||
}), objectMapper, mock(), dateTimeFormatter)
|
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
|
||||||
|
|
||||||
val body = Follow(
|
val body = Follow(
|
||||||
apObject = "https://example.com",
|
apObject = "https://example.com",
|
||||||
|
@ -194,7 +195,7 @@ class APRequestServiceImplTest {
|
||||||
assertEquals(0, it.body.toByteArray().size)
|
assertEquals(0, it.body.toByteArray().size)
|
||||||
|
|
||||||
respondOk("{}")
|
respondOk("{}")
|
||||||
}), objectMapper, mock(), dateTimeFormatter)
|
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
|
||||||
|
|
||||||
apRequestServiceImpl.apPost("https://example.com", null, null)
|
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 dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
|
||||||
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
|
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
|
||||||
val src = it.body.toByteArray()
|
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"))
|
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())
|
assertEquals(digest, it.headers["Digest"].orEmpty().split("256=").last())
|
||||||
|
|
||||||
respondOk("{}")
|
respondOk("{}")
|
||||||
}), objectMapper, mock(), dateTimeFormatter)
|
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
|
||||||
|
|
||||||
val body = Follow(
|
val body = Follow(
|
||||||
apObject = "https://example.com",
|
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 dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
|
||||||
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
|
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
|
||||||
val src = it.body.toByteArray()
|
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"))
|
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())
|
assertEquals(digest, it.headers["Digest"].orEmpty().split("256=").last())
|
||||||
|
|
||||||
respondOk("{}")
|
respondOk("{}")
|
||||||
}), objectMapper, mock(), dateTimeFormatter)
|
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
|
||||||
|
|
||||||
val body = Follow(
|
val body = Follow(
|
||||||
apObject = "https://example.com",
|
apObject = "https://example.com",
|
||||||
|
@ -278,7 +279,7 @@ class APRequestServiceImplTest {
|
||||||
}
|
}
|
||||||
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
|
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
|
||||||
val src = it.body.toByteArray()
|
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"))
|
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())
|
assertEquals(digest, it.headers["Digest"].orEmpty().split("256=").last())
|
||||||
|
|
||||||
respondOk("{}")
|
respondOk("{}")
|
||||||
}), objectMapper, httpSignatureSigner, dateTimeFormatter)
|
}), ActivityPubConfig().objectMapper(), httpSignatureSigner, dateTimeFormatter)
|
||||||
|
|
||||||
val body = Follow(
|
val body = Follow(
|
||||||
apObject = "https://example.com",
|
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 dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US)
|
||||||
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
|
val apRequestServiceImpl = APRequestServiceImpl(HttpClient(MockEngine {
|
||||||
val src = it.body.toByteArray()
|
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"))
|
assertThat(readValue.context).contains(StringOrObject("https://www.w3.org/ns/activitystreams"))
|
||||||
|
|
||||||
respondOk(src.decodeToString())
|
respondOk(src.decodeToString())
|
||||||
}), objectMapper, mock(), dateTimeFormatter)
|
}), ActivityPubConfig().objectMapper(), mock(), dateTimeFormatter)
|
||||||
|
|
||||||
val body = Follow(
|
val body = Follow(
|
||||||
apObject = "https://example.com",
|
apObject = "https://example.com",
|
||||||
|
|
Loading…
Reference in New Issue