-
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.
tests: improve test speed and restructure test package
* delete empty XesarApiInstanceTest.kt * change package structure (now splitted into integration and unit) * remove unnessary integration tests for every command testing if an OptionalEventException/RequiredEventException was thrown (instead unit tests ExecuteACommandAndSimulateDifferentResultScenarios.kt)
- Loading branch information
Showing
139 changed files
with
1,213 additions
and
3,150 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
xesar-connect/src/test/kotlin/com/open200/xesar/connect/XesarApiInstanceTest.kt
This file was deleted.
Oops, something went wrong.
517 changes: 0 additions & 517 deletions
517
xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddEvvaComponentTest.kt
This file was deleted.
Oops, something went wrong.
534 changes: 0 additions & 534 deletions
534
...c/test/kotlin/com/open200/xesar/connect/command/AssignAuthorizationProfileToMediumTest.kt
This file was deleted.
Oops, something went wrong.
607 changes: 0 additions & 607 deletions
607
...nnect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationProfileTest.kt
This file was deleted.
Oops, something went wrong.
518 changes: 0 additions & 518 deletions
518
...-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateInstallationPointTest.kt
This file was deleted.
Oops, something went wrong.
541 changes: 0 additions & 541 deletions
541
...t/src/test/kotlin/com/open200/xesar/connect/command/RequestAddMediumToInstallationTest.kt
This file was deleted.
Oops, something went wrong.
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
6 changes: 4 additions & 2 deletions
6
...n200/xesar/connect/DelayUntilCloseTest.kt → ...t/test/integration/DelayUntilCloseTest.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
6 changes: 4 additions & 2 deletions
6
...com/open200/xesar/connect/ListenerTest.kt → .../connect/test/integration/ListenerTest.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
2 changes: 1 addition & 1 deletion
2
...r/connect/testutils/MosquittoContainer.kt → ...ct/test/integration/MosquittoContainer.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
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
6 changes: 4 additions & 2 deletions
6
...200/xesar/connect/SubscribedTopicsTest.kt → .../test/integration/SubscribedTopicsTest.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
103 changes: 103 additions & 0 deletions
103
...rc/test/kotlin/com/open200/xesar/connect/test/integration/command/AddEvvaComponentTest.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,103 @@ | ||
package com.open200.xesar.connect.test.integration.command | ||
|
||
import com.open200.xesar.connect.* | ||
import com.open200.xesar.connect.extension.addEvvaComponentAsync | ||
import com.open200.xesar.connect.messages.ComponentType | ||
import com.open200.xesar.connect.messages.event.* | ||
import com.open200.xesar.connect.messages.query.ComponentStatus | ||
import com.open200.xesar.connect.test.integration.MosquittoContainer | ||
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.kotest.matchers.shouldBe | ||
import io.mockk.coEvery | ||
import java.time.LocalDateTime | ||
import java.util.* | ||
import kotlinx.coroutines.CompletableDeferred | ||
import kotlinx.coroutines.launch | ||
|
||
class AddEvvaComponentTest : | ||
FunSpec({ | ||
val container = MosquittoContainer.container() | ||
val config = MosquittoContainer.config(container) | ||
listener(container.perProject()) | ||
|
||
test("add evva component returning both events") { | ||
coEvery { config.uuidGenerator.generateId() } | ||
.returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) | ||
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.ADD_EVVA_COMPONENT -> { | ||
commandReceived.complete(payload.decodeToString()) | ||
} | ||
} | ||
} | ||
|
||
simulatedBackendReady.complete(Unit) | ||
|
||
val commandContent = commandReceived.await() | ||
|
||
commandContent.shouldBeEqual( | ||
"{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"type\":\"Cylinder\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}") | ||
|
||
val apiEvent = | ||
ApiEvent( | ||
UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), | ||
InstallationPointChanged( | ||
aggregateId = | ||
UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"))) | ||
|
||
val apiEvent2 = | ||
ApiEvent( | ||
UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), | ||
EvvaComponentAdded( | ||
id = UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), | ||
evvaComponentId = | ||
UUID.fromString("3a33c05b-133d-4b9d-a496-5d30dfd2d2c3"), | ||
type = ComponentType.Cylinder, | ||
stateChangedAt = LocalDateTime.MIN, | ||
status = ComponentStatus.AssembledPrepared)) | ||
|
||
client | ||
.publishAsync( | ||
Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) | ||
.await() | ||
|
||
client | ||
.publishAsync(Topics.Event.EVVA_COMPONENT_ADDED, encodeEvent(apiEvent2)) | ||
.await() | ||
} | ||
} | ||
launch { | ||
simulatedBackendReady.await() | ||
|
||
val api = XesarConnect.connectAndLoginAsync(config).await() | ||
api.subscribeAsync( | ||
Topics( | ||
Topics.Event.INSTALLATION_POINT_CHANGED, | ||
Topics.Event.EVVA_COMPONENT_ADDED)) | ||
.await() | ||
|
||
val addEvvaComponentEventPair = | ||
api.addEvvaComponentAsync( | ||
UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), | ||
ComponentType.Cylinder) | ||
val test = addEvvaComponentEventPair.installationPointChangedDeferred.await() | ||
test.aggregateId.shouldBeEqual( | ||
UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) | ||
val evvaComponentAdded = | ||
addEvvaComponentEventPair.evvaComponentAddedDeferred.await() | ||
evvaComponentAdded.type.shouldBe(ComponentType.Cylinder) | ||
} | ||
} | ||
} | ||
}) |
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
102 changes: 102 additions & 0 deletions
102
.../open200/xesar/connect/test/integration/command/AssignAuthorizationProfileToMediumTest.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,102 @@ | ||
package com.open200.xesar.connect.test.integration.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.assignAuthorizationProfileToMediumAsync | ||
import com.open200.xesar.connect.messages.event.* | ||
import com.open200.xesar.connect.test.integration.MosquittoContainer | ||
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.* | ||
import kotlinx.coroutines.CompletableDeferred | ||
import kotlinx.coroutines.launch | ||
|
||
class AssignAuthorizationProfileToMediumTest : | ||
FunSpec({ | ||
val container = MosquittoContainer.container() | ||
val config = MosquittoContainer.config(container) | ||
listener(container.perProject()) | ||
|
||
test("assign authorization profile to medium returning both events") { | ||
coEvery { config.uuidGenerator.generateId() } | ||
.returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) | ||
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.ASSIGN_AUTHORIZATION_PROFILE_TO_MEDIUM -> { | ||
commandReceived.complete(payload.decodeToString()) | ||
} | ||
} | ||
} | ||
|
||
simulatedBackendReady.complete(Unit) | ||
|
||
val commandContent = commandReceived.await() | ||
|
||
commandContent.shouldBeEqual( | ||
"{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"authorizationProfileId\":null,\"id\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}") | ||
|
||
val apiEvent2 = | ||
ApiEvent( | ||
UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), | ||
MediumAuthorizationProfileChanged( | ||
id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"))) | ||
|
||
val apiEvent = | ||
ApiEvent( | ||
UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), | ||
MediumChanged( | ||
id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), | ||
accessBeginAt = | ||
LocalDateTime.parse("2023-08-24T16:25:52.225991"), | ||
changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"))) | ||
|
||
client | ||
.publishAsync(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) | ||
.await() | ||
|
||
client | ||
.publishAsync( | ||
Topics.Event.MEDIUM_AUTHORIZATION_PROFILE_CHANGED, | ||
encodeEvent(apiEvent2)) | ||
.await() | ||
} | ||
} | ||
launch { | ||
simulatedBackendReady.await() | ||
|
||
val api = XesarConnect.connectAndLoginAsync(config).await() | ||
api.subscribeAsync( | ||
Topics( | ||
Topics.Event.MEDIUM_CHANGED, | ||
Topics.Event.MEDIUM_AUTHORIZATION_PROFILE_CHANGED)) | ||
.await() | ||
|
||
val assignAuthorizationProfileToMediumResult = | ||
api.assignAuthorizationProfileToMediumAsync( | ||
UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be")) | ||
val test = | ||
assignAuthorizationProfileToMediumResult | ||
.mediumAuthorizationProfileChangedDeferred | ||
.await() | ||
test.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) | ||
val mediumChanged = | ||
assignAuthorizationProfileToMediumResult.mediumChangedDeferred.await() | ||
mediumChanged.id.shouldBeEqual( | ||
UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) | ||
} | ||
} | ||
} | ||
}) |
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
Oops, something went wrong.