Skip to content

Commit

Permalink
Fake UserRepository implementation for when Mockoon can't be used
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoAlvarez28 committed Aug 11, 2023
1 parent 540daf5 commit 5102292
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
- APP_DATABASE_SCHEMA=kotlin_crud
- APP_DATABASE_USERNAME=postgres
- APP_DATABASE_PASSWORD=blue-elephant
- USERS_API_IMPL=mockoon
- USERS_API_MOCKOON_URL=http://mockoon:8180
depends_on:
- mockoon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package alvarez.fernando.kotlincrud.domain.users

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.stereotype.Repository
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import java.util.*

/**
* [UserRepository] implementation that have only one hardcoded user: "`Temp O'Rary`", as defined inside Mockoon's JSON.
*
* Useful if Mockoon ([UserRepositoryMockoonImpl]) can't be used/reached in the environment.
*/
@Repository
@ConditionalOnProperty(name = ["users.api.impl"], havingValue = "fake")
class UserRepositoryFakeImpl(private val user: User = User(UUID.fromString("0787f0bc-46df-4d15-abe9-c9c3e6dcfe21"), "Temp O'Rary", "temp orary", "withoutPassword")): UserRepository {

override fun getAll(): Flux<User> {
return Flux.fromIterable(Collections.singleton(this.user))
}

override fun getById(id: UUID): Mono<User> {
return if (this.user.id == id) Mono.just(this.user) else Mono.empty()
}

override fun getByUsername(username: String): Mono<User> {
return if (this.user.username == username) Mono.just(this.user) else Mono.empty()
}

}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ app.security.refresh=NAAiWv%s5x9J{^HHFU+!&ud<^s'x@~&zRju23]"@TDgz;td*gsp<k}7Aw'U
app.security.token.access.expiration-in-minutes=15
app.security.token.refresh.expiration-in-minutes=240

# "mockoon" or "fake"; see UserRepository
users.api.impl=mockoon
users.api.mockoon.url=http://localhost:8180

0 comments on commit 5102292

Please sign in to comment.