-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fake UserRepository implementation for when Mockoon can't be used
- Loading branch information
1 parent
540daf5
commit 5102292
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/alvarez/fernando/kotlincrud/domain/users/UserRepositoryFakeImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters