This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/delete schema from schema registry (#48)
* Add delete button * Add logic to delete the schema from the registry * Add happy path test * Add schema list viewmodel
- Loading branch information
1 parent
d71d96a
commit c7e7c25
Showing
9 changed files
with
142 additions
and
38 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
24 changes: 19 additions & 5 deletions
24
src/main/kotlin/insulator/viewmodel/main/schemaregistry/ListSchemaViewModel.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 |
---|---|---|
@@ -1,19 +1,33 @@ | ||
package insulator.viewmodel.main.schemaregistry | ||
|
||
import arrow.core.extensions.either.applicativeError.handleError | ||
import insulator.lib.helpers.runOnFXThread | ||
import insulator.lib.kafka.SchemaRegistry | ||
import insulator.viewmodel.common.InsulatorViewModel | ||
import javafx.collections.FXCollections | ||
import javafx.collections.ObservableList | ||
import tornadofx.ViewModel | ||
|
||
class ListSchemaViewModel : ViewModel() { | ||
class ListSchemaViewModel : InsulatorViewModel() { | ||
|
||
private val schemaRegistryClient: SchemaRegistry by di() | ||
|
||
fun listSchemas(): ObservableList<String> = schemaRegistryClient.getAllSubjects() | ||
.map { FXCollections.observableList(it.toList()) } | ||
.fold({ throw it }, { it }) | ||
val listSchema: ObservableList<String> = FXCollections.observableArrayList<String>() | ||
|
||
init { refresh() } | ||
|
||
fun getSchema(subject: String) = schemaRegistryClient.getSubject(subject) | ||
.map { SchemaViewModel(it) } | ||
.fold({ throw it }, { it }) | ||
|
||
fun refresh() = schemaRegistryClient | ||
.getAllSubjects() | ||
.map { it.sorted() } | ||
.map { | ||
it.runOnFXThread { | ||
listSchema.clear() | ||
listSchema.addAll(it) | ||
} | ||
}.handleError { | ||
error.set(it) | ||
} | ||
} |
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
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
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
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
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
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
38 changes: 38 additions & 0 deletions
38
src/test/kotlin/insulator/viewmodel/configurations/ListSchemaViewModelTest.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,38 @@ | ||
package insulator.viewmodel.configurations | ||
|
||
import arrow.core.left | ||
import insulator.lib.kafka.SchemaRegistry | ||
import insulator.viewmodel.main.schemaregistry.ListSchemaViewModel | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import tornadofx.* // ktlint-disable no-wildcard-imports | ||
import kotlin.reflect.KClass | ||
|
||
class ListSchemaViewModelTest : FunSpec({ | ||
|
||
val errorMessage = "Example error" | ||
|
||
test("Show an error if unable to retrieve the configuration") { | ||
// arrange | ||
val sut = ListSchemaViewModel() | ||
// act | ||
val clusters = sut.listSchema | ||
// assert | ||
clusters.size shouldBe 0 | ||
sut.error.value!!.message shouldBe errorMessage | ||
} | ||
|
||
beforeTest { | ||
FX.dicontainer = object : DIContainer { | ||
@Suppress("UNCHECKED_CAST", "IMPLICIT_CAST_TO_ANY") | ||
override fun <T : Any> getInstance(type: KClass<T>): T = when (type.java) { | ||
SchemaRegistry::class.java -> mockk<SchemaRegistry> { | ||
every { getAllSubjects() } returns Throwable(errorMessage).left() | ||
} | ||
else -> throw IllegalArgumentException("Missing dependency") | ||
} as T | ||
} | ||
} | ||
}) |