From b2834b2c8c632651ed3a742b7c4f2839893903c1 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 25 Sep 2023 17:40:51 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/service/ap/APNoteService.kt | 2 +- .../hideout/plugins/ActivityPubKtTest.kt | 6 +++-- .../usbharu/hideout/plugins/KtorKeyMapTest.kt | 3 ++- .../service/ap/APNoteServiceImplTest.kt | 24 ++++++++++++------- .../ap/APReceiveFollowServiceImplTest.kt | 9 +++++-- .../hideout/service/user/UserServiceTest.kt | 6 +++-- .../kotlin/utils/TestApplicationConfig.kt | 8 +++++++ 7 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 src/test/kotlin/utils/TestApplicationConfig.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt index 3aece244..3c719104 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/APNoteService.kt @@ -36,7 +36,7 @@ interface APNoteService { } @Service -class APNoteServiceImpl private constructor( +class APNoteServiceImpl( private val httpClient: HttpClient, private val jobQueueParentService: JobQueueParentService, private val postRepository: PostRepository, diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt index 3fb3f006..52ac0b6b 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt @@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer import org.mockito.kotlin.mock +import utils.JsonObjectMapper.objectMapper +import utils.TestApplicationConfig.testApplicationConfig import utils.TestTransaction import java.security.KeyPairGenerator import java.time.Instant @@ -41,7 +43,7 @@ class ActivityPubKtTest { } } runBlocking { - val ktorKeyMap = KtorKeyMap(userQueryService, TestTransaction) + val ktorKeyMap = KtorKeyMap(userQueryService, TestTransaction, testApplicationConfig) val httpClient = HttpClient( MockEngine { httpRequestData -> @@ -57,7 +59,7 @@ class ActivityPubKtTest { } } - httpClient.postAp("https://localhost", "test", JsonLd(emptyList())) + httpClient.postAp("https://localhost", "test", JsonLd(emptyList()), objectMapper) } } } diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt index 0c7eb45e..6eeca290 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer import org.mockito.kotlin.mock +import utils.TestApplicationConfig.testApplicationConfig import utils.TestTransaction import java.security.KeyPairGenerator import java.time.Instant @@ -36,7 +37,7 @@ class KtorKeyMapTest { ) } } - val ktorKeyMap = KtorKeyMap(userQueryService, TestTransaction) + val ktorKeyMap = KtorKeyMap(userQueryService, TestTransaction, testApplicationConfig) ktorKeyMap.getPrivateKey("test") } diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt index 071c6625..26e1ae4e 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APNoteServiceImplTest.kt @@ -22,13 +22,15 @@ import org.junit.jupiter.api.Test import org.mockito.Mockito.eq import org.mockito.kotlin.* import utils.JsonObjectMapper +import utils.JsonObjectMapper.objectMapper +import utils.TestApplicationConfig.testApplicationConfig import java.time.Instant import kotlin.test.assertEquals class APNoteServiceImplTest { @Test fun `createPost 新しい投稿`() = runTest { - val followers = listOf( + val followers = listOf( User.of( 2L, "follower", @@ -84,7 +86,9 @@ class APNoteServiceImplTest { mock(), userQueryService, followerQueryService, - mock() + mock(), + objectMapper = objectMapper, + applicationConfig = testApplicationConfig ) val postEntity = Post.of( 1L, @@ -109,13 +113,15 @@ class APNoteServiceImplTest { } ) val activityPubNoteService = APNoteServiceImpl( - httpClient, - mock(), - mock(), - mock(), - mock(), - mock(), - mock() + httpClient = httpClient, + jobQueueParentService = mock(), + postRepository = mock(), + apUserService = mock(), + userQueryService = mock(), + followerQueryService = mock(), + postQueryService = mock(), + objectMapper = objectMapper, + applicationConfig = testApplicationConfig ) activityPubNoteService.createNoteJob( JobProps( diff --git a/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt index 98222b11..79c93816 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/ap/APReceiveFollowServiceImplTest.kt @@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.* import utils.JsonObjectMapper +import utils.JsonObjectMapper.objectMapper import utils.TestTransaction import java.time.Instant @@ -34,7 +35,10 @@ class APReceiveFollowServiceImplTest { onBlocking { schedule(eq(ReceiveFollowJob), any()) } doReturn Unit } val activityPubFollowService = - APReceiveFollowServiceImpl(jobQueueParentService, mock(), mock(), mock(), mock(), TestTransaction) + APReceiveFollowServiceImpl( + jobQueueParentService, mock(), mock(), mock(), mock(), TestTransaction, + objectMapper + ) activityPubFollowService.receiveFollow( Follow( emptyList(), @@ -163,7 +167,8 @@ class APReceiveFollowServiceImplTest { } ), userQueryService, - TestTransaction + TestTransaction, + objectMapper ) activityPubFollowService.receiveFollowJob( JobProps( diff --git a/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt index deb5b5e9..650fd81c 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/user/UserServiceTest.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Test import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.* +import utils.TestApplicationConfig.testApplicationConfig import java.security.KeyPairGenerator import kotlin.test.assertEquals import kotlin.test.assertNull @@ -28,7 +29,8 @@ class UserServiceTest { onBlocking { hash(anyString()) } doReturn "hashedPassword" onBlocking { generateKeyPair() } doReturn generateKeyPair } - val userService = UserServiceImpl(userRepository, userAuthService, mock(), mock(), mock()) + val userService = + UserServiceImpl(userRepository, userAuthService, mock(), mock(), mock(), testApplicationConfig) userService.createLocalUser(UserCreateDto("test", "testUser", "XXXXXXXXXXXXX", "test")) verify(userRepository, times(1)).save(any()) argumentCaptor { @@ -54,7 +56,7 @@ class UserServiceTest { val userRepository = mock { onBlocking { nextId() } doReturn 113345L } - val userService = UserServiceImpl(userRepository, mock(), mock(), mock(), mock()) + val userService = UserServiceImpl(userRepository, mock(), mock(), mock(), mock(), testApplicationConfig) val user = RemoteUserCreateDto( "test", "example.com", diff --git a/src/test/kotlin/utils/TestApplicationConfig.kt b/src/test/kotlin/utils/TestApplicationConfig.kt new file mode 100644 index 00000000..9d064eab --- /dev/null +++ b/src/test/kotlin/utils/TestApplicationConfig.kt @@ -0,0 +1,8 @@ +package utils + +import dev.usbharu.hideout.config.ApplicationConfig +import java.net.URL + +object TestApplicationConfig { + val testApplicationConfig = ApplicationConfig(URL("https://example.com")) +}