From c839370d9caee9a3d2ad52497df8e25695add6a3 Mon Sep 17 00:00:00 2001 From: Tor Egil Jacobsen Date: Sat, 11 Apr 2026 11:37:36 +0200 Subject: [PATCH 1/2] #4: bump spring-boot, 4.0.4 -> 4.0.5 - also in README.md - codeformatting in JsonMapperTest.kt --- README.md | 4 ++-- gradle/libs.versions.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f72308f..9a94e90 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ archived project [jactor-rises](https://github.com/jactor-rises/jactor-rises)) ### Set up -* a spring-boot 3 application +* a spring-boot 4 application * build with [gradle](https://gradle.org). * is using [h2](http://h2database.com) (in-memory database) * run it with spring-boot @@ -50,7 +50,7 @@ java -jar build/lib/jactor-persistence--SNAPSHOT.jar #### Implementation -* [spring-boot 3.5.x](https://spring.io/projects/spring-boot) +* [spring-boot 4.x](https://spring.io/projects/spring-boot) * [jetbrains-exposed](https://www.jetbrains.com/exposed/) * [h2](http://h2database.com) * [kotlin 2.x](https://kotlinlang.org) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a64109e..1ac8109 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ jvm = "25" kotlin = "2.3.20" kotlin-logging = "8.0.01" ktlint = "14.0.1" -spring-boot = "4.0.4" +spring-boot = "4.0.5" springdoc-openapi = "1.8.0" springmockk = "5.0.1" versions-plugin = "0.53.0" From b9eec3b0feb40b0a78d1e7f9d9160d801e9d8991 Mon Sep 17 00:00:00 2001 From: Tor Egil Jacobsen Date: Sat, 11 Apr 2026 12:00:43 +0200 Subject: [PATCH 2/2] #4: ktlintFormatAndCheck in build.gradle.kts - code formatting in the project - synchronizing ordering of imports in IntelliJ with .editorconfig --- .editorconfig | 3 +- build.gradle.kts | 36 ++- .../rises/persistence/ExceptionHandler.kt | 9 +- .../rises/persistence/JactorPersistence.kt | 9 +- .../rises/persistence/PersistenceHandler.kt | 9 +- .../jactor/rises/persistence/Persistent.kt | 15 +- .../jactor/rises/persistence/PersistentDao.kt | 15 +- .../rises/persistence/address/Address.kt | 27 +- .../rises/persistence/address/AddressDao.kt | 19 +- .../address/AddressRepositoryObject.kt | 11 +- .../rises/persistence/address/Addresses.kt | 7 +- .../jactor/rises/persistence/blog/Blog.kt | 32 +-- .../rises/persistence/blog/BlogController.kt | 79 +++--- .../jactor/rises/persistence/blog/BlogDao.kt | 13 +- .../rises/persistence/blog/BlogEntries.kt | 7 +- .../rises/persistence/blog/BlogEntry.kt | 34 ++- .../rises/persistence/blog/BlogEntryDao.kt | 13 +- .../persistence/blog/BlogRepositoryObject.kt | 152 +++++----- .../jactor/rises/persistence/blog/Blogs.kt | 7 +- .../rises/persistence/config/ExposedConfig.kt | 14 +- .../rises/persistence/guestbook/GuestBook.kt | 41 ++- .../guestbook/GuestBookController.kt | 63 ++--- .../persistence/guestbook/GuestBookDao.kt | 16 +- .../persistence/guestbook/GuestBookEntries.kt | 7 +- .../persistence/guestbook/GuestBookEntry.kt | 34 ++- .../guestbook/GuestBookEntryDao.kt | 22 +- .../guestbook/GuestBookRepositoryObject.kt | 146 +++++----- .../persistence/guestbook/GuestBookService.kt | 63 ++--- .../rises/persistence/guestbook/GuestBooks.kt | 7 +- .../jactor/rises/persistence/person/People.kt | 7 +- .../jactor/rises/persistence/person/Person.kt | 42 ++- .../rises/persistence/person/PersonDao.kt | 26 +- .../person/PersonRepositoryObject.kt | 76 +++-- .../jactor/rises/persistence/user/Model.kt | 21 +- .../jactor/rises/persistence/user/User.kt | 44 ++- .../rises/persistence/user/UserController.kt | 55 ++-- .../jactor/rises/persistence/user/UserDao.kt | 27 +- .../persistence/user/UserRepositoryObject.kt | 114 ++++---- .../jactor/rises/persistence/user/Users.kt | 7 +- .../jactor/rises/persistence/DtoMapperTest.kt | 13 +- .../rises/persistence/JsonMappingTest.kt | 7 +- .../persistence/PersistenceHandlerTest.kt | 203 +++++++------ .../rises/persistence/PersistentDaoTest.kt | 40 ++- .../rises/persistence/RepositoriesTest.kt | 43 ++- .../address/AddressRepositoryTest.kt | 34 ++- .../rises/persistence/address/AddressTest.kt | 51 ++-- .../address/AddressTestRepositoryObject.kt | 72 +++-- .../persistence/blog/BlogControllerTest.kt | 267 ++++++++---------- .../rises/persistence/blog/BlogEntryTest.kt | 52 ++-- .../persistence/blog/BlogRepositoryTest.kt | 112 ++++---- .../rises/persistence/blog/BlogServiceTest.kt | 15 +- .../jactor/rises/persistence/blog/BlogTest.kt | 39 ++- .../blog/BlogTestRepositoryObject.kt | 14 +- .../persistence/cucumber/RestServiceSteps.kt | 10 +- .../guestbook/GuestBookControllerTest.kt | 159 +++++------ .../guestbook/GuestBookEntryTest.kt | 52 ++-- .../guestbook/GuestBookRepositoryTest.kt | 205 ++++++-------- .../guestbook/GuestBookServiceTest.kt | 169 ++++++----- .../persistence/guestbook/GuestBookTest.kt | 33 +-- .../GuestBookTestRepositoryObject.kt | 11 +- .../person/PersonRepositoryTest.kt | 81 +++--- .../rises/persistence/person/PersonTest.kt | 44 ++- .../person/PersonTestRepositoryObject.kt | 17 +- .../AbstractSpringBootNoDirtyContextTest.kt | 54 ++-- .../persistence/test/AssertExtensions.kt | 9 +- .../persistence/test/PersistenceExtensions.kt | 42 ++- .../persistence/test/StringExtensions.kt | 15 +- .../jactor/rises/persistence/test/TestUtil.kt | 48 ++-- .../persistence/user/UserControllerTest.kt | 123 ++++---- .../persistence/user/UserRepositoryTest.kt | 60 ++-- .../jactor/rises/persistence/user/UserTest.kt | 33 +-- 71 files changed, 1594 insertions(+), 1862 deletions(-) diff --git a/.editorconfig b/.editorconfig index 551c01c..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 @@ -19,4 +20,4 @@ ktlint_standard_function-expression-body = disabled ktlint_standard_function-signature = disabled ktlint_standard_modifier-list-spacing = disabled ktlint_standard_multiline-expression-wrapping = disabled -ktlint_standard_parameter-list-wrapping = disabled \ No newline at end of file +ktlint_standard_parameter-list-wrapping = disabled diff --git a/build.gradle.kts b/build.gradle.kts index 4df0462..cd36b8d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -64,20 +64,34 @@ repositories { } tasks.register("printVersion") { - doLast { - println(project.version) - } + doLast { println(project.version) } } -tasks.test { - useJUnitPlatform() +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 + } + } + + 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*") + 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 + 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/persistence/ExceptionHandler.kt b/src/main/kotlin/com/github/jactor/rises/persistence/ExceptionHandler.kt index bd51555..908a88b 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/ExceptionHandler.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/ExceptionHandler.kt @@ -47,11 +47,10 @@ fun Throwable.exceptionMessageMedCause(): String { return "$exceptionMessage$causeMessage".take(10000) } -private fun Throwable.exceptionMessage() = - when (this is HttpClientErrorException) { - true -> "Internal client, $statusCode: ${simpleExceptionMessage()}" - false -> simpleExceptionMessage() - } +private fun Throwable.exceptionMessage() = when (this is HttpClientErrorException) { + true -> "Internal client, $statusCode: ${simpleExceptionMessage()}" + false -> simpleExceptionMessage() +} private fun Throwable?.findRootCauseMessage(): String? { var rootCause: Throwable? = this diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/JactorPersistence.kt b/src/main/kotlin/com/github/jactor/rises/persistence/JactorPersistence.kt index 9cbd97a..29e4787 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/JactorPersistence.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/JactorPersistence.kt @@ -36,11 +36,10 @@ class JactorPersistence { } } -private fun list(args: Array) = - when (args.isEmpty()) { - true -> "without arguments!" - false -> "with arguments: ${args.joinToString { " " }}!" - } +private fun list(args: Array) = when (args.isEmpty()) { + true -> "without arguments!" + false -> "with arguments: ${args.joinToString { " " }}!" +} fun main(args: Array) { runApplication(*args) diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/PersistenceHandler.kt b/src/main/kotlin/com/github/jactor/rises/persistence/PersistenceHandler.kt index d8fc705..b5abdd6 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/PersistenceHandler.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/PersistenceHandler.kt @@ -8,9 +8,8 @@ class PersistenceHandler { suspend fun > modifyAndSave( dao: T, modifier: suspend (T) -> T, - ): T = - run { - dao.isPersisted.whenTrue { dao.modifiedBy(modifier = "todo") } - modifier(dao) - } + ): T = run { + dao.isPersisted.whenTrue { dao.modifiedBy(modifier = "todo") } + modifier(dao) + } } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/Persistent.kt b/src/main/kotlin/com/github/jactor/rises/persistence/Persistent.kt index 1fe378c..29ab2ad 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/Persistent.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/Persistent.kt @@ -12,12 +12,11 @@ data class Persistent( val timeOfCreation: LocalDateTime = LocalDateTime.now(), val timeOfModification: LocalDateTime = LocalDateTime.now(), ) { - fun toPersistentDto() = - PersistentDto( - id = id, - createdBy = createdBy, - modifiedBy = modifiedBy, - timeOfCreation = timeOfCreation, - timeOfModification = timeOfModification, - ) + fun toPersistentDto() = PersistentDto( + id = id, + createdBy = createdBy, + modifiedBy = modifiedBy, + timeOfCreation = timeOfCreation, + timeOfModification = timeOfModification, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/PersistentDao.kt b/src/main/kotlin/com/github/jactor/rises/persistence/PersistentDao.kt index 6e49fcc..6b9b485 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/PersistentDao.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/PersistentDao.kt @@ -17,12 +17,11 @@ interface PersistentDao { fun modifiedBy(modifier: String): T - fun toPersistent() = - Persistent( - id = id, - createdBy = createdBy, - modifiedBy = modifiedBy, - timeOfCreation = timeOfCreation, - timeOfModification = timeOfModification, - ) + fun toPersistent() = Persistent( + id = id, + createdBy = createdBy, + modifiedBy = modifiedBy, + timeOfCreation = timeOfCreation, + timeOfModification = timeOfModification, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/address/Address.kt b/src/main/kotlin/com/github/jactor/rises/persistence/address/Address.kt index 14becce..f82c7fc 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/address/Address.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/address/Address.kt @@ -26,18 +26,17 @@ data class Address( zipCode = dao.zipCode, ) - fun toAddressDao() = - AddressDao( - id = null, - createdBy = persistent.createdBy, - timeOfCreation = persistent.timeOfCreation, - modifiedBy = persistent.modifiedBy, - timeOfModification = persistent.timeOfModification, - addressLine1 = addressLine1, - addressLine2 = addressLine2, - addressLine3 = addressLine3, - city = city, - country = country, - zipCode = zipCode, - ) + fun toAddressDao() = AddressDao( + id = null, + createdBy = persistent.createdBy, + timeOfCreation = persistent.timeOfCreation, + modifiedBy = persistent.modifiedBy, + timeOfModification = persistent.timeOfModification, + addressLine1 = addressLine1, + addressLine2 = addressLine2, + addressLine3 = addressLine3, + city = city, + country = country, + zipCode = zipCode, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/address/AddressDao.kt b/src/main/kotlin/com/github/jactor/rises/persistence/address/AddressDao.kt index c052fe6..afc8625 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/address/AddressDao.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/address/AddressDao.kt @@ -26,14 +26,13 @@ data class AddressDao( return this } - fun toAddress() = - Address( - persistent = toPersistent(), - addressLine1 = addressLine1, - addressLine2 = addressLine2, - addressLine3 = addressLine3, - city = city, - country = country, - zipCode = zipCode, - ) + fun toAddress() = Address( + persistent = toPersistent(), + addressLine1 = addressLine1, + addressLine2 = addressLine2, + addressLine3 = addressLine3, + city = city, + country = country, + zipCode = zipCode, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/address/AddressRepositoryObject.kt b/src/main/kotlin/com/github/jactor/rises/persistence/address/AddressRepositoryObject.kt index 9a1ca6e..3bee2b7 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/address/AddressRepositoryObject.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/address/AddressRepositoryObject.kt @@ -7,10 +7,9 @@ import org.jetbrains.exposed.v1.jdbc.selectAll import java.util.UUID object AddressRepositoryObject : AddressRepository { - override fun findById(id: UUID): AddressDao? = - Addresses - .selectAll() - .andWhere { Addresses.id eq id } - .singleOrNull() - ?.toAddressDao() + override fun findById(id: UUID): AddressDao? = Addresses + .selectAll() + .andWhere { Addresses.id eq id } + .singleOrNull() + ?.toAddressDao() } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/address/Addresses.kt b/src/main/kotlin/com/github/jactor/rises/persistence/address/Addresses.kt index 5e71f4b..2940e1b 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/address/Addresses.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/address/Addresses.kt @@ -9,10 +9,9 @@ import org.jetbrains.exposed.v1.javatime.datetime import java.util.UUID object Addresses : IdTable(name = "T_ADDRESS") { - override val id: Column> = - javaUUID("ID") - .clientDefault { UUIDv7.generate() } - .entityId() + override val id: Column> = javaUUID("ID") + .clientDefault { UUIDv7.generate() } + .entityId() val createdBy = text("CREATED_BY") val modifiedBy = text("UPDATED_BY") diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/blog/Blog.kt b/src/main/kotlin/com/github/jactor/rises/persistence/blog/Blog.kt index aacb3c6..8004e3f 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/blog/Blog.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/blog/Blog.kt @@ -14,22 +14,20 @@ data class Blog( ) { val id: UUID? get() = persistent.id - fun toBlogDao() = - BlogDao( - id = persistent.id, - created = created ?: persistent.timeOfCreation.toLocalDate(), - createdBy = persistent.createdBy, - modifiedBy = persistent.modifiedBy, - timeOfCreation = persistent.timeOfCreation, - timeOfModification = persistent.timeOfModification, - title = title, - userId = userId, - ) + fun toBlogDao() = BlogDao( + id = persistent.id, + created = created ?: persistent.timeOfCreation.toLocalDate(), + createdBy = persistent.createdBy, + modifiedBy = persistent.modifiedBy, + timeOfCreation = persistent.timeOfCreation, + timeOfModification = persistent.timeOfModification, + title = title, + userId = userId, + ) - fun toBlogDto() = - BlogDto( - persistentDto = persistent.toPersistentDto(), - title = title, - userId = userId, - ) + fun toBlogDto() = BlogDto( + persistentDto = persistent.toPersistentDto(), + title = title, + userId = userId, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogController.kt b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogController.kt index e90f2e5..69974cd 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogController.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogController.kt @@ -41,9 +41,9 @@ class BlogController( @GetMapping("/{id}") suspend operator fun get( @PathVariable("id") blogId: UUID, - ): ResponseEntity = - blogService.find(blogId)?.let { ResponseEntity(it.toBlogDto(), HttpStatus.OK) } - ?: ResponseEntity(HttpStatus.NO_CONTENT) + ): ResponseEntity = blogService.find(blogId) + ?.let { ResponseEntity(it.toBlogDto(), HttpStatus.OK) } + ?: ResponseEntity(HttpStatus.NO_CONTENT) @ApiResponses( value = [ @@ -76,10 +76,9 @@ class BlogController( suspend fun findByTitle( @PathVariable("title") title: String, ): ResponseEntity> { - val blogsByTitle = - blogService - .findBlogsBy(title) - .map { it.toBlogDto() } + val blogsByTitle = blogService + .findBlogsBy(title) + .map { it.toBlogDto() } return when (blogsByTitle.isNotEmpty()) { true -> ResponseEntity(blogsByTitle, HttpStatus.OK) @@ -101,10 +100,9 @@ class BlogController( suspend fun findEntriesByBlogId( @PathVariable("id") blogId: UUID, ): ResponseEntity> { - val entriesForBlog = - blogService - .findEntriesForBlog(blogId) - .map { it.toBlogEntryDto() } + val entriesForBlog = blogService + .findEntriesForBlog(blogId) + .map { it.toBlogEntryDto() } return when (entriesForBlog.isNotEmpty()) { true -> ResponseEntity(entriesForBlog, HttpStatus.OK) @@ -126,13 +124,12 @@ class BlogController( suspend fun put( @RequestBody updateBlogTitleCommand: UpdateBlogTitleCommand, @PathVariable blogId: UUID, - ): ResponseEntity = - (updateBlogTitleCommand.blogId ?: blogId).let { - ResponseEntity( - blogService.update(updateBlogTitle = updateBlogTitleCommand.toUpdateBlogTitle()).toBlogDto(), - HttpStatus.ACCEPTED, - ) - } + ): ResponseEntity = (updateBlogTitleCommand.blogId ?: blogId).let { + ResponseEntity( + blogService.update(updateBlogTitle = updateBlogTitleCommand.toUpdateBlogTitle()).toBlogDto(), + HttpStatus.ACCEPTED, + ) + } @ApiResponses( value = [ @@ -145,15 +142,13 @@ class BlogController( @PostMapping suspend fun post( @RequestBody blogDto: BlogDto, - ): ResponseEntity = - when (blogDto.harIdentifikator()) { - true -> ResponseEntity(HttpStatus.BAD_REQUEST) - false -> - ResponseEntity( - blogService.saveOrUpdate(blog = blogDto.toBlog()).toBlogDto(), - HttpStatus.CREATED, - ) - } + ): ResponseEntity = when (blogDto.harIdentifikator()) { + true -> ResponseEntity(HttpStatus.BAD_REQUEST) + false -> ResponseEntity( + blogService.saveOrUpdate(blog = blogDto.toBlog()).toBlogDto(), + HttpStatus.CREATED, + ) + } @ApiResponses( value = [ @@ -169,15 +164,13 @@ class BlogController( suspend fun putEntry( @RequestBody blogEntryDto: BlogEntryDto, @PathVariable blogEntryId: UUID, - ): ResponseEntity = - when (blogEntryDto.harIkkeIdentifikator()) { - true -> ResponseEntity(HttpStatus.BAD_REQUEST) - false -> - ResponseEntity( - blogService.saveOrUpdate(blogEntry = blogEntryDto.toBlogEntry()).toBlogEntryDto(), - HttpStatus.ACCEPTED, - ) - } + ): ResponseEntity = when (blogEntryDto.harIkkeIdentifikator()) { + true -> ResponseEntity(HttpStatus.BAD_REQUEST) + false -> ResponseEntity( + blogService.saveOrUpdate(blogEntry = blogEntryDto.toBlogEntry()).toBlogEntryDto(), + HttpStatus.ACCEPTED, + ) + } @ApiResponses( value = [ @@ -191,13 +184,9 @@ class BlogController( @PostMapping("/entry") suspend fun postEntry( @RequestBody createBlogEntryCommand: CreateBlogEntryCommand, - ): ResponseEntity = - createBlogEntryCommand - .toCreateBlogEntry() - .let { - blogService.create(createBlogEntry = it) - }.toBlogEntryDto() - .let { - ResponseEntity(it, HttpStatus.CREATED) - } + ): ResponseEntity = createBlogEntryCommand + .toCreateBlogEntry() + .let { blogService.create(createBlogEntry = it) } + .toBlogEntryDto() + .let { ResponseEntity(it, HttpStatus.CREATED) } } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogDao.kt b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogDao.kt index f61e2cb..c65aef8 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogDao.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogDao.kt @@ -24,11 +24,10 @@ data class BlogDao( return this } - fun toBlog(): Blog = - Blog( - created = created, - persistent = toPersistent(), - title = title, - userId = userId, - ) + fun toBlog(): Blog = Blog( + created = created, + persistent = toPersistent(), + title = title, + userId = userId, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntries.kt b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntries.kt index efe47c4..58826a2 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntries.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntries.kt @@ -9,10 +9,9 @@ import org.jetbrains.exposed.v1.javatime.datetime import java.util.UUID object BlogEntries : IdTable(name = "T_BLOG_ENTRY") { - override val id: Column> = - javaUUID("ID") - .clientDefault { UUIDv7.generate() } - .entityId() + override val id: Column> = javaUUID("ID") + .clientDefault { UUIDv7.generate() } + .entityId() val blogId = javaUUID("BLOG_ID").references(Blogs.id) val createdBy = text("CREATED_BY") diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntry.kt b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntry.kt index 2d99744..42fe104 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntry.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntry.kt @@ -13,23 +13,21 @@ data class BlogEntry( ) { val id: UUID? get() = persistent.id - fun toBlogEntryDto() = - BlogEntryDto( - persistentDto = persistent.toPersistentDto(), - blogId = blogId, - creatorName = creatorName, - entry = entry, - ) + fun toBlogEntryDto() = BlogEntryDto( + persistentDto = persistent.toPersistentDto(), + blogId = blogId, + creatorName = creatorName, + entry = entry, + ) - fun toBlogEntryDao() = - BlogEntryDao( - id = persistent.id, - blogId = blogId, - createdBy = persistent.createdBy, - creatorName = creatorName, - entry = entry, - timeOfCreation = persistent.timeOfCreation, - modifiedBy = persistent.modifiedBy, - timeOfModification = persistent.timeOfModification, - ) + fun toBlogEntryDao() = BlogEntryDao( + id = persistent.id, + blogId = blogId, + createdBy = persistent.createdBy, + creatorName = creatorName, + entry = entry, + timeOfCreation = persistent.timeOfCreation, + modifiedBy = persistent.modifiedBy, + timeOfModification = persistent.timeOfModification, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntryDao.kt b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntryDao.kt index 6e8bd0e..7daafe7 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntryDao.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogEntryDao.kt @@ -25,11 +25,10 @@ data class BlogEntryDao( return this } - fun toBlogEntry() = - BlogEntry( - persistent = toPersistent(), - blogId = blogId, - creatorName = creatorName, - entry = entry, - ) + fun toBlogEntry() = BlogEntry( + persistent = toPersistent(), + blogId = blogId, + creatorName = creatorName, + entry = entry, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogRepositoryObject.kt b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogRepositoryObject.kt index 83ce363..7c090fb 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogRepositoryObject.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/blog/BlogRepositoryObject.kt @@ -10,98 +10,82 @@ import org.jetbrains.exposed.v1.jdbc.update import java.util.UUID object BlogRepositoryObject : BlogRepository { - override fun findBlogById(id: UUID): BlogDao? = - Blogs - .selectAll() - .andWhere { Blogs.id eq id } - .map { it.toBlogDao() } - .singleOrNull() + override fun findBlogById(id: UUID): BlogDao? = Blogs + .selectAll() + .andWhere { Blogs.id eq id } + .map { it.toBlogDao() } + .singleOrNull() - override fun findBlogsByUserId(id: UUID): List = - Blogs - .selectAll() - .andWhere { Blogs.userId eq id } - .map { it.toBlogDao() } + override fun findBlogsByUserId(id: UUID): List = Blogs + .selectAll() + .andWhere { Blogs.userId eq id } + .map { it.toBlogDao() } - override fun findBlogEntryById(id: UUID): BlogEntryDao? = - BlogEntries - .selectAll() - .andWhere { BlogEntries.id eq id } - .map { it.toBlogEntryDao() } - .singleOrNull() + override fun findBlogEntryById(id: UUID): BlogEntryDao? = BlogEntries + .selectAll() + .andWhere { BlogEntries.id eq id } + .map { it.toBlogEntryDao() } + .singleOrNull() - override fun findBlogsByTitle(title: String): List = - Blogs - .selectAll() - .andWhere { Blogs.title eq title } - .map { it.toBlogDao() } + override fun findBlogsByTitle(title: String): List = Blogs + .selectAll() + .andWhere { Blogs.title eq title } + .map { it.toBlogDao() } - override fun findBlogEntriesByBlogId(id: UUID): List = - BlogEntries - .selectAll() - .andWhere { BlogEntries.blogId eq id } - .map { it.toBlogEntryDao() } + override fun findBlogEntriesByBlogId(id: UUID): List = BlogEntries + .selectAll() + .andWhere { BlogEntries.blogId eq id } + .map { it.toBlogEntryDao() } - override fun save(blogDao: BlogDao): BlogDao = - when (blogDao.isNotPersisted) { - true -> insert(blogDao) - false -> update(blogDao) - } + override fun save(blogDao: BlogDao): BlogDao = when (blogDao.isNotPersisted) { + true -> insert(blogDao) + false -> update(blogDao) + } - private fun insert(blogDao: BlogDao): BlogDao = - Blogs - .insertAndGetId { - it[Blogs.created] = blogDao.created - it[Blogs.createdBy] = blogDao.createdBy - it[Blogs.modifiedBy] = blogDao.modifiedBy - it[Blogs.timeOfCreation] = blogDao.timeOfCreation - it[Blogs.timeOfModification] = blogDao.timeOfModification - it[Blogs.title] = blogDao.title - it[Blogs.userId] = requireNotNull(blogDao.userId) { "A blog must belong to a user" } - }.value - .let { blogDao.copy(id = it) } + private fun insert(blogDao: BlogDao): BlogDao = Blogs.insertAndGetId { + it[Blogs.created] = blogDao.created + it[Blogs.createdBy] = blogDao.createdBy + it[Blogs.modifiedBy] = blogDao.modifiedBy + it[Blogs.timeOfCreation] = blogDao.timeOfCreation + it[Blogs.timeOfModification] = blogDao.timeOfModification + it[Blogs.title] = blogDao.title + it[Blogs.userId] = requireNotNull(blogDao.userId) { "A blog must belong to a user" } + }.value + .let { blogDao.copy(id = it) } - private fun update(blogDao: BlogDao): BlogDao = - Blogs - .update( - where = { Blogs.id eq blogDao.id }, - ) { update -> - update[Blogs.modifiedBy] = blogDao.modifiedBy - update[Blogs.timeOfModification] = blogDao.timeOfModification - update[Blogs.created] = blogDao.created - update[Blogs.title] = blogDao.title - update[Blogs.userId] = requireNotNull(blogDao.userId) { "A blog must belong to a user" } - }.let { blogDao } + private fun update(blogDao: BlogDao): BlogDao = Blogs.update( + where = { Blogs.id eq blogDao.id }, + ) { update -> + update[Blogs.modifiedBy] = blogDao.modifiedBy + update[Blogs.timeOfModification] = blogDao.timeOfModification + update[Blogs.created] = blogDao.created + update[Blogs.title] = blogDao.title + update[Blogs.userId] = requireNotNull(blogDao.userId) { "A blog must belong to a user" } + }.let { blogDao } - override fun save(blogEntryDao: BlogEntryDao): BlogEntryDao = - when (blogEntryDao.isNotPersisted) { - true -> insert(blogEntryDao) - false -> update(blogEntryDao) - } + override fun save(blogEntryDao: BlogEntryDao): BlogEntryDao = when (blogEntryDao.isNotPersisted) { + true -> insert(blogEntryDao) + false -> update(blogEntryDao) + } - private fun insert(blogEntryDao: BlogEntryDao): BlogEntryDao = - BlogEntries - .insertAndGetId { insert -> - insert[blogId] = requireNotNull(blogEntryDao.blogId) { "A blog entry must belong to a blog" } - insert[createdBy] = blogEntryDao.createdBy - insert[creatorName] = blogEntryDao.creatorName - insert[entry] = blogEntryDao.entry - insert[modifiedBy] = blogEntryDao.modifiedBy - insert[timeOfCreation] = blogEntryDao.timeOfCreation - insert[timeOfModification] = blogEntryDao.timeOfModification - }.value - .let { blogEntryDao.copy(id = it) } + private fun insert(blogEntryDao: BlogEntryDao): BlogEntryDao = BlogEntries.insertAndGetId { insert -> + insert[blogId] = requireNotNull(blogEntryDao.blogId) { "A blog entry must belong to a blog" } + insert[createdBy] = blogEntryDao.createdBy + insert[creatorName] = blogEntryDao.creatorName + insert[entry] = blogEntryDao.entry + insert[modifiedBy] = blogEntryDao.modifiedBy + insert[timeOfCreation] = blogEntryDao.timeOfCreation + insert[timeOfModification] = blogEntryDao.timeOfModification + }.value.let { blogEntryDao.copy(id = it) } - private fun update(blogEntryDao: BlogEntryDao): BlogEntryDao = - BlogEntries - .update( - where = { BlogEntries.id eq blogEntryDao.id }, - ) { update -> - update[blogId] = requireNotNull(blogEntryDao.blogId) { "A blog entry must belong to a blog" } - update[createdBy] = blogEntryDao.createdBy - update[creatorName] = blogEntryDao.creatorName - update[modifiedBy] = blogEntryDao.modifiedBy - update[timeOfCreation] = blogEntryDao.timeOfCreation - update[timeOfModification] = blogEntryDao.timeOfModification - }.let { blogEntryDao } + private fun update(blogEntryDao: BlogEntryDao): BlogEntryDao = BlogEntries.update( + where = { BlogEntries.id eq blogEntryDao.id }, + ) { update -> + update[blogId] = requireNotNull(blogEntryDao.blogId) { "A blog entry must belong to a blog" } + update[createdBy] = blogEntryDao.createdBy + update[creatorName] = blogEntryDao.creatorName + update[modifiedBy] = blogEntryDao.modifiedBy + update[timeOfCreation] = blogEntryDao.timeOfCreation + update[timeOfModification] = blogEntryDao.timeOfModification + }.let { blogEntryDao } } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/blog/Blogs.kt b/src/main/kotlin/com/github/jactor/rises/persistence/blog/Blogs.kt index 8f694fd..34405b1 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/blog/Blogs.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/blog/Blogs.kt @@ -11,10 +11,9 @@ import org.jetbrains.exposed.v1.javatime.datetime import java.util.UUID object Blogs : IdTable(name = "T_BLOG") { - override val id: Column> = - javaUUID("ID") - .clientDefault { UUIDv7.generate() } - .entityId() + override val id: Column> = javaUUID("ID") + .clientDefault { UUIDv7.generate() } + .entityId() val createdBy = text("CREATED_BY") val modifiedBy = text("UPDATED_BY") diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/config/ExposedConfig.kt b/src/main/kotlin/com/github/jactor/rises/persistence/config/ExposedConfig.kt index 326fa0b..92dc201 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/config/ExposedConfig.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/config/ExposedConfig.kt @@ -14,19 +14,17 @@ import javax.sql.DataSource @OpenAPIDefinition(info = Info(title = "jactor-persistence.exposed", version = "v2")) class ExposedConfig { @Bean - fun databaseConfig() = - DatabaseConfig.Companion { - useNestedTransactions = true - } + fun databaseConfig() = DatabaseConfig.Companion { + useNestedTransactions = true + } @Bean fun database( dataSource: DataSource, databaseConfig: DatabaseConfig, - ): Database = - Database.connect(dataSource, databaseConfig = databaseConfig).also { - TransactionManager.defaultDatabase = it - } + ): Database = Database.connect(dataSource, databaseConfig = databaseConfig).also { + TransactionManager.defaultDatabase = it + } @Bean fun transactionManager(dataSource: DataSource) = SpringTransactionManager(dataSource) diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBook.kt b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBook.kt index 9cbd204..7c3b312 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBook.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBook.kt @@ -25,28 +25,25 @@ data class GuestBook( userId = guestBookDto.userId, ) - fun toDto(): GuestBookDto = - GuestBookDto( - persistentDto = persistent.toPersistentDto(), - title = title, - userId = userId, - ) + fun toDto(): GuestBookDto = GuestBookDto( + persistentDto = persistent.toPersistentDto(), + title = title, + userId = userId, + ) - fun toGuestBookDao() = - GuestBookDao( - id = persistent.id, - createdBy = persistent.createdBy, - modifiedBy = persistent.modifiedBy, - timeOfCreation = persistent.timeOfCreation, - timeOfModification = persistent.timeOfModification, - title = requireNotNull(title) { "Title cannot be null!" }, - userId = userId, - ) + fun toGuestBookDao() = GuestBookDao( + id = persistent.id, + createdBy = persistent.createdBy, + modifiedBy = persistent.modifiedBy, + timeOfCreation = persistent.timeOfCreation, + timeOfModification = persistent.timeOfModification, + title = requireNotNull(title) { "Title cannot be null!" }, + userId = userId, + ) - fun toGuestBookDto() = - GuestBookDto( - persistentDto = persistent.toPersistentDto(), - title = title, - userId = userId, - ) + fun toGuestBookDto() = GuestBookDto( + persistentDto = persistent.toPersistentDto(), + title = title, + userId = userId, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookController.kt b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookController.kt index 6ac797f..a81e564 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookController.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookController.kt @@ -38,9 +38,8 @@ class GuestBookController( @Operation(description = "Henter en gjesdebok ved å angi id") suspend operator fun get( @PathVariable("id") id: UUID, - ): ResponseEntity = - guestBookService.findGuestBook(id)?.let { ResponseEntity(it.toDto(), HttpStatus.OK) } - ?: ResponseEntity(HttpStatus.NO_CONTENT) + ): ResponseEntity = guestBookService.findGuestBook(id)?.let { ResponseEntity(it.toDto(), HttpStatus.OK) } + ?: ResponseEntity(HttpStatus.NO_CONTENT) @ApiResponses( value = [ @@ -72,11 +71,10 @@ class GuestBookController( @PostMapping suspend fun post( @RequestBody createGuestBookCommand: CreateGuestBookCommand, - ): ResponseEntity = - ResponseEntity( - guestBookService.create(createGuestBook = createGuestBookCommand.toCreateGuestBook()).toGuestBookDto(), - HttpStatus.CREATED, - ) + ): ResponseEntity = ResponseEntity( + guestBookService.create(createGuestBook = createGuestBookCommand.toCreateGuestBook()).toGuestBookDto(), + HttpStatus.CREATED, + ) @ApiResponses( value = [ @@ -91,15 +89,14 @@ class GuestBookController( @PutMapping("/update") suspend fun put( @RequestBody guestBookDto: GuestBookDto, - ): ResponseEntity = - when (guestBookDto.harIkkeIdentifikator()) { - true -> ResponseEntity(HttpStatus.BAD_REQUEST) - false -> - ResponseEntity( - guestBookService.saveOrUpdate(GuestBook(guestBookDto = guestBookDto)).toDto(), - HttpStatus.ACCEPTED, - ) - } + ): ResponseEntity = when (guestBookDto.harIkkeIdentifikator()) { + true -> ResponseEntity(HttpStatus.BAD_REQUEST) + false -> + ResponseEntity( + guestBookService.saveOrUpdate(GuestBook(guestBookDto = guestBookDto)).toDto(), + HttpStatus.ACCEPTED, + ) + } @ApiResponses( value = [ @@ -116,14 +113,13 @@ class GuestBookController( @PostMapping("/entry") suspend fun postEntry( @RequestBody createGuestBookEntryCommand: CreateGuestBookEntryCommand, - ): ResponseEntity = - ResponseEntity( - guestBookService - .create( - createGuestBookEntry = createGuestBookEntryCommand.toCreateGuestBook(), - ).toGuestBookEntryDto(), - HttpStatus.CREATED, - ) + ): ResponseEntity = ResponseEntity( + guestBookService + .create( + createGuestBookEntry = createGuestBookEntryCommand.toCreateGuestBook(), + ).toGuestBookEntryDto(), + HttpStatus.CREATED, + ) @ApiResponses( value = [ @@ -138,13 +134,12 @@ class GuestBookController( @PutMapping("/entry/update") suspend fun putEntry( @RequestBody guestBookEntryDto: GuestBookEntryDto, - ): ResponseEntity = - when (guestBookEntryDto.harIkkeIdentifikator()) { - true -> ResponseEntity(HttpStatus.BAD_REQUEST) - false -> - ResponseEntity( - guestBookService.saveOrUpdate(GuestBookEntry(guestBookEntryDto = guestBookEntryDto)).toGuestBookEntryDto(), - HttpStatus.ACCEPTED, - ) - } + ): ResponseEntity = when (guestBookEntryDto.harIkkeIdentifikator()) { + true -> ResponseEntity(HttpStatus.BAD_REQUEST) + false -> + ResponseEntity( + guestBookService.saveOrUpdate(GuestBookEntry(guestBookEntryDto = guestBookEntryDto)).toGuestBookEntryDto(), + HttpStatus.ACCEPTED, + ) + } } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookDao.kt b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookDao.kt index fd72b70..a822257 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookDao.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookDao.kt @@ -13,17 +13,13 @@ data class GuestBookDao( var title: String = "no-name", internal var userId: UUID? = null, ) : PersistentDao { - fun toGuestBook(): GuestBook = - GuestBook( - persistent = toPersistent(), - title = title, - userId = userId, - ) + fun toGuestBook(): GuestBook = GuestBook( + persistent = toPersistent(), + title = title, + userId = userId, + ) - override fun copyWithoutId(): GuestBookDao = - copy( - id = null, - ) + override fun copyWithoutId(): GuestBookDao = copy(id = null) override fun modifiedBy(modifier: String): GuestBookDao { modifiedBy = modifier diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntries.kt b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntries.kt index 042083d..31cff6b 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntries.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntries.kt @@ -9,10 +9,9 @@ import org.jetbrains.exposed.v1.javatime.datetime import java.util.UUID object GuestBookEntries : IdTable(name = "T_GUEST_BOOK_ENTRY") { - override val id: Column> = - javaUUID("ID") - .clientDefault { UUIDv7.generate() } - .entityId() + override val id: Column> = javaUUID("ID") + .clientDefault { UUIDv7.generate() } + .entityId() val createdBy = text("CREATED_BY") val guestName = text("GUEST_NAME") diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntry.kt b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntry.kt index f6e998a..9e82d10 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntry.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntry.kt @@ -21,23 +21,21 @@ data class GuestBookEntry( guestBookId = guestBookEntryDto.guestBookId, ) - fun toGuestBookEntryDto() = - GuestBookEntryDto( - entry = entry, - creatorName = guestName, - guestBookId = guestBookId, - persistentDto = persistent.toPersistentDto(), - ) + fun toGuestBookEntryDto() = GuestBookEntryDto( + entry = entry, + creatorName = guestName, + guestBookId = guestBookId, + persistentDto = persistent.toPersistentDto(), + ) - fun toGuestBookEntryDao() = - GuestBookEntryDao( - id = id, - createdBy = persistent.createdBy, - modifiedBy = persistent.modifiedBy, - timeOfCreation = persistent.timeOfCreation, - timeOfModification = persistent.timeOfModification, - guestName = guestName, - entry = entry, - guestBookId = guestBookId, - ) + fun toGuestBookEntryDao() = GuestBookEntryDao( + id = id, + createdBy = persistent.createdBy, + modifiedBy = persistent.modifiedBy, + timeOfCreation = persistent.timeOfCreation, + timeOfModification = persistent.timeOfModification, + guestName = guestName, + entry = entry, + guestBookId = guestBookId, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntryDao.kt b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntryDao.kt index db59419..8a44a9b 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntryDao.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntryDao.kt @@ -22,19 +22,17 @@ data class GuestBookEntryDao( guestName = value } - fun toGuestBookEntry() = - GuestBookEntry( - persistent = toPersistent(), - guestName = guestName, - entry = entry, - guestBookId = guestBookId, - ) + fun toGuestBookEntry() = GuestBookEntry( + persistent = toPersistent(), + guestName = guestName, + entry = entry, + guestBookId = guestBookId, + ) - override fun copyWithoutId() = - copy( - id = null, - guestBookId = null, - ) + override fun copyWithoutId() = copy( + id = null, + guestBookId = null, + ) override fun modifiedBy(modifier: String): GuestBookEntryDao { modifiedBy = modifier diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookRepositoryObject.kt b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookRepositoryObject.kt index 99a449c..c4fb529 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookRepositoryObject.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookRepositoryObject.kt @@ -12,94 +12,78 @@ import java.util.UUID object GuestBookRepositoryObject : GuestBookRepository { override fun findAllGuestBooks(): List = GuestBooks.selectAll().map { it.toGuestBookDao() } - override fun findByUserId(userId: UUID): GuestBookDao? = - GuestBooks - .selectAll() - .andWhere { GuestBooks.userId eq userId } - .map { it.toGuestBookDao() } - .singleOrNull() + override fun findByUserId(userId: UUID): GuestBookDao? = GuestBooks + .selectAll() + .andWhere { GuestBooks.userId eq userId } + .map { it.toGuestBookDao() } + .singleOrNull() - override fun findGuestBookById(id: UUID): GuestBookDao? = - GuestBooks - .selectAll() - .andWhere { GuestBooks.id eq id } - .singleOrNull() - ?.toGuestBookDao() + override fun findGuestBookById(id: UUID): GuestBookDao? = GuestBooks + .selectAll() + .andWhere { GuestBooks.id eq id } + .singleOrNull() + ?.toGuestBookDao() - override fun findGuestBookEntryById(id: UUID): GuestBookEntryDao? = - GuestBookEntries - .selectAll() - .andWhere { GuestBookEntries.id eq id } - .singleOrNull() - ?.toGuestBookEntryDao() + override fun findGuestBookEntryById(id: UUID): GuestBookEntryDao? = GuestBookEntries + .selectAll() + .andWhere { GuestBookEntries.id eq id } + .singleOrNull() + ?.toGuestBookEntryDao() - override fun findGuestBookEtriesByGuestBookId(id: UUID): List = - GuestBookEntries - .selectAll() - .andWhere { GuestBookEntries.guestBookId eq id } - .map { it.toGuestBookEntryDao() } + override fun findGuestBookEtriesByGuestBookId(id: UUID): List = GuestBookEntries + .selectAll() + .andWhere { GuestBookEntries.guestBookId eq id } + .map { it.toGuestBookEntryDao() } - override fun save(guestBookDao: GuestBookDao): GuestBookDao = - when (guestBookDao.isPersisted) { - true -> update(guestBookDao) - false -> insert(guestBookDao) - } + override fun save(guestBookDao: GuestBookDao): GuestBookDao = when (guestBookDao.isPersisted) { + true -> update(guestBookDao) + false -> insert(guestBookDao) + } - private fun update(guestBookDao: GuestBookDao): GuestBookDao = - GuestBooks - .update( - where = { GuestBooks.id eq guestBookDao.id }, - ) { - it[createdBy] = guestBookDao.createdBy - it[title] = guestBookDao.title - it[modifiedBy] = guestBookDao.modifiedBy - it[timeOfCreation] = guestBookDao.timeOfCreation - it[timeOfModification] = guestBookDao.timeOfModification - it[userId] = requireNotNull(guestBookDao.userId) { "UserId cannot be null!" } - }.let { guestBookDao } + private fun update(guestBookDao: GuestBookDao): GuestBookDao = GuestBooks.update( + where = { GuestBooks.id eq guestBookDao.id }, + ) { + it[createdBy] = guestBookDao.createdBy + it[title] = guestBookDao.title + it[modifiedBy] = guestBookDao.modifiedBy + it[timeOfCreation] = guestBookDao.timeOfCreation + it[timeOfModification] = guestBookDao.timeOfModification + it[userId] = requireNotNull(guestBookDao.userId) { "UserId cannot be null!" } + }.let { guestBookDao } - private fun insert(guestBookDao: GuestBookDao): GuestBookDao = - GuestBooks - .insertAndGetId { - it[createdBy] = guestBookDao.createdBy - it[title] = guestBookDao.title - it[modifiedBy] = guestBookDao.modifiedBy - it[timeOfCreation] = guestBookDao.timeOfCreation - it[timeOfModification] = guestBookDao.timeOfModification - it[userId] = requireNotNull(guestBookDao.userId) { "UserId cannot be null!" } - }.value - .let { guestBookDao.copy(id = it) } + private fun insert(guestBookDao: GuestBookDao): GuestBookDao = GuestBooks.insertAndGetId { + it[createdBy] = guestBookDao.createdBy + it[title] = guestBookDao.title + it[modifiedBy] = guestBookDao.modifiedBy + it[timeOfCreation] = guestBookDao.timeOfCreation + it[timeOfModification] = guestBookDao.timeOfModification + it[userId] = requireNotNull(guestBookDao.userId) { "UserId cannot be null!" } + }.value.let { guestBookDao.copy(id = it) } - override fun save(guestBookEntryDao: GuestBookEntryDao): GuestBookEntryDao = - when (guestBookEntryDao.isPersisted) { - true -> update(guestBookEntryDao) - false -> insert(guestBookEntryDao) - } + override fun save(guestBookEntryDao: GuestBookEntryDao): GuestBookEntryDao = when (guestBookEntryDao.isPersisted) { + true -> update(guestBookEntryDao) + false -> insert(guestBookEntryDao) + } - private fun update(guestBookEntryDao: GuestBookEntryDao): GuestBookEntryDao = - GuestBookEntries - .update( - where = { GuestBookEntries.id eq guestBookEntryDao.id }, - ) { - it[createdBy] = guestBookEntryDao.createdBy - it[guestBookId] = requireNotNull(guestBookEntryDao.guestBookId) { "GuestBookId cannot be null!" } - it[guestName] = guestBookEntryDao.guestName - it[entry] = guestBookEntryDao.entry - it[modifiedBy] = guestBookEntryDao.modifiedBy - it[timeOfCreation] = guestBookEntryDao.timeOfCreation - it[timeOfModification] = guestBookEntryDao.timeOfModification - }.let { guestBookEntryDao } + private fun update(guestBookEntryDao: GuestBookEntryDao): GuestBookEntryDao = GuestBookEntries.update( + where = { GuestBookEntries.id eq guestBookEntryDao.id }, + ) { + it[createdBy] = guestBookEntryDao.createdBy + it[guestBookId] = requireNotNull(guestBookEntryDao.guestBookId) { "GuestBookId cannot be null!" } + it[guestName] = guestBookEntryDao.guestName + it[entry] = guestBookEntryDao.entry + it[modifiedBy] = guestBookEntryDao.modifiedBy + it[timeOfCreation] = guestBookEntryDao.timeOfCreation + it[timeOfModification] = guestBookEntryDao.timeOfModification + }.let { guestBookEntryDao } - private fun insert(guestBookEntryDao: GuestBookEntryDao): GuestBookEntryDao = - GuestBookEntries - .insertAndGetId { - it[createdBy] = guestBookEntryDao.createdBy - it[guestBookId] = requireNotNull(guestBookEntryDao.guestBookId) { "GuestBookId cannot be null!" } - it[guestName] = guestBookEntryDao.guestName - it[entry] = guestBookEntryDao.entry - it[modifiedBy] = guestBookEntryDao.modifiedBy - it[timeOfCreation] = guestBookEntryDao.timeOfCreation - it[timeOfModification] = guestBookEntryDao.timeOfModification - }.value - .let { guestBookEntryDao.copy(id = it) } + private fun insert(guestBookEntryDao: GuestBookEntryDao): GuestBookEntryDao = GuestBookEntries.insertAndGetId { + it[createdBy] = guestBookEntryDao.createdBy + it[guestBookId] = requireNotNull(guestBookEntryDao.guestBookId) { "GuestBookId cannot be null!" } + it[guestName] = guestBookEntryDao.guestName + it[entry] = guestBookEntryDao.entry + it[modifiedBy] = guestBookEntryDao.modifiedBy + it[timeOfCreation] = guestBookEntryDao.timeOfCreation + it[timeOfModification] = guestBookEntryDao.timeOfModification + }.value.let { guestBookEntryDao.copy(id = it) } } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookService.kt b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookService.kt index 99f679c..eaf598f 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookService.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookService.kt @@ -23,39 +23,38 @@ class GuestBookServiceBean( private val guestBookRepository: GuestBookRepository, private val persistenceHandler: PersistenceHandler, ) : GuestBookService { - override suspend fun create(createGuestBook: CreateGuestBook): GuestBook = - persistenceHandler - .modifyAndSave( - dao = GuestBookDao(title = createGuestBook.title, userId = createGuestBook.userId), - ) { guestBookRepository.save(guestBookDao = it) } - .toGuestBook() - - override suspend fun create(createGuestBookEntry: CreateGuestBookEntry): GuestBookEntry = - persistenceHandler - .modifyAndSave( - dao = - GuestBookEntryDao( - guestName = createGuestBookEntry.creatorName, - entry = createGuestBookEntry.entry, - guestBookId = createGuestBookEntry.guestBookId, - ), - ) { guestBookRepository.save(guestBookEntryDao = it) } - .toGuestBookEntry() + override suspend fun create(createGuestBook: CreateGuestBook): GuestBook = persistenceHandler.modifyAndSave( + dao = GuestBookDao(title = createGuestBook.title, userId = createGuestBook.userId), + ) { guestBookRepository.save(guestBookDao = it) } + .toGuestBook() + + override suspend fun create( + createGuestBookEntry: CreateGuestBookEntry, + ): GuestBookEntry = persistenceHandler.modifyAndSave( + dao = GuestBookEntryDao( + guestName = createGuestBookEntry.creatorName, + entry = createGuestBookEntry.entry, + guestBookId = createGuestBookEntry.guestBookId, + ), + ) { + guestBookRepository.save(guestBookEntryDao = it) + }.toGuestBookEntry() override suspend fun findGuestBook(id: UUID): GuestBook? = guestBookRepository.findGuestBookById(id)?.toGuestBook() - override suspend fun findEntry(id: UUID): GuestBookEntry? = guestBookRepository.findGuestBookEntryById(id)?.toGuestBookEntry() - - override suspend fun saveOrUpdate(guestBook: GuestBook): GuestBook = - persistenceHandler - .modifyAndSave( - dao = guestBook.toGuestBookDao(), - ) { guestBookRepository.save(guestBookDao = it) } - .toGuestBook() - - override suspend fun saveOrUpdate(guestBookEntry: GuestBookEntry): GuestBookEntry = - persistenceHandler - .modifyAndSave(dao = guestBookEntry.toGuestBookEntryDao()) { - guestBookRepository.save(guestBookEntryDao = it) - }.toGuestBookEntry() + override suspend fun findEntry( + id: UUID, + ): GuestBookEntry? = guestBookRepository.findGuestBookEntryById(id)?.toGuestBookEntry() + + override suspend fun saveOrUpdate(guestBook: GuestBook): GuestBook = persistenceHandler.modifyAndSave( + dao = guestBook.toGuestBookDao(), + ) { + guestBookRepository.save(guestBookDao = it) + }.toGuestBook() + + override suspend fun saveOrUpdate( + guestBookEntry: GuestBookEntry, + ): GuestBookEntry = persistenceHandler.modifyAndSave(dao = guestBookEntry.toGuestBookEntryDao()) { + guestBookRepository.save(guestBookEntryDao = it) + }.toGuestBookEntry() } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBooks.kt b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBooks.kt index 6ffd509..5a987ee 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBooks.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBooks.kt @@ -10,10 +10,9 @@ import org.jetbrains.exposed.v1.javatime.datetime import java.util.UUID object GuestBooks : IdTable(name = "T_GUEST_BOOK") { - override val id: Column> = - javaUUID("ID") - .clientDefault { UUIDv7.generate() } - .entityId() + override val id: Column> = javaUUID("ID") + .clientDefault { UUIDv7.generate() } + .entityId() val createdBy = text("CREATED_BY") val modifiedBy = text("UPDATED_BY") diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/person/People.kt b/src/main/kotlin/com/github/jactor/rises/persistence/person/People.kt index 06f2199..af26469 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/person/People.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/person/People.kt @@ -10,10 +10,9 @@ import org.jetbrains.exposed.v1.javatime.datetime import java.util.UUID object People : IdTable(name = "T_PERSON") { - override val id: Column> = - javaUUID("ID") - .clientDefault { UUIDv7.generate() } - .entityId() + override val id: Column> = javaUUID("ID") + .clientDefault { UUIDv7.generate() } + .entityId() val createdBy = text("CREATED_BY") val modifiedBy = text("UPDATED_BY") diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/person/Person.kt b/src/main/kotlin/com/github/jactor/rises/persistence/person/Person.kt index 2002dcb..6da8185 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/person/Person.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/person/Person.kt @@ -16,27 +16,25 @@ data class Person( ) { val id: UUID? @JsonIgnore get() = persistent.id - fun toPersonDao() = - PersonDao( - id = persistent.id, - createdBy = persistent.createdBy, - timeOfCreation = persistent.timeOfCreation, - modifiedBy = persistent.modifiedBy, - timeOfModification = persistent.timeOfModification, - description = description, - firstName = firstName, - surname = surname, - locale = locale, - addressId = addressId, - ) + fun toPersonDao() = PersonDao( + id = persistent.id, + createdBy = persistent.createdBy, + timeOfCreation = persistent.timeOfCreation, + modifiedBy = persistent.modifiedBy, + timeOfModification = persistent.timeOfModification, + description = description, + firstName = firstName, + surname = surname, + locale = locale, + addressId = addressId, + ) - fun toPersonDto() = - PersonDto( - persistentDto = persistent.toPersistentDto(), - addressId = addressId, - locale = locale, - firstName = firstName, - surname = surname, - description = description, - ) + fun toPersonDto() = PersonDto( + persistentDto = persistent.toPersistentDto(), + addressId = addressId, + locale = locale, + firstName = firstName, + surname = surname, + description = description, + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/person/PersonDao.kt b/src/main/kotlin/com/github/jactor/rises/persistence/person/PersonDao.kt index 3906eb5..bb78200 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/person/PersonDao.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/person/PersonDao.kt @@ -16,21 +16,19 @@ data class PersonDao( var surname: String, var addressId: UUID? = null, ) : PersistentDao { - fun toPerson() = - Person( - persistent = toPersistent(), - addressId = addressId, - locale = locale, - firstName = firstName, - surname = surname, - description = description, - ) + fun toPerson() = Person( + persistent = toPersistent(), + addressId = addressId, + locale = locale, + firstName = firstName, + surname = surname, + description = description, + ) - override fun copyWithoutId(): PersonDao = - copy( - id = null, - addressId = null, - ) + override fun copyWithoutId(): PersonDao = copy( + id = null, + addressId = null, + ) override fun modifiedBy(modifier: String): PersonDao { modifiedBy = modifier diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/person/PersonRepositoryObject.kt b/src/main/kotlin/com/github/jactor/rises/persistence/person/PersonRepositoryObject.kt index 737f3e1..bf7ec3f 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/person/PersonRepositoryObject.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/person/PersonRepositoryObject.kt @@ -9,49 +9,43 @@ import org.jetbrains.exposed.v1.jdbc.update import java.util.UUID object PersonRepositoryObject : PersonRepository { - override fun findById(id: UUID): PersonDao? = - People - .selectAll() - .andWhere { People.id eq id } - .map { it.toPersonDao() } - .singleOrNull() + override fun findById(id: UUID): PersonDao? = People + .selectAll() + .andWhere { People.id eq id } + .map { it.toPersonDao() } + .singleOrNull() - override fun save(personDao: PersonDao): PersonDao = - when (personDao.isNotPersisted) { - true -> insert(personDao) - false -> update(personDao) - } + override fun save(personDao: PersonDao): PersonDao = when (personDao.isNotPersisted) { + true -> insert(personDao) + false -> update(personDao) + } - private fun insert(personDao: PersonDao): PersonDao = - People - .insertAndGetId { row -> - row[createdBy] = personDao.createdBy - row[modifiedBy] = personDao.modifiedBy - row[timeOfCreation] = personDao.timeOfCreation - row[timeOfModification] = personDao.timeOfModification - row[description] = personDao.description - row[firstName] = personDao.firstName - row[surname] = personDao.surname - row[locale] = personDao.locale - personDao.addressId?.let { - row[addressId] = it - } - }.let { newId -> personDao.also { it.id = newId.value } } + private fun insert(personDao: PersonDao): PersonDao = People.insertAndGetId { row -> + row[createdBy] = personDao.createdBy + row[modifiedBy] = personDao.modifiedBy + row[timeOfCreation] = personDao.timeOfCreation + row[timeOfModification] = personDao.timeOfModification + row[description] = personDao.description + row[firstName] = personDao.firstName + row[surname] = personDao.surname + row[locale] = personDao.locale + personDao.addressId?.let { + row[addressId] = it + } + }.let { newId -> personDao.also { it.id = newId.value } } - private fun update(personDao: PersonDao): PersonDao = - People - .update( - where = { People.id eq personDao.id }, - ) { row -> - row[modifiedBy] = personDao.modifiedBy - row[timeOfModification] = personDao.timeOfModification - row[description] = personDao.description - row[firstName] = personDao.firstName - row[surname] = personDao.surname - row[locale] = personDao.locale + private fun update(personDao: PersonDao): PersonDao = People.update( + where = { People.id eq personDao.id }, + ) { row -> + row[modifiedBy] = personDao.modifiedBy + row[timeOfModification] = personDao.timeOfModification + row[description] = personDao.description + row[firstName] = personDao.firstName + row[surname] = personDao.surname + row[locale] = personDao.locale - personDao.addressId?.let { - row[addressId] = it - } - }.let { personDao } + personDao.addressId?.let { + row[addressId] = it + } + }.let { personDao } } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/user/Model.kt b/src/main/kotlin/com/github/jactor/rises/persistence/user/Model.kt index ed9bd58..738b620 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/user/Model.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/user/Model.kt @@ -22,17 +22,16 @@ data class CreateUser( val language: String?, val country: String?, ) { - fun toUserDao() = - UserDao( - createdBy = username, - modifiedBy = username, - timeOfCreation = LocalDateTime.now(), - timeOfModification = LocalDateTime.now(), - emailAddress = emailAddress, - personId = personId, - username = username, - userType = UserType.ACTIVE, - ) + fun toUserDao() = UserDao( + createdBy = username, + modifiedBy = username, + timeOfCreation = LocalDateTime.now(), + timeOfModification = LocalDateTime.now(), + emailAddress = emailAddress, + personId = personId, + username = username, + userType = UserType.ACTIVE, + ) } enum class UserType { diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/user/User.kt b/src/main/kotlin/com/github/jactor/rises/persistence/user/User.kt index 4a8feac..96c5d24 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/user/User.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/user/User.kt @@ -16,29 +16,25 @@ data class User( val id: UUID get() = persistent.id ?: error("User is not persisted!") - fun toUserDao() = - UserDao( - id = persistent.id, - createdBy = persistent.createdBy, - modifiedBy = persistent.modifiedBy, - timeOfCreation = persistent.timeOfCreation, - timeOfModification = persistent.timeOfModification, - emailAddress = emailAddress, - personId = personId, - username = username ?: "na", - userType = - UserType.entries.firstOrNull { it.name == userType.name } - ?: error(message = "Unknown UserType: $userType"), - ) + fun toUserDao() = UserDao( + id = persistent.id, + createdBy = persistent.createdBy, + modifiedBy = persistent.modifiedBy, + timeOfCreation = persistent.timeOfCreation, + timeOfModification = persistent.timeOfModification, + emailAddress = emailAddress, + personId = personId, + username = username ?: "na", + userType = UserType.entries.firstOrNull { it.name == userType.name } + ?: error(message = "Unknown UserType: $userType"), + ) - fun toUserDto() = - UserDto( - persistentDto = persistent.toPersistentDto(), - emailAddress = emailAddress, - personId = personId, - username = username, - userType = - (userType == UserType.ADMIN).whenTrue { UserTypeDto.ACTIVE } - ?: UserTypeDto.valueOf(userType.name), - ) + fun toUserDto() = UserDto( + persistentDto = persistent.toPersistentDto(), + emailAddress = emailAddress, + personId = personId, + username = username, + userType = (userType == UserType.ADMIN).whenTrue { UserTypeDto.ACTIVE } + ?: UserTypeDto.valueOf(userType.name), + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/user/UserController.kt b/src/main/kotlin/com/github/jactor/rises/persistence/user/UserController.kt index 8d204de..b2595fa 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/user/UserController.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/user/UserController.kt @@ -35,9 +35,9 @@ class UserController( @Operation(description = "Find a user by its username") suspend fun find( @PathVariable("username") username: String, - ): ResponseEntity = - userService.find(username = username)?.let { ResponseEntity(it.toUserDto(), HttpStatus.OK) } - ?: ResponseEntity(HttpStatus.NO_CONTENT) + ): ResponseEntity = userService.find(username = username) + ?.let { ResponseEntity(it.toUserDto(), HttpStatus.OK) } + ?: ResponseEntity(HttpStatus.NO_CONTENT) @ApiResponses( value = [ @@ -49,9 +49,9 @@ class UserController( @Operation(description = "Get a user by its id") suspend operator fun get( @PathVariable("id") id: UUID, - ): ResponseEntity = - userService.find(id)?.let { ResponseEntity(it.toUserDto(), HttpStatus.OK) } - ?: ResponseEntity(HttpStatus.NOT_FOUND) + ): ResponseEntity = userService.find(id) + ?.let { ResponseEntity(it.toUserDto(), HttpStatus.OK) } + ?: ResponseEntity(HttpStatus.NOT_FOUND) @ApiResponses( value = [ @@ -63,15 +63,13 @@ class UserController( @PostMapping(consumes = [MediaType.APPLICATION_JSON_VALUE]) suspend fun post( @RequestBody createUserCommand: CreateUserCommand, - ): ResponseEntity = - when (userService.isAlreadyPersisted(username = createUserCommand.username)) { - true -> ResponseEntity(HttpStatus.BAD_REQUEST) - false -> - ResponseEntity( - userService.create(createUserCommand.toCreateUser()).toUserDto(), - HttpStatus.CREATED, - ) - } + ): ResponseEntity = when (userService.isAlreadyPersisted(username = createUserCommand.username)) { + true -> ResponseEntity(HttpStatus.BAD_REQUEST) + false -> ResponseEntity( + userService.create(createUserCommand.toCreateUser()).toUserDto(), + HttpStatus.CREATED, + ) + } @ApiResponses( value = [ @@ -83,26 +81,23 @@ class UserController( @PutMapping("/update") suspend fun put( @RequestBody userDto: UserDto, - ): ResponseEntity = - when (userDto.harIkkeIdentifikator()) { - true -> ResponseEntity(HttpStatus.BAD_REQUEST) - false -> - ResponseEntity( - userService.update(user = userDto.toUser()).toUserDto(), - HttpStatus.ACCEPTED, - ) - } + ): ResponseEntity = when (userDto.harIkkeIdentifikator()) { + true -> ResponseEntity(HttpStatus.BAD_REQUEST) + false -> ResponseEntity( + userService.update(user = userDto.toUser()).toUserDto(), + HttpStatus.ACCEPTED, + ) + } @ApiResponses(ApiResponse(responseCode = "200", description = "List of usernames found")) @GetMapping("/usernames") @Operation(description = "Find all usernames for a user type") suspend fun findAllUsernames( @RequestParam(required = false, defaultValue = "ACTIVE") userType: String, - ): ResponseEntity> = - userService.findUsernames(userType = UserType.valueOf(userType)).let { - when (it.isEmpty()) { - true -> ResponseEntity(HttpStatus.NO_CONTENT) - false -> ResponseEntity(it, HttpStatus.OK) - } + ): ResponseEntity> = userService.findUsernames(userType = UserType.valueOf(userType)).let { + when (it.isEmpty()) { + true -> ResponseEntity(HttpStatus.NO_CONTENT) + false -> ResponseEntity(it, HttpStatus.OK) } + } } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/user/UserDao.kt b/src/main/kotlin/com/github/jactor/rises/persistence/user/UserDao.kt index 27c748f..a784f8a 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/user/UserDao.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/user/UserDao.kt @@ -15,11 +15,10 @@ data class UserDao( internal var personId: UUID? = null, internal var username: String = "na", ) : PersistentDao { - override fun copyWithoutId(): UserDao = - copy( - id = null, - personId = null, - ) + override fun copyWithoutId(): UserDao = copy( + id = null, + personId = null, + ) override fun modifiedBy(modifier: String): UserDao { modifiedBy = modifier @@ -28,14 +27,12 @@ data class UserDao( return this } - fun toUser() = - User( - persistent = toPersistent(), - username = username, - emailAddress = emailAddress, - personId = personId, - userType = - UserType.entries.firstOrNull { it.name == userType.name } - ?: error("Unknown UserType: $userType"), - ) + fun toUser() = User( + persistent = toPersistent(), + username = username, + emailAddress = emailAddress, + personId = personId, + userType = UserType.entries.firstOrNull { it.name == userType.name } + ?: error("Unknown UserType: $userType"), + ) } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/user/UserRepositoryObject.kt b/src/main/kotlin/com/github/jactor/rises/persistence/user/UserRepositoryObject.kt index 05ab188..a68ce9a 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/user/UserRepositoryObject.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/user/UserRepositoryObject.kt @@ -11,74 +11,62 @@ import org.jetbrains.exposed.v1.jdbc.update import java.util.UUID object UserRepositoryObject : UserRepository { - override fun contains(username: String): Boolean = - Users - .select(column = Users.username) - .andWhere { Users.username eq username } - .count() > 0 + override fun contains(username: String): Boolean = Users + .select(column = Users.username) + .andWhere { Users.username eq username } + .count() > 0 - override fun findById(id: UUID): UserDao? = - Users - .selectAll() - .andWhere { Users.id eq id } - .map { it.toUserDao() } - .singleOrNull() - - override fun findByPersonId(id: UUID): List = - Users - .selectAll() - .andWhere { Users.personId eq id } - .map { it.toUserDao() } + override fun findById(id: UUID): UserDao? = Users + .selectAll() + .andWhere { Users.id eq id } + .map { it.toUserDao() } + .singleOrNull() - override fun findByUsername(username: String): UserDao? = - Users - .selectAll() - .andWhere { Users.username eq username } - .singleOrNull() - ?.toUserDao() + override fun findByPersonId(id: UUID): List = Users + .selectAll() + .andWhere { Users.personId eq id } + .map { it.toUserDao() } - override fun findUsernames(userType: List): List = - run { - val userTypes = userType.map { it.name } + override fun findByUsername(username: String): UserDao? = Users + .selectAll() + .andWhere { Users.username eq username } + .singleOrNull() + ?.toUserDao() - Users - .select(column = Users.username) - .andWhere { Users.userType inList userTypes } - .withDistinct() - .map { it[Users.username] } - } + override fun findUsernames(userType: List): List = userType.map { it.name }.let { types -> + Users + .select(column = Users.username) + .andWhere { Users.userType inList types } + .withDistinct() + .map { it[Users.username] } + } - override fun save(userDao: UserDao): UserDao = - when (userDao.isPersisted) { - true -> update(user = userDao) - false -> insert(user = userDao) - } + override fun save(userDao: UserDao): UserDao = when (userDao.isPersisted) { + true -> update(user = userDao) + false -> insert(user = userDao) + } - private fun insert(user: UserDao): UserDao = - Users - .insertAndGetId { row -> - row[createdBy] = user.createdBy - row[modifiedBy] = user.modifiedBy - row[timeOfCreation] = user.timeOfCreation - row[timeOfModification] = user.timeOfModification - row[emailAddress] = user.emailAddress - row[username] = user.username - row[personId] = requireNotNull(user.personId) { "Person id cannot be null when inserting a user." } - row[userType] = user.userType.name - }.value - .let { newId -> user.also { it.id = newId } } + private fun insert(user: UserDao): UserDao = Users.insertAndGetId { row -> + row[createdBy] = user.createdBy + row[modifiedBy] = user.modifiedBy + row[timeOfCreation] = user.timeOfCreation + row[timeOfModification] = user.timeOfModification + row[emailAddress] = user.emailAddress + row[username] = user.username + row[personId] = requireNotNull(user.personId) { "Person id cannot be null when inserting a user." } + row[userType] = user.userType.name + }.value + .let { newId -> user.also { it.id = newId } } - private fun update(user: UserDao): UserDao = - Users - .update( - where = { Users.id eq user.id }, - ) { - it[modifiedBy] = user.modifiedBy - it[timeOfModification] = user.timeOfModification - it[emailAddress] = user.emailAddress - it[username] = user.username - it[userType] = userType.name - it[personId] = personId - // createdBy & timeOfCreation are intentionally not updated - }.let { user } + private fun update(user: UserDao): UserDao = Users.update( + where = { Users.id eq user.id }, + ) { + it[modifiedBy] = user.modifiedBy + it[timeOfModification] = user.timeOfModification + it[emailAddress] = user.emailAddress + it[username] = user.username + it[userType] = userType.name + it[personId] = personId + // createdBy & timeOfCreation are intentionally not updated + }.let { user } } diff --git a/src/main/kotlin/com/github/jactor/rises/persistence/user/Users.kt b/src/main/kotlin/com/github/jactor/rises/persistence/user/Users.kt index e92374a..01c8b5d 100644 --- a/src/main/kotlin/com/github/jactor/rises/persistence/user/Users.kt +++ b/src/main/kotlin/com/github/jactor/rises/persistence/user/Users.kt @@ -10,10 +10,9 @@ import org.jetbrains.exposed.v1.javatime.datetime import java.util.UUID object Users : IdTable(name = "T_USER") { - override val id: Column> = - javaUUID("ID") - .clientDefault { UUIDv7.generate() } - .entityId() + override val id: Column> = javaUUID("ID") + .clientDefault { UUIDv7.generate() } + .entityId() val createdBy = text("CREATED_BY") val modifiedBy = text("UPDATED_BY") diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/DtoMapperTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/DtoMapperTest.kt index 038036c..4269005 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/DtoMapperTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/DtoMapperTest.kt @@ -17,13 +17,12 @@ internal class DtoMapperTest { @Test fun `should map a user to json`() { val uuid = UUID.randomUUID() - val userDto = - UserDto( - persistentDto = PersistentDto(id = uuid), - emailAddress = "some@where", - username = "mine", - userType = UserType.ACTIVE, - ) + val userDto = UserDto( + persistentDto = PersistentDto(id = uuid), + emailAddress = "some@where", + username = "mine", + userType = UserType.ACTIVE, + ) val json = objectMapper.writeValueAsString(userDto) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/JsonMappingTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/JsonMappingTest.kt index 0d32ac2..31db1d0 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/JsonMappingTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/JsonMappingTest.kt @@ -55,10 +55,9 @@ internal class JsonMappingTest @Test fun `skal mappe BlogEntryDto til jason og tilbake til BlogEntryDto`() { val uuid = UUID.randomUUID() - val json = - objectMapper.writeValueAsString( - BlogEntryDto(blogId = uuid), - ) + val json = objectMapper.writeValueAsString( + BlogEntryDto(blogId = uuid), + ) val blogEntry = objectMapper.readValue(json, BlogEntryDto::class.java) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/PersistenceHandlerTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/PersistenceHandlerTest.kt index cbac103..16ea883 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/PersistenceHandlerTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/PersistenceHandlerTest.kt @@ -21,135 +21,128 @@ internal class PersistenceHandlerTest { private val persistenceHandler = PersistenceHandler() @Test - fun `should modify timestamp on address when used`() = - runTest { - val withId = initAddressDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) - val withoutId = initAddressDao(id = null, timeOfModification = oneMinuteAgo) - - assertAll { - persistenceHandler.modifyAndSave(withId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) - return@modifyAndSave dao - } - - persistenceHandler.modifyAndSave(withoutId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) - return@modifyAndSave dao - } + fun `should modify timestamp on address when used`() = runTest { + val withId = initAddressDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) + val withoutId = initAddressDao(id = null, timeOfModification = oneMinuteAgo) + + assertAll { + persistenceHandler.modifyAndSave(withId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) + return@modifyAndSave dao + } + + persistenceHandler.modifyAndSave(withoutId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) + return@modifyAndSave dao } } + } @Test - fun `should modify timestamp on blog when used`() = - runTest { - val withId = initBlogDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) - val withoutId = initBlogDao(id = null, timeOfModification = oneMinuteAgo) - - assertAll { - persistenceHandler.modifyAndSave(withId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) - return@modifyAndSave dao - } - - persistenceHandler.modifyAndSave(withoutId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) - return@modifyAndSave dao - } + fun `should modify timestamp on blog when used`() = runTest { + val withId = initBlogDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) + val withoutId = initBlogDao(id = null, timeOfModification = oneMinuteAgo) + + assertAll { + persistenceHandler.modifyAndSave(withId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) + return@modifyAndSave dao + } + + persistenceHandler.modifyAndSave(withoutId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) + return@modifyAndSave dao } } + } @Test - fun `should modify timestamp on blogEntry when used`() = - runTest { - val withId = initBlogEntryDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) - val withoutId = initBlogEntryDao(id = null, timeOfModification = oneMinuteAgo) - - assertAll { - persistenceHandler.modifyAndSave(withId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) - return@modifyAndSave dao - } - - persistenceHandler.modifyAndSave(withoutId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) - return@modifyAndSave dao - } + fun `should modify timestamp on blogEntry when used`() = runTest { + val withId = initBlogEntryDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) + val withoutId = initBlogEntryDao(id = null, timeOfModification = oneMinuteAgo) + + assertAll { + persistenceHandler.modifyAndSave(withId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) + return@modifyAndSave dao + } + + persistenceHandler.modifyAndSave(withoutId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) + return@modifyAndSave dao } } + } @Test - fun `should modify timestamp on guestBook when used`() = - runTest { - val withId = initGuestBookDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) - val withoutId = initGuestBookDao(id = null, timeOfModification = oneMinuteAgo) - - assertAll { - persistenceHandler.modifyAndSave(withId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) - return@modifyAndSave dao - } - - persistenceHandler.modifyAndSave(withoutId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) - return@modifyAndSave dao - } + fun `should modify timestamp on guestBook when used`() = runTest { + val withId = initGuestBookDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) + val withoutId = initGuestBookDao(id = null, timeOfModification = oneMinuteAgo) + + assertAll { + persistenceHandler.modifyAndSave(withId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) + return@modifyAndSave dao + } + + persistenceHandler.modifyAndSave(withoutId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) + return@modifyAndSave dao } } + } @Test - fun `should modify timestamp on guestBookEntry when used`() = - runTest { - val withId = initGuestBookEntryDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) - val withoutId = initGuestBookEntryDao(id = null, timeOfModification = oneMinuteAgo) - - assertAll { - persistenceHandler.modifyAndSave(withId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) - return@modifyAndSave dao - } - - persistenceHandler.modifyAndSave(withoutId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) - return@modifyAndSave dao - } + fun `should modify timestamp on guestBookEntry when used`() = runTest { + val withId = initGuestBookEntryDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) + val withoutId = initGuestBookEntryDao(id = null, timeOfModification = oneMinuteAgo) + + assertAll { + persistenceHandler.modifyAndSave(withId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) + return@modifyAndSave dao + } + + persistenceHandler.modifyAndSave(withoutId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) + return@modifyAndSave dao } } + } @Test - fun `should modify timestamp on person when used`() = - runTest { - val withId = initPersonDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) - val withoutId = initPersonDao(id = null, timeOfModification = oneMinuteAgo) - - assertAll { - persistenceHandler.modifyAndSave(withId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) - return@modifyAndSave dao - } - - persistenceHandler.modifyAndSave(withoutId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) - return@modifyAndSave dao - } + fun `should modify timestamp on person when used`() = runTest { + val withId = initPersonDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) + val withoutId = initPersonDao(id = null, timeOfModification = oneMinuteAgo) + + assertAll { + persistenceHandler.modifyAndSave(withId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) + return@modifyAndSave dao + } + + persistenceHandler.modifyAndSave(withoutId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) + return@modifyAndSave dao } } + } @Test - fun `should modify timestamp on user when used`() = - runTest { - val withId = initUserDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) - val withoutId = initUserDao(id = null, timeOfModification = oneMinuteAgo) - - assertAll { - persistenceHandler.modifyAndSave(withId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) - return@modifyAndSave dao - } - - persistenceHandler.modifyAndSave(withoutId) { dao -> - assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) - return@modifyAndSave dao - } + fun `should modify timestamp on user when used`() = runTest { + val withId = initUserDao(id = UUID.randomUUID(), timeOfModification = oneMinuteAgo) + val withoutId = initUserDao(id = null, timeOfModification = oneMinuteAgo) + + assertAll { + persistenceHandler.modifyAndSave(withId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "with id").isEqualTo(0) + return@modifyAndSave dao + } + + persistenceHandler.modifyAndSave(withoutId) { dao -> + assertThat(dao.timeOfModification.countSecondsUntilNow(), "without id").isEqualTo(60) + return@modifyAndSave dao } } + } } diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/PersistentDaoTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/PersistentDaoTest.kt index 4b8e5e2..b216920 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/PersistentDaoTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/PersistentDaoTest.kt @@ -50,12 +50,11 @@ internal class PersistentDaoTest { @Test fun `should be able to copy a user without the id`() { - persistentDaoToTest = - initUser( - persistent = Persistent(id = UUID.randomUUID()), - emailAddress = "i.am@home", - username = "jactor", - ).withId().toUserDao() + persistentDaoToTest = initUser( + persistent = Persistent(id = UUID.randomUUID()), + emailAddress = "i.am@home", + username = "jactor", + ).withId().toUserDao() val copy = persistentDaoToTest.copyWithoutId() as PersistentDao<*> @@ -69,11 +68,10 @@ internal class PersistentDaoTest { @Test fun `should be able to copy a blog without the id`() { - persistentDaoToTest = - initBlog( - title = "general ignorance", - userId = UUID.randomUUID(), - ).withId().toBlogDao() + persistentDaoToTest = initBlog( + title = "general ignorance", + userId = UUID.randomUUID(), + ).withId().toBlogDao() val copy = persistentDaoToTest.copyWithoutId() as PersistentDao<*> @@ -87,12 +85,11 @@ internal class PersistentDaoTest { @Test fun `should be able to copy a blog entry without the id`() { - val blogEntry = - BlogEntry( - blogId = UUID.randomUUID(), - creatorName = "jactor", - entry = "the one", - ).withId() + val blogEntry = BlogEntry( + blogId = UUID.randomUUID(), + creatorName = "jactor", + entry = "the one", + ).withId() persistentDaoToTest = blogEntry.toBlogEntryDao() val copy = persistentDaoToTest.copyWithoutId() as PersistentDao<*> @@ -107,11 +104,10 @@ internal class PersistentDaoTest { @Test fun `should be able to copy a guest book without the id`() { - persistentDaoToTest = - initGuestBook( - title = "enter when applied", - user = initUser(persistent = Persistent(id = UUID.randomUUID())), - ).withId().toGuestBookDao() + persistentDaoToTest = initGuestBook( + title = "enter when applied", + user = initUser(persistent = Persistent(id = UUID.randomUUID())), + ).withId().toGuestBookDao() val copy = persistentDaoToTest.copyWithoutId() as PersistentDao<*> diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/RepositoriesTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/RepositoriesTest.kt index 641b2b8..93116f0 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/RepositoriesTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/RepositoriesTest.kt @@ -30,37 +30,32 @@ internal class RepositoriesTest @Test fun `should use a BlogRepository to save blogs and find them on on user which was earlier saved`() { - val address = - save( - address = - initAddress( - zipCode = "1001", - addressLine1 = "Test Boulevard 1", - city = "Testoplis", - ), - ) + val address = save( + address = initAddress( + zipCode = "1001", + addressLine1 = "Test Boulevard 1", + city = "Testoplis", + ), + ) val person = save(person = initPerson(address = address, locale = "no_NO", surname = "Skywalker")) save( - user = - initUser( - person = person, - emailAddress = "brains@rebels.com", - username = "r2d2", - ), + user = initUser( + person = person, + emailAddress = "brains@rebels.com", + username = "r2d2", + ), ) - var userByUsername = - userRepository.findByUsername("r2d2") - ?: fail { "User not found!" } + var userByUsername = userRepository.findByUsername("r2d2") + ?: fail { "User not found!" } save( - blog = - Blog( - created = LocalDate.now(), - title = "Far, far, away...", - userId = userByUsername.id, - ), + blog = Blog( + created = LocalDate.now(), + title = "Far, far, away...", + userId = userByUsername.id, + ), ) userByUsername = userRepository.findByUsername("r2d2") diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressRepositoryTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressRepositoryTest.kt index 2700db3..65321c5 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressRepositoryTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressRepositoryTest.kt @@ -55,15 +55,14 @@ internal class AddressRepositoryTest @Test fun `should write then read an address dao by id`() { - val addressToPersist = - initAddress( - addressLine1 = "somewhere out there", - addressLine2 = "where the streets have no name", - addressLine3 = "in the middle of it", - city = "Rud", - country = "NO", - zipCode = "1234", - ).toAddressDao() + val addressToPersist = initAddress( + addressLine1 = "somewhere out there", + addressLine2 = "where the streets have no name", + addressLine3 = "in the middle of it", + city = "Rud", + country = "NO", + zipCode = "1234", + ).toAddressDao() AddressTestRepositoryObject.save(addressToPersist) @@ -83,15 +82,14 @@ internal class AddressRepositoryTest @Test fun `should write then update and read an address dao`() { - val addressToPersist = - initAddress( - addressLine1 = "somewhere out there", - addressLine2 = "where the streets have no name", - addressLine3 = "in the middle of it", - city = "Rud", - country = "NO", - zipCode = "1234", - ).toAddressDao() + val addressToPersist = initAddress( + addressLine1 = "somewhere out there", + addressLine2 = "where the streets have no name", + addressLine3 = "in the middle of it", + city = "Rud", + country = "NO", + zipCode = "1234", + ).toAddressDao() AddressTestRepositoryObject.save(addressToPersist) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressTest.kt index b1b5224..670a76b 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressTest.kt @@ -12,15 +12,14 @@ import java.util.UUID internal class AddressTest { @Test fun `should have a copy constructor`() { - val address = - initAddress( - addressLine1 = "address line one", - addressLine2 = "address line two", - addressLine3 = "address line three", - city = "oslo", - country = "NO", - zipCode = "1234", - ).toAddressDao() + val address = initAddress( + addressLine1 = "address line one", + addressLine2 = "address line two", + addressLine3 = "address line three", + city = "oslo", + country = "NO", + zipCode = "1234", + ).toAddressDao() val (_, addressLine1, addressLine2, addressLine3, city, country, zipCode) = Address(dao = address) @@ -36,25 +35,23 @@ internal class AddressTest { @Test fun `should give values to PersistentDto`() { - val persistent = - Persistent( - createdBy = "jactor", - id = UUID.randomUUID(), - modifiedBy = "tip", - timeOfCreation = LocalDateTime.now(), - timeOfModification = LocalDateTime.now(), - ) + val persistent = Persistent( + createdBy = "jactor", + id = UUID.randomUUID(), + modifiedBy = "tip", + timeOfCreation = LocalDateTime.now(), + timeOfModification = LocalDateTime.now(), + ) - val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = - Address( - persistent = persistent, - addressLine1 = "address line one", - addressLine2 = "address line two", - addressLine3 = "address line three", - city = "oslo", - country = "NO", - zipCode = "1234", - ).persistent + val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = Address( + persistent = persistent, + addressLine1 = "address line one", + addressLine2 = "address line two", + addressLine3 = "address line three", + city = "oslo", + country = "NO", + zipCode = "1234", + ).persistent assertAll { assertThat(createdBy).isEqualTo(persistent.createdBy) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressTestRepositoryObject.kt b/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressTestRepositoryObject.kt index a279cf7..704fd72 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressTestRepositoryObject.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/address/AddressTestRepositoryObject.kt @@ -8,47 +8,43 @@ import org.jetbrains.exposed.v1.jdbc.selectAll import org.jetbrains.exposed.v1.jdbc.update object AddressTestRepositoryObject { - fun findByZipCode(zipCode: String): List = - Addresses - .selectAll() - .andWhere { Addresses.zipCode eq zipCode } - .map { it.toAddressDao() } + fun findByZipCode(zipCode: String): List = Addresses + .selectAll() + .andWhere { Addresses.zipCode eq zipCode } + .map { it.toAddressDao() } - fun save(addressDao: AddressDao): AddressDao = - when (addressDao.isNotPersisted) { - true -> insert(addressDao) - false -> update(addressDao) - } + fun save(addressDao: AddressDao): AddressDao = when (addressDao.isNotPersisted) { + true -> insert(addressDao) + false -> update(addressDao) + } - private fun insert(addressDao: AddressDao): AddressDao = - Addresses - .insertAndGetId { row -> - row[createdBy] = addressDao.createdBy - row[modifiedBy] = addressDao.modifiedBy - row[timeOfCreation] = addressDao.timeOfCreation - row[timeOfModification] = addressDao.timeOfModification + private fun insert(addressDao: AddressDao): AddressDao = Addresses + .insertAndGetId { row -> + row[createdBy] = addressDao.createdBy + row[modifiedBy] = addressDao.modifiedBy + row[timeOfCreation] = addressDao.timeOfCreation + row[timeOfModification] = addressDao.timeOfModification - row[addressLine1] = addressDao.addressLine1 - row[addressLine2] = addressDao.addressLine2 - row[addressLine3] = addressDao.addressLine3 - row[city] = addressDao.city - row[country] = addressDao.country - row[zipCode] = addressDao.zipCode - }.let { newId -> addressDao.also { it.id = newId.value } } + row[addressLine1] = addressDao.addressLine1 + row[addressLine2] = addressDao.addressLine2 + row[addressLine3] = addressDao.addressLine3 + row[city] = addressDao.city + row[country] = addressDao.country + row[zipCode] = addressDao.zipCode + }.let { newId -> addressDao.also { it.id = newId.value } } - internal fun update(addressDao: AddressDao): AddressDao = - Addresses - .update( - { Addresses.id eq addressDao.id }, - ) { row -> - row[modifiedBy] = addressDao.modifiedBy - row[timeOfModification] = addressDao.timeOfModification + internal fun update(addressDao: AddressDao): AddressDao = Addresses + .update( + { Addresses.id eq addressDao.id }, + ) { row -> + row[modifiedBy] = addressDao.modifiedBy + row[timeOfModification] = addressDao.timeOfModification - row[addressLine1] = addressDao.addressLine1 - row[addressLine2] = addressDao.addressLine2 - row[addressLine3] = addressDao.addressLine3 - row[city] = addressDao.city - row[country] = addressDao.country - row[zipCode] = addressDao.zipCode - }.let { addressDao } + row[addressLine1] = addressDao.addressLine1 + row[addressLine2] = addressDao.addressLine2 + row[addressLine3] = addressDao.addressLine3 + row[city] = addressDao.city + row[country] = addressDao.country + row[zipCode] = addressDao.zipCode + }.let { addressDao } } diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogControllerTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogControllerTest.kt index aeb32c0..5bf43d5 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogControllerTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogControllerTest.kt @@ -33,84 +33,76 @@ internal class BlogControllerTest ) { @Test fun `should find a blog`() { - val uuid = - UUID.randomUUID().also { - coEvery { blogServiceMockk.find(it) } returns initBlog() - } - - val blogResponse = - webTestClient - .get() - .uri("/blog/$uuid") - .exchange() - .expectStatus() - .isOk - .expectBody(BlogDto::class.java) - .returnResult() - .responseBody + val uuid = UUID.randomUUID().also { + coEvery { blogServiceMockk.find(it) } returns initBlog() + } + + val blogResponse = webTestClient + .get() + .uri("/blog/$uuid") + .exchange() + .expectStatus() + .isOk + .expectBody(BlogDto::class.java) + .returnResult() + .responseBody assertThat(blogResponse).isNotNull() } @Test fun `should not find a blog`() { - val uuid = - UUID.randomUUID().also { - coEvery { blogServiceMockk.find(id = it) } returns null - } - - val blogResponse = - webTestClient - .get() - .uri("/blog/$uuid") - .exchange() - .expectStatus() - .isNoContent - .expectBody(BlogDto::class.java) - .returnResult() - .responseBody + val uuid = UUID.randomUUID().also { + coEvery { blogServiceMockk.find(id = it) } returns null + } + + val blogResponse = webTestClient + .get() + .uri("/blog/$uuid") + .exchange() + .expectStatus() + .isNoContent + .expectBody(BlogDto::class.java) + .returnResult() + .responseBody assertThat(blogResponse).isNull() } @Test fun `should find a blog entry`() { - val uuid = - UUID.randomUUID().also { - coEvery { blogServiceMockk.findEntryBy(it) } returns initBlogEntry() - } - - val blogEntryDto = - webTestClient - .get() - .uri("/blog/entry/$uuid") - .exchange() - .expectStatus() - .isOk - .expectBody(BlogEntryDto::class.java) - .returnResult() - .responseBody + val uuid = UUID.randomUUID().also { + coEvery { blogServiceMockk.findEntryBy(it) } returns initBlogEntry() + } + + val blogEntryDto = webTestClient + .get() + .uri("/blog/entry/$uuid") + .exchange() + .expectStatus() + .isOk + .expectBody(BlogEntryDto::class.java) + .returnResult() + .responseBody assertThat(blogEntryDto).isNotNull() } @Test fun `should not find a blog entry`() { - val uuid = - UUID.randomUUID().also { - coEvery { blogServiceMockk.findEntryBy(it) } returns null - } - - val result = - webTestClient - .get() - .uri("/blog/entry/$uuid") - .exchange() - .expectStatus() - .isNoContent - .expectBody(BlogEntryDto::class.java) - .returnResult() - .responseBody + val uuid = UUID.randomUUID().also { + coEvery { blogServiceMockk.findEntryBy(it) } returns null + } + + val result = webTestClient + .get() + .uri("/blog/entry/$uuid") + .exchange() + .expectStatus() + .isNoContent + .expectBody(BlogEntryDto::class.java) + .returnResult() + .responseBody assertThat(result).isNull() } @@ -131,26 +123,24 @@ internal class BlogControllerTest fun `should find blogs by title`() { coEvery { blogServiceMockk.findBlogsBy("Anything") } returns listOf(initBlog()) - val blogs = - webTestClient - .get() - .uri("/blog/title/Anything") - .exchange() - .expectStatus() - .isOk - .expectBody(object : ParameterizedTypeReference>() {}) - .returnResult() - .responseBody + val blogs = webTestClient + .get() + .uri("/blog/title/Anything") + .exchange() + .expectStatus() + .isOk + .expectBody(object : ParameterizedTypeReference>() {}) + .returnResult() + .responseBody assertThat(blogs).isNotNull().hasSize(1) } @Test fun `should not find blog entries by blog id`() { - val uuid = - UUID.randomUUID().also { - coEvery { blogServiceMockk.findEntriesForBlog(blogId = it) } returns emptyList() - } + val uuid = UUID.randomUUID().also { + coEvery { blogServiceMockk.findEntriesForBlog(blogId = it) } returns emptyList() + } webTestClient .get() @@ -162,81 +152,74 @@ internal class BlogControllerTest @Test fun `should find blog entries by blog id`() { - val uuid = - UUID.randomUUID().also { - coEvery { blogServiceMockk.findEntriesForBlog(it) } returns listOf(initBlogEntry()) - } - - val blogEntries = - webTestClient - .get() - .uri("/blog/$uuid/entries") - .exchange() - .expectStatus() - .isOk - .expectBody(object : ParameterizedTypeReference>() {}) - .returnResult() - .responseBody + val uuid = UUID.randomUUID().also { + coEvery { blogServiceMockk.findEntriesForBlog(it) } returns listOf(initBlogEntry()) + } + + val blogEntries = webTestClient + .get() + .uri("/blog/$uuid/entries") + .exchange() + .expectStatus() + .isOk + .expectBody(object : ParameterizedTypeReference>() {}) + .returnResult() + .responseBody assertThat(blogEntries).isNotNull().isNotEmpty() } @Test fun `should persist changes to existing blog`() { - val updateBlogTitleCommand = - UpdateBlogTitleCommand( - blogId = UUID.randomUUID(), - title = "A new title", - ) + val updateBlogTitleCommand = UpdateBlogTitleCommand( + blogId = UUID.randomUUID(), + title = "A new title", + ) coEvery { blogServiceMockk.update(updateBlogTitle = any()) } returns initBlog() - val blogDto = - webTestClient - .put() - .uri("/blog/${updateBlogTitleCommand.blogId}") - .bodyValue(updateBlogTitleCommand) - .exchange() - .expectStatus() - .isAccepted - .expectBody(BlogDto::class.java) - .returnResult() - .responseBody + val blogDto = webTestClient + .put() + .uri("/blog/${updateBlogTitleCommand.blogId}") + .bodyValue(updateBlogTitleCommand) + .exchange() + .expectStatus() + .isAccepted + .expectBody(BlogDto::class.java) + .returnResult() + .responseBody assertThat(blogDto).isNotNull() coVerify { blogServiceMockk.update( - updateBlogTitle = - withArg { - assertThat(it.title).isEqualTo(updateBlogTitleCommand.title) - }, + updateBlogTitle = withArg { + assertThat(it.title).isEqualTo(updateBlogTitleCommand.title) + }, ) } } @Test fun `should create a blog`() { - val blog = - initBlog( - created = LocalDate.now(), - title = "Another title", - userId = UUID.randomUUID(), - ) + val blog = initBlog( + created = LocalDate.now(), + title = "Another title", + userId = UUID.randomUUID(), + ) coEvery { blogServiceMockk.saveOrUpdate(blog = any()) } returns blog - val createdBlog = - webTestClient - .post() - .uri("/blog") - .bodyValue(blog.toBlogDto()) - .exchange() - .expectStatus() - .isCreated - .expectBody(BlogDto::class.java) - .returnResult() - .responseBody + val createdBlog = webTestClient + .post() + .uri("/blog") + .bodyValue(blog.toBlogDto()) + .exchange() + .expectStatus() + .isCreated + .expectBody(BlogDto::class.java) + .returnResult() + .responseBody assertThat(createdBlog).isNotNull().given { assertThat(it.persistentDto.id).isEqualTo(blog.id) @@ -247,28 +230,26 @@ internal class BlogControllerTest @Test fun `should create blog entry`() { - val creatBlogEntryCommand = - CreateBlogEntryCommand( - blogId = UUID.randomUUID(), - creatorName = "me", - entry = "hi", - ) + val creatBlogEntryCommand = CreateBlogEntryCommand( + blogId = UUID.randomUUID(), + creatorName = "me", + entry = "hi", + ) coEvery { blogServiceMockk.create(createBlogEntry = any()) } answers { initBlogEntry(blog = initBlog().withId(), entry = (arg(0) as CreateBlogEntry).entry).withId() } - val blogEntry = - webTestClient - .post() - .uri("/blog/entry") - .bodyValue(creatBlogEntryCommand) - .exchange() - .expectStatus() - .isCreated - .expectBody(BlogEntryDto::class.java) - .returnResult() - .responseBody + val blogEntry = webTestClient + .post() + .uri("/blog/entry") + .bodyValue(creatBlogEntryCommand) + .exchange() + .expectStatus() + .isCreated + .expectBody(BlogEntryDto::class.java) + .returnResult() + .responseBody assertThat(blogEntry?.entry).isEqualTo(creatBlogEntryCommand.entry) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogEntryTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogEntryTest.kt index 6492bc8..da06c47 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogEntryTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogEntryTest.kt @@ -11,20 +11,18 @@ import java.util.UUID internal class BlogEntryTest { @Test fun `should have a copy constructor`() { - val blogEntry = - BlogEntry( - blogId = UUID.randomUUID(), - creatorName = "someone", - entry = "entry", - ) + val blogEntry = BlogEntry( + blogId = UUID.randomUUID(), + creatorName = "someone", + entry = "entry", + ) - val (blog, creatorName, entry) = - BlogEntry( - persistent = blogEntry.persistent, - blogId = blogEntry.blogId, - creatorName = blogEntry.creatorName, - entry = blogEntry.entry, - ) + val (blog, creatorName, entry) = BlogEntry( + persistent = blogEntry.persistent, + blogId = blogEntry.blogId, + creatorName = blogEntry.creatorName, + entry = blogEntry.entry, + ) assertAll { assertThat(blog).isEqualTo(blogEntry.blogId) @@ -35,22 +33,20 @@ internal class BlogEntryTest { @Test fun `should give values to PersistentDto`() { - val persistent = - Persistent( - createdBy = "jactor", - id = UUID.randomUUID(), - modifiedBy = "tip", - timeOfCreation = LocalDateTime.now(), - timeOfModification = LocalDateTime.now(), - ) + val persistent = Persistent( + createdBy = "jactor", + id = UUID.randomUUID(), + modifiedBy = "tip", + timeOfCreation = LocalDateTime.now(), + timeOfModification = LocalDateTime.now(), + ) - val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = - BlogEntry( - persistent = persistent, - blogId = UUID.randomUUID(), - creatorName = persistent.createdBy, - entry = "test", - ).persistent + val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = BlogEntry( + persistent = persistent, + blogId = UUID.randomUUID(), + creatorName = persistent.createdBy, + entry = "test", + ).persistent assertAll { assertThat(createdBy).isEqualTo(persistent.createdBy) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogRepositoryTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogRepositoryTest.kt index 4973c41..3c6c771 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogRepositoryTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogRepositoryTest.kt @@ -25,21 +25,18 @@ internal class BlogRepositoryTest ) : AbstractSpringBootNoDirtyContextTest() { @Test fun `should save and then read blog dao`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), + ) val person = save(person = initPerson(address = address, surname = "Adder")) - val user = - save( - user = - initUser( - person = person, - emailAddress = "public@services.com", - username = "black", - ), - ) + val user = save( + user = initUser( + person = person, + emailAddress = "public@services.com", + username = "black", + ), + ) blogRepository.save( blogDao = BlogDao(created = LocalDate.now(), title = "Blah", userId = user.persistent.id), @@ -55,29 +52,25 @@ internal class BlogRepositoryTest @Test fun `should save then update and read blog dao`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), + ) val person = save(person = initPerson(address = address, surname = "Adder")) - val user = - save( - user = - initUser( - person = person, - emailAddress = "public@services.com", - username = "black", - ), - ) + val user = save( + user = initUser( + person = person, + emailAddress = "public@services.com", + username = "black", + ), + ) val blogToSave = BlogDao(created = LocalDate.now(), title = "Blah", userId = user.persistent.id) blogRepository.save(blogDao = blogToSave) - val blogDaoSaved = - blogRepository.findBlogsByTitle(title = blogToSave.title).firstOrNull() ?: fail { - "Unable to find any blogs by title $${blogToSave.title}" - } + val blogDaoSaved = blogRepository.findBlogsByTitle(title = blogToSave.title).firstOrNull() ?: fail { + "Unable to find any blogs by title $${blogToSave.title}" + } blogDaoSaved.title = "Duh" @@ -95,22 +88,19 @@ internal class BlogRepositoryTest @Test fun `should find blog by title`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), + ) val person = save(person = initPerson(address = address, surname = "Adder")) - val user = - save( - user = - User( - personId = person.id, - emailAddress = "public@services.com", - username = "black", - userType = UserType.ACTIVE, - ), - ) + val user = save( + user = User( + personId = person.id, + emailAddress = "public@services.com", + username = "black", + userType = UserType.ACTIVE, + ), + ) val blogToSave = Blog(created = LocalDate.now(), title = "Blah", userId = user.id).toBlogDao() @@ -127,29 +117,25 @@ internal class BlogRepositoryTest @Test fun `should save then read blog entry`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), + ) val person = save(person = initPerson(address = address, surname = "Adder")) - val user = - save( - user = - initUser( - person = person, - emailAddress = "public@services.com", - username = "white", - ), - ) + val user = save( + user = initUser( + person = person, + emailAddress = "public@services.com", + username = "white", + ), + ) val blog = save(blog = initBlog(created = LocalDate.now(), title = "and then some...", userId = user.id)) - val blogEntryDao = - BlogEntryDao( - blogId = blog.persistent.id ?: error("Blog is not persisted!"), - creatorName = "smith", - entry = "once upon a time", - ) + val blogEntryDao = BlogEntryDao( + blogId = blog.persistent.id ?: error("Blog is not persisted!"), + creatorName = "smith", + entry = "once upon a time", + ) blogRepository.save(blogEntryDao = blogEntryDao) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogServiceTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogServiceTest.kt index 9a5e75d..abc1858 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogServiceTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogServiceTest.kt @@ -25,14 +25,13 @@ import java.util.UUID internal class BlogServiceTest { private val blogRepositoryMockk: BlogRepository = mockk {} private val userRepositoryMockk: UserRepository = mockk {} - private val blogServiceToTest: BlogService = - BlogServiceImpl( - blogRepository = blogRepositoryMockk, - persistenceHandler = PersistenceHandler(), - ).also { - JactorPersistenceRepositiesConfig.fetchBlogRelation = { id -> blogRepositoryMockk.findBlogById(id = id) } - JactorPersistenceRepositiesConfig.fetchUserRelation = { id -> userRepositoryMockk.findById(id = id) } - } + private val blogServiceToTest: BlogService = BlogServiceImpl( + blogRepository = blogRepositoryMockk, + persistenceHandler = PersistenceHandler(), + ).also { + JactorPersistenceRepositiesConfig.fetchBlogRelation = { id -> blogRepositoryMockk.findBlogById(id = id) } + JactorPersistenceRepositiesConfig.fetchUserRelation = { id -> userRepositoryMockk.findById(id = id) } + } private val uuid: UUID = UUID.randomUUID() diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogTest.kt index ead0e44..899fbdb 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogTest.kt @@ -12,12 +12,11 @@ import java.util.UUID internal class BlogTest { @Test fun `should have a copy constructor`() { - val blog = - Blog( - created = LocalDate.now(), - title = "title", - userId = UUID.randomUUID(), - ) + val blog = Blog( + created = LocalDate.now(), + title = "title", + userId = UUID.randomUUID(), + ) val (_, created, title, userId) = blog.copy() @@ -30,22 +29,20 @@ internal class BlogTest { @Test fun `should give values to PersistentDto`() { - val persistent = - Persistent( - createdBy = "jactor", - id = UUID.randomUUID(), - modifiedBy = "tip", - timeOfCreation = LocalDateTime.now(), - timeOfModification = LocalDateTime.now(), - ) + val persistent = Persistent( + createdBy = "jactor", + id = UUID.randomUUID(), + modifiedBy = "tip", + timeOfCreation = LocalDateTime.now(), + timeOfModification = LocalDateTime.now(), + ) - val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = - Blog( - persistent = persistent, - created = LocalDate.now(), - title = "title", - userId = null, - ).persistent + val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = Blog( + persistent = persistent, + created = LocalDate.now(), + title = "title", + userId = null, + ).persistent assertAll { assertThat(createdBy).isEqualTo(persistent.createdBy) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogTestRepositoryObject.kt b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogTestRepositoryObject.kt index 23532d1..f2cfd09 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogTestRepositoryObject.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/blog/BlogTestRepositoryObject.kt @@ -5,13 +5,11 @@ import com.github.jactor.rises.persistence.util.toBlogEntryDao import org.jetbrains.exposed.v1.jdbc.selectAll object BlogTestRepositoryObject { - fun findBlogEntries(): List = - BlogEntries - .selectAll() - .map { it.toBlogEntryDao() } + fun findBlogEntries(): List = BlogEntries + .selectAll() + .map { it.toBlogEntryDao() } - fun findBlogs(): List = - Blogs - .selectAll() - .map { it.toBlogDao() } + fun findBlogs(): List = Blogs + .selectAll() + .map { it.toBlogDao() } } diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/cucumber/RestServiceSteps.kt b/src/test/kotlin/com/github/jactor/rises/persistence/cucumber/RestServiceSteps.kt index 475ff14..42fef6f 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/cucumber/RestServiceSteps.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/cucumber/RestServiceSteps.kt @@ -29,15 +29,13 @@ internal class RestServiceSteps : } Når("en get gjøres på resttjenesten") { - scenarioValues.entityExchangeResult = - scenarioValues.restService - .exchangeGet(parameternavn = null, parameter = null) { webTestClient } + scenarioValues.entityExchangeResult = scenarioValues.restService + .exchangeGet(parameternavn = null, parameter = null) { webTestClient } } Når("en get gjøres på resttjenesten med parameter {string} = {string}") { parameternavn: String, verdi: String -> - scenarioValues.entityExchangeResult = - scenarioValues.restService - .exchangeGet(parameternavn, verdi) { webTestClient } + scenarioValues.entityExchangeResult = scenarioValues.restService + .exchangeGet(parameternavn, verdi) { webTestClient } } Når("en post gjøres med body:") { json: String -> diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookControllerTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookControllerTest.kt index dc04161..38545fe 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookControllerTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookControllerTest.kt @@ -35,16 +35,15 @@ internal class GuestBookControllerTest val uuid = UUID.randomUUID() coEvery { guestBookServiceMockk.findGuestBook(id = uuid) } returns null - val guestBookExchangeBody = - webTestClient - .get() - .uri("/guestBook/$uuid") - .exchange() - .expectStatus() - .isNoContent - .expectBody(GuestBook::class.java) - .returnResult() - .responseBody + val guestBookExchangeBody = webTestClient + .get() + .uri("/guestBook/$uuid") + .exchange() + .expectStatus() + .isNoContent + .expectBody(GuestBook::class.java) + .returnResult() + .responseBody assertThat(guestBookExchangeBody).isNull() } @@ -54,16 +53,15 @@ internal class GuestBookControllerTest val uuid = UUID.randomUUID() coEvery { guestBookServiceMockk.findGuestBook(id = uuid) } returns initGuestBook() - val guestBook = - webTestClient - .get() - .uri("/guestBook/$uuid") - .exchange() - .expectStatus() - .isOk - .expectBody(GuestBookDto::class.java) - .returnResult() - .responseBody + val guestBook = webTestClient + .get() + .uri("/guestBook/$uuid") + .exchange() + .expectStatus() + .isOk + .expectBody(GuestBookDto::class.java) + .returnResult() + .responseBody assertThat(guestBook).isNotNull() } @@ -73,16 +71,15 @@ internal class GuestBookControllerTest val uuid = UUID.randomUUID() coEvery { guestBookServiceMockk.findEntry(id = uuid) } returns null - val guestBookEntry = - webTestClient - .get() - .uri("/guestBook/entry/$uuid") - .exchange() - .expectStatus() - .isNoContent - .expectBody(GuestBook::class.java) - .returnResult() - .responseBody + val guestBookEntry = webTestClient + .get() + .uri("/guestBook/entry/$uuid") + .exchange() + .expectStatus() + .isNoContent + .expectBody(GuestBook::class.java) + .returnResult() + .responseBody assertThat(guestBookEntry).isNull() } @@ -94,16 +91,15 @@ internal class GuestBookControllerTest initGuestBookEntry() .withPersistedData(id = uuid) - val guestBookEntry = - webTestClient - .get() - .uri("/guestBook/entry/$uuid") - .exchange() - .expectStatus() - .isOk - .expectBody(GuestBookEntryDto::class.java) - .returnResult() - .responseBody + val guestBookEntry = webTestClient + .get() + .uri("/guestBook/entry/$uuid") + .exchange() + .expectStatus() + .isOk + .expectBody(GuestBookEntryDto::class.java) + .returnResult() + .responseBody assertThat(guestBookEntry).isNotNull() } @@ -132,28 +128,26 @@ internal class GuestBookControllerTest @Test fun `should create a guest book`() { val createdId = UUID.randomUUID() - val createGuestBookCommand = - CreateGuestBookCommand( - title = "A title", - userId = UUID.randomUUID(), - ) + val createGuestBookCommand = CreateGuestBookCommand( + title = "A title", + userId = UUID.randomUUID(), + ) coEvery { guestBookServiceMockk.create(createGuestBook = any()) } returns initGuestBook( persistent = Persistent(id = createdId), ) - val guestbook = - webTestClient - .post() - .uri("/guestBook") - .bodyValue(createGuestBookCommand) - .exchange() - .expectStatus() - .isCreated - .expectBody(GuestBookDto::class.java) - .returnResult() - .responseBody + val guestbook = webTestClient + .post() + .uri("/guestBook") + .bodyValue(createGuestBookCommand) + .exchange() + .expectStatus() + .isCreated + .expectBody(GuestBookDto::class.java) + .returnResult() + .responseBody assertThat(guestbook?.persistentDto?.id).isEqualTo(createdId) @@ -167,17 +161,16 @@ internal class GuestBookControllerTest coEvery { guestBookServiceMockk.saveOrUpdate(guestBookEntry) } returns guestBookEntry - val guestbookEntry = - webTestClient - .put() - .uri("/guestBook/entry/update") - .bodyValue(guestBookEntry.toGuestBookEntryDto()) - .exchange() - .expectStatus() - .isAccepted - .expectBody(GuestBookEntryDto::class.java) - .returnResult() - .responseBody + val guestbookEntry = webTestClient + .put() + .uri("/guestBook/entry/update") + .bodyValue(guestBookEntry.toGuestBookEntryDto()) + .exchange() + .expectStatus() + .isAccepted + .expectBody(GuestBookEntryDto::class.java) + .returnResult() + .responseBody assertAll { assertThat(guestbookEntry?.persistentDto?.id).isEqualTo(guestBookEntry.id) @@ -189,28 +182,26 @@ internal class GuestBookControllerTest @Test fun `should create a guest book entry`() { val createdId = UUID.randomUUID() - val createGuestBookEntryCommand = - CreateGuestBookEntryCommand( - creatorName = "creator", - entry = "an entry", - guestBookId = UUID.randomUUID(), - ) + val createGuestBookEntryCommand = CreateGuestBookEntryCommand( + creatorName = "creator", + entry = "an entry", + guestBookId = UUID.randomUUID(), + ) coEvery { guestBookServiceMockk.create(createGuestBookEntry = any()) } returns initGuestBookEntry() .withPersistedData(id = createdId) - val guestbookEntry = - webTestClient - .post() - .uri("/guestBook/entry") - .bodyValue(createGuestBookEntryCommand) - .exchange() - .expectStatus() - .isCreated - .expectBody(GuestBookEntryDto::class.java) - .returnResult() - .responseBody + val guestbookEntry = webTestClient + .post() + .uri("/guestBook/entry") + .bodyValue(createGuestBookEntryCommand) + .exchange() + .expectStatus() + .isCreated + .expectBody(GuestBookEntryDto::class.java) + .returnResult() + .responseBody assertAll { assertThat(guestbookEntry?.persistentDto?.id).isEqualTo(createdId) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntryTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntryTest.kt index 9d87ade..bfd6295 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntryTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookEntryTest.kt @@ -14,20 +14,18 @@ import java.util.UUID internal class GuestBookEntryTest { @Test fun `should have a copy constructor`() { - val guestBookEntry = - initGuestBookEntry( - creatorName = "me", - entry = "entry", - guestBook = initGuestBook().withId(), - ) + val guestBookEntry = initGuestBookEntry( + creatorName = "me", + entry = "entry", + guestBook = initGuestBook().withId(), + ) - val (entry, creatorName, guestBookId) = - GuestBookEntry( - guestName = guestBookEntry.guestName, - entry = guestBookEntry.entry, - persistent = guestBookEntry.persistent, - guestBookId = guestBookEntry.guestBookId, - ) + val (entry, creatorName, guestBookId) = GuestBookEntry( + guestName = guestBookEntry.guestName, + entry = guestBookEntry.entry, + persistent = guestBookEntry.persistent, + guestBookId = guestBookEntry.guestBookId, + ) assertAll { assertThat(creatorName).isEqualTo(guestBookEntry.guestName) @@ -38,22 +36,20 @@ internal class GuestBookEntryTest { @Test fun `should give values to PersistentDto`() { - val persistent = - Persistent( - createdBy = "jactor", - id = UUID.randomUUID(), - modifiedBy = "tip", - timeOfCreation = LocalDateTime.now(), - timeOfModification = LocalDateTime.now(), - ) + val persistent = Persistent( + createdBy = "jactor", + id = UUID.randomUUID(), + modifiedBy = "tip", + timeOfCreation = LocalDateTime.now(), + timeOfModification = LocalDateTime.now(), + ) - val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = - GuestBookEntry( - guestName = persistent.createdBy, - entry = "entry", - persistent = persistent, - guestBookId = null, - ).persistent + val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = GuestBookEntry( + guestName = persistent.createdBy, + entry = "entry", + persistent = persistent, + guestBookId = null, + ).persistent assertAll { assertThat(createdBy).isEqualTo(persistent.createdBy) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookRepositoryTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookRepositoryTest.kt index 290844c..e5a871d 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookRepositoryTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookRepositoryTest.kt @@ -28,28 +28,24 @@ internal class GuestBookRepositoryTest @Test fun `should write then read guest book`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), + ) val person = save(person = initPerson(address = address, surname = "Adder")) - val user = - save( - user = - initUser( - person = person, - emailAddress = "casuel@tantooine.com", - username = "causual", - ), - ) + val user = save( + user = initUser( + person = person, + emailAddress = "casuel@tantooine.com", + username = "causual", + ), + ) guestBookRepository.save( - guestBookDao = - GuestBookDao( - title = "home sweet home", - userId = user.id, - ), + guestBookDao = GuestBookDao( + title = "home sweet home", + userId = user.id, + ), ) val guestBookDao = GuestBookTestRepositoryObject.findGuestBookByUserId(id = user.id) @@ -62,78 +58,66 @@ internal class GuestBookRepositoryTest @Test fun `should write then update and read guest book`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testing"), + ) val person = save(person = initPerson(address = address, surname = "Adder")) - val user = - save( - user = - initUser( - person = person, - emailAddress = "casuel@tantooine.com", - username = "causual", - ), - ) + val user = save( + user = initUser( + person = person, + emailAddress = "casuel@tantooine.com", + username = "causual", + ), + ) guestBookRepository.save( - guestBookDao = - initGuestBook( - title = "home sweet home", - user = user, - ).toGuestBookDao(), + guestBookDao = initGuestBook( + title = "home sweet home", + user = user, + ).toGuestBookDao(), ) - val guestBookDaoToUpdate = - GuestBookTestRepositoryObject.findGuestBookByUserId(id = user.id) - ?: fail(message = "Should have found a guest book for user ${user.username}") + val guestBookDaoToUpdate = GuestBookTestRepositoryObject.findGuestBookByUserId(id = user.id) + ?: fail(message = "Should have found a guest book for user ${user.username}") guestBookDaoToUpdate.title = "5000 thousands miles away from home" guestBookRepository.save(guestBookDaoToUpdate) - val guestBookDao = - GuestBookTestRepositoryObject.findGuestBookByUserId(id = user.id) - ?: fail(message = "Should have found a guest book for user ${user.username}") + val guestBookDao = GuestBookTestRepositoryObject.findGuestBookByUserId(id = user.id) + ?: fail(message = "Should have found a guest book for user ${user.username}") assertThat(guestBookDao.title).isEqualTo("5000 thousands miles away from home") } @Test fun `should save then read dao for guest book entry`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), + ) val person = save(person = initPerson(address = address, surname = "AA")) - val user = - save( - user = - initUser( - person = person, - emailAddress = "casuel@tantooine.com", - username = "causual", - ), - ) - - val guestBook = - save( - guestBook = - initGuestBook( - title = "home sweet home", - user = user, - ), - ) - - val guestBookEntry = - initGuestBookEntry( - guestBook = guestBook, - creatorName = "Harry", - entry = "Draco Dormiens Nunquam Tittilandus", - ).toGuestBookEntryDao() + val user = save( + user = initUser( + person = person, + emailAddress = "casuel@tantooine.com", + username = "causual", + ), + ) + + val guestBook = save( + guestBook = initGuestBook( + title = "home sweet home", + user = user, + ), + ) + + val guestBookEntry = initGuestBookEntry( + guestBook = guestBook, + creatorName = "Harry", + entry = "Draco Dormiens Nunquam Tittilandus", + ).toGuestBookEntryDao() guestBookRepository.save(guestBookEntryDao = guestBookEntry) @@ -149,61 +133,52 @@ internal class GuestBookRepositoryTest @Test fun `should write two entries to a guest book and then find one entry`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), + ) val person = save(person = initPerson(address = address, surname = "AA")) - val user = - save( - user = - initUser( - person = person, - emailAddress = "casuel@tantooine.com", - username = "causual", - ), - ) - - val guestBook = - save( - guestBook = - initGuestBook( - title = "home sweet home", - user = user, - ), - ) + val user = save( + user = initUser( + person = person, + emailAddress = "casuel@tantooine.com", + username = "causual", + ), + ) - guestBookRepository.save( - guestBookEntryDao = - initGuestBookEntry( - creatorName = "somone", - entry = "jadda", - guestBook = guestBook, - ).toGuestBookEntryDao(), + val guestBook = save( + guestBook = initGuestBook( + title = "home sweet home", + user = user, + ), ) - val anEntry = - initGuestBookEntry( + guestBookRepository.save( + guestBookEntryDao = initGuestBookEntry( + creatorName = "somone", + entry = "jadda", guestBook = guestBook, - creatorName = "shriek", - entry = "i am out there", - ) + ).toGuestBookEntryDao(), + ) - val anotherEntry = - initGuestBookEntry( - guestBook = guestBook, - creatorName = "shrek", - entry = "far far away", - ) + val anEntry = initGuestBookEntry( + guestBook = guestBook, + creatorName = "shriek", + entry = "i am out there", + ) + + val anotherEntry = initGuestBookEntry( + guestBook = guestBook, + creatorName = "shrek", + entry = "far far away", + ) guestBookRepository.save(guestBookEntryDao = anEntry.toGuestBookEntryDao()) guestBookRepository.save(guestBookEntryDao = anotherEntry.toGuestBookEntryDao()) - val lastEntry = - guestBookRepository - .findGuestBookEtriesByGuestBookId(id = guestBook.id) - .lastOrNull() + val lastEntry = guestBookRepository + .findGuestBookEtriesByGuestBookId(id = guestBook.id) + .lastOrNull() assertAll { assertThat(lastEntry, "last entry").isNotNull() diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookServiceTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookServiceTest.kt index 2a0889a..486b7d4 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookServiceTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookServiceTest.kt @@ -23,109 +23,100 @@ import java.util.UUID internal class GuestBookServiceTest { private val guestBookRepositoryMockk: GuestBookRepository = mockk {} private val userRepositoryMockk: UserRepository = mockk {} - private val guestBookServiceToTest: GuestBookService = - GuestBookServiceBean( - guestBookRepository = guestBookRepositoryMockk, - persistenceHandler = PersistenceHandler(), - ).also { - JactorPersistenceRepositiesConfig.fetchUserRelation = { id -> userRepositoryMockk.findById(id = id) } - JactorPersistenceRepositiesConfig.fetchGuestBookRelation = { id -> - guestBookRepositoryMockk.findGuestBookById(id = id) - } + private val guestBookServiceToTest: GuestBookService = GuestBookServiceBean( + guestBookRepository = guestBookRepositoryMockk, + persistenceHandler = PersistenceHandler(), + ).also { + JactorPersistenceRepositiesConfig.fetchUserRelation = { id -> userRepositoryMockk.findById(id = id) } + JactorPersistenceRepositiesConfig.fetchGuestBookRelation = { id -> + guestBookRepositoryMockk.findGuestBookById(id = id) } + } private val uuid = UUID.randomUUID() @Test - fun `should map guest book to a dto`() = - runTest { - val guestBookDao = - initGuestBook(title = "@home").withId().toGuestBookDao().apply { - userId = UUID.randomUUID() - } + fun `should map guest book to a dto`() = runTest { + val guestBookDao = initGuestBook(title = "@home").withId().toGuestBookDao().apply { + userId = UUID.randomUUID() + } - every { guestBookRepositoryMockk.findGuestBookById(id = uuid) } returns guestBookDao - every { userRepositoryMockk.findById(any()) } returns initUser().withId().toUserDao() + every { guestBookRepositoryMockk.findGuestBookById(id = uuid) } returns guestBookDao + every { userRepositoryMockk.findById(any()) } returns initUser().withId().toUserDao() - val (_, title, _) = guestBookServiceToTest.findGuestBook(id = uuid) ?: fail { "missed mocking?" } + val (_, title, _) = guestBookServiceToTest.findGuestBook(id = uuid) ?: fail { "missed mocking?" } - assertThat(title).isEqualTo("@home") - } + assertThat(title).isEqualTo("@home") + } @Test - fun `should map guest book entry to a dto`() = - runTest { - val anEntry = - initGuestBookEntry( - guestBook = initGuestBook(title = "guest who?").withId(), - creatorName = "me", - entry = "too", - persistent = Persistent(id = uuid), - ).toGuestBookEntryDao() - - every { guestBookRepositoryMockk.findGuestBookById(id = any()) } returns mockk(relaxed = true) - every { guestBookRepositoryMockk.findGuestBookEntryById(id = uuid) } returns anEntry - - val guestBookEntryModel = guestBookServiceToTest.findEntry(id = uuid) ?: fail { "missed mocking?" } - - assertAll { - assertThat(guestBookEntryModel.guestName).isEqualTo("me") - assertThat(guestBookEntryModel.entry).isEqualTo("too") - } + fun `should map guest book entry to a dto`() = runTest { + val anEntry = initGuestBookEntry( + guestBook = initGuestBook(title = "guest who?").withId(), + creatorName = "me", + entry = "too", + persistent = Persistent(id = uuid), + ).toGuestBookEntryDao() + + every { guestBookRepositoryMockk.findGuestBookById(id = any()) } returns mockk(relaxed = true) + every { guestBookRepositoryMockk.findGuestBookEntryById(id = uuid) } returns anEntry + + val guestBookEntryModel = guestBookServiceToTest.findEntry(id = uuid) ?: fail { "missed mocking?" } + + assertAll { + assertThat(guestBookEntryModel.guestName).isEqualTo("me") + assertThat(guestBookEntryModel.entry).isEqualTo("too") } + } @Test - fun `should save GuestBookDto as GuestBookDao`() = - runTest { - val guestBookDaoSlot = slot() - val user = initUser().withId() - val guestBook = - initGuestBook( - persistent = Persistent(id = uuid), - title = "home sweet home", - user = user, - ) - - every { userRepositoryMockk.findById(id = guestBook.userId!!) } returns user.toUserDao() - every { - guestBookRepositoryMockk.save(guestBookDao = capture(guestBookDaoSlot)) - } returns guestBook.toGuestBookDao() - - guestBookServiceToTest.saveOrUpdate(guestBook) - val guestBookDao = guestBookDaoSlot.captured - - assertThat(guestBookDao.title).isEqualTo("home sweet home") - } + fun `should save GuestBookDto as GuestBookDao`() = runTest { + val guestBookDaoSlot = slot() + val user = initUser().withId() + val guestBook = initGuestBook( + persistent = Persistent(id = uuid), + title = "home sweet home", + user = user, + ) + + every { userRepositoryMockk.findById(id = guestBook.userId!!) } returns user.toUserDao() + every { + guestBookRepositoryMockk.save(guestBookDao = capture(guestBookDaoSlot)) + } returns guestBook.toGuestBookDao() + + guestBookServiceToTest.saveOrUpdate(guestBook) + val guestBookDao = guestBookDaoSlot.captured + + assertThat(guestBookDao.title).isEqualTo("home sweet home") + } @Test - fun `should save GuestBookEntryDto as guestBookEntryDao`() = - runTest { - val guestBookEntryDaoSlot = slot() - val user = initUser().withId() - val guestBook = initGuestBook(title = "guest who?", user = user).withId() - val guestBookEntry = - initGuestBookEntry( - guestBook = guestBook, - creatorName = "me", - entry = "if i where a rich man...", - ) - - every { userRepositoryMockk.findById(id = guestBook.userId!!) } returns user.toUserDao() - every { guestBookRepositoryMockk.findGuestBookById(id = guestBookEntry.guestBookId!!) } returns - guestBook - .toGuestBookDao() - - every { - guestBookRepositoryMockk.save(guestBookEntryDao = capture(guestBookEntryDaoSlot)) - } returns guestBookEntry.toGuestBookEntryDao() - - guestBookServiceToTest.saveOrUpdate(guestBookEntry) - val guestBookEntryDao = guestBookEntryDaoSlot.captured - - assertAll { - assertThat(guestBookEntryDao.guestBookId).isNotNull() - assertThat(guestBookEntryDao.guestName).isEqualTo("me") - assertThat(guestBookEntryDao.entry).isEqualTo("if i where a rich man...") - } + fun `should save GuestBookEntryDto as guestBookEntryDao`() = runTest { + val guestBookEntryDaoSlot = slot() + val user = initUser().withId() + val guestBook = initGuestBook(title = "guest who?", user = user).withId() + val guestBookEntry = initGuestBookEntry( + guestBook = guestBook, + creatorName = "me", + entry = "if i where a rich man...", + ) + + every { userRepositoryMockk.findById(id = guestBook.userId!!) } returns user.toUserDao() + every { guestBookRepositoryMockk.findGuestBookById(id = guestBookEntry.guestBookId!!) } returns + guestBook + .toGuestBookDao() + + every { + guestBookRepositoryMockk.save(guestBookEntryDao = capture(guestBookEntryDaoSlot)) + } returns guestBookEntry.toGuestBookEntryDao() + + guestBookServiceToTest.saveOrUpdate(guestBookEntry) + val guestBookEntryDao = guestBookEntryDaoSlot.captured + + assertAll { + assertThat(guestBookEntryDao.guestBookId).isNotNull() + assertThat(guestBookEntryDao.guestName).isEqualTo("me") + assertThat(guestBookEntryDao.entry).isEqualTo("if i where a rich man...") } + } } diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookTest.kt index 119a808..98a0529 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookTest.kt @@ -14,11 +14,10 @@ import java.util.UUID internal class GuestBookTest { @Test fun `should have a copy constructor`() { - val guestBook = - initGuestBook( - title = "title", - user = initUser().withId(), - ) + val guestBook = initGuestBook( + title = "title", + user = initUser().withId(), + ) val (_, title, userId) = GuestBook(guestBook.persistent, guestBook) @@ -30,20 +29,18 @@ internal class GuestBookTest { @Test fun `should give values to PersistentDto`() { - val persistent = - Persistent( - createdBy = "jactor", - id = UUID.randomUUID(), - modifiedBy = "tip", - timeOfCreation = LocalDateTime.now(), - timeOfModification = LocalDateTime.now(), - ) + val persistent = Persistent( + createdBy = "jactor", + id = UUID.randomUUID(), + modifiedBy = "tip", + timeOfCreation = LocalDateTime.now(), + timeOfModification = LocalDateTime.now(), + ) - val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = - GuestBook( - persistent, - guestBook = initGuestBook(), - ).persistent + val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = GuestBook( + persistent, + guestBook = initGuestBook(), + ).persistent assertAll { assertThat(createdBy).isEqualTo(persistent.createdBy) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookTestRepositoryObject.kt b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookTestRepositoryObject.kt index 4667963..fb0d1c6 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookTestRepositoryObject.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/guestbook/GuestBookTestRepositoryObject.kt @@ -7,10 +7,9 @@ import org.jetbrains.exposed.v1.jdbc.selectAll import java.util.UUID object GuestBookTestRepositoryObject { - fun findGuestBookByUserId(id: UUID): GuestBookDao? = - GuestBooks - .selectAll() - .andWhere { GuestBooks.userId eq id } - .singleOrNull() - ?.toGuestBookDao() + fun findGuestBookByUserId(id: UUID): GuestBookDao? = GuestBooks + .selectAll() + .andWhere { GuestBooks.userId eq id } + .singleOrNull() + ?.toGuestBookDao() } diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonRepositoryTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonRepositoryTest.kt index 393cff9..24bc410 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonRepositoryTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonRepositoryTest.kt @@ -20,10 +20,9 @@ internal class PersonRepositoryTest ) : AbstractSpringBootNoDirtyContextTest() { @Test fun `should find default persons`() { - val firstNames = - PersonTestRepositoryObject - .findBySurname("Jacobsen") - .map { it.firstName } + val firstNames = PersonTestRepositoryObject + .findBySurname("Jacobsen") + .map { it.firstName } assertAll { assertThat(firstNames).contains("Tor Egil") @@ -33,31 +32,28 @@ internal class PersonRepositoryTest @Test fun `should save then read a person dao`() { - val addressId = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevar 1", city = "Testington"), - ).persistent.id ?: fail { "not persisted?!!!" } + val addressId = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevar 1", city = "Testington"), + ).persistent.id ?: fail { "not persisted?!!!" } val addressDao = addressRepository.findById(id = addressId) ?: fail { "Address (id=$addressId) not found???" } val allreadyPresentPeople = PersonTestRepositoryObject.findAll().count() - val personToPersist = - PersonDao( - addressId = addressDao.id, - description = "Me, myself, and I", - firstName = "Born", - locale = "no_NO", - surname = "Sometime", - ) + val personToPersist = PersonDao( + addressId = addressDao.id, + description = "Me, myself, and I", + firstName = "Born", + locale = "no_NO", + surname = "Sometime", + ) personRepository.save(personToPersist) val people = PersonTestRepositoryObject.findAll() assertThat(people, "allready present people").hasSize(allreadyPresentPeople + 1) - val personDao = - personToPersist.surname.let { - PersonTestRepositoryObject.findBySurname(surname = it).firstOrNull() ?: fail { "Person with surname $it not found" } - } + val personDao = personToPersist.surname.let { + PersonTestRepositoryObject.findBySurname(surname = it).firstOrNull() ?: fail { "Person with surname $it not found" } + } assertAll { assertThat(personDao.addressId).isEqualTo(personToPersist.addressId) @@ -69,39 +65,36 @@ internal class PersonRepositoryTest @Test fun `should save then update and read a person dao`() { - val addressId = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevar 1", city = "Testington"), - ).persistent.id ?: fail { "not persisted?!!!" } + val addressId = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevar 1", city = "Testington"), + ).persistent.id ?: fail { "not persisted?!!!" } val addressDao = addressRepository.findById(id = addressId) ?: fail { "Address (id=$addressId) not found???" } personRepository.save( - personDao = - PersonDao( - addressId = addressDao.id, - firstName = "B", - description = "Just me...", - locale = "no_NO", - surname = "Mine", - ), + personDao = PersonDao( + addressId = addressDao.id, + firstName = "B", + description = "Just me...", + locale = "no_NO", + surname = "Mine", + ), ) - val personDao = - ("Mine" to "Cula").let { - val mine = PersonTestRepositoryObject.findBySurname(surname = it.first) - val person = mine.firstOrNull() ?: fail { "Person with surname ${it.first} not found" } + val personDao = ("Mine" to "Cula").let { + val mine = PersonTestRepositoryObject.findBySurname(surname = it.first) + val person = mine.firstOrNull() ?: fail { "Person with surname ${it.first} not found" } - person.description = "There is no try" - person.locale = "dk_DK" - person.firstName = "Dr. A." - person.surname = it.second + person.description = "There is no try" + person.locale = "dk_DK" + person.firstName = "Dr. A." + person.surname = it.second - personRepository.save(personDao = person) - val foundCula = PersonTestRepositoryObject.findBySurname(surname = it.second) + personRepository.save(personDao = person) + val foundCula = PersonTestRepositoryObject.findBySurname(surname = it.second) - foundCula.firstOrNull() - } + foundCula.firstOrNull() + } assertAll { assertThat(personDao?.description).isEqualTo("There is no try") diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonTest.kt index a75106b..94e0895 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonTest.kt @@ -14,19 +14,17 @@ import java.util.UUID internal class PersonTest { @Test fun `should have a copy constructor`() { - val person = - initPerson( - address = initAddress().withId(), - firstName = "first name", - description = "description", - locale = "no", - surname = "surname", - ) + val person = initPerson( + address = initAddress().withId(), + firstName = "first name", + description = "description", + locale = "no", + surname = "surname", + ) - val (_, addressId, locale, firstName, surname, description) = - person.copy( - persistent = person.persistent, - ) + val (_, addressId, locale, firstName, surname, description) = person.copy( + persistent = person.persistent, + ) assertAll { assertThat(addressId).isEqualTo(person.addressId) @@ -39,19 +37,17 @@ internal class PersonTest { @Test fun `should give values to PersistentDto`() { - val persistent = - Persistent( - createdBy = "jactor", - id = UUID.randomUUID(), - modifiedBy = "tip", - timeOfModification = LocalDateTime.now(), - timeOfCreation = LocalDateTime.now(), - ) + val persistent = Persistent( + createdBy = "jactor", + id = UUID.randomUUID(), + modifiedBy = "tip", + timeOfModification = LocalDateTime.now(), + timeOfCreation = LocalDateTime.now(), + ) - val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = - initPerson( - persistent = persistent, - ).persistent + val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = initPerson( + persistent = persistent, + ).persistent assertAll { assertThat(createdBy).isEqualTo(persistent.createdBy) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonTestRepositoryObject.kt b/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonTestRepositoryObject.kt index d522e78..2baed42 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonTestRepositoryObject.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/person/PersonTestRepositoryObject.kt @@ -8,14 +8,13 @@ import org.jetbrains.exposed.v1.jdbc.selectAll object PersonTestRepositoryObject { fun findAll(): List = People.selectAll().map { it.toPersonDao() } - fun findBySurname(surname: String?): List = - when { - (surname?.isBlank() ?: true) -> emptyList() + fun findBySurname(surname: String?): List = when { + (surname?.isBlank() ?: true) -> emptyList() - else -> - People - .selectAll() - .andWhere { People.surname eq surname } - .map { it.toPersonDao() } - } + else -> + People + .selectAll() + .andWhere { People.surname eq surname } + .map { it.toPersonDao() } + } } diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/test/AbstractSpringBootNoDirtyContextTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/test/AbstractSpringBootNoDirtyContextTest.kt index 702ec56..4dac8c7 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/test/AbstractSpringBootNoDirtyContextTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/test/AbstractSpringBootNoDirtyContextTest.kt @@ -23,36 +23,30 @@ abstract class AbstractSpringBootNoDirtyContextTest { @Autowired private lateinit var jactorPersistenceRepositiesConfig: JactorPersistenceRepositiesConfig - protected fun save(address: Address): Address = - AddressTestRepositoryObject - .save( - addressDao = address.toAddressDao(), - ).toAddress() - - protected fun save(blog: Blog): Blog = - jactorPersistenceRepositiesConfig.blogRepository - .save(blogDao = blog.toBlogDao()) - .toBlog() - - protected fun save(blogEntry: BlogEntry): BlogEntry = - jactorPersistenceRepositiesConfig.blogRepository - .save(blogEntryDao = blogEntry.toBlogEntryDao()) - .toBlogEntry() - - protected fun save(guestBook: GuestBook): GuestBook = - jactorPersistenceRepositiesConfig.guestBookRepository - .save(guestBookDao = guestBook.toGuestBookDao()) - .toGuestBook() - - protected fun save(person: Person): Person = - jactorPersistenceRepositiesConfig.personRepository - .save(personDao = person.toPersonDao()) - .toPerson() - - protected fun save(user: User): User = - jactorPersistenceRepositiesConfig.userRepository - .save(userDao = user.toUserDao()) - .toUser() + protected fun save(address: Address): Address = AddressTestRepositoryObject + .save( + addressDao = address.toAddressDao(), + ).toAddress() + + protected fun save(blog: Blog): Blog = jactorPersistenceRepositiesConfig.blogRepository + .save(blogDao = blog.toBlogDao()) + .toBlog() + + protected fun save(blogEntry: BlogEntry): BlogEntry = jactorPersistenceRepositiesConfig.blogRepository + .save(blogEntryDao = blogEntry.toBlogEntryDao()) + .toBlogEntry() + + protected fun save(guestBook: GuestBook): GuestBook = jactorPersistenceRepositiesConfig.guestBookRepository + .save(guestBookDao = guestBook.toGuestBookDao()) + .toGuestBook() + + protected fun save(person: Person): Person = jactorPersistenceRepositiesConfig.personRepository + .save(personDao = person.toPersonDao()) + .toPerson() + + protected fun save(user: User): User = jactorPersistenceRepositiesConfig.userRepository + .save(userDao = user.toUserDao()) + .toUser() protected fun resetFetchRelations() { jactorPersistenceRepositiesConfig.initFetchRelations() diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/test/AssertExtensions.kt b/src/test/kotlin/com/github/jactor/rises/persistence/test/AssertExtensions.kt index 6555017..a7fe453 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/test/AssertExtensions.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/test/AssertExtensions.kt @@ -13,8 +13,7 @@ infix fun Assert.contains(substring: String) = isNotNull().given { it.c infix fun Assert.equals(actual: T?): Unit = actual?.let { this.isEqualTo(it) } ?: this.isNull() -fun Assert.isNotOlderThan(seconds: Long) = - isStrictlyBetween( - LocalDateTime.now().minusSeconds(seconds), - LocalDateTime.now(), - ) +fun Assert.isNotOlderThan(seconds: Long) = isStrictlyBetween( + LocalDateTime.now().minusSeconds(seconds), + LocalDateTime.now(), +) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/test/PersistenceExtensions.kt b/src/test/kotlin/com/github/jactor/rises/persistence/test/PersistenceExtensions.kt index cac681e..f4883c2 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/test/PersistenceExtensions.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/test/PersistenceExtensions.kt @@ -24,26 +24,22 @@ fun Person.withId() = copy(persistent = persistent.copy(id = UUID.randomUUID())) fun User.withId() = copy(persistent = persistent.copy(id = UUID.randomUUID())) -fun GuestBookEntry.withPersistedData(id: UUID): GuestBookEntry = - copy( - persistent = Persistent().withPersistedData(id = id), - ) - -fun Persistent.withPersistedData(id: UUID? = UUID.randomUUID()) = - copy( - id = id, - createdBy = "unit test", - modifiedBy = "user test", - ) - -fun PersistentDto.withPersistedData(id: UUID? = UUID.randomUUID()) = - copy( - id = id, - createdBy = "unit test", - modifiedBy = "user test", - ) - -fun UserDto.withPersistedData(id: UUID = UUID.randomUUID()): UserDto = - copy( - persistentDto = persistentDto.withPersistedData(id = id), - ) +fun GuestBookEntry.withPersistedData(id: UUID): GuestBookEntry = copy( + persistent = Persistent().withPersistedData(id = id), +) + +fun Persistent.withPersistedData(id: UUID? = UUID.randomUUID()) = copy( + id = id, + createdBy = "unit test", + modifiedBy = "user test", +) + +fun PersistentDto.withPersistedData(id: UUID? = UUID.randomUUID()) = copy( + id = id, + createdBy = "unit test", + modifiedBy = "user test", +) + +fun UserDto.withPersistedData(id: UUID = UUID.randomUUID()): UserDto = copy( + persistentDto = persistentDto.withPersistedData(id = id), +) diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/test/StringExtensions.kt b/src/test/kotlin/com/github/jactor/rises/persistence/test/StringExtensions.kt index d31d210..92ccbc7 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/test/StringExtensions.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/test/StringExtensions.kt @@ -4,13 +4,12 @@ import assertk.Assert import assertk.assertions.support.expected import assertk.assertions.support.show -fun > Assert.containsSubstring(expected: String) = - given { strings -> - strings.forEach { - if (it.contains(expected)) { - return@given - } +fun > Assert.containsSubstring(expected: String) = given { strings -> + strings.forEach { + if (it.contains(expected)) { + return@given } - - expected("to contain substring:${show(expected)}, but list was:${show(strings)}") } + + expected("to contain substring:${show(expected)}, but list was:${show(strings)}") +} diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/test/TestUtil.kt b/src/test/kotlin/com/github/jactor/rises/persistence/test/TestUtil.kt index 537d76e..20b488c 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/test/TestUtil.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/test/TestUtil.kt @@ -175,31 +175,29 @@ fun initUserDao( personId: UUID? = null, username: String = "whoami", timeOfModification: LocalDateTime = LocalDateTime.now(), -): UserDao = - UserDao( - id = id, - createdBy = "unit test", - emailAddress = null, - modifiedBy = "unit test", - personId = personId, - username = username, - userType = UserType.ACTIVE, - timeOfCreation = LocalDateTime.now(), - timeOfModification = timeOfModification, - ) - -fun initUserDao(createUserCommand: CreateUserCommand) = - UserDao( - id = UUID.randomUUID(), - createdBy = createUserCommand.username, - emailAddress = null, - modifiedBy = createUserCommand.username, - personId = createUserCommand.personId, - username = createUserCommand.username, - userType = UserType.ACTIVE, - timeOfCreation = LocalDateTime.now(), - timeOfModification = LocalDateTime.now(), - ) +): UserDao = UserDao( + id = id, + createdBy = "unit test", + emailAddress = null, + modifiedBy = "unit test", + personId = personId, + username = username, + userType = UserType.ACTIVE, + timeOfCreation = LocalDateTime.now(), + timeOfModification = timeOfModification, +) + +fun initUserDao(createUserCommand: CreateUserCommand) = UserDao( + id = UUID.randomUUID(), + createdBy = createUserCommand.username, + emailAddress = null, + modifiedBy = createUserCommand.username, + personId = createUserCommand.personId, + username = createUserCommand.username, + userType = UserType.ACTIVE, + timeOfCreation = LocalDateTime.now(), + timeOfModification = LocalDateTime.now(), +) fun initPerson( id: UUID? = null, diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/user/UserControllerTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/user/UserControllerTest.kt index 89b4595..87e7542 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/user/UserControllerTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/user/UserControllerTest.kt @@ -53,16 +53,15 @@ internal class UserControllerTest fun `should find a user by username`() { every { userRepositoryMockk.findByUsername(username = "me") } returns initUser().toUserDao() - val userDto = - webTestClient - .get() - .uri("/user/name/me") - .exchange() - .expectStatus() - .isOk - .expectBody() - .returnResult() - .responseBody + val userDto = webTestClient + .get() + .uri("/user/name/me") + .exchange() + .expectStatus() + .isOk + .expectBody() + .returnResult() + .responseBody assertThat(userDto).isNotNull() } @@ -85,16 +84,15 @@ internal class UserControllerTest val uuid = UUID.randomUUID() every { userRepositoryMockk.findById(id = any()) } returns initUserDao(id = uuid) - val userDto = - webTestClient - .get() - .uri("/user/$uuid") - .exchange() - .expectStatus() - .isOk - .expectBody() - .returnResult() - .responseBody + val userDto = webTestClient + .get() + .uri("/user/$uuid") + .exchange() + .expectStatus() + .isOk + .expectBody() + .returnResult() + .responseBody assertThat(userDto).isNotNull() } @@ -107,17 +105,16 @@ internal class UserControllerTest every { userRepositoryMockk.findById(uuid) } returns user.toUserDao() every { userRepositoryMockk.save(any()) } answers { arg(0) } - val userDto = - webTestClient - .put() - .uri("/user/update") - .bodyValue(user.toUserDto()) - .exchange() - .expectStatus() - .isAccepted - .expectBody() - .returnResult() - .responseBody + val userDto = webTestClient + .put() + .uri("/user/update") + .bodyValue(user.toUserDto()) + .exchange() + .expectStatus() + .isAccepted + .expectBody() + .returnResult() + .responseBody assertThat(userDto).isNotNull() } @@ -128,29 +125,27 @@ internal class UserControllerTest userRepositoryMockk.findUsernames(userType = listOf(UserType.ACTIVE)) } returns listOf("bart", "lisa") - val usernames = - webTestClient - .get() - .uri("/user/usernames") - .exchange() - .expectStatus() - .isOk - .expectBody() - .returnResult() - .responseBody + val usernames = webTestClient + .get() + .uri("/user/usernames") + .exchange() + .expectStatus() + .isOk + .expectBody() + .returnResult() + .responseBody assertThat(usernames).isEqualTo("""["bart","lisa"]""") } @Test fun `should accept if user id is not null`() { - val uuid = - UUID.randomUUID().also { - every { userRepositoryMockk.save(any()) } answers { arg(0) } - every { userRepositoryMockk.findById(id = it) } returns - initUser(persistent = Persistent(id = it)) - .toUserDao() - } + val uuid = UUID.randomUUID().also { + every { userRepositoryMockk.save(any()) } answers { arg(0) } + every { userRepositoryMockk.findById(id = it) } returns + initUser(persistent = Persistent(id = it)) + .toUserDao() + } webTestClient .put() @@ -222,12 +217,11 @@ internal class UserControllerTest @Test fun `should create a new user with an email address`() { - val createUserCommand = - CreateUserCommand( - username = timestamped("turbo"), - surname = "Someone", - emailAddress = "somewhere@somehow.com", - ) + val createUserCommand = CreateUserCommand( + username = timestamped("turbo"), + surname = "Someone", + emailAddress = "somewhere@somehow.com", + ) coEvery { userRepositoryMockk.contains(any()) } returns false coEvery { userRepositoryMockk.save(any()) } returns @@ -236,17 +230,16 @@ internal class UserControllerTest emailAddress = createUserCommand.emailAddress, ).withId().toUserDao() - val userDto = - webTestClient - .post() - .uri("/user") - .bodyValue(createUserCommand) - .exchange() - .expectStatus() - .isCreated - .expectBody() - .returnResult() - .responseBody ?: fail(message = "no user created") + val userDto = webTestClient + .post() + .uri("/user") + .bodyValue(createUserCommand) + .exchange() + .expectStatus() + .isCreated + .expectBody() + .returnResult() + .responseBody ?: fail(message = "no user created") assertThat(userDto).all { emailAddress named "email address" equals "somewhere@somehow.com" diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/user/UserRepositoryTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/user/UserRepositoryTest.kt index ad3f604..b7b4534 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/user/UserRepositoryTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/user/UserRepositoryTest.kt @@ -26,20 +26,18 @@ internal class UserRepositoryTest @Test fun `should write then read a user dao`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), + ) val person = save(person = initPerson(address = address, surname = "Solo")) - val userToPersist = - User( - personId = person.id, - emailAddress = "smuggle.fast@tantooine.com", - username = "smuggler", - userType = UserType.ACTIVE, - ).toUserDao() + val userToPersist = User( + personId = person.id, + emailAddress = "smuggle.fast@tantooine.com", + username = "smuggler", + userType = UserType.ACTIVE, + ).toUserDao() userRepository.save(userToPersist) @@ -55,19 +53,17 @@ internal class UserRepositoryTest @Test fun `should write then update and read a user dao`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), + ) val person = save(person = initPerson(address = address, surname = "AA")) - val userToPersist = - initUser( - persistent = Persistent(), - person = person, - emailAddress = "casuel@tantooine.com", - username = "causual", - ).toUserDao() + val userToPersist = initUser( + persistent = Persistent(), + person = person, + emailAddress = "casuel@tantooine.com", + username = "causual", + ).toUserDao() userRepository.save(userToPersist) @@ -87,20 +83,18 @@ internal class UserRepositoryTest @Test fun `should find active users and admins`() { - val address = - save( - address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), - ) + val address = save( + address = initAddress(zipCode = "1001", addressLine1 = "Test Boulevard 1", city = "Testington"), + ) val spidyPerson = save(person = initPerson(address = address, surname = "Parker")) val superPerson = save(person = initPerson(address = address, surname = "Kent")) - val userDao = - initUser( - persistent = Persistent(), - person = spidyPerson, - emailAddress = null, - username = "spiderman", - ).toUserDao() + val userDao = initUser( + persistent = Persistent(), + person = spidyPerson, + emailAddress = null, + username = "spiderman", + ).toUserDao() userRepository.save(userDao) userRepository.save( diff --git a/src/test/kotlin/com/github/jactor/rises/persistence/user/UserTest.kt b/src/test/kotlin/com/github/jactor/rises/persistence/user/UserTest.kt index abc24a8..017b79a 100644 --- a/src/test/kotlin/com/github/jactor/rises/persistence/user/UserTest.kt +++ b/src/test/kotlin/com/github/jactor/rises/persistence/user/UserTest.kt @@ -14,12 +14,11 @@ import java.util.UUID internal class UserTest { @Test fun `should have a copy constructor`() { - val user = - initUser( - emailAddress = "somewhere@time", - person = initPerson().withId(), - username = "me", - ) + val user = initUser( + emailAddress = "somewhere@time", + person = initPerson().withId(), + username = "me", + ) val (_, emailAddress, personId, username) = user.copy(persistent = user.persistent) @@ -32,19 +31,17 @@ internal class UserTest { @Test fun `should give values to PersistentDto`() { - val persistent = - Persistent( - createdBy = "jactor", - id = UUID.randomUUID(), - modifiedBy = "tip", - timeOfCreation = LocalDateTime.now(), - timeOfModification = LocalDateTime.now(), - ) + val persistent = Persistent( + createdBy = "jactor", + id = UUID.randomUUID(), + modifiedBy = "tip", + timeOfCreation = LocalDateTime.now(), + timeOfModification = LocalDateTime.now(), + ) - val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = - initUser( - persistent = persistent, - ).persistent + val (id, createdBy, modifiedBy, timeOfCreation, timeOfModification) = initUser( + persistent = persistent, + ).persistent assertAll { assertThat(createdBy).isEqualTo(persistent.createdBy)