test: テストを修正

This commit is contained in:
usbharu 2023-09-25 17:40:51 +09:00
parent 09442d2bdf
commit 778d8a4968
7 changed files with 41 additions and 17 deletions

View File

@ -36,7 +36,7 @@ interface APNoteService {
} }
@Service @Service
class APNoteServiceImpl private constructor( class APNoteServiceImpl(
private val httpClient: HttpClient, private val httpClient: HttpClient,
private val jobQueueParentService: JobQueueParentService, private val jobQueueParentService: JobQueueParentService,
private val postRepository: PostRepository, private val postRepository: PostRepository,

View File

@ -12,6 +12,8 @@ import org.junit.jupiter.api.Test
import org.mockito.kotlin.any import org.mockito.kotlin.any
import org.mockito.kotlin.doAnswer import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.mock import org.mockito.kotlin.mock
import utils.JsonObjectMapper.objectMapper
import utils.TestApplicationConfig.testApplicationConfig
import utils.TestTransaction import utils.TestTransaction
import java.security.KeyPairGenerator import java.security.KeyPairGenerator
import java.time.Instant import java.time.Instant
@ -41,7 +43,7 @@ class ActivityPubKtTest {
} }
} }
runBlocking { runBlocking {
val ktorKeyMap = KtorKeyMap(userQueryService, TestTransaction) val ktorKeyMap = KtorKeyMap(userQueryService, TestTransaction, testApplicationConfig)
val httpClient = HttpClient( val httpClient = HttpClient(
MockEngine { httpRequestData -> MockEngine { httpRequestData ->
@ -57,7 +59,7 @@ class ActivityPubKtTest {
} }
} }
httpClient.postAp("https://localhost", "test", JsonLd(emptyList())) httpClient.postAp("https://localhost", "test", JsonLd(emptyList()), objectMapper)
} }
} }
} }

View File

@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test
import org.mockito.kotlin.any import org.mockito.kotlin.any
import org.mockito.kotlin.doAnswer import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.mock import org.mockito.kotlin.mock
import utils.TestApplicationConfig.testApplicationConfig
import utils.TestTransaction import utils.TestTransaction
import java.security.KeyPairGenerator import java.security.KeyPairGenerator
import java.time.Instant import java.time.Instant
@ -36,7 +37,7 @@ class KtorKeyMapTest {
) )
} }
} }
val ktorKeyMap = KtorKeyMap(userQueryService, TestTransaction) val ktorKeyMap = KtorKeyMap(userQueryService, TestTransaction, testApplicationConfig)
ktorKeyMap.getPrivateKey("test") ktorKeyMap.getPrivateKey("test")
} }

View File

@ -22,13 +22,15 @@ import org.junit.jupiter.api.Test
import org.mockito.Mockito.eq import org.mockito.Mockito.eq
import org.mockito.kotlin.* import org.mockito.kotlin.*
import utils.JsonObjectMapper import utils.JsonObjectMapper
import utils.JsonObjectMapper.objectMapper
import utils.TestApplicationConfig.testApplicationConfig
import java.time.Instant import java.time.Instant
import kotlin.test.assertEquals import kotlin.test.assertEquals
class APNoteServiceImplTest { class APNoteServiceImplTest {
@Test @Test
fun `createPost 新しい投稿`() = runTest { fun `createPost 新しい投稿`() = runTest {
val followers = listOf<User>( val followers = listOf(
User.of( User.of(
2L, 2L,
"follower", "follower",
@ -84,7 +86,9 @@ class APNoteServiceImplTest {
mock(), mock(),
userQueryService, userQueryService,
followerQueryService, followerQueryService,
mock() mock(),
objectMapper = objectMapper,
applicationConfig = testApplicationConfig
) )
val postEntity = Post.of( val postEntity = Post.of(
1L, 1L,
@ -109,13 +113,15 @@ class APNoteServiceImplTest {
} }
) )
val activityPubNoteService = APNoteServiceImpl( val activityPubNoteService = APNoteServiceImpl(
httpClient, httpClient = httpClient,
mock(), jobQueueParentService = mock(),
mock(), postRepository = mock(),
mock(), apUserService = mock(),
mock(), userQueryService = mock(),
mock(), followerQueryService = mock(),
mock() postQueryService = mock(),
objectMapper = objectMapper,
applicationConfig = testApplicationConfig
) )
activityPubNoteService.createNoteJob( activityPubNoteService.createNoteJob(
JobProps( JobProps(

View File

@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.anyString
import org.mockito.kotlin.* import org.mockito.kotlin.*
import utils.JsonObjectMapper import utils.JsonObjectMapper
import utils.JsonObjectMapper.objectMapper
import utils.TestTransaction import utils.TestTransaction
import java.time.Instant import java.time.Instant
@ -34,7 +35,10 @@ class APReceiveFollowServiceImplTest {
onBlocking { schedule(eq(ReceiveFollowJob), any()) } doReturn Unit onBlocking { schedule(eq(ReceiveFollowJob), any()) } doReturn Unit
} }
val activityPubFollowService = val activityPubFollowService =
APReceiveFollowServiceImpl(jobQueueParentService, mock(), mock(), mock(), mock(), TestTransaction) APReceiveFollowServiceImpl(
jobQueueParentService, mock(), mock(), mock(), mock(), TestTransaction,
objectMapper
)
activityPubFollowService.receiveFollow( activityPubFollowService.receiveFollow(
Follow( Follow(
emptyList(), emptyList(),
@ -163,7 +167,8 @@ class APReceiveFollowServiceImplTest {
} }
), ),
userQueryService, userQueryService,
TestTransaction TestTransaction,
objectMapper
) )
activityPubFollowService.receiveFollowJob( activityPubFollowService.receiveFollowJob(
JobProps( JobProps(

View File

@ -12,6 +12,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.anyString
import org.mockito.kotlin.* import org.mockito.kotlin.*
import utils.TestApplicationConfig.testApplicationConfig
import java.security.KeyPairGenerator import java.security.KeyPairGenerator
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertNull import kotlin.test.assertNull
@ -28,7 +29,8 @@ class UserServiceTest {
onBlocking { hash(anyString()) } doReturn "hashedPassword" onBlocking { hash(anyString()) } doReturn "hashedPassword"
onBlocking { generateKeyPair() } doReturn generateKeyPair 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")) userService.createLocalUser(UserCreateDto("test", "testUser", "XXXXXXXXXXXXX", "test"))
verify(userRepository, times(1)).save(any()) verify(userRepository, times(1)).save(any())
argumentCaptor<dev.usbharu.hideout.domain.model.hideout.entity.User> { argumentCaptor<dev.usbharu.hideout.domain.model.hideout.entity.User> {
@ -54,7 +56,7 @@ class UserServiceTest {
val userRepository = mock<UserRepository> { val userRepository = mock<UserRepository> {
onBlocking { nextId() } doReturn 113345L onBlocking { nextId() } doReturn 113345L
} }
val userService = UserServiceImpl(userRepository, mock(), mock(), mock(), mock()) val userService = UserServiceImpl(userRepository, mock(), mock(), mock(), mock(), testApplicationConfig)
val user = RemoteUserCreateDto( val user = RemoteUserCreateDto(
"test", "test",
"example.com", "example.com",

View File

@ -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"))
}