diff --git a/.editorconfig b/.editorconfig index 308ebc6..9fe1f88 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,6 +10,7 @@ insert_final_newline = true trim_trailing_whitespace = true [*.{kt,kts}] +ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^ ktlint_standard_annotation = disabled ktlint_standard_annotation-spacing = disabled ktlint_standard_blank-line-before-declaration = disabled diff --git a/build.gradle.kts b/build.gradle.kts index 300eb60..a15706f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,32 +24,52 @@ java { toolchain { languageVersion = JavaLanguageVersion.of(libs.versions.jvm.get().toInt()) } + withSourcesJar() } repositories { + gradlePluginPortal() mavenCentral() mavenLocal() } +tasks.register("printVersion") { + doLast { println(project.version) } +} + kotlin { compilerOptions { freeCompilerArgs.addAll("-Xjsr305=strict", "-Xannotation-default-target=param-property") } } -tasks.withType { - useJUnitPlatform() - testLogging { - events("passed", "skipped", "failed") - showStandardStreams = true - exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL +tasks { + val ktlintFormatAndCheck by registering { + dependsOn("ktlintFormat") + doLast { + ProcessBuilder("${project.rootDir}/gradlew", "ktlintCheck") + .directory(project.rootDir).inheritIO() + .start().waitFor() // venter på at prosessen skal fullføre før vi går videre til testene + } } -} -tasks.register("printVersion") { - doLast { - println(project.version) + matching { it.name.startsWith("runKtlintCheck") }.configureEach { + mustRunAfter(project.tasks.matching { it.name.startsWith("runKtlintFormat") }) + } + + test { + useJUnitPlatform() + + jvmArgs("--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED") + exclude("**/RunCucumberTest*") + dependsOn(ktlintFormatAndCheck) + + testLogging { + events("passed", "skipped", "failed") + showStandardStreams = true + exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL + } } } diff --git a/src/main/kotlin/com/github/jactor/rises/shared/api/Command.kt b/src/main/kotlin/com/github/jactor/rises/shared/api/Command.kt index 7109019..cf89477 100644 --- a/src/main/kotlin/com/github/jactor/rises/shared/api/Command.kt +++ b/src/main/kotlin/com/github/jactor/rises/shared/api/Command.kt @@ -22,45 +22,41 @@ data class CreateUserCommand( @param:Schema(description = "The city of a user") val city: String? = null, @param:Schema(description = "The country of a user") val country: String? = null, ) { - fun toUserDto() = - UserDto( - persistentDto = toPersistentDto(), - personId = personId, - emailAddress = emailAddress, - username = username, - ) - - fun toPersonDto() = - PersonDto( - persistentDto = toPersistentDto(id = personId), - addressId = addressId, - locale = language, - firstName = firstName, - surname = surname, - description = description, - ) + fun toUserDto() = UserDto( + persistentDto = toPersistentDto(), + personId = personId, + emailAddress = emailAddress, + username = username, + ) - private fun toAddressDto(): AddressDto? = - zipCode?.let { - AddressDto( - persistentDto = PersistentDto(id = addressId), - zipCode = zipCode, - addressLine1 = addressLine1, - addressLine2 = addressLine2, - addressLine3 = addressLine3, - city = city, - country = country, - ) - } + fun toPersonDto() = PersonDto( + persistentDto = toPersistentDto(id = personId), + addressId = addressId, + locale = language, + firstName = firstName, + surname = surname, + description = description, + ) - private fun toPersistentDto(id: UUID? = null) = - PersistentDto( - id = id, - createdBy = username, - modifiedBy = username, - timeOfCreation = LocalDateTime.now(), - timeOfModification = LocalDateTime.now(), + private fun toAddressDto(): AddressDto? = zipCode?.let { + AddressDto( + persistentDto = PersistentDto(id = addressId), + zipCode = zipCode, + addressLine1 = addressLine1, + addressLine2 = addressLine2, + addressLine3 = addressLine3, + city = city, + country = country, ) + } + + private fun toPersistentDto(id: UUID? = null) = PersistentDto( + id = id, + createdBy = username, + modifiedBy = username, + timeOfCreation = LocalDateTime.now(), + timeOfModification = LocalDateTime.now(), + ) } @JvmRecord diff --git a/src/main/kotlin/com/github/jactor/rises/shared/serialization/JsonMapper.kt b/src/main/kotlin/com/github/jactor/rises/shared/serialization/JsonMapper.kt index 758283c..95a44bb 100644 --- a/src/main/kotlin/com/github/jactor/rises/shared/serialization/JsonMapper.kt +++ b/src/main/kotlin/com/github/jactor/rises/shared/serialization/JsonMapper.kt @@ -7,10 +7,9 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import java.text.SimpleDateFormat object JsonMapper { - val objectMapper: ObjectMapper = - ObjectMapper() - .registerModule(JavaTimeModule()) - .registerModule(Jdk8Module()) - .setDateFormat(SimpleDateFormat("yyyy-MM-dd")) - .setDefaultPropertyInclusion(Include.NON_NULL) + val objectMapper: ObjectMapper = ObjectMapper() + .registerModule(JavaTimeModule()) + .registerModule(Jdk8Module()) + .setDateFormat(SimpleDateFormat("yyyy-MM-dd")) + .setDefaultPropertyInclusion(Include.NON_NULL) } diff --git a/src/test/kotlin/com/github/jactor/rises/shared/serialization/JsonMapperTest.kt b/src/test/kotlin/com/github/jactor/rises/shared/serialization/JsonMapperTest.kt index ad78db2..74f220c 100644 --- a/src/test/kotlin/com/github/jactor/rises/shared/serialization/JsonMapperTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/shared/serialization/JsonMapperTest.kt @@ -37,86 +37,85 @@ class JsonMapperTest { companion object { @JvmStatic - fun initDataForSerialization(): List = - listOf( - CreateUserCommand( - addressId = UUID.randomUUID(), - personId = UUID.randomUUID(), - username = "burn", - surname = "stakehouse", - emailAddress = "somewhere@ourt.there.com", - description = "it is cold outside", - firstName = "kevin", - language = "nb", - addressLine1 = "one street", - addressLine2 = "on the corner", - addressLine3 = "by the way", - zipCode = "12345", - city = "the big one", - country = "no", - ) to CreateUserCommand::class.java, - CreateBlogEntryCommand( - blogId = UUID.randomUUID(), - creatorName = "me", - entry = "life is good", - ) to CreateBlogEntryCommand::class.java, - CreateGuestBookCommand( - title = "once upon a time", - userId = UUID.randomUUID(), - ) to CreateGuestBookCommand::class.java, - CreateGuestBookEntryCommand( - guestBookId = UUID.randomUUID(), - creatorName = "visitor", - entry = "nice place you have here", - ) to CreateGuestBookEntryCommand::class.java, - UpdateBlogTitleCommand( - blogId = UUID.randomUUID(), - title = "a new dawn", - ) to UpdateBlogTitleCommand::class.java, - BlogDto( - persistentDto = initPersistentDto(), - title = "my blog", - userId = UUID.randomUUID(), - ) to BlogDto::class.java, - BlogEntryDto( - persistentDto = initPersistentDto(), - blogId = UUID.randomUUID(), - creatorName = "author", - ) to BlogEntryDto::class.java, - GuestBookDto( - persistentDto = initPersistentDto(), - title = "the guest book", - userId = UUID.randomUUID(), - ) to GuestBookDto::class.java, - GuestBookEntryDto( - persistentDto = initPersistentDto(), - creatorName = "guest", - entry = "hello world", - guestBookId = UUID.randomUUID(), - ) to GuestBookEntryDto::class.java, - UserDto( - persistentDto = initPersistentDto(), - emailAddress = "somewhat@strange.com", - personId = UUID.randomUUID(), - username = "strangeuser", - userType = com.github.jactor.rises.shared.api.UserType.ACTIVE, - ) to UserDto::class.java, - PersonDto( - persistentDto = initPersistentDto(), - addressId = UUID.randomUUID(), - locale = "en", - firstName = "first", - surname = "last", - description = "just a person", - ) to PersonDto::class.java, - ).map { Arguments.of(Named.of(it.first::class.simpleName!!, it.first), it.second) } - private fun initPersistentDto(): PersistentDto = - PersistentDto( - id = UUID.randomUUID(), - createdBy = "creator", - modifiedBy = "modifier", - timeOfCreation = LocalDateTime.now().roundDownToMinute(), - timeOfModification = LocalDateTime.now().roundDownToMinute(), - ) + fun initDataForSerialization(): List = listOf( + CreateUserCommand( + addressId = UUID.randomUUID(), + personId = UUID.randomUUID(), + username = "burn", + surname = "stakehouse", + emailAddress = "somewhere@ourt.there.com", + description = "it is cold outside", + firstName = "kevin", + language = "nb", + addressLine1 = "one street", + addressLine2 = "on the corner", + addressLine3 = "by the way", + zipCode = "12345", + city = "the big one", + country = "no", + ) to CreateUserCommand::class.java, + CreateBlogEntryCommand( + blogId = UUID.randomUUID(), + creatorName = "me", + entry = "life is good", + ) to CreateBlogEntryCommand::class.java, + CreateGuestBookCommand( + title = "once upon a time", + userId = UUID.randomUUID(), + ) to CreateGuestBookCommand::class.java, + CreateGuestBookEntryCommand( + guestBookId = UUID.randomUUID(), + creatorName = "visitor", + entry = "nice place you have here", + ) to CreateGuestBookEntryCommand::class.java, + UpdateBlogTitleCommand( + blogId = UUID.randomUUID(), + title = "a new dawn", + ) to UpdateBlogTitleCommand::class.java, + BlogDto( + persistentDto = initPersistentDto(), + title = "my blog", + userId = UUID.randomUUID(), + ) to BlogDto::class.java, + BlogEntryDto( + persistentDto = initPersistentDto(), + blogId = UUID.randomUUID(), + creatorName = "author", + ) to BlogEntryDto::class.java, + GuestBookDto( + persistentDto = initPersistentDto(), + title = "the guest book", + userId = UUID.randomUUID(), + ) to GuestBookDto::class.java, + GuestBookEntryDto( + persistentDto = initPersistentDto(), + creatorName = "guest", + entry = "hello world", + guestBookId = UUID.randomUUID(), + ) to GuestBookEntryDto::class.java, + UserDto( + persistentDto = initPersistentDto(), + emailAddress = "somewhat@strange.com", + personId = UUID.randomUUID(), + username = "strangeuser", + userType = com.github.jactor.rises.shared.api.UserType.ACTIVE, + ) to UserDto::class.java, + PersonDto( + persistentDto = initPersistentDto(), + addressId = UUID.randomUUID(), + locale = "en", + firstName = "first", + surname = "last", + description = "just a person", + ) to PersonDto::class.java, + ).map { Arguments.of(Named.of(it.first::class.simpleName!!, it.first), it.second) } + + private fun initPersistentDto(): PersistentDto = PersistentDto( + id = UUID.randomUUID(), + createdBy = "creator", + modifiedBy = "modifier", + timeOfCreation = LocalDateTime.now().roundDownToMinute(), + timeOfModification = LocalDateTime.now().roundDownToMinute(), + ) } }