diff --git a/src/test/kotlin/dev/usbharu/hideout/Empty.kt b/src/test/kotlin/dev/usbharu/hideout/Empty.kt index 2feb27f1..c5282364 100644 --- a/src/test/kotlin/dev/usbharu/hideout/Empty.kt +++ b/src/test/kotlin/dev/usbharu/hideout/Empty.kt @@ -3,5 +3,4 @@ package dev.usbharu.hideout import io.ktor.server.application.* fun Application.empty() { - } diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt index 921dc740..e788e4bb 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/ActivityPubKtTest.kt @@ -15,7 +15,6 @@ import java.time.Instant class ActivityPubKtTest { @Test fun HttpSignTest(): Unit = runBlocking { - val ktorKeyMap = KtorKeyMap(object : IUserRepository { override suspend fun save(user: User): User { TODO("Not yet implemented") @@ -96,12 +95,13 @@ class ActivityPubKtTest { override suspend fun nextId(): Long { TODO("Not yet implemented") } - }) - val httpClient = HttpClient(MockEngine { httpRequestData -> - respondOk() - }) { + val httpClient = HttpClient( + MockEngine { httpRequestData -> + respondOk() + } + ) { install(httpSignaturePlugin) { keyMap = ktorKeyMap } @@ -112,7 +112,5 @@ class ActivityPubKtTest { } httpClient.postAp("https://localhost", "test", JsonLd(emptyList())) - - } } diff --git a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt index 62ddd05a..710b2620 100644 --- a/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/plugins/KtorKeyMapTest.kt @@ -46,7 +46,6 @@ class KtorKeyMapTest { generateKeyPair.private.toPem(), createdAt = Instant.now() ) - } override suspend fun findByDomain(domain: String): List { @@ -92,7 +91,6 @@ class KtorKeyMapTest { override suspend fun nextId(): Long { TODO("Not yet implemented") } - }) ktorKeyMap.getPrivateKey("test") diff --git a/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt b/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt index b4f9d42f..aab82880 100644 --- a/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/repository/UserRepositoryTest.kt @@ -18,7 +18,6 @@ import java.time.Clock import java.time.Instant import java.time.ZoneId - class UserRepositoryTest { lateinit var db: Database @@ -35,7 +34,6 @@ class UserRepositoryTest { @AfterEach fun tearDown() { transaction(db) { - SchemaUtils.drop(UsersFollowers) SchemaUtils.drop(Users) } @@ -43,11 +41,14 @@ class UserRepositoryTest { @Test fun `findFollowersById フォロワー一覧を取得`() = runTest { - val userRepository = UserRepository(db, object : IdGenerateService { - override suspend fun generateId(): Long { - TODO("Not yet implemented") + val userRepository = UserRepository( + db, + object : IdGenerateService { + override suspend fun generateId(): Long { + TODO("Not yet implemented") + } } - }) + ) val user = userRepository.save( User( id = 0L, @@ -98,16 +99,18 @@ class UserRepositoryTest { userRepository.findFollowersById(user.id).let { assertIterableEquals(listOf(follower, follower2), it) } - } @Test fun `createFollower フォロワー追加`() = runTest { - val userRepository = UserRepository(db, object : IdGenerateService { - override suspend fun generateId(): Long { - TODO("Not yet implemented") + val userRepository = UserRepository( + db, + object : IdGenerateService { + override suspend fun generateId(): Long { + TODO("Not yet implemented") + } } - }) + ) val user = userRepository.save( User( 0L, @@ -140,11 +143,9 @@ class UserRepositoryTest { ) userRepository.createFollower(user.id, follower.id) transaction { - val followerIds = UsersFollowers.select { UsersFollowers.userId eq user.id }.map { it[UsersFollowers.followerId] } assertIterableEquals(listOf(follower.id), followerIds) } - } } diff --git a/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt b/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt index 0e997f43..03bf53a4 100644 --- a/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/routing/activitypub/UsersAPTest.kt @@ -32,7 +32,6 @@ import java.time.Instant import kotlin.test.assertEquals import kotlin.test.assertTrue - class UsersAPTest { @Test() @@ -100,8 +99,8 @@ class UsersAPTest { } } + // @Disabled @Test() -// @Disabled fun `ユーザのURLにAcceptヘッダーをActivityとJson-LDにしてアクセスしたときPersonが返ってくる`() = testApplication { environment { config = ApplicationConfig("empty.conf") @@ -167,16 +166,21 @@ class UsersAPTest { } } + // @Disabled @Test -// @Disabled fun contentType_Test() { - assertTrue(ContentType.Application.Activity.match("application/activity+json")) val listOf = listOf(ContentType.Application.JsonLd, ContentType.Application.Activity) - assertTrue(listOf.find { contentType -> - contentType.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") - }.let { it != null }) - assertTrue(ContentType.Application.JsonLd.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"")) + assertTrue( + listOf.find { contentType -> + contentType.match("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"") + }.let { it != null } + ) + assertTrue( + ContentType.Application.JsonLd.match( + "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" + ) + ) } @Test diff --git a/src/test/kotlin/dev/usbharu/hideout/service/TwitterSnowflakeIdGenerateServiceTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/TwitterSnowflakeIdGenerateServiceTest.kt index d1d5ff60..e1aab2f3 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/TwitterSnowflakeIdGenerateServiceTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/TwitterSnowflakeIdGenerateServiceTest.kt @@ -1,6 +1,6 @@ package dev.usbharu.hideout.service -//import kotlinx.coroutines.NonCancellable.message +// import kotlinx.coroutines.NonCancellable.message import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch @@ -16,17 +16,13 @@ class TwitterSnowflakeIdGenerateServiceTest { val mutex = Mutex() val mutableListOf = mutableListOf() coroutineScope { - repeat(500000) { - launch(Dispatchers.IO) { val id = TwitterSnowflakeIdGenerateService.generateId() mutex.withLock { mutableListOf.add(id) - } } - } } diff --git a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubFollowServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubFollowServiceImplTest.kt index a8eae660..93dfec61 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubFollowServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubFollowServiceImplTest.kt @@ -122,28 +122,30 @@ class ActivityPubFollowServiceImplTest { mock(), activityPubUserService, userService, - HttpClient(MockEngine { httpRequestData -> - assertEquals(person.inbox, httpRequestData.url.toString()) - val accept = Accept( - type = emptyList(), - name = "Follow", - `object` = Follow( + HttpClient( + MockEngine { httpRequestData -> + assertEquals(person.inbox, httpRequestData.url.toString()) + val accept = Accept( type = emptyList(), name = "Follow", - `object` = "https://example.com", - actor = "https://follower.example.com" - ), - actor = "https://example.com" - ) - accept.context += "https://www.w3.org/ns/activitystreams" - assertEquals( - accept, - Config.configData.objectMapper.readValue( - httpRequestData.body.toByteArray().decodeToString() + `object` = Follow( + type = emptyList(), + name = "Follow", + `object` = "https://example.com", + actor = "https://follower.example.com" + ), + actor = "https://example.com" ) - ) - respondOk() - }) + accept.context += "https://www.w3.org/ns/activitystreams" + assertEquals( + accept, + Config.configData.objectMapper.readValue( + httpRequestData.body.toByteArray().decodeToString() + ) + ) + respondOk() + } + ) ) activityPubFollowService.receiveFollowJob( JobProps( diff --git a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt index bb15ffde..af5274de 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubNoteServiceImplTest.kt @@ -73,7 +73,13 @@ class ActivityPubNoteServiceImplTest { val jobQueueParentService = mock() val activityPubNoteService = ActivityPubNoteServiceImpl(mock(), jobQueueParentService, userService) val postEntity = PostEntity( - 1L, 1L, null, "test text", 1L, 1, "https://example.com" + 1L, + 1L, + null, + "test text", + 1L, + 1, + "https://example.com" ) activityPubNoteService.createNote(postEntity) verify(jobQueueParentService, times(2)).schedule(eq(DeliverPostJob), any()) @@ -82,17 +88,19 @@ class ActivityPubNoteServiceImplTest { @Test fun `createPostJob 新しい投稿のJob`() = runTest { Config.configData = ConfigData(objectMapper = JsonObjectMapper.objectMapper) - val httpClient = HttpClient(MockEngine { httpRequestData -> - assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString()) - respondOk() - }) + val httpClient = HttpClient( + MockEngine { httpRequestData -> + assertEquals("https://follower.example.com/inbox", httpRequestData.url.toString()) + respondOk() + } + ) val activityPubNoteService = ActivityPubNoteServiceImpl(httpClient, mock(), mock()) activityPubNoteService.createNoteJob( JobProps( data = mapOf( DeliverPostJob.actor.name to "https://follower.example.com", DeliverPostJob.post.name to "{\"id\":1,\"userId\":1,\"inReplyToId\":null,\"text\":\"test text\"," + - "\"createdAt\":1,\"updatedAt\":1,\"url\":\"https://example.com\"}", + "\"createdAt\":1,\"updatedAt\":1,\"url\":\"https://example.com\"}", DeliverPostJob.inbox.name to "https://follower.example.com/inbox" ), json = Json diff --git a/src/test/kotlin/dev/usbharu/hideout/service/impl/UserServiceTest.kt b/src/test/kotlin/dev/usbharu/hideout/service/impl/UserServiceTest.kt index 42606f8b..deab1ce6 100644 --- a/src/test/kotlin/dev/usbharu/hideout/service/impl/UserServiceTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/service/impl/UserServiceTest.kt @@ -50,10 +50,8 @@ class UserServiceTest { @Test fun `createRemoteUser リモートユーザーを作成できる`() = runTest { - Config.configData = ConfigData(domain = "example.com", url = "https://example.com") - val userRepository = mock { onBlocking { nextId() } doReturn 113345L } diff --git a/src/test/kotlin/utils/DatabaseTestBase.kt b/src/test/kotlin/utils/DatabaseTestBase.kt index 10653631..d81f8b80 100644 --- a/src/test/kotlin/utils/DatabaseTestBase.kt +++ b/src/test/kotlin/utils/DatabaseTestBase.kt @@ -4,7 +4,6 @@ import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.DatabaseConfig import org.junit.jupiter.api.extension.ExtendWith - @ExtendWith(DBResetInterceptor::class) abstract class DatabaseTestBase { companion object { @@ -12,7 +11,8 @@ abstract class DatabaseTestBase { Database.connect( "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = "org.h2.Driver", - databaseConfig = DatabaseConfig { useNestedTransactions = true }) + databaseConfig = DatabaseConfig { useNestedTransactions = true } + ) } } }