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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
dependencies {
implementation(project(":domain"))
testImplementation(libs.h2)
testImplementation(libs.konsist)
testImplementation(libs.kotest.engine)
testImplementation(libs.kotest.assertions)
testImplementation(libs.kotest.runner)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.alleslocker.backend.domain.user.UserRole
import java.time.Instant
import kotlin.math.log

class ActivateUserUseCaseImpl(
internal class ActivateUserUseCaseImpl(
val userGateway: UserGateway,
val logger: Logger,
) : ActivateUserUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.alleslocker.backend.domain.user.UserId
import com.alleslocker.backend.domain.user.UserRole
import java.time.Instant

class AdminResetPasswordUserUseCaseImpl(
internal class AdminResetPasswordUserUseCaseImpl(
private val userGateway: UserGateway,
private val passwordHasher: PasswordHasher,
private val passwordGeneratorService: PasswordGeneratorService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.alleslocker.backend.domain.user.UserId
import com.alleslocker.backend.domain.user.UserRole
import java.time.Instant

class ChangeUserRoleUseCaseImpl(
internal class ChangeUserRoleUseCaseImpl(
private val userGateway: UserGateway,
private val logger: Logger,
) : ChangeUserRoleUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.alleslocker.backend.domain.user.UserRole
import com.alleslocker.backend.domain.user.Username
import java.time.Instant

class CreateUserUseCaseImpl(
internal class CreateUserUseCaseImpl(
private val userGateway: UserGateway,
private val logger: Logger,
private val passwordGeneratorService: PasswordGeneratorService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.alleslocker.backend.domain.user.UserRole
import java.time.Instant
import kotlin.math.log

class DeactivateUserUseCaseImpl(
internal class DeactivateUserUseCaseImpl(
val userGateway: UserGateway,
val logger: Logger,
) : DeactivateUserUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.alleslocker.backend.application.user.dto.response.GetUsersPagedRespon
import com.alleslocker.backend.application.user.gateway.UserGateway
import com.alleslocker.backend.application.user.mapper.toDto

class GetUsersPagedUseCaseImpl(
internal class GetUsersPagedUseCaseImpl(
private val userGateway: UserGateway,
private val logger: Logger,
) : GetUsersPagedUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.alleslocker.backend.domain.user.UserId
import com.alleslocker.backend.domain.user.UserRole
import java.time.Instant

class RequestUserPasswordChangeUseCaseImpl(
internal class RequestUserPasswordChangeUseCaseImpl(
private val userGateway: UserGateway,
private val logger: Logger,
) : RequestUserPasswordChangeUseCase {
Expand All @@ -22,7 +22,7 @@ class RequestUserPasswordChangeUseCaseImpl(
) {
val requestorId =
try {
UserId(request.userId)
UserId(request.requestorId)
} catch (e: IllegalArgumentException) {
presenter.presentFailure(ErrorResponse.BadRequest("Invalid id: ${e.message}"))
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.alleslocker.backend.application.user.gateway.UserGateway
import com.alleslocker.backend.domain.user.PasswordHash
import com.alleslocker.backend.domain.user.UserId

class ResetPasswordUserUseCaseImpl(
internal class ResetPasswordUserUseCaseImpl(
private val passwordHasher: PasswordHasher,
private val logger: Logger,
private val userGateway: UserGateway,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alleslocker.backend.bootstrap
package com.alleslocker.backend.application

import com.lemonappdev.konsist.api.Konsist
import com.lemonappdev.konsist.api.architecture.KoArchitectureCreator.assertArchitecture
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.alleslocker.backend.application.integration.config

import com.alleslocker.backend.application.common.adapter.Adapter
import com.alleslocker.backend.application.common.factory.AdapterFactory
import java.lang.reflect.Proxy
import kotlin.reflect.KClass

class TestAdapterFactory(
private val adapters: List<Adapter>,
) : AdapterFactory {
override fun <T : Adapter> make(adapter: KClass<out T>): T {
val match = adapters.firstOrNull { adapter.isInstance(it) }
if (match != null) {
@Suppress("UNCHECKED_CAST")
return match as T
}

@Suppress("UNCHECKED_CAST")
return Proxy.newProxyInstance(
adapter.java.classLoader,
arrayOf(adapter.java),
) { _, method, _ ->
when (method.returnType) {
Boolean::class.javaPrimitiveType -> false
Int::class.javaPrimitiveType -> 0
Long::class.javaPrimitiveType -> 0L
else -> null
}
} as T
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.alleslocker.backend.application.integration.config

import com.alleslocker.backend.application.common.factory.GatewayFactory
import com.alleslocker.backend.application.common.gateway.Gateway
import java.lang.reflect.Proxy
import kotlin.reflect.KClass

class TestGatewayFactory(
private val gateways: List<Gateway>,
) : GatewayFactory {
override fun <T : Gateway> make(gateway: KClass<out T>): T {
val match = gateways.firstOrNull { gateway.isInstance(it) }
if (match != null) {
@Suppress("UNCHECKED_CAST")
return match as T
}

@Suppress("UNCHECKED_CAST")
return Proxy.newProxyInstance(
gateway.java.classLoader,
arrayOf(gateway.java),
) { _, method, _ ->
when (method.returnType) {
Boolean::class.javaPrimitiveType -> false
Int::class.javaPrimitiveType -> 0
Long::class.javaPrimitiveType -> 0L
else -> null
}
} as T
}

override fun migrate() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.alleslocker.backend.application.integration.config

import com.alleslocker.backend.application.common.Logger
import com.alleslocker.backend.domain.auditlog.AuditLog

class TestLogger : Logger {
val auditLogs = mutableListOf<AuditLog>()
val infoMessages = mutableListOf<String>()
val errorMessages = mutableListOf<String>()

fun clear() {
auditLogs.clear()
infoMessages.clear()
errorMessages.clear()
}

override fun info(message: String) {
infoMessages.add(message)
}

override fun error(
message: String,
throwable: Throwable?,
) {
errorMessages.add(message)
}

override fun audit(auditLog: AuditLog) {
auditLogs.add(auditLog)
}

override fun debug(message: String) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.alleslocker.backend.application.integration.config

import com.alleslocker.backend.application.common.security.PasswordHasher
import java.security.MessageDigest

class TestPasswordHasher : PasswordHasher {
private val digest = MessageDigest.getInstance("SHA-256")

override fun hash(raw: String): String = digest.digest(raw.toByteArray()).joinToString("") { "%02x".format(it) }

override fun verify(
raw: String,
hash: String,
): Boolean = hash(raw) == hash
Comment thread
wan0v marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.alleslocker.backend.application.integration.config

import com.alleslocker.backend.application.common.ErrorResponse
import com.alleslocker.backend.application.common.OutputBoundary

class TestPresenter<R> : OutputBoundary<R> {
var response: R? = null
var error: ErrorResponse? = null

override fun present(response: R) {
this.response = response
}

override fun presentFailure(error: ErrorResponse) {
this.error = error
}
}
Loading
Loading