test: テストを追加

This commit is contained in:
usbharu 2023-12-14 14:37:36 +09:00
parent 382fe89142
commit 48bbf6a53b
5 changed files with 213 additions and 13 deletions

View File

@ -83,7 +83,9 @@ tasks.withType<Test> {
useJUnitPlatform() useJUnitPlatform()
doFirst { doFirst {
jvmArgs = arrayOf( jvmArgs = arrayOf(
"--add-opens", "java.base/java.lang=ALL-UNNAMED" "--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED",
"--add-opens", "java.naming/javax.naming=ALL-UNNAMED",
).toMutableList() ).toMutableList()
} }
} }

View File

@ -1,10 +1,15 @@
package dev.usbharu.hideout package dev.usbharu.hideout
import com.fasterxml.jackson.module.kotlin.isKotlinClass
import com.jparams.verifier.tostring.ToStringVerifier import com.jparams.verifier.tostring.ToStringVerifier
import com.jparams.verifier.tostring.preset.Presets
import nl.jqno.equalsverifier.EqualsVerifier import nl.jqno.equalsverifier.EqualsVerifier
import nl.jqno.equalsverifier.Warning import nl.jqno.equalsverifier.Warning
import nl.jqno.equalsverifier.internal.reflection.PackageScanner import nl.jqno.equalsverifier.internal.reflection.PackageScanner
import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.DynamicTest.dynamicTest
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestFactory
import java.lang.reflect.Modifier import java.lang.reflect.Modifier
import kotlin.test.assertFails import kotlin.test.assertFails
@ -20,23 +25,32 @@ class EqualsAndToStringTest {
} }
} }
@Test @TestFactory
fun toStringTest() { fun toStringTest(): List<DynamicTest> {
PackageScanner.getClassesIn("dev.usbharu.hideout", null, true) return PackageScanner.getClassesIn("dev.usbharu.hideout", null, true)
.filter { .filter {
it != null && !it.isEnum && !it.isInterface && !Modifier.isAbstract(it.modifiers) it != null && !it.isEnum && !it.isInterface && !Modifier.isAbstract(it.modifiers)
} }
.forEach { .filter {
val clazz = it.getMethod(it::toString.name).declaringClass
clazz != Any::class.java && clazz != Throwable::class.java
}
.filter {
it.superclass == Any::class.java || it.superclass?.packageName?.startsWith("dev.usbharu") ?: true
}
.map {
dynamicTest(it.name) {
if (it.isKotlinClass()) {
println(" at ${it.name}.toString(${it.simpleName}.kt:1)")
}
try { try {
ToStringVerifier.forClass(it).verify() ToStringVerifier.forClass(it).withPreset(Presets.INTELLI_J).verify()
} catch (e: AssertionError) {
println(it.name)
e.printStackTrace()
} catch (e: Exception) { } catch (e: Exception) {
println(it.name)
e.printStackTrace() e.printStackTrace()
} }
} }
} }
} }
}

View File

@ -0,0 +1,83 @@
package dev.usbharu.hideout.activitypub.domain.model
import com.fasterxml.jackson.module.kotlin.readValue
import dev.usbharu.hideout.application.config.ActivityPubConfig
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Test
class CreateTest {
@Test
fun Createのデイシリアライズができる() {
@Language("JSON") val json = """{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"sensitive": "as:sensitive",
"Hashtag": "as:Hashtag",
"quoteUrl": "as:quoteUrl",
"toot": "http://joinmastodon.org/ns#",
"Emoji": "toot:Emoji",
"featured": "toot:featured",
"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#"
}
],
"id": "https://misskey.usbharu.dev/notes/9f2i9cm88e/activity",
"actor": "https://misskey.usbharu.dev/users/97ws8y3rj6",
"type": "Create",
"published": "2023-05-22T14:26:53.600Z",
"object": {
"id": "https://misskey.usbharu.dev/notes/9f2i9cm88e",
"type": "Note",
"attributedTo": "https://misskey.usbharu.dev/users/97ws8y3rj6",
"content": "<p><a href=\"https://calckey.jp/@trapezial\" class=\"u-url mention\">@trapezial@calckey.jp</a><span> いやそういうことじゃなくて、連合先と自インスタンスで状態が狂うことが多いのでどっちに合わせるべきかと…</span></p>",
"_misskey_content": "@trapezial@calckey.jp いやそういうことじゃなくて、連合先と自インスタンスで状態が狂うことが多いのでどっちに合わせるべきかと…",
"source": {
"content": "@trapezial@calckey.jp いやそういうことじゃなくて、連合先と自インスタンスで状態が狂うことが多いのでどっちに合わせるべきかと…",
"mediaType": "text/x.misskeymarkdown"
},
"published": "2023-05-22T14:26:53.600Z",
"to": [
"https://misskey.usbharu.dev/users/97ws8y3rj6/followers"
],
"cc": [
"https://www.w3.org/ns/activitystreams#Public",
"https://calckey.jp/users/9bu1xzwjyb"
],
"inReplyTo": "https://calckey.jp/notes/9f2i7ymf1d",
"attachment": [],
"sensitive": false,
"tag": [
{
"type": "Mention",
"href": "https://calckey.jp/users/9bu1xzwjyb",
"name": "@trapezial@calckey.jp"
}
]
},
"to": [
"https://misskey.usbharu.dev/users/97ws8y3rj6/followers"
],
"cc": [
"https://www.w3.org/ns/activitystreams#Public",
"https://calckey.jp/users/9bu1xzwjyb"
]
}
"""
val objectMapper = ActivityPubConfig().objectMapper()
objectMapper.readValue<Create>(json)
}
}

View File

@ -0,0 +1,37 @@
package dev.usbharu.hideout.activitypub.domain.model
import com.fasterxml.jackson.module.kotlin.readValue
import dev.usbharu.hideout.application.config.ActivityPubConfig
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Test
class DocumentTest {
@Test
fun Documentをデシリアライズできる() {
@Language("JSON") val json = """{
"type": "Document",
"mediaType": "image/webp",
"url": "https://s3misskey.usbharu.dev/misskey-minio/misskey-minio/data/81ec9ad1-2581-466e-b90c-d9d2350ab95c.webp",
"name": "ALTテスト"
}"""
val objectMapper = ActivityPubConfig().objectMapper()
objectMapper.readValue<Document>(json)
}
@Test
fun nameがnullなDocumentのデイシリアライズができる() {
//language=JSON
val json = """{
"type": "Document",
"mediaType": "image/webp",
"url": "https://s3misskey.usbharu.dev/misskey-minio/misskey-minio/data/81ec9ad1-2581-466e-b90c-d9d2350ab95c.webp",
"name": null
}"""
val objectMapper = ActivityPubConfig().objectMapper()
objectMapper.readValue<Document>(json)
}
}

View File

@ -72,4 +72,68 @@ class PersonSerializeTest {
val readValue = objectMapper.readValue<Person>(personString) val readValue = objectMapper.readValue<Person>(personString)
} }
@Test
fun MisskeyのnameがnullのPersonのデシリアライズができる() {
//language=JSON
val json = """{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"sensitive": "as:sensitive",
"Hashtag": "as:Hashtag",
"quoteUrl": "as:quoteUrl",
"toot": "http://joinmastodon.org/ns#",
"Emoji": "toot:Emoji",
"featured": "toot:featured",
"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#"
}
],
"type": "Person",
"id": "https://misskey.usbharu.dev/users/9ghwhv9zgg",
"inbox": "https://misskey.usbharu.dev/users/9ghwhv9zgg/inbox",
"outbox": "https://misskey.usbharu.dev/users/9ghwhv9zgg/outbox",
"followers": "https://misskey.usbharu.dev/users/9ghwhv9zgg/followers",
"following": "https://misskey.usbharu.dev/users/9ghwhv9zgg/following",
"featured": "https://misskey.usbharu.dev/users/9ghwhv9zgg/collections/featured",
"sharedInbox": "https://misskey.usbharu.dev/inbox",
"endpoints": {
"sharedInbox": "https://misskey.usbharu.dev/inbox"
},
"url": "https://misskey.usbharu.dev/@relay_test",
"preferredUsername": "relay_test",
"name": null,
"summary": null,
"_misskey_summary": null,
"icon": null,
"image": null,
"tag": [],
"manuallyApprovesFollowers": true,
"discoverable": true,
"publicKey": {
"id": "https://misskey.usbharu.dev/users/9ghwhv9zgg#main-key",
"type": "Key",
"owner": "https://misskey.usbharu.dev/users/9ghwhv9zgg",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA2n5yekTaI4ex5VDWzQfE\nJpWMURAMWl8RcXHLPyLQVQ/PrHp7qatGXmKJUnAOBcq1cwk+VCqTEqx8vJCOZsr1\nMq+D3FMcFdwgtJ0nivPJPx2457b5kfQ4LTkWajcFhj2qixa/XFq6hHei3LDaE6hJ\nGQbdj9NTVlMd7VpiFQkoU09vAPUwGxRoP9Qbc/sh7jrKYFB3iRmY/+zOc+PFpnfn\nG8V1d2v+lnkb9f7t0Z8y2ckk6TVcLPRZktF15eGClVptlgts3hwhrcyrpBs2Dn0U\n35KgIhkhZGAjzk0uyplpfKcserXuGvsjJvelZ3BtMGsuR4kGLHrmiRQp23mIoA1I\n8tfVuV0zPOyO3ruLk2fOjoeZ4XvFHGRNKo66Qx055/8G8Ug5vU8lvIGXm9sflaA9\ntR3AKDNsyxEfjAfrfgJ7cwlKSlLZmkU51jtYEqJ48ZkiIa6fMC0m4QGXdaXmhFWC\no1sGoIErRFpRHewdGlLC9S8R/cMxjex+n8maF0yh79y7aVvU+TS6pRWg5wYjY8r3\nZqAVg/PGRVGAbjVdIdcsjH5ClwAFBW16S633D3m7HJypwwVCzVOvMZqPqcQ/2o8c\nUk+xa88xQG+OPqoAaQqyV9iqsmCMgYM/AcX/BC2h7L2mE/PWoXnoCxGPxr5uvyBf\nHQakDGg4pFZcpVNrDlYo260CAwEAAQ==\n-----END PUBLIC KEY-----\n"
},
"isCat": false
}"""
val objectMapper = ActivityPubConfig().objectMapper()
objectMapper.readValue<Person>(json)
}
} }