-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add ChangeMediumMetadataValue command and test (#162) #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andreasgrill
merged 3 commits into
main
from
162-add-changemediummetadatavaluemapi-command
Feb 8, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
23 changes: 23 additions & 0 deletions
23
...c/main/kotlin/com/open200/xesar/connect/messages/command/ChangeMediumMetadataValueMapi.kt
This file contains hidden or 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,23 @@ | ||
| package com.open200.xesar.connect.messages.command | ||
|
|
||
| import com.open200.xesar.connect.utils.UUIDSerializer | ||
| import java.util.* | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * Represents a command POJO to change a custom data field value for a medium. | ||
| * | ||
| * @param commandId The id of the command. | ||
| * @param id The id of the medium. | ||
| * @param metadataId The id of the custom data field. | ||
| * @param value The new value of the custom data field. | ||
| * @param token The token of the command. | ||
| */ | ||
| @Serializable | ||
| data class ChangeMediumMetadataValueMapi( | ||
| override val commandId: @Serializable(with = UUIDSerializer::class) UUID, | ||
| val id: @Serializable(with = UUIDSerializer::class) UUID? = null, | ||
| val metadataId: @Serializable(with = UUIDSerializer::class) UUID, | ||
| val value: String, | ||
| val token: String, | ||
| ) : Command |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
104 changes: 104 additions & 0 deletions
104
...ect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeMediumMetadataValueTest.kt
This file contains hidden or 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,104 @@ | ||
| package com.open200.xesar.connect.it.command | ||
|
|
||
| import com.open200.xesar.connect.Topics | ||
| import com.open200.xesar.connect.XesarConnect | ||
| import com.open200.xesar.connect.XesarMqttClient | ||
| import com.open200.xesar.connect.extension.changeMediumMetadataValueAsync | ||
| import com.open200.xesar.connect.it.MosquittoContainer | ||
| import com.open200.xesar.connect.messages.EntityMetadata | ||
| import com.open200.xesar.connect.messages.event.ApiEvent | ||
| import com.open200.xesar.connect.messages.event.MediumChanged | ||
| import com.open200.xesar.connect.messages.event.encodeEvent | ||
| import io.kotest.common.runBlocking | ||
| import io.kotest.core.spec.style.FunSpec | ||
| import io.kotest.extensions.testcontainers.perProject | ||
| import io.kotest.matchers.equals.shouldBeEqual | ||
| import io.mockk.coEvery | ||
| import java.time.LocalDateTime | ||
| import java.util.UUID | ||
| import kotlinx.coroutines.CompletableDeferred | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| class ChangeMediumMetadataValueTest : | ||
| FunSpec({ | ||
| val container = MosquittoContainer.container() | ||
| val config = MosquittoContainer.config(container) | ||
| listener(container.perProject()) | ||
|
|
||
| test("change medium metadata value") { | ||
| coEvery { config.uuidGenerator.generateId() } | ||
| .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) | ||
|
|
||
| val mediumId = UUID.fromString("11111111-2222-3333-4444-555555555555") | ||
| val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") | ||
|
|
||
| runBlocking { | ||
| val simulatedBackendReady = CompletableDeferred<Unit>() | ||
| val commandReceived = CompletableDeferred<String>() | ||
|
|
||
| launch { | ||
| XesarMqttClient.connectAsync(config).await().use { client -> | ||
| client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() | ||
|
|
||
| client.onMessage = { topic, payload -> | ||
| when (topic) { | ||
| Topics.Command.CHANGE_MEDIUM_METADATA_VALUE -> { | ||
| commandReceived.complete(payload.decodeToString()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| simulatedBackendReady.complete(Unit) | ||
|
|
||
| val commandContent = commandReceived.await() | ||
|
|
||
| commandContent.shouldBeEqual( | ||
| "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"11111111-2222-3333-4444-555555555555\",\"metadataId\":\"aaaaaaaa-0000-0000-0000-000000000001\",\"value\":\"Vogons\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" | ||
| ) | ||
|
|
||
| val apiEvent = | ||
| ApiEvent( | ||
| UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), | ||
| MediumChanged( | ||
| id = mediumId, | ||
| changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"), | ||
| entityMetadata = | ||
| listOf( | ||
| EntityMetadata( | ||
| id = metadataId, | ||
| name = "Group", | ||
| value = "Vogons", | ||
PaulWinter91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
| client | ||
| .publishAsync(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) | ||
| .await() | ||
| } | ||
| } | ||
|
|
||
| launch { | ||
| simulatedBackendReady.await() | ||
|
|
||
| val api = XesarConnect.connectAndLoginAsync(config).await() | ||
| api.subscribeAsync(Topics(Topics.Event.MEDIUM_CHANGED)).await() | ||
|
|
||
| val result = | ||
| api.changeMediumMetadataValueAsync( | ||
| id = mediumId, | ||
| metadataId = metadataId, | ||
| value = "Vogons", | ||
| ) | ||
| .await() | ||
|
|
||
| result.id.shouldBeEqual(mediumId) | ||
| result.entityMetadata!! | ||
| .single { it.id == metadataId } | ||
| .value | ||
| ?.shouldBeEqual("Vogons") | ||
| } | ||
| } | ||
| } | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.