Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 30 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test> {
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
}
}
}

Expand Down
68 changes: 32 additions & 36 deletions src/main/kotlin/com/github/jactor/rises/shared/api/Command.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,86 +37,85 @@ class JsonMapperTest {

companion object {
@JvmStatic
fun initDataForSerialization(): List<Arguments> =
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<Arguments> = 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(),
)
}
}
Loading