From fdeff684b44fc2cc84634dace2693de7106a02cb Mon Sep 17 00:00:00 2001 From: Andreas Grill <1265844+andreasgrill@users.noreply.github.com> Date: Sun, 13 Sep 2026 19:40:47 +0200 Subject: [PATCH] refactor: replace repetitive command/query integration tests with mock harness tests Most command and query integration tests started a Mosquitto container and simulated the backend over MQTT, although the extension functions under test are thin wrappers around sendCommandAsync/queryListAsync. - add MockedXesarConnect test harness (mocked MqttAsyncClient, recorded publishes, responders simulating the backend) - convert 94 command/query integration tests into harness tests in command/ and query/ with unchanged calls, events, assertions and expected payloads - keep LockMediumTest, ChangeAuthorizationProfileTest and QueryCalendarTest as representative integration tests - rename RequestNewRegistrationCodeMapi test to RequestNewRegistrationCodeTest - assert the published payload for the "no result" medium identifier query - document the harness in CLAUDE.md Closes: #187 Co-Authored-By: Claude Opus 5 --- CLAUDE.md | 4 + .../AddEntityMetadataDefinitionTest.kt | 79 ++++ .../connect/command/AddEvvaComponentTest.kt | 70 ++++ ...tallationPointAuthorizationToMediumTest.kt | 62 +++ .../command/AddInstallationPointToZoneTest.kt | 56 +++ .../AddSmartphoneToInstallationTest.kt | 69 ++++ .../AddZoneAuthorizationToMediumTest.kt | 60 +++ .../AssignAuthorizationProfileToMediumTest.kt | 68 ++++ .../command/AssignPersonToMediumTest.kt | 53 +++ ...geAuthorizationProfileMetadataValueTest.kt | 67 ++++ .../command/ChangeAuthorizationProfileTest.kt | 92 +++++ .../ChangeAuthorizationTimeProfileTest.kt | 59 +++ .../connect/command/ChangeCalendarTest.kt | 53 +++ .../command/ChangeCodingStationTest.kt | 49 +++ ...hangeInstallationPointMetadataValueTest.kt | 64 ++++ .../command/ChangeInstallationPointTest.kt | 49 +++ .../command/ChangeMediumMetadataValueTest.kt | 66 ++++ .../ChangeOfficeModeTimeProfileTest.kt | 56 +++ .../command/ChangePersonInformationTest.kt | 53 +++ .../command/ChangePersonMetadataValueTest.kt | 120 ++++++ .../connect/command/ChangeZoneDataTest.kt | 51 +++ .../command/ChangeZoneMetadataValueTest.kt | 66 ++++ ...gureAssignableAuthorizationProfilesTest.kt | 51 +++ .../command/ConfigureBluetoothStateTest.kt | 51 +++ ...onfigureManualOfficeModeAndShopModeTest.kt | 51 +++ .../command/ConfigureMediaUpgradeTest.kt | 50 +++ .../ConfigureOfficeModeTimeProfileTest.kt | 50 +++ .../command/ConfigureReleaseDurationTest.kt | 52 +++ .../command/ConfirmSmartphoneRevokeTest.kt | 50 +++ .../command/ConfirmSmartphoneUpdateTest.kt | 50 +++ .../command/CreateAuthorizationProfileTest.kt | 55 +++ .../CreateAuthorizationTimeProfileTest.kt | 58 +++ .../connect/command/CreateCalendarTest.kt | 54 +++ .../command/CreateCodingStationTest.kt | 51 +++ .../command/CreateInstallationPointTest.kt | 67 ++++ .../CreateOfficeModeTimeProfileTest.kt | 58 +++ .../xesar/connect/command/CreatePersonTest.kt | 55 +++ .../xesar/connect/command/CreateZoneTest.kt | 57 +++ .../command/DeleteAuthorizationProfileTest.kt | 49 +++ .../DeleteAuthorizationTimeProfileTest.kt | 49 +++ .../connect/command/DeleteCalendarTest.kt | 45 +++ .../command/DeleteCodingStationTest.kt | 48 +++ .../DeleteEntityMetadataDefinitionTest.kt | 67 ++++ .../command/DeleteInstallationPointTest.kt | 51 +++ .../DeleteOfficeModeTimeProfileTest.kt | 49 +++ .../xesar/connect/command/DeletePersonTest.kt | 43 +++ .../xesar/connect/command/DeleteZoneTest.kt | 46 +++ .../connect/command/FindComponentTest.kt | 48 +++ .../command/ForceRemoveEvvaComponentTest.kt | 56 +++ .../xesar/connect/command/LockMediumTest.kt | 44 +++ .../PrepareRemovalOfEvvaComponentTest.kt | 51 +++ .../command/RemoteDisengagePermanentTest.kt | 51 +++ .../connect/command/RemoteDisengageTest.kt | 47 +++ ...llationPointAuthorizationFromMediumTest.kt | 57 +++ .../RemoveInstallationPointFromZoneTest.kt | 59 +++ .../RemoveZoneAuthorizationFromMediumTest.kt | 56 +++ .../RenameEntityMetadataDefinitionTest.kt | 70 ++++ .../RequestAddMediumToInstallationTest.kt | 71 ++++ .../command/RequestNewRegistrationCodeTest.kt | 48 +++ .../ResendSmartphoneAuthorizationsTest.kt | 50 +++ ...RevertPrepareRemovalOfEvvaComponentTest.kt | 54 +++ .../connect/command/RevokeSmartphoneTest.kt | 47 +++ .../connect/command/SetAccessBeginAtTest.kt | 50 +++ .../connect/command/SetAccessEndAtTest.kt | 50 +++ .../SetDailySchedulerExecutionTimeTest.kt | 46 +++ ...efaultAuthorizationProfileForPersonTest.kt | 45 +++ .../SetDefaultDisengagePeriodForPersonTest.kt | 52 +++ ...etDefaultSmartphoneValidityDurationTest.kt | 43 +++ .../command/SetDefaultValidityDurationTest.kt | 44 +++ .../command/SetDisengagePeriodOnMediumTest.kt | 52 +++ ...ationPointPersonalReferenceDurationTest.kt | 52 +++ .../connect/command/SetLabelOnMediumTest.kt | 51 +++ .../SetMessageLanguageOnSmartphoneTest.kt | 51 +++ .../command/SetMobileServiceModeTest.kt | 48 +++ .../SetPersonPersonalReferenceDurationTest.kt | 46 +++ ...ferenceDurationForInstallationPointTest.kt | 66 ++++ ...etPersonalReferenceDurationInPersonTest.kt | 52 +++ .../command/SetPhoneNumberOnSmartphoneTest.kt | 59 +++ .../SetReplacementMediumDurationTest.kt | 44 +++ .../command/SetValidityDurationTest.kt | 51 +++ .../command/SetValidityThresholdTest.kt | 44 +++ .../command/UnassignPersonFromMediumTest.kt | 48 +++ .../command/UnregisterSmartphoneTest.kt | 47 +++ ...hdrawAuthorizationProfileFromMediumTest.kt | 57 +++ .../AddEntityMetadataDefinitionTest.kt | 116 ------ .../it/command/AddEvvaComponentTest.kt | 114 ------ ...tallationPointAuthorizationToMediumTest.kt | 98 ----- .../command/AddInstallationPointToZoneTest.kt | 91 ----- .../AddSmartphoneToInstallationTest.kt | 105 ----- .../AddZoneAuthorizationToMediumTest.kt | 96 ----- .../AssignAuthorizationProfileToMediumTest.kt | 112 ------ .../it/command/AssignPersonToMediumTest.kt | 87 ----- ...geAuthorizationProfileMetadataValueTest.kt | 106 ------ .../ChangeAuthorizationTimeProfileTest.kt | 96 ----- .../connect/it/command/ChangeCalendarTest.kt | 87 ----- .../it/command/ChangeCodingStationTest.kt | 86 ----- ...hangeInstallationPointMetadataValueTest.kt | 105 ----- .../it/command/ChangeInstallationPointTest.kt | 87 ----- .../command/ChangeMediumMetadataValueTest.kt | 104 ----- .../ChangeOfficeModeTimeProfileTest.kt | 90 ----- .../it/command/ChangePersonInformationTest.kt | 87 ----- .../command/ChangePersonMetadataValueTest.kt | 187 --------- .../connect/it/command/ChangeZoneDataTest.kt | 85 ----- .../it/command/ChangeZoneMetadataValueTest.kt | 104 ----- ...gureAssignableAuthorizationProfilesTest.kt | 87 ----- .../it/command/ConfigureBluetoothStateTest.kt | 88 ----- ...onfigureManualOfficeModeAndShopModeTest.kt | 88 ----- .../it/command/ConfigureMediaUpgradeTest.kt | 87 ----- .../ConfigureOfficeModeTimeProfileTest.kt | 87 ----- .../command/ConfigureReleaseDurationTest.kt | 89 ----- .../it/command/ConfirmSmartphoneRevokeTest.kt | 92 ----- .../it/command/ConfirmSmartphoneUpdateTest.kt | 92 ----- .../command/CreateAuthorizationProfileTest.kt | 94 ----- .../CreateAuthorizationTimeProfileTest.kt | 94 ----- .../connect/it/command/CreateCalendarTest.kt | 88 ----- .../it/command/CreateCodingStationTest.kt | 88 ----- .../it/command/CreateInstallationPointTest.kt | 114 ------ .../CreateOfficeModeTimeProfileTest.kt | 94 ----- .../connect/it/command/CreatePersonTest.kt | 89 ----- .../connect/it/command/CreateZoneTest.kt | 91 ----- .../command/DeleteAuthorizationProfileTest.kt | 86 ----- .../DeleteAuthorizationTimeProfileTest.kt | 84 ---- .../connect/it/command/DeleteCalendarTest.kt | 81 ---- .../it/command/DeleteCodingStationTest.kt | 85 ----- .../DeleteEntityMetadataDefinitionTest.kt | 105 ----- .../it/command/DeleteInstallationPointTest.kt | 90 ----- .../DeleteOfficeModeTimeProfileTest.kt | 84 ---- .../connect/it/command/DeletePersonTest.kt | 77 ---- .../connect/it/command/DeleteZoneTest.kt | 80 ---- .../connect/it/command/FindComponentTest.kt | 85 ----- .../command/ForceRemoveEvvaComponentTest.kt | 94 ----- .../PrepareRemovalOfEvvaComponentTest.kt | 90 ----- .../command/RemoteDisengagePermanentTest.kt | 86 ----- .../connect/it/command/RemoteDisengageTest.kt | 84 ---- ...llationPointAuthorizationFromMediumTest.kt | 90 ----- .../RemoveInstallationPointFromZoneTest.kt | 96 ----- .../RemoveZoneAuthorizationFromMediumTest.kt | 91 ----- .../RenameEntityMetadataDefinitionTest.kt | 108 ------ .../RequestAddMediumToInstallationTest.kt | 119 ------ .../command/RequestNewRegistrationCodeMapi.kt | 85 ----- .../ResendSmartphoneAuthorizationsTest.kt | 86 ----- ...RevertPrepareRemovalOfEvvaComponentTest.kt | 89 ----- .../it/command/RevokeSmartphoneTest.kt | 85 ----- .../it/command/SetAccessBeginAtTest.kt | 85 ----- .../connect/it/command/SetAccessEndAtTest.kt | 85 ----- .../SetDailySchedulerExecutionTimeTest.kt | 81 ---- ...efaultAuthorizationProfileForPersonTest.kt | 79 ---- .../SetDefaultDisengagePeriodForPersonTest.kt | 86 ----- ...etDefaultSmartphoneValidityDurationTest.kt | 76 ---- .../command/SetDefaultValidityDurationTest.kt | 78 ---- .../command/SetDisengagePeriodOnMediumTest.kt | 86 ----- ...ationPointPersonalReferenceDurationTest.kt | 87 ----- .../it/command/SetLabelOnMediumTest.kt | 85 ----- .../SetMessageLanguageOnSmartphoneTest.kt | 85 ----- .../it/command/SetMobileServiceModeTest.kt | 85 ----- .../SetPersonPersonalReferenceDurationTest.kt | 80 ---- ...ferenceDurationForInstallationPointTest.kt | 100 ----- ...etPersonalReferenceDurationInPersonTest.kt | 86 ----- .../command/SetPhoneNumberOnSmartphoneTest.kt | 97 ----- .../SetReplacementMediumDurationTest.kt | 78 ---- .../it/command/SetValidityDurationTest.kt | 85 ----- .../it/command/SetValidityThresholdTest.kt | 78 ---- .../command/UnassignPersonFromMediumTest.kt | 86 ----- .../it/command/UnregisterSmartphoneTest.kt | 85 ----- ...hdrawAuthorizationProfileFromMediumTest.kt | 94 ----- .../it/query/QueryAccessProtocolEventTest.kt | 94 ----- .../it/query/QueryAuthorizationProfileTest.kt | 154 -------- .../it/query/QueryCodingStationTest.kt | 158 -------- .../it/query/QueryEvvaComponentTest.kt | 156 -------- ...QueryIdentificationMediumAccessDataTest.kt | 204 ---------- .../it/query/QueryIdentificationMediumTest.kt | 360 ------------------ .../it/query/QueryInstallationPointTest.kt | 156 -------- .../connect/it/query/QueryOfficeModeTest.kt | 153 -------- .../xesar/connect/it/query/QueryPersonTest.kt | 162 -------- .../connect/it/query/QueryTimeProfileTest.kt | 149 -------- .../xesar/connect/it/query/QueryUserTest.kt | 93 ----- .../xesar/connect/it/query/QueryZoneTest.kt | 143 ------- .../query/QueryAccessProtocolEventTest.kt | 60 +++ .../query/QueryAuthorizationProfileTest.kt | 95 +++++ .../xesar/connect/query/QueryCalendarTest.kt | 95 +++++ .../connect/query/QueryCodingStationTest.kt | 94 +++++ .../connect/query/QueryEvvaComponentTest.kt | 90 +++++ ...QueryIdentificationMediumAccessDataTest.kt | 142 +++++++ .../query/QueryIdentificationMediumTest.kt | 215 +++++++++++ .../query/QueryInstallationPointTest.kt | 93 +++++ .../connect/query/QueryOfficeModeTest.kt | 91 +++++ .../xesar/connect/query/QueryPersonTest.kt | 109 ++++++ .../connect/query/QueryTimeProfileTest.kt | 89 +++++ .../xesar/connect/query/QueryUserTest.kt | 60 +++ .../xesar/connect/query/QueryZoneTest.kt | 86 +++++ .../xesar/connect/util/MockedXesarConnect.kt | 113 ++++++ 191 files changed, 6012 insertions(+), 9414 deletions(-) create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddEntityMetadataDefinitionTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddEvvaComponentTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddInstallationPointAuthorizationToMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddInstallationPointToZoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddSmartphoneToInstallationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddZoneAuthorizationToMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AssignAuthorizationProfileToMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AssignPersonToMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationProfileMetadataValueTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationTimeProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeCalendarTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeCodingStationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeInstallationPointMetadataValueTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeInstallationPointTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeMediumMetadataValueTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeOfficeModeTimeProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangePersonInformationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangePersonMetadataValueTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeZoneDataTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeZoneMetadataValueTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureAssignableAuthorizationProfilesTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureBluetoothStateTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureManualOfficeModeAndShopModeTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureMediaUpgradeTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureOfficeModeTimeProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureReleaseDurationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfirmSmartphoneRevokeTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfirmSmartphoneUpdateTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateAuthorizationProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateAuthorizationTimeProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateCalendarTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateCodingStationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateInstallationPointTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateOfficeModeTimeProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreatePersonTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateZoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteAuthorizationProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteAuthorizationTimeProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteCalendarTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteCodingStationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteEntityMetadataDefinitionTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteInstallationPointTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteOfficeModeTimeProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeletePersonTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteZoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/FindComponentTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ForceRemoveEvvaComponentTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/LockMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/PrepareRemovalOfEvvaComponentTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoteDisengagePermanentTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoteDisengageTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveInstallationPointAuthorizationFromMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveInstallationPointFromZoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveZoneAuthorizationFromMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RenameEntityMetadataDefinitionTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RequestAddMediumToInstallationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RequestNewRegistrationCodeTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ResendSmartphoneAuthorizationsTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RevertPrepareRemovalOfEvvaComponentTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RevokeSmartphoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetAccessBeginAtTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetAccessEndAtTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDailySchedulerExecutionTimeTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultAuthorizationProfileForPersonTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultDisengagePeriodForPersonTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultSmartphoneValidityDurationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultValidityDurationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDisengagePeriodOnMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetInstallationPointPersonalReferenceDurationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetLabelOnMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetMessageLanguageOnSmartphoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetMobileServiceModeTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonPersonalReferenceDurationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonalReferenceDurationForInstallationPointTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonalReferenceDurationInPersonTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPhoneNumberOnSmartphoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetReplacementMediumDurationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetValidityDurationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetValidityThresholdTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/UnassignPersonFromMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/UnregisterSmartphoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/WithdrawAuthorizationProfileFromMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddEntityMetadataDefinitionTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddEvvaComponentTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddInstallationPointAuthorizationToMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddInstallationPointToZoneTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddSmartphoneToInstallationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddZoneAuthorizationToMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AssignAuthorizationProfileToMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AssignPersonToMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeAuthorizationProfileMetadataValueTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeAuthorizationTimeProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeCalendarTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeCodingStationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeInstallationPointMetadataValueTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeInstallationPointTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeMediumMetadataValueTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeOfficeModeTimeProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangePersonInformationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangePersonMetadataValueTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeZoneDataTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeZoneMetadataValueTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureAssignableAuthorizationProfilesTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureBluetoothStateTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureManualOfficeModeAndShopModeTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureMediaUpgradeTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureOfficeModeTimeProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureReleaseDurationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfirmSmartphoneRevokeTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfirmSmartphoneUpdateTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateAuthorizationProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateAuthorizationTimeProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateCalendarTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateCodingStationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateInstallationPointTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateOfficeModeTimeProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreatePersonTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateZoneTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteAuthorizationProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteAuthorizationTimeProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteCalendarTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteCodingStationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteEntityMetadataDefinitionTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteInstallationPointTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteOfficeModeTimeProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeletePersonTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteZoneTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/FindComponentTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ForceRemoveEvvaComponentTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/PrepareRemovalOfEvvaComponentTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoteDisengagePermanentTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoteDisengageTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveInstallationPointAuthorizationFromMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveInstallationPointFromZoneTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveZoneAuthorizationFromMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RenameEntityMetadataDefinitionTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RequestAddMediumToInstallationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RequestNewRegistrationCodeMapi.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ResendSmartphoneAuthorizationsTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RevertPrepareRemovalOfEvvaComponentTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RevokeSmartphoneTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetAccessBeginAtTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetAccessEndAtTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDailySchedulerExecutionTimeTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultAuthorizationProfileForPersonTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultDisengagePeriodForPersonTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultSmartphoneValidityDurationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultValidityDurationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDisengagePeriodOnMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetInstallationPointPersonalReferenceDurationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetLabelOnMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetMessageLanguageOnSmartphoneTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetMobileServiceModeTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonPersonalReferenceDurationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonalReferenceDurationForInstallationPointTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonalReferenceDurationInPersonTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPhoneNumberOnSmartphoneTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetReplacementMediumDurationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetValidityDurationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetValidityThresholdTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/UnassignPersonFromMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/UnregisterSmartphoneTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/WithdrawAuthorizationProfileFromMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryAccessProtocolEventTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryAuthorizationProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryCodingStationTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryEvvaComponentTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryIdentificationMediumAccessDataTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryIdentificationMediumTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryInstallationPointTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryOfficeModeTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryPersonTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryTimeProfileTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryUserTest.kt delete mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryZoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryAccessProtocolEventTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryAuthorizationProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryCalendarTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryCodingStationTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryEvvaComponentTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryIdentificationMediumAccessDataTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryIdentificationMediumTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryInstallationPointTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryOfficeModeTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryPersonTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryTimeProfileTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryUserTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryZoneTest.kt create mode 100644 xesar-connect/src/test/kotlin/com/open200/xesar/connect/util/MockedXesarConnect.kt diff --git a/CLAUDE.md b/CLAUDE.md index e0569be8..ad92ef43 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -164,6 +164,10 @@ Add at least one: - Unit test for payload parsing/serialization - Test for command tracking and response correlation (if applicable) +Tests for extension functions (commands/queries) use `util/MockedXesarConnect` (no MQTT broker) +and live in `command/` and `query/`. Only a few representative integration tests with +testcontainers remain in `it/` — don't add new ones for plain commands/queries. + --- ## Code Style & Formatting diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddEntityMetadataDefinitionTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddEntityMetadataDefinitionTest.kt new file mode 100644 index 00000000..98da4a9e --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddEntityMetadataDefinitionTest.kt @@ -0,0 +1,79 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.addEntityMetadataDefinitionAsync +import com.open200.xesar.connect.messages.EntityMetadata +import com.open200.xesar.connect.messages.EntityType +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class AddEntityMetadataDefinitionTest : + FunSpec({ + test("add entity metadata definition") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.ADD_ENTITY_METADATA_DEFINITION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + entityMetadataDefinitions = + PartitionChanged.EntityMetadataDefinitions( + authorizationProfiles = emptyList(), + identificationMedia = emptyList(), + installationPoints = emptyList(), + persons = + listOf( + EntityMetadata( + id = + UUID.fromString( + "aaaaaaaa-0000-0000-0000-000000000001" + ), + name = "nickname", + ), + EntityMetadata( + id = + UUID.fromString( + "bbbbbbbb-0000-0000-0000-000000000002" + ), + name = "department", + ), + ), + zones = emptyList(), + ), + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.addEntityMetadataDefinitionAsync( + EntityType.PERSON, + "nickname", + "department", + ) + .await() + + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.entityMetadataDefinitions!! + .persons + .map { it.name } + .shouldBeEqual(listOf("nickname", "department")) + + harness + .publishedPayload(Topics.Command.ADD_ENTITY_METADATA_DEFINITION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"entityType\":\"PERSON\",\"names\":[\"nickname\",\"department\"],\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddEvvaComponentTest.kt new file mode 100644 index 00000000..9b37f0e7 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddEvvaComponentTest.kt @@ -0,0 +1,70 @@ +package com.open200.xesar.connect.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.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class AddEvvaComponentTest : + FunSpec({ + test("add evva component returning both events") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.ADD_EVVA_COMPONENT) { + 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, + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) + + emitMessage(Topics.Event.EVVA_COMPONENT_ADDED, encodeEvent(apiEvent2)) + } + + val api = harness.api + 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) + + harness + .publishedPayload(Topics.Command.ADD_EVVA_COMPONENT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"type\":\"Cylinder\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddInstallationPointAuthorizationToMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddInstallationPointAuthorizationToMediumTest.kt new file mode 100644 index 00000000..62e3ffdb --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddInstallationPointAuthorizationToMediumTest.kt @@ -0,0 +1,62 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.addInstallationPointAuthorizationToMediumAsync +import com.open200.xesar.connect.messages.command.AuthorizationData +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.IndividualAuthorizationsAddedToMedium +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class AddInstallationPointAuthorizationToMediumTest : + FunSpec({ + test("add installation point authorization to medium") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.ADD_INSTALLATION_POINT_AUTHORIZATION_TO_MEDIUM) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + IndividualAuthorizationsAddedToMedium( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + emitMessage( + Topics.Event.INDIVIDUAL_AUTHORIZATIONS_ADDED_TO_MEDIUM, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val authorizationData = + AuthorizationData( + "authorizationName", + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), + "timeProfileName", + UUID.fromString("8c124504-8263-4201-8b17-f49a6c2f8671"), + true, + UUID.fromString("e9b31e62-8969-4794-a219-8c81ff10c91d"), + ) + val result = + api.addInstallationPointAuthorizationToMediumAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + authorizationData, + ) + result + .await() + .id + .shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.ADD_INSTALLATION_POINT_AUTHORIZATION_TO_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"authorization\":{\"authorizationName\":\"authorizationName\",\"authorizationProfileId\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"timeProfileName\":\"timeProfileName\",\"authorizationId\":\"8c124504-8263-4201-8b17-f49a6c2f8671\",\"installationPoint\":true,\"timeProfileId\":\"e9b31e62-8969-4794-a219-8c81ff10c91d\"},\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddInstallationPointToZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddInstallationPointToZoneTest.kt new file mode 100644 index 00000000..834e6c75 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddInstallationPointToZoneTest.kt @@ -0,0 +1,56 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.addInstallationPointToZoneAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointsInZoneChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class AddInstallationPointToZoneTest : + FunSpec({ + test("add installation point to zone") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.ADD_INSTALLATION_POINT_TO_ZONE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointsInZoneChanged( + 123, + listOf(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")), + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), + ), + ) + + emitMessage( + Topics.Event.INSTALLATION_POINTS_IN_ZONE_CHANGED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.addInstallationPointToZoneAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), + ) + .await() + result.addedInstallationPoints.size.shouldBeEqual(1) + result.aggregateId.shouldBeEqual( + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be") + ) + result.accessId.shouldBeEqual(123) + + harness + .publishedPayload(Topics.Command.ADD_INSTALLATION_POINT_TO_ZONE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"id\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddSmartphoneToInstallationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddSmartphoneToInstallationTest.kt new file mode 100644 index 00000000..b8480d6e --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddSmartphoneToInstallationTest.kt @@ -0,0 +1,69 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.addSmartphoneToInstallationAsync +import com.open200.xesar.connect.messages.DisengagePeriod +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.SmartphoneAddedToInstallation +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class AddSmartphoneToInstallationTest : + FunSpec({ + test("add smartphone to installation") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.ADD_SMARTPHONE_TO_INSTALLATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + SmartphoneAddedToInstallation( + accessBeginAt = LocalDateTime.parse("2024-08-08T12:25"), + partitionId = + UUID.fromString("5679d684-41c6-484c-8292-204feb085ef0"), + disengagePeriod = DisengagePeriod.SHORT, + mediumIdentifier = 8, + authorizationProfileId = + UUID.fromString("00000000-0000-0000-0000-000000000001"), + individualAuthorizations = emptyList(), + sagaId = UUID.fromString("a14d08c0-6f7a-4fc6-8469-be15a3e7b575"), + messageLanguage = "en", + label = "new f228c89d-c2e1-450d-8b79-89072b7b24c3", + validityBeginAt = LocalDateTime.parse("2024-08-08T12:20"), + accessEndAt = null, + validityEndAt = LocalDateTime.parse("2024-12-09T14:20"), + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + issuedAt = LocalDateTime.parse("2024-08-08T12:29:55.708239786"), + ), + ) + + emitMessage( + Topics.Event.SMARTPHONE_ADDED_TO_INSTALLATION, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.addSmartphoneToInstallationAsync( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + + result.aggregateId.shouldBe(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.ADD_SMARTPHONE_TO_INSTALLATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"accessBeginAt\":null,\"partitionId\":null,\"disengagePeriod\":null,\"authorizationProfileId\":null,\"individualAuthorizations\":[],\"messageLanguage\":null,\"label\":null,\"accessEndAt\":null,\"phoneNumber\":null,\"validityDuration\":null,\"personId\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddZoneAuthorizationToMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddZoneAuthorizationToMediumTest.kt new file mode 100644 index 00000000..ed696562 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AddZoneAuthorizationToMediumTest.kt @@ -0,0 +1,60 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.addZoneAuthorizationToMediumAsync +import com.open200.xesar.connect.messages.command.AuthorizationData +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.IndividualAuthorizationsAddedToMedium +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class AddZoneAuthorizationToMediumTest : + FunSpec({ + test("add installation point authorization to medium") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.ADD_ZONE_AUTHORIZATION_TO_MEDIUM) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + IndividualAuthorizationsAddedToMedium( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + emitMessage( + Topics.Event.INDIVIDUAL_AUTHORIZATIONS_ADDED_TO_MEDIUM, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val authorizationData = + AuthorizationData( + "authorizationName", + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), + "timeProfileName", + UUID.fromString("8c124504-8263-4201-8b17-f49a6c2f8671"), + false, + UUID.fromString("e9b31e62-8969-4794-a219-8c81ff10c91d"), + ) + val result = + api.addZoneAuthorizationToMediumAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + authorizationData, + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.ADD_ZONE_AUTHORIZATION_TO_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"authorization\":{\"authorizationName\":\"authorizationName\",\"authorizationProfileId\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"timeProfileName\":\"timeProfileName\",\"authorizationId\":\"8c124504-8263-4201-8b17-f49a6c2f8671\",\"installationPoint\":false,\"timeProfileId\":\"e9b31e62-8969-4794-a219-8c81ff10c91d\"},\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AssignAuthorizationProfileToMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AssignAuthorizationProfileToMediumTest.kt new file mode 100644 index 00000000..69234e33 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AssignAuthorizationProfileToMediumTest.kt @@ -0,0 +1,68 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.assignAuthorizationProfileToMediumAsync +import com.open200.xesar.connect.messages.event.* +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class AssignAuthorizationProfileToMediumTest : + FunSpec({ + test("assign authorization profile to medium returning both events") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.ASSIGN_AUTHORIZATION_PROFILE_TO_MEDIUM) { + 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"), + ), + ) + + emitMessage(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) + + emitMessage( + Topics.Event.MEDIUM_AUTHORIZATION_PROFILE_CHANGED, + encodeEvent(apiEvent2), + ) + } + + val api = harness.api + 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") + ) + + harness + .publishedPayload(Topics.Command.ASSIGN_AUTHORIZATION_PROFILE_TO_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"authorizationProfileId\":null,\"id\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AssignPersonToMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AssignPersonToMediumTest.kt new file mode 100644 index 00000000..faa01242 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/AssignPersonToMediumTest.kt @@ -0,0 +1,53 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.assignPersonToMediumAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.MediumPersonChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class AssignPersonToMediumTest : + FunSpec({ + test("assign person to medium") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.ASSIGN_PERSON_TO_MEDIUM) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + MediumPersonChanged( + oldPersonId = + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.MEDIUM_PERSON_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.assignPersonToMediumAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), + ) + .await() + + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.oldPersonId!!.shouldBeEqual( + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be") + ) + + harness + .publishedPayload(Topics.Command.ASSIGN_PERSON_TO_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"personId\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationProfileMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationProfileMetadataValueTest.kt new file mode 100644 index 00000000..db999a09 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationProfileMetadataValueTest.kt @@ -0,0 +1,67 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeAuthorizationProfileMetadataValueAsync +import com.open200.xesar.connect.messages.EntityMetadata +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.AuthorizationProfileInfoChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeAuthorizationProfileMetadataValueTest : + FunSpec({ + test("change authorization profile metadata value") { + val authorizationProfileId = UUID.fromString("11111111-2222-3333-4444-555555555555") + val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_AUTHORIZATION_PROFILE_METADATA_VALUE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationProfileInfoChanged( + id = authorizationProfileId, + entityMetadata = + listOf( + EntityMetadata( + id = metadataId, + name = "test", + value = "Test Value", + ) + ), + ), + ) + + emitMessage( + Topics.Event.AUTHORIZATION_PROFILE_INFO_CHANGED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.changeAuthorizationProfileMetadataValueAsync( + id = authorizationProfileId, + metadataId = metadataId, + value = "Test Value", + ) + .await() + + result.id?.shouldBeEqual(authorizationProfileId) + result.entityMetadata!! + .single { it.id == metadataId } + .value + ?.shouldBeEqual("Test Value") + + harness + .publishedPayload(Topics.Command.CHANGE_AUTHORIZATION_PROFILE_METADATA_VALUE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"11111111-2222-3333-4444-555555555555\",\"metadataId\":\"aaaaaaaa-0000-0000-0000-000000000001\",\"value\":\"Test Value\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationProfileTest.kt new file mode 100644 index 00000000..e3214953 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationProfileTest.kt @@ -0,0 +1,92 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeAuthorizationProfileAsync +import com.open200.xesar.connect.messages.event.* +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeAuthorizationProfileTest : + FunSpec({ + test("change authorization profile returning all events") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_AUTHORIZATION_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationProfileChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + val apiEvent2 = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationProfileAccessChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + val apiEvent3 = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationProfileInfoChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + emitMessage(Topics.Event.AUTHORIZATION_PROFILE_CHANGED, encodeEvent(apiEvent)) + + emitMessage( + Topics.Event.AUTHORIZATION_PROFILE_ACCESS_CHANGED, + encodeEvent(apiEvent2), + ) + + emitMessage( + Topics.Event.AUTHORIZATION_PROFILE_INFO_CHANGED, + encodeEvent(apiEvent3), + ) + } + + val api = harness.api + val changeAuthorizationProfileResult = + api.changeAuthorizationProfileAsync( + emptyList(), + true, + "new name", + "new description", + null, + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), + emptyList(), + ) + val authorizationProfileInfoChanged = + changeAuthorizationProfileResult.authorizationProfileInfoChangedDeferred.await() + + authorizationProfileInfoChanged.id.shouldBe( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + val authorizationProfileChanged = + changeAuthorizationProfileResult.authorizationProfileChangedDeferred.await() + authorizationProfileChanged.id.shouldBe( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + + val authorizationProfileAccessChanged = + changeAuthorizationProfileResult.authorizationProfileAccessChangedDeferred + .await() + authorizationProfileAccessChanged.id.shouldBe( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + + harness + .publishedPayload(Topics.Command.CHANGE_AUTHORIZATION_PROFILE) + .shouldBeEqual( + "{\"installationPoints\":[],\"manualOfficeMode\":true,\"name\":\"new name\",\"description\":\"new description\",\"standardTimeProfile\":null,\"id\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"zones\":[],\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationTimeProfileTest.kt new file mode 100644 index 00000000..c6d99ca5 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeAuthorizationTimeProfileTest.kt @@ -0,0 +1,59 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeAuthorizationTimeProfileAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.AuthorizationTimeProfileChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.TimeProfileFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeAuthorizationTimeProfileTest : + FunSpec({ + test("change authorization time profile") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_AUTHORIZATION_TIME_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationTimeProfileChanged( + timeSeries = TimeProfileFixture.timeSeries, + exceptionTimeSeries = TimeProfileFixture.exceptionTimeSerie, + name = "timeProfileName", + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + validStandardTimeProfile = true, + ), + ) + + emitMessage( + Topics.Event.AUTHORIZATION_TIME_PROFILE_CHANGED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.changeAuthorizationTimeProfileAsync( + timeProfileId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + timeProfileName = "timeProfileName", + timeSeries = TimeProfileFixture.timeSeries, + exceptionTimeSeries = TimeProfileFixture.exceptionTimeSerie, + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.exceptionTimeSeries.shouldBeEqual(TimeProfileFixture.exceptionTimeSerie) + result.name.shouldBeEqual("timeProfileName") + + harness + .publishedPayload(Topics.Command.CHANGE_AUTHORIZATION_TIME_PROFILE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"name\":\"timeProfileName\",\"description\":null,\"timeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"days\":[\"MONDAY\"]}],\"exceptionTimeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"calendars\":[\"497f6eca-6276-4993-bfeb-53cbbbba6f08\"]}],\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeCalendarTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeCalendarTest.kt new file mode 100644 index 00000000..ae075d90 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeCalendarTest.kt @@ -0,0 +1,53 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeCalendarAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.CalendarChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDate +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeCalendarTest : + FunSpec({ + test("change calendar") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_CALENDAR) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + CalendarChanged( + "calendarName", + 123, + listOf(LocalDate.parse("2018-02-25")), + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.CALENDAR_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changeCalendarAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + "calendarName", + specialDays = listOf(LocalDate.parse("2018-02-25")), + ) + .await() + result.name.shouldBeEqual("calendarName") + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.CHANGE_CALENDAR) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"calendarName\",\"specialDays\":[\"2018-02-25\"],\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeCodingStationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeCodingStationTest.kt new file mode 100644 index 00000000..1fd64bdc --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeCodingStationTest.kt @@ -0,0 +1,49 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeCodingStationAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.CodingStationChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeCodingStationTest : + FunSpec({ + test("change coding station") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_CODING_STATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + CodingStationChanged( + name = "codingStationName", + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.CODING_STATION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changeCodingStationAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + "codingStationName", + ) + .await() + result.name?.shouldBeEqual("codingStationName") + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.CHANGE_CODING_STATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"name\":\"codingStationName\",\"description\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeInstallationPointMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeInstallationPointMetadataValueTest.kt new file mode 100644 index 00000000..67918860 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeInstallationPointMetadataValueTest.kt @@ -0,0 +1,64 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeInstallationPointMetadataValueAsync +import com.open200.xesar.connect.messages.EntityMetadata +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeInstallationPointMetadataValueTest : + FunSpec({ + test("change installation point metadata value") { + val installationPointId = UUID.fromString("11111111-2222-3333-4444-555555555555") + val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_INSTALLATION_POINT_METADATA_VALUE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointChanged( + aggregateId = installationPointId, + entityMetadata = + listOf( + EntityMetadata( + id = metadataId, + name = "test", + value = "Test Value", + ) + ), + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changeInstallationPointMetadataValueAsync( + id = installationPointId, + metadataId = metadataId, + value = "Test Value", + ) + .await() + + result.aggregateId.shouldBeEqual(installationPointId) + result.entityMetadata!! + .single { it.id == metadataId } + .value + ?.shouldBeEqual("Test Value") + + harness + .publishedPayload(Topics.Command.CHANGE_INSTALLATION_POINT_METADATA_VALUE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"11111111-2222-3333-4444-555555555555\",\"metadataId\":\"aaaaaaaa-0000-0000-0000-000000000001\",\"value\":\"Test Value\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeInstallationPointTest.kt new file mode 100644 index 00000000..c7ec617d --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeInstallationPointTest.kt @@ -0,0 +1,49 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeInstallationPointAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeInstallationPointTest : + FunSpec({ + test("change installation point") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_INSTALLATION_POINT) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointChanged( + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + installationType = "installation type", + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changeInstallationPointAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + "installation type", + ) + .await() + result.installationType?.shouldBeEqual("installation type") + + harness + .publishedPayload(Topics.Command.CHANGE_INSTALLATION_POINT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"aggregateId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"installationType\":\"installation type\",\"name\":null,\"description\":null,\"installationId\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeMediumMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeMediumMetadataValueTest.kt new file mode 100644 index 00000000..909ece5a --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeMediumMetadataValueTest.kt @@ -0,0 +1,66 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeMediumMetadataValueAsync +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 com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.UUID +import kotlinx.coroutines.test.runTest + +class ChangeMediumMetadataValueTest : + FunSpec({ + test("change medium metadata value") { + val mediumId = UUID.fromString("11111111-2222-3333-4444-555555555555") + val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_MEDIUM_METADATA_VALUE) { + 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", + ) + ), + ), + ) + + emitMessage(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changeMediumMetadataValueAsync( + id = mediumId, + metadataId = metadataId, + value = "Vogons", + ) + .await() + + result.id.shouldBeEqual(mediumId) + result.entityMetadata!! + .single { it.id == metadataId } + .value + ?.shouldBeEqual("Vogons") + + harness + .publishedPayload(Topics.Command.CHANGE_MEDIUM_METADATA_VALUE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"11111111-2222-3333-4444-555555555555\",\"metadataId\":\"aaaaaaaa-0000-0000-0000-000000000001\",\"value\":\"Vogons\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeOfficeModeTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeOfficeModeTimeProfileTest.kt new file mode 100644 index 00000000..18d5873b --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeOfficeModeTimeProfileTest.kt @@ -0,0 +1,56 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeOfficeModeTimeProfileAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.OfficeModeTimeProfileChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.TimeProfileFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeOfficeModeTimeProfileTest : + FunSpec({ + test("change office mode time profile") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_OFFICE_MODE_TIME_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + OfficeModeTimeProfileChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + name = "name", + timeSeries = TimeProfileFixture.timeSeries, + ), + ) + + emitMessage( + Topics.Event.OFFICE_MODE_TIME_PROFILE_CHANGED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.changeOfficeModeTimeProfileAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + "name", + timeSeries = TimeProfileFixture.timeSeries, + ) + .await() + result.id.shouldBe(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.timeSeries.shouldBe(TimeProfileFixture.timeSeries) + + harness + .publishedPayload(Topics.Command.CHANGE_OFFICE_MODE_TIME_PROFILE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"name\":\"name\",\"description\":null,\"timeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"days\":[\"MONDAY\"]}],\"exceptionTimeSeries\":[],\"exceptionTimePointSeries\":[],\"timePointSeries\":[],\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangePersonInformationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangePersonInformationTest.kt new file mode 100644 index 00000000..185569c5 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangePersonInformationTest.kt @@ -0,0 +1,53 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changePersonInformationAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PersonChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangePersonInformationTest : + FunSpec({ + test("change person information") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_PERSON_INFORMATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PersonChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + firstName = "first name", + lastName = "last name", + identifier = "", + ), + ) + + emitMessage(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changePersonInformationAsync( + firstName = "first name", + lastName = "last name", + identifier = "", + externalId = "EXT-4711", + ) + .await() + result.firstName.shouldBeEqual("first name") + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.CHANGE_PERSON_INFORMATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"firstName\":\"first name\",\"lastName\":\"last name\",\"identifier\":\"\",\"externalId\":\"EXT-4711\",\"id\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangePersonMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangePersonMetadataValueTest.kt new file mode 100644 index 00000000..fe7aeb6d --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangePersonMetadataValueTest.kt @@ -0,0 +1,120 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changePersonMetadataValueAsync +import com.open200.xesar.connect.messages.EntityMetadata +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PersonChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.UUID +import kotlinx.coroutines.test.runTest + +class ChangePersonMetadataValueTest : + FunSpec({ + test("change person metadata value via externalId") { + val externalId = "P-12345" + val personId = UUID.fromString("11111111-2222-3333-4444-555555555555") + val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_PERSON_METADATA_VALUE) { + // Order-sensitive raw JSON + + // Simulate success PERSON_CHANGED with updated entity metadata + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PersonChanged( + firstName = "Tester", + lastName = "Testington", + id = personId, + entityMetadata = + listOf( + EntityMetadata( + id = metadataId, + name = "department", + value = "Sales", + ) + ), + ), + ) + + emitMessage(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changePersonMetadataValueAsync( + externalId = externalId, + id = null, + metadataId = metadataId, + value = "Sales", + ) + .await() + + result.id.shouldBeEqual(personId) + result.entityMetadata!!.single { it.id == metadataId }.value?.shouldBeEqual("Sales") + + harness + .publishedPayload(Topics.Command.CHANGE_PERSON_METADATA_VALUE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"externalId\":\"P-12345\",\"id\":null,\"metadataId\":\"aaaaaaaa-0000-0000-0000-000000000001\",\"value\":\"Sales\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + + test("change person metadata value via id") { + val personId = UUID.fromString("11111111-2222-3333-4444-555555555555") + val metadataId = UUID.fromString("bbbbbbbb-0000-0000-0000-000000000002") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_PERSON_METADATA_VALUE) { + // Order-sensitive raw JSON + + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PersonChanged( + firstName = "Tester", + lastName = "Testington", + id = personId, + entityMetadata = + listOf( + EntityMetadata( + id = metadataId, + name = "team", + value = "Team Blue", + ) + ), + ), + ) + + emitMessage(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changePersonMetadataValueAsync( + id = personId, + metadataId = metadataId, + value = "Team Blue", + ) + .await() + + result.id.shouldBeEqual(personId) + result.entityMetadata!! + .single { it.id == metadataId } + .value + ?.shouldBeEqual("Team Blue") + + harness + .publishedPayload(Topics.Command.CHANGE_PERSON_METADATA_VALUE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"externalId\":null,\"id\":\"$personId\",\"metadataId\":\"$metadataId\",\"value\":\"Team Blue\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeZoneDataTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeZoneDataTest.kt new file mode 100644 index 00000000..2c7bc90b --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeZoneDataTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeZoneDataAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.ZoneChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeZoneDataTest : + FunSpec({ + test("change zone data") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_ZONE_DATA) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + ZoneChanged( + "zoneName", + "zoneDescription", + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.ZONE_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changeZoneDataAsync( + "zoneName", + "zoneDescription", + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.description.shouldBeEqual("zoneDescription") + + harness + .publishedPayload(Topics.Command.CHANGE_ZONE_DATA) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"zoneName\",\"description\":\"zoneDescription\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeZoneMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeZoneMetadataValueTest.kt new file mode 100644 index 00000000..41a07cf4 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ChangeZoneMetadataValueTest.kt @@ -0,0 +1,66 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.changeZoneMetadataValueAsync +import com.open200.xesar.connect.messages.EntityMetadata +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.ZoneChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ChangeZoneMetadataValueTest : + FunSpec({ + test("change zone metadata value") { + val zoneId = UUID.fromString("11111111-2222-3333-4444-555555555555") + val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CHANGE_ZONE_METADATA_VALUE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + ZoneChanged( + name = "Test Zone", + description = "Test Description", + id = zoneId, + entityMetadata = + listOf( + EntityMetadata( + id = metadataId, + name = "security clearance required", + value = "Top Secret", + ) + ), + ), + ) + + emitMessage(Topics.Event.ZONE_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.changeZoneMetadataValueAsync( + id = zoneId, + metadataId = metadataId, + value = "Top Secret", + ) + .await() + + result.id.shouldBeEqual(zoneId) + result.entityMetadata!! + .single { it.id == metadataId } + .value + ?.shouldBeEqual("Top Secret") + + harness + .publishedPayload(Topics.Command.CHANGE_ZONE_METADATA_VALUE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"11111111-2222-3333-4444-555555555555\",\"metadataId\":\"aaaaaaaa-0000-0000-0000-000000000001\",\"value\":\"Top Secret\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureAssignableAuthorizationProfilesTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureAssignableAuthorizationProfilesTest.kt new file mode 100644 index 00000000..23257e70 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureAssignableAuthorizationProfilesTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.configureAssignableAuthorizationProfilesAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.UserGroupChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ConfigureAssignableAuthorizationProfilesTest : + FunSpec({ + test("configure assignable authorization profiles") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CONFIGURE_ASSIGNABLE_AUTHORIZATION_PROFILES) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + UserGroupChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + name = "name", + description = "description", + assignableAuthorizationProfiles = + listOf(UUID.fromString("4e6f78d6-51c7-4bc2-a992-78971eecfbda")), + ), + ) + + emitMessage(Topics.Event.USER_GROUP_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.configureAssignableAuthorizationProfilesAsync( + listOf(UUID.fromString("4e6f78d6-51c7-4bc2-a992-78971eecfbda")), + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.CONFIGURE_ASSIGNABLE_AUTHORIZATION_PROFILES) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"assignableAuthorizationProfiles\":[\"4e6f78d6-51c7-4bc2-a992-78971eecfbda\"],\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureBluetoothStateTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureBluetoothStateTest.kt new file mode 100644 index 00000000..f64dfe57 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureBluetoothStateTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.configureBluetoothStateAsync +import com.open200.xesar.connect.messages.BluetoothState +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.util.* +import kotlinx.coroutines.test.runTest + +class ConfigureBluetoothStateTest : + FunSpec({ + test("configure bluetooth state of an installation point") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CONFIGURE_BLUETOOTH_STATE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointChanged( + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + bluetoothState = BluetoothState.ENABLED, + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.configureBluetoothStateAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + BluetoothState.ENABLED, + ) + .await() + result.bluetoothState.shouldBe(BluetoothState.ENABLED) + + harness + .publishedPayload(Topics.Command.CONFIGURE_BLUETOOTH_STATE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"bluetoothState\":\"ENABLED\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureManualOfficeModeAndShopModeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureManualOfficeModeAndShopModeTest.kt new file mode 100644 index 00000000..d005645f --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureManualOfficeModeAndShopModeTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.configureManualOfficeModeAndShopModeMapiAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.booleans.shouldBeTrue +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ConfigureManualOfficeModeAndShopModeTest : + FunSpec({ + test("configure assignable authorization profiles") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CONFIGURE_MANUAL_OFFICE_MODE_AND_SHOP_MODE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointChanged( + shopMode = true, + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.configureManualOfficeModeAndShopModeMapiAsync( + shopMode = true, + installationPointId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.shopMode?.shouldBeTrue() + + harness + .publishedPayload(Topics.Command.CONFIGURE_MANUAL_OFFICE_MODE_AND_SHOP_MODE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"shopMode\":true,\"manualOfficeMode\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureMediaUpgradeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureMediaUpgradeTest.kt new file mode 100644 index 00000000..7f49419b --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureMediaUpgradeTest.kt @@ -0,0 +1,50 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.configureMediaUpgradeMapiAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.booleans.shouldBeTrue +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ConfigureMediaUpgradeTest : + FunSpec({ + test("configure media upgrade") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CONFIGURE_MEDIA_UPGRADE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointChanged( + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + upgradeMedia = true, + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.configureMediaUpgradeMapiAsync( + true, + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.upgradeMedia?.shouldBeTrue() + + harness + .publishedPayload(Topics.Command.CONFIGURE_MEDIA_UPGRADE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"upgradeMedia\":true,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureOfficeModeTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureOfficeModeTimeProfileTest.kt new file mode 100644 index 00000000..3a03f208 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureOfficeModeTimeProfileTest.kt @@ -0,0 +1,50 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.configureOfficeModeTimeProfileAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.nulls.shouldBeNull +import java.util.* +import kotlinx.coroutines.test.runTest + +class ConfigureOfficeModeTimeProfileTest : + FunSpec({ + test("configure media upgrade") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CONFIGURE_OFFICE_MODE_TIME_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointChanged( + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + timeProfileId = null, + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.configureOfficeModeTimeProfileAsync( + null, + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.timeProfileId.shouldBeNull() + + harness + .publishedPayload(Topics.Command.CONFIGURE_OFFICE_MODE_TIME_PROFILE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"timeProfileId\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureReleaseDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureReleaseDurationTest.kt new file mode 100644 index 00000000..953627b0 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfigureReleaseDurationTest.kt @@ -0,0 +1,52 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.configureReleaseDurationAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ConfigureReleaseDurationTest : + FunSpec({ + test("configure release duration") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CONFIGURE_RELEASE_DURATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointChanged( + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + releaseDurationShort = 10, + releaseDurationLong = 20, + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.configureReleaseDurationAsync( + 10, + 20, + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.releaseDurationShort?.shouldBeEqual(10) + result.releaseDurationLong?.shouldBeEqual(20) + + harness + .publishedPayload(Topics.Command.CONFIGURE_RELEASE_DURATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"releaseDurationShort\":10,\"releaseDurationLong\":20,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfirmSmartphoneRevokeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfirmSmartphoneRevokeTest.kt new file mode 100644 index 00000000..4bf71ca7 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfirmSmartphoneRevokeTest.kt @@ -0,0 +1,50 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.confirmSmartphoneRevokeAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.SmartphoneRevokeConfirmed +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.UUID +import kotlinx.coroutines.test.runTest + +class ConfirmSmartphoneRevokeTest : + FunSpec({ + test("confirm smartphone revoke in Self Service Mode") { + val smartphoneId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + val transactionId = UUID.fromString("1e4a12b3-3c5f-4a6e-9b7d-8f0e1d2c3b4a") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CONFIRM_SMARTPHONE_REVOKE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + SmartphoneRevokeConfirmed( + mediumId = smartphoneId, + transactionId = transactionId, + ), + ) + + emitMessage(Topics.Event.SMARTPHONE_REVOKE_CONFIRMED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.confirmSmartphoneRevokeAsync(smartphoneId, transactionId).await() + + result.mediumId.shouldBeEqual(smartphoneId) + result.transactionId.shouldBeEqual(transactionId) + + harness + .publishedPayload(Topics.Command.CONFIRM_SMARTPHONE_REVOKE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\"," + + "\"mediumId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\"," + + "\"transactionId\":\"1e4a12b3-3c5f-4a6e-9b7d-8f0e1d2c3b4a\"," + + "\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfirmSmartphoneUpdateTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfirmSmartphoneUpdateTest.kt new file mode 100644 index 00000000..0003df27 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ConfirmSmartphoneUpdateTest.kt @@ -0,0 +1,50 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.confirmSmartphoneUpdateAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.SmartphoneUpdateConfirmed +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.UUID +import kotlinx.coroutines.test.runTest + +class ConfirmSmartphoneUpdateTest : + FunSpec({ + test("confirm smartphone update in Self Service Mode") { + val smartphoneId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + val transactionId = UUID.fromString("1e4a12b3-3c5f-4a6e-9b7d-8f0e1d2c3b4a") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CONFIRM_SMARTPHONE_UPDATE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + SmartphoneUpdateConfirmed( + mediumId = smartphoneId, + transactionId = transactionId, + ), + ) + + emitMessage(Topics.Event.SMARTPHONE_UPDATE_CONFIRMED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.confirmSmartphoneUpdateAsync(smartphoneId, transactionId).await() + + result.mediumId.shouldBeEqual(smartphoneId) + result.transactionId.shouldBeEqual(transactionId) + + harness + .publishedPayload(Topics.Command.CONFIRM_SMARTPHONE_UPDATE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\"," + + "\"mediumId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\"," + + "\"transactionId\":\"1e4a12b3-3c5f-4a6e-9b7d-8f0e1d2c3b4a\"," + + "\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateAuthorizationProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateAuthorizationProfileTest.kt new file mode 100644 index 00000000..cae0d6f6 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateAuthorizationProfileTest.kt @@ -0,0 +1,55 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.createAuthorizationProfileAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.AuthorizationProfileCreated +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.util.* +import kotlinx.coroutines.test.runTest + +class CreateAuthorizationProfileTest : + FunSpec({ + test("create an authorization profile") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CREATE_AUTHORIZATION_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationProfileCreated( + true, + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + "authorizationProfile1", + "", + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + true, + ), + ) + + emitMessage(Topics.Event.AUTHORIZATION_PROFILE_CREATED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.createAuthorizationProfileAsync( + "authorizationProfile1", + "", + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.name.shouldBe("authorizationProfile1") + result.partitionId.shouldBe(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.CREATE_AUTHORIZATION_PROFILE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"authorizationProfile1\",\"description\":\"\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateAuthorizationTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateAuthorizationTimeProfileTest.kt new file mode 100644 index 00000000..facdf563 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateAuthorizationTimeProfileTest.kt @@ -0,0 +1,58 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.createAuthorizationTimeProfileAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.AuthorizationTimeProfileCreated +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.messages.query.TimeProfileType +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.TimeProfileFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class CreateAuthorizationTimeProfileTest : + FunSpec({ + test("create authorization time profile") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CREATE_AUTHORIZATION_TIME_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationTimeProfileCreated( + timeSeries = TimeProfileFixture.timeSeries, + name = "timeProfileName", + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + type = TimeProfileType.AUTHORIZATION_PROFILE, + validStandardTimeProfile = true, + ), + ) + + emitMessage( + Topics.Event.AUTHORIZATION_TIME_PROFILE_CREATED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.createAuthorizationTimeProfileAsync( + name = "timeProfileName", + timeProfileId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + timeSeries = TimeProfileFixture.timeSeries, + ) + .await() + result.name.shouldBeEqual("timeProfileName") + result.type.shouldBeEqual(TimeProfileType.AUTHORIZATION_PROFILE) + + harness + .publishedPayload(Topics.Command.CREATE_AUTHORIZATION_TIME_PROFILE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"timeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"days\":[\"MONDAY\"]}],\"exceptionTimeSeries\":[],\"name\":\"timeProfileName\",\"description\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateCalendarTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateCalendarTest.kt new file mode 100644 index 00000000..125b0618 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateCalendarTest.kt @@ -0,0 +1,54 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.createCalendarAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.CalendarCreated +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDate +import java.util.* +import kotlinx.coroutines.test.runTest + +class CreateCalendarTest : + FunSpec({ + test("create calendar") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CREATE_CALENDAR) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + CalendarCreated( + UUID.fromString("905a9d0a-111f-44ad-a871-f9d0a24335f3"), + 123, + "calendarName", + listOf(LocalDate.parse("2018-02-25")), + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.CALENDAR_CREATED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.createCalendarAsync( + "calendarName", + listOf(LocalDate.parse("2018-02-25")), + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.name.shouldBeEqual("calendarName") + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.CREATE_CALENDAR) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"calendarName\",\"specialDays\":[\"2018-02-25\"],\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateCodingStationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateCodingStationTest.kt new file mode 100644 index 00000000..177b4efb --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateCodingStationTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.createCodingStationAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.CodingStationCreated +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class CreateCodingStationTest : + FunSpec({ + test("create coding station") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CREATE_CODING_STATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + CodingStationCreated( + partitionId = + UUID.fromString("5c4d62bb-cdf9-4630-83ff-816ee8166d62"), + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + name = "coding station name", + ), + ) + + emitMessage(Topics.Event.CODING_STATION_CREATED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.createCodingStationAsync( + name = "coding station name", + codingStationId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.CREATE_CODING_STATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"coding station name\",\"description\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateInstallationPointTest.kt new file mode 100644 index 00000000..48884d6e --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateInstallationPointTest.kt @@ -0,0 +1,67 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.createInstallationPointAsync +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.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class CreateInstallationPointTest : + FunSpec({ + test("add evva component returning both events") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CREATE_INSTALLATION_POINT) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointCreated( + id = 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, + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CREATED, encodeEvent(apiEvent)) + + emitMessage(Topics.Event.EVVA_COMPONENT_ADDED, encodeEvent(apiEvent2)) + } + + val api = harness.api + val createInstallationPointResult = + api.createInstallationPointAsync( + ComponentType.Cylinder, + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + val test = createInstallationPointResult.installationPointCreatedDeferred.await() + test.id.shouldBe(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + val evvaComponentAdded = + createInstallationPointResult.evvaComponentAddedDeferred.await() + evvaComponentAdded.type.shouldBe(ComponentType.Cylinder) + + harness + .publishedPayload(Topics.Command.CREATE_INSTALLATION_POINT) + .shouldBeEqual( + "{\"componentType\":\"Cylinder\",\"aggregateId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"linkedInstallationPoints\":{},\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateOfficeModeTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateOfficeModeTimeProfileTest.kt new file mode 100644 index 00000000..d04fd8b0 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateOfficeModeTimeProfileTest.kt @@ -0,0 +1,58 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.createOfficeModeTimeProfileAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.OfficeModeTimeProfileCreated +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.TimeProfileFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class CreateOfficeModeTimeProfileTest : + FunSpec({ + test("create office mode time profile") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CREATE_OFFICE_MODE_TIME_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + OfficeModeTimeProfileCreated( + name = "timeProfileName", + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + timeSeries = TimeProfileFixture.timeSeries, + exceptionTimeSeries = listOf(), + exceptionTimePointSeries = listOf(), + timePointSeries = listOf(), + ), + ) + + emitMessage( + Topics.Event.OFFICE_MODE_TIME_PROFILE_CREATED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.createOfficeModeTimeProfileAsync( + name = "timeProfileName", + timeSeries = TimeProfileFixture.timeSeries, + timeProfileId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.name.shouldBeEqual("timeProfileName") + result.timeSeries.shouldBeEqual(TimeProfileFixture.timeSeries) + + harness + .publishedPayload(Topics.Command.CREATE_OFFICE_MODE_TIME_PROFILE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"timeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"days\":[\"MONDAY\"]}],\"exceptionTimeSeries\":[],\"exceptionTimePointSeries\":[],\"name\":\"timeProfileName\",\"description\":null,\"timePointSeries\":[],\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreatePersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreatePersonTest.kt new file mode 100644 index 00000000..137253bb --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreatePersonTest.kt @@ -0,0 +1,55 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.createPersonAsync +import com.open200.xesar.connect.messages.PersonalLog +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PersonCreated +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class CreatePersonTest : + FunSpec({ + test("create person") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CREATE_PERSON) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PersonCreated( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + firstName = "firstName", + lastName = "lastName", + partitionId = + UUID.fromString("5c4d62bb-cdf9-4630-83ff-816ee8166d62"), + personalReferenceDuration = PersonalLog(days = 30), + ), + ) + + emitMessage(Topics.Event.PERSON_CREATED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.createPersonAsync( + firstName = "firstName", + lastName = "lastName", + personId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + .await() + result.firstName.shouldBeEqual("firstName") + result.lastName.shouldBeEqual("lastName") + + harness + .publishedPayload(Topics.Command.CREATE_PERSON) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"firstName\":\"firstName\",\"lastName\":\"lastName\",\"identifier\":null,\"externalId\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"entityMetadata\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateZoneTest.kt new file mode 100644 index 00000000..10b4a67e --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/CreateZoneTest.kt @@ -0,0 +1,57 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.createZoneAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.ZoneCreated +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class CreateZoneTest : + FunSpec({ + test("create zone") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.CREATE_ZONE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + ZoneCreated( + 123, + UUID.fromString("dc6f8102-af8f-4e8d-afd4-2d6ed1f5722d"), + "zoneName", + null, + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.ZONE_CREATED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.createZoneAsync( + name = "zoneName", + zoneId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + installationPoints = + listOf( + UUID.fromString("720eb694-a085-47e8-8f18-512aa1a63bef"), + UUID.fromString("c457a028-dd08-4040-a1bb-17767e2b2c28"), + ), + ) + .await() + result.name.shouldBeEqual("zoneName") + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.CREATE_ZONE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPoints\":[\"720eb694-a085-47e8-8f18-512aa1a63bef\",\"c457a028-dd08-4040-a1bb-17767e2b2c28\"],\"name\":\"zoneName\",\"description\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteAuthorizationProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteAuthorizationProfileTest.kt new file mode 100644 index 00000000..009bb288 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteAuthorizationProfileTest.kt @@ -0,0 +1,49 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.deleteAuthorizationProfileAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.AuthorizationProfileDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.booleans.shouldBeFalse +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class DeleteAuthorizationProfileTest : + FunSpec({ + test("delete authorization profile") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.DELETE_AUTHORIZATION_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationProfileDeleted( + individual = false, + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.AUTHORIZATION_PROFILE_DELETED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.deleteAuthorizationProfileAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.individual.shouldBeFalse() + + harness + .publishedPayload(Topics.Command.DELETE_AUTHORIZATION_PROFILE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteAuthorizationTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteAuthorizationTimeProfileTest.kt new file mode 100644 index 00000000..9bec8f02 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteAuthorizationTimeProfileTest.kt @@ -0,0 +1,49 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.deleteAuthorizationTimeProfileAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.AuthorizationTimeProfileDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class DeleteAuthorizationTimeProfileTest : + FunSpec({ + test("create authorization time profile") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.DELETE_AUTHORIZATION_TIME_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationTimeProfileDeleted( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + emitMessage( + Topics.Event.AUTHORIZATION_TIME_PROFILE_DELETED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.deleteAuthorizationTimeProfileAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.DELETE_AUTHORIZATION_TIME_PROFILE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteCalendarTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteCalendarTest.kt new file mode 100644 index 00000000..a88167e4 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteCalendarTest.kt @@ -0,0 +1,45 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.deleteCalendarAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.CalendarDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class DeleteCalendarTest : + FunSpec({ + test("delete calendar") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.DELETE_CALENDAR) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + CalendarDeleted( + 123, + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.CALENDAR_DELETED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.deleteCalendarAsync(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.DELETE_CALENDAR) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteCodingStationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteCodingStationTest.kt new file mode 100644 index 00000000..874413cf --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteCodingStationTest.kt @@ -0,0 +1,48 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.deleteCodingStationAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.CodingStationDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class DeleteCodingStationTest : + FunSpec({ + test("delete coding station") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.DELETE_CODING_STATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + CodingStationDeleted( + LocalDateTime.parse("2023-07-05T15:22:13.509825"), + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.CODING_STATION_DELETED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.deleteCodingStationAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.DELETE_CODING_STATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteEntityMetadataDefinitionTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteEntityMetadataDefinitionTest.kt new file mode 100644 index 00000000..a89c8f4b --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteEntityMetadataDefinitionTest.kt @@ -0,0 +1,67 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.deleteEntityMetadataDefinitionAsync +import com.open200.xesar.connect.messages.EntityMetadata +import com.open200.xesar.connect.messages.EntityType +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class DeleteEntityMetadataDefinitionTest : + FunSpec({ + test("delete entity metadata definition") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.DELETE_ENTITY_METADATA_DEFINITION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + entityMetadataDefinitions = + PartitionChanged.EntityMetadataDefinitions( + authorizationProfiles = emptyList(), + identificationMedia = emptyList(), + installationPoints = emptyList(), + persons = + listOf( + EntityMetadata( + id = + UUID.fromString( + "aaaaaaaa-0000-0000-0000-000000000001" + ), + name = "nickname", + ) + ), + zones = emptyList(), + ), + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.deleteEntityMetadataDefinitionAsync(EntityType.PERSON, "department").await() + + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.entityMetadataDefinitions!! + .persons + .map { it.name } + .shouldBeEqual(listOf("nickname")) + + harness + .publishedPayload(Topics.Command.DELETE_ENTITY_METADATA_DEFINITION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"entityType\":\"PERSON\",\"names\":[\"department\"],\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteInstallationPointTest.kt new file mode 100644 index 00000000..f00b39e7 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteInstallationPointTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.deleteInstallationPointAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class DeleteInstallationPointTest : + FunSpec({ + test("delete installation point") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.DELETE_INSTALLATION_POINT) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointDeleted( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + linkedInstallationPoints = + listOf(UUID.fromString("dc6f8102-af8f-4e8d-afd4-2d6ed1f5722d")), + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_DELETED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.deleteInstallationPointAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.linkedInstallationPoints.shouldBeEqual( + listOf(UUID.fromString("dc6f8102-af8f-4e8d-afd4-2d6ed1f5722d")) + ) + + harness + .publishedPayload(Topics.Command.DELETE_INSTALLATION_POINT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteOfficeModeTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteOfficeModeTimeProfileTest.kt new file mode 100644 index 00000000..2ced1ab6 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteOfficeModeTimeProfileTest.kt @@ -0,0 +1,49 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.deleteOfficeModeTimeProfileAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.OfficeModeTimeProfileDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class DeleteOfficeModeTimeProfileTest : + FunSpec({ + test("delete office mode time profile") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.DELETE_OFFICE_MODE_TIME_PROFILE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + OfficeModeTimeProfileDeleted( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + emitMessage( + Topics.Event.OFFICE_MODE_TIME_PROFILE_DELETED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.deleteOfficeModeTimeProfileAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.DELETE_OFFICE_MODE_TIME_PROFILE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeletePersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeletePersonTest.kt new file mode 100644 index 00000000..8b5dc04c --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeletePersonTest.kt @@ -0,0 +1,43 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.deletePersonAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PersonDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class DeletePersonTest : + FunSpec({ + test("delete person") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.DELETE_PERSON) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PersonDeleted( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + emitMessage(Topics.Event.PERSON_DELETED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.deletePersonAsync("EXT-123").await() + + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.DELETE_PERSON) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"externalId\":\"EXT-123\",\"id\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteZoneTest.kt new file mode 100644 index 00000000..e15f59cb --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/DeleteZoneTest.kt @@ -0,0 +1,46 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.deleteZoneAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.ZoneDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class DeleteZoneTest : + FunSpec({ + test("delete zone") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.DELETE_ZONE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + ZoneDeleted( + deletedAt = LocalDateTime.parse("2023-06-15T16:25:52.225991"), + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.ZONE_DELETED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.deleteZoneAsync(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.DELETE_ZONE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/FindComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/FindComponentTest.kt new file mode 100644 index 00000000..175fd33e --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/FindComponentTest.kt @@ -0,0 +1,48 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.findComponentAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.FindComponentPerformed +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.InstallationPointFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.ktor.http.* +import java.util.* +import kotlinx.coroutines.test.runTest + +class FindComponentTest : + FunSpec({ + test("find Component with success") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.FIND_COMPONENT) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + FindComponentPerformed("ok"), + ) + + emitMessage(Topics.Event.FIND_COMPONENT_PERFORMED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.findComponentAsync( + InstallationPointFixture.installationPointFixture.id, + true, + ) + .await() + + result.ok.shouldBeEqual("ok") + + harness + .publishedPayload(Topics.Command.FIND_COMPONENT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"${InstallationPointFixture.installationPointFixture.id}\",\"enable\":true,\"token\":\"${MockedXesarConnect.TOKEN}\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ForceRemoveEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ForceRemoveEvvaComponentTest.kt new file mode 100644 index 00000000..b3cb9d61 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ForceRemoveEvvaComponentTest.kt @@ -0,0 +1,56 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.forceRemoveEvvaComponentAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.EvvaComponentRemoved +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class ForceRemoveEvvaComponentTest : + FunSpec({ + test("force remove evva component") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.FORCE_REMOVE_EVVA_COMPONENT) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + EvvaComponentRemoved( + accessId = 123, + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + useOddKey = true, + forced = true, + stateChangedAt = LocalDateTime.parse("2023-06-15T16:23:25.229593"), + nonce = 1, + ), + ) + + emitMessage(Topics.Event.EVVA_COMPONENT_REMOVED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.forceRemoveEvvaComponentAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + result.aggregateId.shouldBeEqual( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + result.accessId.shouldBeEqual(123) + + harness + .publishedPayload(Topics.Command.FORCE_REMOVE_EVVA_COMPONENT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/LockMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/LockMediumTest.kt new file mode 100644 index 00000000..e17ef91c --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/LockMediumTest.kt @@ -0,0 +1,44 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.lockMediumAsync +import com.open200.xesar.connect.messages.event.MediumLocked +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class LockMediumTest : + FunSpec({ + test("lock medium") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.LOCK_MEDIUM) { + emitEvent( + Topics.Event.MEDIUM_LOCKED, + MediumLocked( + aggregateId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + hasMasterKeyAccess = false, + mediumIdentifier = 123L, + ), + ) + } + + val result = + harness.api + .lockMediumAsync(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + .await() + + harness + .publishedPayload(Topics.Command.LOCK_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + result.mediumIdentifier.shouldBeEqual(123L) + result.aggregateId.shouldBeEqual( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/PrepareRemovalOfEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/PrepareRemovalOfEvvaComponentTest.kt new file mode 100644 index 00000000..568ceb76 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/PrepareRemovalOfEvvaComponentTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.prepareRemovalOfEvvaComponentAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.EvvaComponentRemovalPrepared +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class PrepareRemovalOfEvvaComponentTest : + FunSpec({ + test("prepare removal of evva component") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.PREPARE_REMOVAL_OF_EVVA_COMPONENT) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + EvvaComponentRemovalPrepared( + stateChangeAt = LocalDateTime.parse("2023-06-15T16:25:52.225991"), + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.EVVA_COMPONENT_REMOVAL_PREPARED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.prepareRemovalOfEvvaComponentAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + result.aggregateId.shouldBeEqual( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + + harness + .publishedPayload(Topics.Command.PREPARE_REMOVAL_OF_EVVA_COMPONENT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoteDisengagePermanentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoteDisengagePermanentTest.kt new file mode 100644 index 00000000..543af81e --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoteDisengagePermanentTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.executeRemoteDisengagePermanentAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.RemoteDisengagePerformed +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.InstallationPointFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.ktor.http.* +import java.util.* +import kotlinx.coroutines.test.runTest + +class RemoteDisengagePermanentTest : + FunSpec({ + test("remote disengage permanent with success") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.REMOTE_DISENGAGE_PERMANENT) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + RemoteDisengagePerformed("ok"), + ) + + emitMessage( + Topics.Event.REMOTE_DISENGAGE_PERMANENT_PERFORMED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.executeRemoteDisengagePermanentAsync( + InstallationPointFixture.installationPointFixture.id, + true, + ) + .await() + + result.ok.shouldBeEqual("ok") + + harness + .publishedPayload(Topics.Command.REMOTE_DISENGAGE_PERMANENT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"${InstallationPointFixture.installationPointFixture.id}\",\"enable\":true,\"token\":\"${MockedXesarConnect.TOKEN}\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoteDisengageTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoteDisengageTest.kt new file mode 100644 index 00000000..590246ff --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoteDisengageTest.kt @@ -0,0 +1,47 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.executeRemoteDisengageAsync +import com.open200.xesar.connect.messages.event.* +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.InstallationPointFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.ktor.http.* +import java.util.* +import kotlinx.coroutines.test.runTest + +class RemoteDisengageTest : + FunSpec({ + test("remote disengage with success") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.REMOTE_DISENGAGE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + RemoteDisengagePerformed("ok"), + ) + val remoteDisengagePerformed = encodeEvent(apiEvent) + + emitMessage(Topics.Event.REMOTE_DISENGAGE_PERFORMED, remoteDisengagePerformed) + } + + val api = harness.api + val result = + api.executeRemoteDisengageAsync( + InstallationPointFixture.installationPointFixture.id, + true, + ) + .await() + + result.ok.shouldBeEqual("ok") + + harness + .publishedPayload(Topics.Command.REMOTE_DISENGAGE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"${InstallationPointFixture.installationPointFixture.id}\",\"extended\":true,\"token\":\"${MockedXesarConnect.TOKEN}\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveInstallationPointAuthorizationFromMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveInstallationPointAuthorizationFromMediumTest.kt new file mode 100644 index 00000000..4e29d14b --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveInstallationPointAuthorizationFromMediumTest.kt @@ -0,0 +1,57 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.removeInstallationPointAuthorizationFromMediumAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.IndividualAuthorizationsDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class RemoveInstallationPointAuthorizationFromMediumTest : + FunSpec({ + test("remove installation point authorization from medium") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo( + Topics.Command.REMOVE_INSTALLATION_POINT_AUTHORIZATION_FROM_MEDIUM + ) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + IndividualAuthorizationsDeleted( + listOf(UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f")), + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage( + Topics.Event.INDIVIDUAL_AUTHORIZATIONS_DELETED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.removeInstallationPointAuthorizationFromMediumAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f"), + ) + .await() + result.mediumId.shouldBeEqual( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + + harness + .publishedPayload( + Topics.Command.REMOVE_INSTALLATION_POINT_AUTHORIZATION_FROM_MEDIUM + ) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"authorization\":\"8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveInstallationPointFromZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveInstallationPointFromZoneTest.kt new file mode 100644 index 00000000..6142b9d2 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveInstallationPointFromZoneTest.kt @@ -0,0 +1,59 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.removeInstallationPointFromZoneAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointsInZoneChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class RemoveInstallationPointFromZoneTest : + FunSpec({ + test("remove installation point from zone") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.REMOVE_INSTALLATION_POINT_FROM_ZONE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointsInZoneChanged( + accessId = 123, + removedInstallationPoints = + listOf(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")), + aggregateId = + UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f"), + ), + ) + + emitMessage( + Topics.Event.INSTALLATION_POINTS_IN_ZONE_CHANGED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.removeInstallationPointFromZoneAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f"), + ) + .await() + result.aggregateId.shouldBeEqual( + UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f") + ) + result.removedInstallationPoints.shouldBeEqual( + listOf(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + ) + + harness + .publishedPayload(Topics.Command.REMOVE_INSTALLATION_POINT_FROM_ZONE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"id\":\"8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveZoneAuthorizationFromMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveZoneAuthorizationFromMediumTest.kt new file mode 100644 index 00000000..3c8aec6b --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RemoveZoneAuthorizationFromMediumTest.kt @@ -0,0 +1,56 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.removeZoneAuthorizationFromMediumAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.IndividualAuthorizationsDeleted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class RemoveZoneAuthorizationFromMediumTest : + FunSpec({ + test("remove zone authorization from medium") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.REMOVE_ZONE_AUTHORIZATION_FROM_MEDIUM) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + IndividualAuthorizationsDeleted( + listOf(UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f")), + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage( + Topics.Event.INDIVIDUAL_AUTHORIZATIONS_DELETED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.removeZoneAuthorizationFromMediumAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f"), + ) + .await() + result.mediumId.shouldBeEqual( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + result.individualAuthorizations.shouldBeEqual( + listOf(UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f")) + ) + + harness + .publishedPayload(Topics.Command.REMOVE_ZONE_AUTHORIZATION_FROM_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"authorization\":\"8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RenameEntityMetadataDefinitionTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RenameEntityMetadataDefinitionTest.kt new file mode 100644 index 00000000..b0d0c9a9 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RenameEntityMetadataDefinitionTest.kt @@ -0,0 +1,70 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.renameEntityMetadataDefinitionAsync +import com.open200.xesar.connect.messages.EntityMetadata +import com.open200.xesar.connect.messages.EntityType +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class RenameEntityMetadataDefinitionTest : + FunSpec({ + test("rename entity metadata definition") { + val targetId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.RENAME_ENTITY_METADATA_DEFINITION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + entityMetadataDefinitions = + PartitionChanged.EntityMetadataDefinitions( + authorizationProfiles = emptyList(), + identificationMedia = emptyList(), + installationPoints = emptyList(), + persons = + listOf( + EntityMetadata(id = targetId, name = "team"), + EntityMetadata( + id = + UUID.fromString( + "bbbbbbbb-0000-0000-0000-000000000002" + ), + name = "department", + ), + ), + zones = emptyList(), + ), + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.renameEntityMetadataDefinitionAsync(EntityType.PERSON, targetId, "team") + .await() + + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.entityMetadataDefinitions!! + .persons + .map { it.name } + .shouldBeEqual(listOf("team", "department")) + + harness + .publishedPayload(Topics.Command.RENAME_ENTITY_METADATA_DEFINITION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"entityType\":\"PERSON\",\"metadataDefinitionId\":\"$targetId\",\"name\":\"team\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RequestAddMediumToInstallationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RequestAddMediumToInstallationTest.kt new file mode 100644 index 00000000..7d7ed36d --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RequestAddMediumToInstallationTest.kt @@ -0,0 +1,71 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.requestToAddMediumToInstallationAsync +import com.open200.xesar.connect.messages.event.* +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.util.* +import kotlinx.coroutines.test.runTest + +class RequestAddMediumToInstallationTest : + FunSpec({ + test("request add medium to installation returning both events") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.REQUEST_ADD_MEDIUM_TO_INSTALLATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AddMediumToInstallationRequested( + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + hardwareId = "hardwareId", + ), + ) + + val apiEvent2 = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + MediumAddedToInstallation( + aggregateId = + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), + "hardwareId", + ), + ) + + emitMessage( + Topics.Event.ADD_MEDIUM_TO_INSTALLATION_REQUESTED, + encodeEvent(apiEvent), + ) + + emitMessage(Topics.Event.MEDIUM_ADDED_TO_INSTALLATION, encodeEvent(apiEvent2)) + } + + val api = harness.api + val requestToAddMediumToInstallationResult = + api.requestToAddMediumToInstallationAsync( + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), + "hardwareId", + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ) + val mediumAddedToInstallation = + requestToAddMediumToInstallationResult.mediumAddedToInstallationDeferred.await() + mediumAddedToInstallation.aggregateId.shouldBe( + UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be") + ) + val addMediumToInstallationRequested = + requestToAddMediumToInstallationResult.addMediumToInstallationRequestedDeferred + .await() + addMediumToInstallationRequested.hardwareId.shouldBe("hardwareId") + + harness + .publishedPayload(Topics.Command.REQUEST_ADD_MEDIUM_TO_INSTALLATION) + .shouldBeEqual( + "{\"hardwareId\":\"hardwareId\",\"id\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"terminalId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"label\":null,\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RequestNewRegistrationCodeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RequestNewRegistrationCodeTest.kt new file mode 100644 index 00000000..891c9974 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RequestNewRegistrationCodeTest.kt @@ -0,0 +1,48 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.requestNewRegistrationCodeAsync +import com.open200.xesar.connect.messages.event.* +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.util.* +import kotlinx.coroutines.test.runTest + +class RequestNewRegistrationCodeTest : + FunSpec({ + test("request new registration code for a smartphone media") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.REQUEST_NEW_REGISTRATION_CODE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + NewRegistrationCodeRequested( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + emitMessage(Topics.Event.NEW_REGISTRATION_CODE_REQUESTED, encodeEvent(apiEvent)) + } + + val api = harness.api + val requestNewRegistrationCodeResult = + api.requestNewRegistrationCodeAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + + requestNewRegistrationCodeResult.id.shouldBe( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + + harness + .publishedPayload(Topics.Command.REQUEST_NEW_REGISTRATION_CODE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ResendSmartphoneAuthorizationsTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ResendSmartphoneAuthorizationsTest.kt new file mode 100644 index 00000000..096682af --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/ResendSmartphoneAuthorizationsTest.kt @@ -0,0 +1,50 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.resendSmartphoneAuthorizationsAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.SmartphoneUnregistered +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class ResendSmartphoneAuthorizationsTest : + FunSpec({ + test("resend smartphone authorizations") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.RESEND_SMARTPHONE_AUTHORIZATIONS) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + SmartphoneUnregistered( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + emitMessage( + Topics.Event.SMARTPHONE_AUTHORIZATIONS_RESENT, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.resendSmartphoneAuthorizationsAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + + result.id!!.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.RESEND_SMARTPHONE_AUTHORIZATIONS) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RevertPrepareRemovalOfEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RevertPrepareRemovalOfEvvaComponentTest.kt new file mode 100644 index 00000000..3381aaad --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RevertPrepareRemovalOfEvvaComponentTest.kt @@ -0,0 +1,54 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.revertPrepareRemovalOfEvvaComponentAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PrepareEvvaComponentRemovalReverted +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class RevertPrepareRemovalOfEvvaComponentTest : + FunSpec({ + test("revert prepare removal of evva component") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.REVERT_PREPARE_REMOVAL_OF_EVVA_COMPONENT) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PrepareEvvaComponentRemovalReverted( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + LocalDateTime.parse("2023-07-05T15:22:38.230076"), + ), + ) + + emitMessage( + Topics.Event.PREPARE_EVVA_COMPONENT_REMOVAL_REVERTED, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.revertPrepareRemovalOfEvvaComponentAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.stateChangedAt.shouldBeEqual( + LocalDateTime.parse("2023-07-05T15:22:38.230076") + ) + + harness + .publishedPayload(Topics.Command.REVERT_PREPARE_REMOVAL_OF_EVVA_COMPONENT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RevokeSmartphoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RevokeSmartphoneTest.kt new file mode 100644 index 00000000..5b5335ce --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/RevokeSmartphoneTest.kt @@ -0,0 +1,47 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.revokeSmartphoneAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.MediumRevoked +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.UUID +import kotlinx.coroutines.test.runTest + +class RevokeSmartphoneTest : + FunSpec({ + test("revoke smartphone medium") { + val smartphoneId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.REVOKE_SMARTPHONE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + MediumRevoked( + aggregateId = smartphoneId, + mediumIdentifier = 123456L, + hasMasterKeyAccess = false, + ), + ) + + emitMessage(Topics.Event.MEDIUM_REVOKED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.revokeSmartphoneAsync(smartphoneId).await() + + result.aggregateId.shouldBeEqual(smartphoneId) + result.mediumIdentifier.shouldBeEqual(123456L) + + harness + .publishedPayload(Topics.Command.REVOKE_SMARTPHONE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetAccessBeginAtTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetAccessBeginAtTest.kt new file mode 100644 index 00000000..a96a6bbd --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetAccessBeginAtTest.kt @@ -0,0 +1,50 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setAccessBeginAtAsync +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 com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetAccessBeginAtTest : + FunSpec({ + test("set access begin at") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_ACCESS_BEGIN_AT) { + 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"), + ), + ) + + emitMessage(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setAccessBeginAtAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + LocalDateTime.parse("2023-08-24T16:25:52.225991"), + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.SET_ACCESS_BEGIN_AT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"accessBeginAt\":\"2023-08-24T16:25:52.225991\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetAccessEndAtTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetAccessEndAtTest.kt new file mode 100644 index 00000000..64068719 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetAccessEndAtTest.kt @@ -0,0 +1,50 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setAccessEndAtAsync +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 com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetAccessEndAtTest : + FunSpec({ + test("set access end at") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_ACCESS_END_AT) { + 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"), + ), + ) + + emitMessage(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setAccessEndAtAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + LocalDateTime.parse("2023-08-24T16:25:52.225991"), + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.SET_ACCESS_END_AT) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"accessEndAt\":\"2023-08-24T16:25:52.225991\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDailySchedulerExecutionTimeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDailySchedulerExecutionTimeTest.kt new file mode 100644 index 00000000..ac5283fe --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDailySchedulerExecutionTimeTest.kt @@ -0,0 +1,46 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setDailySchedulerExecutionTimeAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.TimeProfileFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetDailySchedulerExecutionTimeTest : + FunSpec({ + test("set daily scheduler execution time") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_DAILY_SCHEDULER_EXECUTION_TIME) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + dailySchedulerExecutionTime = TimeProfileFixture.localTime, + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setDailySchedulerExecutionTimeAsync(TimeProfileFixture.localTime).await() + result.dailySchedulerExecutionTime.shouldBe(TimeProfileFixture.localTime) + + harness + .publishedPayload(Topics.Command.SET_DAILY_SCHEDULER_EXECUTION_TIME) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"dailySchedulerExecutionTime\":\"14:15:00\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultAuthorizationProfileForPersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultAuthorizationProfileForPersonTest.kt new file mode 100644 index 00000000..819c76fe --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultAuthorizationProfileForPersonTest.kt @@ -0,0 +1,45 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setDefaultAuthorizationProfileForPersonAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PersonChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetDefaultAuthorizationProfileForPersonTest : + FunSpec({ + test("set default authorization profile for a person") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_DEFAULT_AUTHORIZATION_PROFILE_FOR_PERSON) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PersonChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + firstName = "firstName", + lastName = "lastName", + ), + ) + + emitMessage(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setDefaultAuthorizationProfileForPersonAsync("EXT-123", null).await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.SET_DEFAULT_AUTHORIZATION_PROFILE_FOR_PERSON) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"externalId\":\"EXT-123\",\"id\":null,\"defaultAuthorizationProfileName\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultDisengagePeriodForPersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultDisengagePeriodForPersonTest.kt new file mode 100644 index 00000000..31201ad5 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultDisengagePeriodForPersonTest.kt @@ -0,0 +1,52 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setDefaultDisengagePeriodForPersonAsync +import com.open200.xesar.connect.messages.DisengagePeriod +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PersonChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetDefaultDisengagePeriodForPersonTest : + FunSpec({ + test("set default disengage period for a person") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_DEFAULT_DISENGAGE_PERIOD_FOR_PERSON) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PersonChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + firstName = "firstName", + lastName = "lastName", + disengagePeriod = DisengagePeriod.SHORT, + ), + ) + + emitMessage(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setDefaultDisengagePeriodForPersonAsync( + "EXT-123", + disengagePeriod = DisengagePeriod.SHORT, + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.disengagePeriod?.shouldBeEqual(DisengagePeriod.SHORT) + + harness + .publishedPayload(Topics.Command.SET_DEFAULT_DISENGAGE_PERIOD_FOR_PERSON) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"disengagePeriod\":\"SHORT\",\"externalId\":\"EXT-123\",\"id\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultSmartphoneValidityDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultSmartphoneValidityDurationTest.kt new file mode 100644 index 00000000..f117df75 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultSmartphoneValidityDurationTest.kt @@ -0,0 +1,43 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setDefaultSmartphoneValidityDurationAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetDefaultSmartphoneValidityDurationTest : + FunSpec({ + test("set default smartphone validity duration for all smartphones") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_DEFAULT_SMARTPHONE_VALIDITIY_DURATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + smartphoneValidityDuration = 10, + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.setDefaultSmartphoneValidityDurationAsync(10).await() + result.smartphoneValidityDuration!!.shouldBeEqual(10) + + harness + .publishedPayload(Topics.Command.SET_DEFAULT_SMARTPHONE_VALIDITIY_DURATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"validityDuration\":10,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultValidityDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultValidityDurationTest.kt new file mode 100644 index 00000000..9a4fba7d --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDefaultValidityDurationTest.kt @@ -0,0 +1,44 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setDefaultValidityDurationAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetDefaultValidityDurationTest : + FunSpec({ + test("set default validity duration") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_DEFAULT_VALIDITY_DURATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + validityDuration = 0, + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.setDefaultValidityDurationAsync(0).await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.validityDuration?.shouldBeEqual(0) + + harness + .publishedPayload(Topics.Command.SET_DEFAULT_VALIDITY_DURATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"validityDuration\":0,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDisengagePeriodOnMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDisengagePeriodOnMediumTest.kt new file mode 100644 index 00000000..a644076a --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetDisengagePeriodOnMediumTest.kt @@ -0,0 +1,52 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setDisengagePeriodOnMediumAsync +import com.open200.xesar.connect.messages.DisengagePeriod +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 com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetDisengagePeriodOnMediumTest : + FunSpec({ + test("set disengage period on medium") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_DISENGAGE_PERIOD_ON_MEDIUM) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + MediumChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"), + disengagePeriod = DisengagePeriod.LONG, + ), + ) + + emitMessage(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setDisengagePeriodOnMediumAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + DisengagePeriod.LONG, + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.disengagePeriod?.shouldBeEqual(DisengagePeriod.LONG) + + harness + .publishedPayload(Topics.Command.SET_DISENGAGE_PERIOD_ON_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"disengagePeriod\":\"LONG\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetInstallationPointPersonalReferenceDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetInstallationPointPersonalReferenceDurationTest.kt new file mode 100644 index 00000000..9343226a --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetInstallationPointPersonalReferenceDurationTest.kt @@ -0,0 +1,52 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setInstallationPointPersonalReferenceDurationAsync +import com.open200.xesar.connect.messages.PersonalLog +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetInstallationPointPersonalReferenceDurationTest : + FunSpec({ + test("set installation point personal reference duration") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo( + Topics.Command.SET_INSTALLATION_POINT_PERSONAL_REFERENCE_DURATION + ) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + installationPointDefaultPersonalReferenceDuration = + PersonalLog(days = 30), + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setInstallationPointPersonalReferenceDurationAsync(PersonalLog(days = 30)) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.installationPointDefaultPersonalReferenceDuration?.days?.shouldBeEqual(30) + + harness + .publishedPayload( + Topics.Command.SET_INSTALLATION_POINT_PERSONAL_REFERENCE_DURATION + ) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"personalReferenceDuration\":{\"logMode\":null,\"days\":30},\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetLabelOnMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetLabelOnMediumTest.kt new file mode 100644 index 00000000..05573e38 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetLabelOnMediumTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setLabelOnMediumAsync +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 com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetLabelOnMediumTest : + FunSpec({ + test("set label on medium") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_LABEL_ON_MEDIUM) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + MediumChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"), + label = "label", + ), + ) + + emitMessage(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setLabelOnMediumAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + "label", + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.label?.shouldBeEqual("label") + + harness + .publishedPayload(Topics.Command.SET_LABEL_ON_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"label\":\"label\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetMessageLanguageOnSmartphoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetMessageLanguageOnSmartphoneTest.kt new file mode 100644 index 00000000..6948fdf7 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetMessageLanguageOnSmartphoneTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setMessageLanguageOnSmartphoneAsync +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 com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetMessageLanguageOnSmartphoneTest : + FunSpec({ + test("set message language on smartphone media") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_MESSAGE_LANGUAGE_ON_SMARTPHONE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + MediumChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"), + messageLanguage = "en", + ), + ) + + emitMessage(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setMessageLanguageOnSmartphoneAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + "en", + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.messageLanguage?.shouldBeEqual("en") + + harness + .publishedPayload(Topics.Command.SET_MESSAGE_LANGUAGE_ON_SMARTPHONE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"messageLanguage\":\"en\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetMobileServiceModeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetMobileServiceModeTest.kt new file mode 100644 index 00000000..a1ba803e --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetMobileServiceModeTest.kt @@ -0,0 +1,48 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setMobileServiceModeAsync +import com.open200.xesar.connect.messages.MobileServiceMode +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.UUID +import kotlinx.coroutines.test.runTest + +class SetMobileServiceModeTest : + FunSpec({ + test("set mobile service mode to SELF_SERVICE") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_MOBILE_SERVICE_MODE) { + // Enums are serialized using @SerialName -> "xms" + + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + mobileServiceMode = MobileServiceMode.SELF_SERVICE, + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.setMobileServiceModeAsync(MobileServiceMode.SELF_SERVICE).await() + + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.mobileServiceMode?.shouldBeEqual(MobileServiceMode.SELF_SERVICE) + + harness + .publishedPayload(Topics.Command.SET_MOBILE_SERVICE_MODE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"mobileServiceMode\":\"self-service\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonPersonalReferenceDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonPersonalReferenceDurationTest.kt new file mode 100644 index 00000000..6a76d7f3 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonPersonalReferenceDurationTest.kt @@ -0,0 +1,46 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setPersonPersonalReferenceDurationAsync +import com.open200.xesar.connect.messages.PersonalLog +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetPersonPersonalReferenceDurationTest : + FunSpec({ + test("set person personal reference duration") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_PERSON_PERSONAL_REFERENCE_DURATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + personDefaultPersonalReferenceDuration = PersonalLog(days = 30), + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setPersonPersonalReferenceDurationAsync(PersonalLog(days = 30)).await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.personDefaultPersonalReferenceDuration?.days?.shouldBeEqual(30) + + harness + .publishedPayload(Topics.Command.SET_PERSON_PERSONAL_REFERENCE_DURATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"personalReferenceDuration\":{\"logMode\":null,\"days\":30},\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonalReferenceDurationForInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonalReferenceDurationForInstallationPointTest.kt new file mode 100644 index 00000000..a1df17ca --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonalReferenceDurationForInstallationPointTest.kt @@ -0,0 +1,66 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setPersonalReferenceDurationForInstallationPointAsync +import com.open200.xesar.connect.messages.PersonalLog +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.InstallationPointChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetPersonalReferenceDurationForInstallationPointTest : + FunSpec({ + test("set personal reference duration for installation point") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo( + Topics.Command.SET_PERSONAL_REFERENCE_DURATION_FOR_INSTALLATION_POINT + ) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + InstallationPointChanged( + aggregateId = + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + personalReferenceDuration = + PersonalLog( + days = 30, + logMode = PersonalLog.PersonalLogModes.saveForDays, + ), + ), + ) + + emitMessage(Topics.Event.INSTALLATION_POINT_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setPersonalReferenceDurationForInstallationPointAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + PersonalLog( + days = 30, + logMode = PersonalLog.PersonalLogModes.saveForDays, + ), + ) + .await() + result.aggregateId.shouldBeEqual( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + result.personalReferenceDuration?.shouldBeEqual( + PersonalLog(days = 30, logMode = PersonalLog.PersonalLogModes.saveForDays) + ) + + harness + .publishedPayload( + Topics.Command.SET_PERSONAL_REFERENCE_DURATION_FOR_INSTALLATION_POINT + ) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"personalReferenceDuration\":{\"logMode\":\"saveForDays\",\"days\":30},\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonalReferenceDurationInPersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonalReferenceDurationInPersonTest.kt new file mode 100644 index 00000000..3ed9d77e --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPersonalReferenceDurationInPersonTest.kt @@ -0,0 +1,52 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setPersonalReferenceDurationInPersonAsync +import com.open200.xesar.connect.messages.PersonalLog +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PersonChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetPersonalReferenceDurationInPersonTest : + FunSpec({ + test("set personal reference duration in person") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_PERSONAL_REFERENCE_DURATION_IN_PERSON) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PersonChanged( + firstName = "firstName", + lastName = "lastName", + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + personalReferenceDuration = PersonalLog(days = 30), + ), + ) + + emitMessage(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setPersonalReferenceDurationInPersonAsync( + "EXT-123", + personalReferenceDuration = PersonalLog(days = 30), + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.personalReferenceDuration?.shouldBeEqual(PersonalLog(days = 30)) + + harness + .publishedPayload(Topics.Command.SET_PERSONAL_REFERENCE_DURATION_IN_PERSON) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"newValue\":{\"logMode\":null,\"days\":30},\"externalId\":\"EXT-123\",\"id\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPhoneNumberOnSmartphoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPhoneNumberOnSmartphoneTest.kt new file mode 100644 index 00000000..f98c3e94 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetPhoneNumberOnSmartphoneTest.kt @@ -0,0 +1,59 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setPhoneNumberOnSmartphoneAsync +import com.open200.xesar.connect.messages.DisengagePeriod +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 com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetPhoneNumberOnSmartphoneTest : + FunSpec({ + test("set phone number on smartphone media") { + val smartphoneMediaId = UUID.fromString("7b21f75f-3fa6-41c8-acff-a14839331b25") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_PHONE_NUMBER_ON_SMARTPHONE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + MediumChanged( + accessBeginAt = LocalDateTime.parse("2024-08-04T10:05"), + disengagePeriod = DisengagePeriod.SHORT, + authorizationProfileId = + UUID.fromString("00000000-0000-0000-0000-000000000001"), + validityDuration = null, + validUntil = null, + changedAt = LocalDateTime.parse("2024-08-08T08:00:40.671784826"), + id = UUID.fromString("16ea9a30-bc2a-4b99-b3d8-73981f01e2d2"), + label = "Test12348", + validFrom = null, + accessEndAt = LocalDateTime.parse("2079-12-31T23:50"), + phoneNumber = "+0123456789", + ), + ) + + emitMessage(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setPhoneNumberOnSmartphoneAsync("+0123456789", smartphoneMediaId) + .mediumChangedDeferred + .await() + result.phoneNumber!!.shouldBeEqual("+0123456789") + + harness + .publishedPayload(Topics.Command.SET_PHONE_NUMBER_ON_SMARTPHONE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"7b21f75f-3fa6-41c8-acff-a14839331b25\",\"phoneNumber\":\"+0123456789\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetReplacementMediumDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetReplacementMediumDurationTest.kt new file mode 100644 index 00000000..9771618e --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetReplacementMediumDurationTest.kt @@ -0,0 +1,44 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setReplacementMediumDurationAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetReplacementMediumDurationTest : + FunSpec({ + test("set replacement medium duration") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_REPLACEMENT_MEDIUM_DURATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + replacementMediumDuration = 123, + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.setReplacementMediumDurationAsync(123).await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.replacementMediumDuration?.shouldBeEqual(123) + + harness + .publishedPayload(Topics.Command.SET_REPLACEMENT_MEDIUM_DURATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"replacementMediumDuration\":123,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetValidityDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetValidityDurationTest.kt new file mode 100644 index 00000000..3fa1ca02 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetValidityDurationTest.kt @@ -0,0 +1,51 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setValidityDurationAsync +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 com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetValidityDurationTest : + FunSpec({ + test("set validity duration") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_VALIDITY_DURATION) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + MediumChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"), + validityDuration = 123, + ), + ) + + emitMessage(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.setValidityDurationAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + 123, + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.validityDuration?.shouldBeEqual(123) + + harness + .publishedPayload(Topics.Command.SET_VALIDITY_DURATION) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"validityDuration\":123,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetValidityThresholdTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetValidityThresholdTest.kt new file mode 100644 index 00000000..0cfa13eb --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/SetValidityThresholdTest.kt @@ -0,0 +1,44 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.setValidityThresholdAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.PartitionChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class SetValidityThresholdTest : + FunSpec({ + test("set validity threshold") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.SET_VALIDITY_THRESHOLD) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + PartitionChanged( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + validityDuration = 123, + ), + ) + + emitMessage(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.setValidityThresholdAsync(123).await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.validityDuration?.shouldBeEqual(123) + + harness + .publishedPayload(Topics.Command.SET_VALIDITY_THRESHOLD) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"validityThreshold\":123,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/UnassignPersonFromMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/UnassignPersonFromMediumTest.kt new file mode 100644 index 00000000..9961891a --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/UnassignPersonFromMediumTest.kt @@ -0,0 +1,48 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.unassignPersonFromMediumAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.MediumPersonChanged +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.nulls.shouldBeNull +import java.util.UUID +import kotlinx.coroutines.test.runTest + +class UnassignPersonFromMediumTest : + FunSpec({ + test("unassign person from medium") { + val mediumId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.UNASSIGN_PERSON_FROM_MEDIUM) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + MediumPersonChanged( + oldPersonId = null, + newPersonId = null, + id = mediumId, + ), + ) + + emitMessage(Topics.Event.MEDIUM_PERSON_CHANGED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = api.unassignPersonFromMediumAsync(mediumId).await() + + result.id.shouldBeEqual(mediumId) + result.newPersonId.shouldBeNull() + + harness + .publishedPayload(Topics.Command.UNASSIGN_PERSON_FROM_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"mediumId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/UnregisterSmartphoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/UnregisterSmartphoneTest.kt new file mode 100644 index 00000000..63f27ef1 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/UnregisterSmartphoneTest.kt @@ -0,0 +1,47 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.unregisterSmartphoneAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.SmartphoneUnregistered +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class UnregisterSmartphoneTest : + FunSpec({ + test("Unregister smartphone") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.UNREGISTER_SMARTPHONE) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + SmartphoneUnregistered( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ), + ) + + emitMessage(Topics.Event.SMARTPHONE_UNREGISTERED, encodeEvent(apiEvent)) + } + + val api = harness.api + val result = + api.unregisterSmartphoneAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") + ) + .await() + + result.id!!.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + + harness + .publishedPayload(Topics.Command.UNREGISTER_SMARTPHONE) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/WithdrawAuthorizationProfileFromMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/WithdrawAuthorizationProfileFromMediumTest.kt new file mode 100644 index 00000000..5e995212 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/command/WithdrawAuthorizationProfileFromMediumTest.kt @@ -0,0 +1,57 @@ +package com.open200.xesar.connect.command + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.withdrawAuthorizationProfileFromMediumAsync +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.AuthorizationProfileWithdrawnFromMedium +import com.open200.xesar.connect.messages.event.encodeEvent +import com.open200.xesar.connect.util.MockedXesarConnect +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.time.LocalDateTime +import java.util.* +import kotlinx.coroutines.test.runTest + +class WithdrawAuthorizationProfileFromMediumTest : + FunSpec({ + test("withdraw authorization profile from medium") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Command.WITHDRAW_AUTHORIZATION_PROFILE_FROM_MEDIUM) { + val apiEvent = + ApiEvent( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + AuthorizationProfileWithdrawnFromMedium( + id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + withdrawnAt = LocalDateTime.parse("2023-08-24T16:25:52.225991"), + authorizationProfileId = + UUID.fromString("00000000-0000-0000-0000-000000000001"), + ), + ) + + emitMessage( + Topics.Event.AUTHORIZATION_PROFILE_WITHDRAWN_FROM_MEDIUM, + encodeEvent(apiEvent), + ) + } + + val api = harness.api + val result = + api.withdrawAuthorizationProfileFromMediumAsync( + UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), + null, + ) + .await() + result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) + result.authorizationProfileId?.shouldBeEqual( + UUID.fromString("00000000-0000-0000-0000-000000000001") + ) + + harness + .publishedPayload(Topics.Command.WITHDRAW_AUTHORIZATION_PROFILE_FROM_MEDIUM) + .shouldBeEqual( + "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"authorizationProfileId\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddEntityMetadataDefinitionTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddEntityMetadataDefinitionTest.kt deleted file mode 100644 index cecbf8be..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddEntityMetadataDefinitionTest.kt +++ /dev/null @@ -1,116 +0,0 @@ -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.addEntityMetadataDefinitionAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.EntityMetadata -import com.open200.xesar.connect.messages.EntityType -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class AddEntityMetadataDefinitionTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("add entity metadata definition") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.ADD_ENTITY_METADATA_DEFINITION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"entityType\":\"PERSON\",\"names\":[\"nickname\",\"department\"],\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - entityMetadataDefinitions = - PartitionChanged.EntityMetadataDefinitions( - authorizationProfiles = emptyList(), - identificationMedia = emptyList(), - installationPoints = emptyList(), - persons = - listOf( - EntityMetadata( - id = - UUID.fromString( - "aaaaaaaa-0000-0000-0000-000000000001" - ), - name = "nickname", - ), - EntityMetadata( - id = - UUID.fromString( - "bbbbbbbb-0000-0000-0000-000000000002" - ), - name = "department", - ), - ), - zones = emptyList(), - ), - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - - val result = - api.addEntityMetadataDefinitionAsync( - EntityType.PERSON, - "nickname", - "department", - ) - .await() - - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.entityMetadataDefinitions!! - .persons - .map { it.name } - .shouldBeEqual(listOf("nickname", "department")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddEvvaComponentTest.kt deleted file mode 100644 index c406c7db..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddEvvaComponentTest.kt +++ /dev/null @@ -1,114 +0,0 @@ -package com.open200.xesar.connect.it.command - -import com.open200.xesar.connect.* -import com.open200.xesar.connect.extension.addEvvaComponentAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.ComponentType -import com.open200.xesar.connect.messages.event.* -import com.open200.xesar.connect.messages.query.ComponentStatus -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() - val commandReceived = CompletableDeferred() - - 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) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddInstallationPointAuthorizationToMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddInstallationPointAuthorizationToMediumTest.kt deleted file mode 100644 index 044b62d6..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddInstallationPointAuthorizationToMediumTest.kt +++ /dev/null @@ -1,98 +0,0 @@ -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.addInstallationPointAuthorizationToMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.command.AuthorizationData -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.IndividualAuthorizationsAddedToMedium -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class AddInstallationPointAuthorizationToMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("add installation point authorization to medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.ADD_INSTALLATION_POINT_AUTHORIZATION_TO_MEDIUM -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"authorization\":{\"authorizationName\":\"authorizationName\",\"authorizationProfileId\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"timeProfileName\":\"timeProfileName\",\"authorizationId\":\"8c124504-8263-4201-8b17-f49a6c2f8671\",\"installationPoint\":true,\"timeProfileId\":\"e9b31e62-8969-4794-a219-8c81ff10c91d\"},\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - IndividualAuthorizationsAddedToMedium( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ), - ) - - client - .publishAsync( - Topics.Event.INDIVIDUAL_AUTHORIZATIONS_ADDED_TO_MEDIUM, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync( - Topics(Topics.Event.INDIVIDUAL_AUTHORIZATIONS_ADDED_TO_MEDIUM) - ) - .await() - val authorizationData = - AuthorizationData( - "authorizationName", - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), - "timeProfileName", - UUID.fromString("8c124504-8263-4201-8b17-f49a6c2f8671"), - true, - UUID.fromString("e9b31e62-8969-4794-a219-8c81ff10c91d"), - ) - val result = - api.addInstallationPointAuthorizationToMediumAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - authorizationData, - ) - result - .await() - .id - .shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddInstallationPointToZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddInstallationPointToZoneTest.kt deleted file mode 100644 index 53158869..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddInstallationPointToZoneTest.kt +++ /dev/null @@ -1,91 +0,0 @@ -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.addInstallationPointToZoneAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointsInZoneChanged -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.kotest.matchers.shouldBe -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class AddInstallationPointToZoneTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("add installation point to zone") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.ADD_INSTALLATION_POINT_TO_ZONE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBe( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"id\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointsInZoneChanged( - 123, - listOf(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")), - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINTS_IN_ZONE_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINTS_IN_ZONE_CHANGED)) - .await() - val result = - api.addInstallationPointToZoneAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), - ) - .await() - result.addedInstallationPoints.size.shouldBeEqual(1) - result.aggregateId.shouldBeEqual( - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be") - ) - result.accessId.shouldBeEqual(123) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddSmartphoneToInstallationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddSmartphoneToInstallationTest.kt deleted file mode 100644 index 5e1d632b..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddSmartphoneToInstallationTest.kt +++ /dev/null @@ -1,105 +0,0 @@ -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.addSmartphoneToInstallationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.DisengagePeriod -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.SmartphoneAddedToInstallation -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.shouldBe -import io.mockk.coEvery -import java.time.LocalDateTime -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class AddSmartphoneToInstallationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("add smartphone to installation") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.ADD_SMARTPHONE_TO_INSTALLATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - commandContent.shouldBe( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"accessBeginAt\":null,\"partitionId\":null,\"disengagePeriod\":null,\"authorizationProfileId\":null,\"individualAuthorizations\":[],\"messageLanguage\":null,\"label\":null,\"accessEndAt\":null,\"phoneNumber\":null,\"validityDuration\":null,\"personId\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - SmartphoneAddedToInstallation( - accessBeginAt = LocalDateTime.parse("2024-08-08T12:25"), - partitionId = - UUID.fromString("5679d684-41c6-484c-8292-204feb085ef0"), - disengagePeriod = DisengagePeriod.SHORT, - mediumIdentifier = 8, - authorizationProfileId = - UUID.fromString("00000000-0000-0000-0000-000000000001"), - individualAuthorizations = emptyList(), - sagaId = - UUID.fromString("a14d08c0-6f7a-4fc6-8469-be15a3e7b575"), - messageLanguage = "en", - label = "new f228c89d-c2e1-450d-8b79-89072b7b24c3", - validityBeginAt = LocalDateTime.parse("2024-08-08T12:20"), - accessEndAt = null, - validityEndAt = LocalDateTime.parse("2024-12-09T14:20"), - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - issuedAt = LocalDateTime.parse("2024-08-08T12:29:55.708239786"), - ), - ) - - client - .publishAsync( - Topics.Event.SMARTPHONE_ADDED_TO_INSTALLATION, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.SMARTPHONE_ADDED_TO_INSTALLATION)) - .await() - val result = - api.addSmartphoneToInstallationAsync( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - - result.aggregateId.shouldBe( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddZoneAuthorizationToMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddZoneAuthorizationToMediumTest.kt deleted file mode 100644 index 825e3ca6..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AddZoneAuthorizationToMediumTest.kt +++ /dev/null @@ -1,96 +0,0 @@ -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.addZoneAuthorizationToMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.command.AuthorizationData -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.IndividualAuthorizationsAddedToMedium -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class AddZoneAuthorizationToMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("add installation point authorization to medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.ADD_ZONE_AUTHORIZATION_TO_MEDIUM -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"authorization\":{\"authorizationName\":\"authorizationName\",\"authorizationProfileId\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"timeProfileName\":\"timeProfileName\",\"authorizationId\":\"8c124504-8263-4201-8b17-f49a6c2f8671\",\"installationPoint\":false,\"timeProfileId\":\"e9b31e62-8969-4794-a219-8c81ff10c91d\"},\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - IndividualAuthorizationsAddedToMedium( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ), - ) - - client - .publishAsync( - Topics.Event.INDIVIDUAL_AUTHORIZATIONS_ADDED_TO_MEDIUM, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync( - Topics(Topics.Event.INDIVIDUAL_AUTHORIZATIONS_ADDED_TO_MEDIUM) - ) - .await() - val authorizationData = - AuthorizationData( - "authorizationName", - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), - "timeProfileName", - UUID.fromString("8c124504-8263-4201-8b17-f49a6c2f8671"), - false, - UUID.fromString("e9b31e62-8969-4794-a219-8c81ff10c91d"), - ) - val result = - api.addZoneAuthorizationToMediumAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - authorizationData, - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AssignAuthorizationProfileToMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AssignAuthorizationProfileToMediumTest.kt deleted file mode 100644 index f788831f..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AssignAuthorizationProfileToMediumTest.kt +++ /dev/null @@ -1,112 +0,0 @@ -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.assignAuthorizationProfileToMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.* -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() - val commandReceived = CompletableDeferred() - - 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") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AssignPersonToMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AssignPersonToMediumTest.kt deleted file mode 100644 index a0c57497..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/AssignPersonToMediumTest.kt +++ /dev/null @@ -1,87 +0,0 @@ -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.assignPersonToMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.MediumPersonChanged -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.kotest.matchers.shouldBe -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class AssignPersonToMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("assign person to medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.ASSIGN_PERSON_TO_MEDIUM -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - commandContent.shouldBe( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"personId\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - MediumPersonChanged( - oldPersonId = - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync(Topics.Event.MEDIUM_PERSON_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.MEDIUM_PERSON_CHANGED)).await() - val result = - api.assignPersonToMediumAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), - ) - .await() - - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.oldPersonId!!.shouldBeEqual( - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeAuthorizationProfileMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeAuthorizationProfileMetadataValueTest.kt deleted file mode 100644 index cc413a01..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeAuthorizationProfileMetadataValueTest.kt +++ /dev/null @@ -1,106 +0,0 @@ -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.changeAuthorizationProfileMetadataValueAsync -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.AuthorizationProfileInfoChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangeAuthorizationProfileMetadataValueTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change authorization profile metadata value") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val authorizationProfileId = UUID.fromString("11111111-2222-3333-4444-555555555555") - val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_AUTHORIZATION_PROFILE_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\":\"Test Value\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - AuthorizationProfileInfoChanged( - id = authorizationProfileId, - entityMetadata = - listOf( - EntityMetadata( - id = metadataId, - name = "test", - value = "Test Value", - ) - ), - ), - ) - - client - .publishAsync( - Topics.Event.AUTHORIZATION_PROFILE_INFO_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.AUTHORIZATION_PROFILE_INFO_CHANGED)) - .await() - - val result = - api.changeAuthorizationProfileMetadataValueAsync( - id = authorizationProfileId, - metadataId = metadataId, - value = "Test Value", - ) - .await() - - result.id?.shouldBeEqual(authorizationProfileId) - result.entityMetadata!! - .single { it.id == metadataId } - .value - ?.shouldBeEqual("Test Value") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeAuthorizationTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeAuthorizationTimeProfileTest.kt deleted file mode 100644 index de469e32..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeAuthorizationTimeProfileTest.kt +++ /dev/null @@ -1,96 +0,0 @@ -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.changeAuthorizationTimeProfileAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.AuthorizationTimeProfileChanged -import com.open200.xesar.connect.messages.event.encodeEvent -import com.open200.xesar.connect.util.fixture.TimeProfileFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangeAuthorizationTimeProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change authorization time profile") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_AUTHORIZATION_TIME_PROFILE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"name\":\"timeProfileName\",\"description\":null,\"timeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"days\":[\"MONDAY\"]}],\"exceptionTimeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"calendars\":[\"497f6eca-6276-4993-bfeb-53cbbbba6f08\"]}],\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - AuthorizationTimeProfileChanged( - timeSeries = TimeProfileFixture.timeSeries, - exceptionTimeSeries = TimeProfileFixture.exceptionTimeSerie, - name = "timeProfileName", - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - validStandardTimeProfile = true, - ), - ) - - client - .publishAsync( - Topics.Event.AUTHORIZATION_TIME_PROFILE_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.AUTHORIZATION_TIME_PROFILE_CHANGED)) - .await() - - val result = - api.changeAuthorizationTimeProfileAsync( - timeProfileId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - timeProfileName = "timeProfileName", - timeSeries = TimeProfileFixture.timeSeries, - exceptionTimeSeries = TimeProfileFixture.exceptionTimeSerie, - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.exceptionTimeSeries.shouldBeEqual(TimeProfileFixture.exceptionTimeSerie) - result.name.shouldBeEqual("timeProfileName") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeCalendarTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeCalendarTest.kt deleted file mode 100644 index ad4da8b0..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeCalendarTest.kt +++ /dev/null @@ -1,87 +0,0 @@ -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.changeCalendarAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.CalendarChanged -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.kotest.matchers.shouldBe -import io.mockk.coEvery -import java.time.LocalDate -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangeCalendarTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change calendar") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_CALENDAR -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBe( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"calendarName\",\"specialDays\":[\"2018-02-25\"],\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - CalendarChanged( - "calendarName", - 123, - listOf(LocalDate.parse("2018-02-25")), - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync(Topics.Event.CALENDAR_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.CALENDAR_CHANGED)).await() - val result = - api.changeCalendarAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - "calendarName", - specialDays = listOf(LocalDate.parse("2018-02-25")), - ) - .await() - result.name.shouldBeEqual("calendarName") - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeCodingStationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeCodingStationTest.kt deleted file mode 100644 index 08e91072..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeCodingStationTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -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.changeCodingStationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.CodingStationChanged -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.kotest.matchers.shouldBe -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangeCodingStationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change coding station") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_CODING_STATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBe( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"name\":\"codingStationName\",\"description\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - CodingStationChanged( - name = "codingStationName", - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync( - Topics.Event.CODING_STATION_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.CODING_STATION_CHANGED)).await() - val result = - api.changeCodingStationAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - "codingStationName", - ) - .await() - result.name?.shouldBeEqual("codingStationName") - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeInstallationPointMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeInstallationPointMetadataValueTest.kt deleted file mode 100644 index c403c116..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeInstallationPointMetadataValueTest.kt +++ /dev/null @@ -1,105 +0,0 @@ -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.changeInstallationPointMetadataValueAsync -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.InstallationPointChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangeInstallationPointMetadataValueTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change installation point metadata value") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val installationPointId = UUID.fromString("11111111-2222-3333-4444-555555555555") - val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_INSTALLATION_POINT_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\":\"Test Value\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointChanged( - aggregateId = installationPointId, - entityMetadata = - listOf( - EntityMetadata( - id = metadataId, - name = "test", - value = "Test Value", - ) - ), - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINT_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINT_CHANGED)).await() - - val result = - api.changeInstallationPointMetadataValueAsync( - id = installationPointId, - metadataId = metadataId, - value = "Test Value", - ) - .await() - - result.aggregateId.shouldBeEqual(installationPointId) - result.entityMetadata!! - .single { it.id == metadataId } - .value - ?.shouldBeEqual("Test Value") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeInstallationPointTest.kt deleted file mode 100644 index 8d82f4d0..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeInstallationPointTest.kt +++ /dev/null @@ -1,87 +0,0 @@ -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.changeInstallationPointAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointChanged -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.kotest.matchers.shouldBe -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangeInstallationPointTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change installation point") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_INSTALLATION_POINT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBe( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"aggregateId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"installationType\":\"installation type\",\"name\":null,\"description\":null,\"installationId\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointChanged( - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - installationType = "installation type", - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINT_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINT_CHANGED)).await() - val result = - api.changeInstallationPointAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - "installation type", - ) - .await() - result.installationType?.shouldBeEqual("installation type") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeMediumMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeMediumMetadataValueTest.kt deleted file mode 100644 index 9adf34b5..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeMediumMetadataValueTest.kt +++ /dev/null @@ -1,104 +0,0 @@ -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() - val commandReceived = CompletableDeferred() - - 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", - ) - ), - ), - ) - - 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") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeOfficeModeTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeOfficeModeTimeProfileTest.kt deleted file mode 100644 index 51957ae5..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeOfficeModeTimeProfileTest.kt +++ /dev/null @@ -1,90 +0,0 @@ -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.changeOfficeModeTimeProfileAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.OfficeModeTimeProfileChanged -import com.open200.xesar.connect.messages.event.encodeEvent -import com.open200.xesar.connect.util.fixture.TimeProfileFixture -import io.kotest.common.runBlocking -import io.kotest.core.spec.style.FunSpec -import io.kotest.extensions.testcontainers.perProject -import io.kotest.matchers.shouldBe -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangeOfficeModeTimeProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change office mode time profile") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_OFFICE_MODE_TIME_PROFILE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - println(commandContent) - commandContent.shouldBe( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"name\":\"name\",\"description\":null,\"timeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"days\":[\"MONDAY\"]}],\"exceptionTimeSeries\":[],\"exceptionTimePointSeries\":[],\"timePointSeries\":[],\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - OfficeModeTimeProfileChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - name = "name", - timeSeries = TimeProfileFixture.timeSeries, - ), - ) - - client - .publishAsync( - Topics.Event.OFFICE_MODE_TIME_PROFILE_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.OFFICE_MODE_TIME_PROFILE_CHANGED)) - .await() - val result = - api.changeOfficeModeTimeProfileAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - "name", - timeSeries = TimeProfileFixture.timeSeries, - ) - .await() - result.id.shouldBe(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.timeSeries.shouldBe(TimeProfileFixture.timeSeries) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangePersonInformationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangePersonInformationTest.kt deleted file mode 100644 index e76167f3..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangePersonInformationTest.kt +++ /dev/null @@ -1,87 +0,0 @@ -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.changePersonInformationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PersonChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangePersonInformationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change person information") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_PERSON_INFORMATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"firstName\":\"first name\",\"lastName\":\"last name\",\"identifier\":\"\",\"externalId\":\"EXT-4711\",\"id\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PersonChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - firstName = "first name", - lastName = "last name", - identifier = "", - ), - ) - - client - .publishAsync(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PERSON_CHANGED)).await() - val result = - api.changePersonInformationAsync( - firstName = "first name", - lastName = "last name", - identifier = "", - externalId = "EXT-4711", - ) - .await() - result.firstName.shouldBeEqual("first name") - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangePersonMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangePersonMetadataValueTest.kt deleted file mode 100644 index 3c854af0..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangePersonMetadataValueTest.kt +++ /dev/null @@ -1,187 +0,0 @@ -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.changePersonMetadataValueAsync -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.PersonChanged -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.util.UUID -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangePersonMetadataValueTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change person metadata value via externalId") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val externalId = "P-12345" - val personId = UUID.fromString("11111111-2222-3333-4444-555555555555") - val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_PERSON_METADATA_VALUE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - // Order-sensitive raw JSON - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"externalId\":\"P-12345\",\"id\":null,\"metadataId\":\"aaaaaaaa-0000-0000-0000-000000000001\",\"value\":\"Sales\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - // Simulate success PERSON_CHANGED with updated entity metadata - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PersonChanged( - firstName = "Tester", - lastName = "Testington", - id = personId, - entityMetadata = - listOf( - EntityMetadata( - id = metadataId, - name = "department", - value = "Sales", - ) - ), - ), - ) - - client - .publishAsync(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PERSON_CHANGED)).await() - - val result = - api.changePersonMetadataValueAsync( - externalId = externalId, - id = null, - metadataId = metadataId, - value = "Sales", - ) - .await() - - result.id.shouldBeEqual(personId) - result.entityMetadata!! - .single { it.id == metadataId } - .value - ?.shouldBeEqual("Sales") - } - } - } - - test("change person metadata value via id") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val personId = UUID.fromString("11111111-2222-3333-4444-555555555555") - val metadataId = UUID.fromString("bbbbbbbb-0000-0000-0000-000000000002") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_PERSON_METADATA_VALUE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - // Order-sensitive raw JSON - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"externalId\":null,\"id\":\"$personId\",\"metadataId\":\"$metadataId\",\"value\":\"Team Blue\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PersonChanged( - firstName = "Tester", - lastName = "Testington", - id = personId, - entityMetadata = - listOf( - EntityMetadata( - id = metadataId, - name = "team", - value = "Team Blue", - ) - ), - ), - ) - - client - .publishAsync(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PERSON_CHANGED)).await() - - val result = - api.changePersonMetadataValueAsync( - id = personId, - metadataId = metadataId, - value = "Team Blue", - ) - .await() - - result.id.shouldBeEqual(personId) - result.entityMetadata!! - .single { it.id == metadataId } - .value - ?.shouldBeEqual("Team Blue") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeZoneDataTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeZoneDataTest.kt deleted file mode 100644 index 5fec01d2..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeZoneDataTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.changeZoneDataAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.ZoneChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangeZoneDataTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change zone data") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_ZONE_DATA -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"zoneName\",\"description\":\"zoneDescription\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - ZoneChanged( - "zoneName", - "zoneDescription", - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync(Topics.Event.ZONE_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.ZONE_CHANGED)).await() - val result = - api.changeZoneDataAsync( - "zoneName", - "zoneDescription", - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.description.shouldBeEqual("zoneDescription") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeZoneMetadataValueTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeZoneMetadataValueTest.kt deleted file mode 100644 index a0bfd903..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ChangeZoneMetadataValueTest.kt +++ /dev/null @@ -1,104 +0,0 @@ -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.changeZoneMetadataValueAsync -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.ZoneChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ChangeZoneMetadataValueTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("change zone metadata value") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val zoneId = UUID.fromString("11111111-2222-3333-4444-555555555555") - val metadataId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CHANGE_ZONE_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\":\"Top Secret\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - ZoneChanged( - name = "Test Zone", - description = "Test Description", - id = zoneId, - entityMetadata = - listOf( - EntityMetadata( - id = metadataId, - name = "security clearance required", - value = "Top Secret", - ) - ), - ), - ) - - client - .publishAsync(Topics.Event.ZONE_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.ZONE_CHANGED)).await() - - val result = - api.changeZoneMetadataValueAsync( - id = zoneId, - metadataId = metadataId, - value = "Top Secret", - ) - .await() - - result.id.shouldBeEqual(zoneId) - result.entityMetadata!! - .single { it.id == metadataId } - .value - ?.shouldBeEqual("Top Secret") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureAssignableAuthorizationProfilesTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureAssignableAuthorizationProfilesTest.kt deleted file mode 100644 index e84aaacb..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureAssignableAuthorizationProfilesTest.kt +++ /dev/null @@ -1,87 +0,0 @@ -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.configureAssignableAuthorizationProfilesAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.UserGroupChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ConfigureAssignableAuthorizationProfilesTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("configure assignable authorization profiles") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CONFIGURE_ASSIGNABLE_AUTHORIZATION_PROFILES -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"assignableAuthorizationProfiles\":[\"4e6f78d6-51c7-4bc2-a992-78971eecfbda\"],\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - UserGroupChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - name = "name", - description = "description", - assignableAuthorizationProfiles = - listOf( - UUID.fromString("4e6f78d6-51c7-4bc2-a992-78971eecfbda") - ), - ), - ) - - client - .publishAsync(Topics.Event.USER_GROUP_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.USER_GROUP_CHANGED)).await() - val result = - api.configureAssignableAuthorizationProfilesAsync( - listOf(UUID.fromString("4e6f78d6-51c7-4bc2-a992-78971eecfbda")), - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureBluetoothStateTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureBluetoothStateTest.kt deleted file mode 100644 index ac443a0c..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureBluetoothStateTest.kt +++ /dev/null @@ -1,88 +0,0 @@ -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.configureBluetoothStateAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.BluetoothState -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointChanged -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.kotest.matchers.shouldBe -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ConfigureBluetoothStateTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("configure bluetooth state of an installation point") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CONFIGURE_BLUETOOTH_STATE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"bluetoothState\":\"ENABLED\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointChanged( - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - bluetoothState = BluetoothState.ENABLED, - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINT_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINT_CHANGED)).await() - val result = - api.configureBluetoothStateAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - BluetoothState.ENABLED, - ) - .await() - result.bluetoothState.shouldBe(BluetoothState.ENABLED) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureManualOfficeModeAndShopModeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureManualOfficeModeAndShopModeTest.kt deleted file mode 100644 index 5f2ea766..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureManualOfficeModeAndShopModeTest.kt +++ /dev/null @@ -1,88 +0,0 @@ -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.configureManualOfficeModeAndShopModeMapiAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointChanged -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.booleans.shouldBeTrue -import io.kotest.matchers.equals.shouldBeEqual -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ConfigureManualOfficeModeAndShopModeTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("configure assignable authorization profiles") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CONFIGURE_MANUAL_OFFICE_MODE_AND_SHOP_MODE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"shopMode\":true,\"manualOfficeMode\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointChanged( - shopMode = true, - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINT_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINT_CHANGED)).await() - val result = - api.configureManualOfficeModeAndShopModeMapiAsync( - shopMode = true, - installationPointId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.shopMode?.shouldBeTrue() - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureMediaUpgradeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureMediaUpgradeTest.kt deleted file mode 100644 index 29ecf7fc..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureMediaUpgradeTest.kt +++ /dev/null @@ -1,87 +0,0 @@ -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.configureMediaUpgradeMapiAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointChanged -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.booleans.shouldBeTrue -import io.kotest.matchers.equals.shouldBeEqual -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ConfigureMediaUpgradeTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("configure media upgrade") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CONFIGURE_MEDIA_UPGRADE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"upgradeMedia\":true,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointChanged( - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - upgradeMedia = true, - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINT_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINT_CHANGED)).await() - val result = - api.configureMediaUpgradeMapiAsync( - true, - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.upgradeMedia?.shouldBeTrue() - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureOfficeModeTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureOfficeModeTimeProfileTest.kt deleted file mode 100644 index 4699dba3..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureOfficeModeTimeProfileTest.kt +++ /dev/null @@ -1,87 +0,0 @@ -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.configureOfficeModeTimeProfileAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointChanged -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.kotest.matchers.nulls.shouldBeNull -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ConfigureOfficeModeTimeProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("configure media upgrade") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CONFIGURE_OFFICE_MODE_TIME_PROFILE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"timeProfileId\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointChanged( - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - timeProfileId = null, - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINT_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINT_CHANGED)).await() - val result = - api.configureOfficeModeTimeProfileAsync( - null, - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.timeProfileId.shouldBeNull() - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureReleaseDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureReleaseDurationTest.kt deleted file mode 100644 index 1b636247..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfigureReleaseDurationTest.kt +++ /dev/null @@ -1,89 +0,0 @@ -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.configureReleaseDurationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ConfigureReleaseDurationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("configure release duration") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CONFIGURE_RELEASE_DURATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"releaseDurationShort\":10,\"releaseDurationLong\":20,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointChanged( - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - releaseDurationShort = 10, - releaseDurationLong = 20, - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINT_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINT_CHANGED)).await() - val result = - api.configureReleaseDurationAsync( - 10, - 20, - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.releaseDurationShort?.shouldBeEqual(10) - result.releaseDurationLong?.shouldBeEqual(20) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfirmSmartphoneRevokeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfirmSmartphoneRevokeTest.kt deleted file mode 100644 index 0d6ea12d..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfirmSmartphoneRevokeTest.kt +++ /dev/null @@ -1,92 +0,0 @@ -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.confirmSmartphoneRevokeAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.SmartphoneRevokeConfirmed -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.util.UUID -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ConfirmSmartphoneRevokeTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("confirm smartphone revoke in Self Service Mode") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val smartphoneId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - val transactionId = UUID.fromString("1e4a12b3-3c5f-4a6e-9b7d-8f0e1d2c3b4a") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CONFIRM_SMARTPHONE_REVOKE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\"," + - "\"mediumId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\"," + - "\"transactionId\":\"1e4a12b3-3c5f-4a6e-9b7d-8f0e1d2c3b4a\"," + - "\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - SmartphoneRevokeConfirmed( - mediumId = smartphoneId, - transactionId = transactionId, - ), - ) - - client - .publishAsync( - Topics.Event.SMARTPHONE_REVOKE_CONFIRMED, - encodeEvent(apiEvent), - ) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.SMARTPHONE_REVOKE_CONFIRMED)).await() - - val result = - api.confirmSmartphoneRevokeAsync(smartphoneId, transactionId).await() - - result.mediumId.shouldBeEqual(smartphoneId) - result.transactionId.shouldBeEqual(transactionId) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfirmSmartphoneUpdateTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfirmSmartphoneUpdateTest.kt deleted file mode 100644 index 7f87b490..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ConfirmSmartphoneUpdateTest.kt +++ /dev/null @@ -1,92 +0,0 @@ -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.confirmSmartphoneUpdateAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.SmartphoneUpdateConfirmed -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.util.UUID -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ConfirmSmartphoneUpdateTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("confirm smartphone update in Self Service Mode") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val smartphoneId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - val transactionId = UUID.fromString("1e4a12b3-3c5f-4a6e-9b7d-8f0e1d2c3b4a") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CONFIRM_SMARTPHONE_UPDATE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\"," + - "\"mediumId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\"," + - "\"transactionId\":\"1e4a12b3-3c5f-4a6e-9b7d-8f0e1d2c3b4a\"," + - "\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - SmartphoneUpdateConfirmed( - mediumId = smartphoneId, - transactionId = transactionId, - ), - ) - - client - .publishAsync( - Topics.Event.SMARTPHONE_UPDATE_CONFIRMED, - encodeEvent(apiEvent), - ) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.SMARTPHONE_UPDATE_CONFIRMED)).await() - - val result = - api.confirmSmartphoneUpdateAsync(smartphoneId, transactionId).await() - - result.mediumId.shouldBeEqual(smartphoneId) - result.transactionId.shouldBeEqual(transactionId) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateAuthorizationProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateAuthorizationProfileTest.kt deleted file mode 100644 index cf8fe4f3..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateAuthorizationProfileTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -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.createAuthorizationProfileAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.AuthorizationProfileCreated -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.kotest.matchers.shouldBe -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class CreateAuthorizationProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("create an authorization profile") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CREATE_AUTHORIZATION_PROFILE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"authorizationProfile1\",\"description\":\"\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - AuthorizationProfileCreated( - true, - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - "authorizationProfile1", - "", - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - true, - ), - ) - - client - .publishAsync( - Topics.Event.AUTHORIZATION_PROFILE_CREATED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.AUTHORIZATION_PROFILE_CREATED)).await() - val result = - api.createAuthorizationProfileAsync( - "authorizationProfile1", - "", - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.name.shouldBe("authorizationProfile1") - result.partitionId.shouldBe( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateAuthorizationTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateAuthorizationTimeProfileTest.kt deleted file mode 100644 index 67220e06..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateAuthorizationTimeProfileTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -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.createAuthorizationTimeProfileAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.AuthorizationTimeProfileCreated -import com.open200.xesar.connect.messages.event.encodeEvent -import com.open200.xesar.connect.messages.query.TimeProfileType -import com.open200.xesar.connect.util.fixture.TimeProfileFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class CreateAuthorizationTimeProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("create authorization time profile") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CREATE_AUTHORIZATION_TIME_PROFILE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"timeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"days\":[\"MONDAY\"]}],\"exceptionTimeSeries\":[],\"name\":\"timeProfileName\",\"description\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - AuthorizationTimeProfileCreated( - timeSeries = TimeProfileFixture.timeSeries, - name = "timeProfileName", - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - type = TimeProfileType.AUTHORIZATION_PROFILE, - validStandardTimeProfile = true, - ), - ) - - client - .publishAsync( - Topics.Event.AUTHORIZATION_TIME_PROFILE_CREATED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.AUTHORIZATION_TIME_PROFILE_CREATED)) - .await() - val result = - api.createAuthorizationTimeProfileAsync( - name = "timeProfileName", - timeProfileId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - timeSeries = TimeProfileFixture.timeSeries, - ) - .await() - result.name.shouldBeEqual("timeProfileName") - result.type.shouldBeEqual(TimeProfileType.AUTHORIZATION_PROFILE) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateCalendarTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateCalendarTest.kt deleted file mode 100644 index 8859ebcb..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateCalendarTest.kt +++ /dev/null @@ -1,88 +0,0 @@ -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.createCalendarAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.CalendarCreated -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.LocalDate -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class CreateCalendarTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("create calendar") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CREATE_CALENDAR -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"calendarName\",\"specialDays\":[\"2018-02-25\"],\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - CalendarCreated( - UUID.fromString("905a9d0a-111f-44ad-a871-f9d0a24335f3"), - 123, - "calendarName", - listOf(LocalDate.parse("2018-02-25")), - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync(Topics.Event.CALENDAR_CREATED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.CALENDAR_CREATED)).await() - val result = - api.createCalendarAsync( - "calendarName", - listOf(LocalDate.parse("2018-02-25")), - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.name.shouldBeEqual("calendarName") - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateCodingStationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateCodingStationTest.kt deleted file mode 100644 index 315ab926..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateCodingStationTest.kt +++ /dev/null @@ -1,88 +0,0 @@ -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.createCodingStationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.CodingStationCreated -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class CreateCodingStationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("create coding station") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CREATE_CODING_STATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"name\":\"coding station name\",\"description\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - CodingStationCreated( - partitionId = - UUID.fromString("5c4d62bb-cdf9-4630-83ff-816ee8166d62"), - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - name = "coding station name", - ), - ) - - client - .publishAsync( - Topics.Event.CODING_STATION_CREATED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.CODING_STATION_CREATED)).await() - val result = - api.createCodingStationAsync( - name = "coding station name", - codingStationId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateInstallationPointTest.kt deleted file mode 100644 index 0adf16b1..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateInstallationPointTest.kt +++ /dev/null @@ -1,114 +0,0 @@ -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.createInstallationPointAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.ComponentType -import com.open200.xesar.connect.messages.event.* -import com.open200.xesar.connect.messages.query.ComponentStatus -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 CreateInstallationPointTest : - 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() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CREATE_INSTALLATION_POINT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"componentType\":\"Cylinder\",\"aggregateId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"linkedInstallationPoints\":{},\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointCreated( - id = 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_CREATED, - 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_CREATED, - Topics.Event.EVVA_COMPONENT_ADDED, - ) - ) - .await() - - val createInstallationPointResult = - api.createInstallationPointAsync( - ComponentType.Cylinder, - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - val test = - createInstallationPointResult.installationPointCreatedDeferred.await() - test.id.shouldBe(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - val evvaComponentAdded = - createInstallationPointResult.evvaComponentAddedDeferred.await() - evvaComponentAdded.type.shouldBe(ComponentType.Cylinder) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateOfficeModeTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateOfficeModeTimeProfileTest.kt deleted file mode 100644 index f09a8040..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateOfficeModeTimeProfileTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -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.createOfficeModeTimeProfileAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.OfficeModeTimeProfileCreated -import com.open200.xesar.connect.messages.event.encodeEvent -import com.open200.xesar.connect.util.fixture.TimeProfileFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class CreateOfficeModeTimeProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("create office mode time profile") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CREATE_OFFICE_MODE_TIME_PROFILE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"timeSeries\":[{\"times\":[{\"start\":\"14:15:00\",\"end\":\"14:15:00\"}],\"days\":[\"MONDAY\"]}],\"exceptionTimeSeries\":[],\"exceptionTimePointSeries\":[],\"name\":\"timeProfileName\",\"description\":null,\"timePointSeries\":[],\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - OfficeModeTimeProfileCreated( - name = "timeProfileName", - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - timeSeries = TimeProfileFixture.timeSeries, - exceptionTimeSeries = listOf(), - exceptionTimePointSeries = listOf(), - timePointSeries = listOf(), - ), - ) - - client - .publishAsync( - Topics.Event.OFFICE_MODE_TIME_PROFILE_CREATED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.OFFICE_MODE_TIME_PROFILE_CREATED)) - .await() - val result = - api.createOfficeModeTimeProfileAsync( - name = "timeProfileName", - timeSeries = TimeProfileFixture.timeSeries, - timeProfileId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.name.shouldBeEqual("timeProfileName") - result.timeSeries.shouldBeEqual(TimeProfileFixture.timeSeries) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreatePersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreatePersonTest.kt deleted file mode 100644 index f156c64c..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreatePersonTest.kt +++ /dev/null @@ -1,89 +0,0 @@ -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.createPersonAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.PersonalLog -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PersonCreated -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class CreatePersonTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("create person") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CREATE_PERSON -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"firstName\":\"firstName\",\"lastName\":\"lastName\",\"identifier\":null,\"externalId\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"entityMetadata\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PersonCreated( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - firstName = "firstName", - lastName = "lastName", - partitionId = - UUID.fromString("5c4d62bb-cdf9-4630-83ff-816ee8166d62"), - personalReferenceDuration = PersonalLog(days = 30), - ), - ) - - client - .publishAsync(Topics.Event.PERSON_CREATED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PERSON_CREATED)).await() - val result = - api.createPersonAsync( - firstName = "firstName", - lastName = "lastName", - personId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - .await() - result.firstName.shouldBeEqual("firstName") - result.lastName.shouldBeEqual("lastName") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateZoneTest.kt deleted file mode 100644 index 62b54eed..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/CreateZoneTest.kt +++ /dev/null @@ -1,91 +0,0 @@ -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.createZoneAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.ZoneCreated -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class CreateZoneTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("create zone") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.CREATE_ZONE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPoints\":[\"720eb694-a085-47e8-8f18-512aa1a63bef\",\"c457a028-dd08-4040-a1bb-17767e2b2c28\"],\"name\":\"zoneName\",\"description\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - ZoneCreated( - 123, - UUID.fromString("dc6f8102-af8f-4e8d-afd4-2d6ed1f5722d"), - "zoneName", - null, - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync(Topics.Event.ZONE_CREATED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.ZONE_CREATED)).await() - val result = - api.createZoneAsync( - name = "zoneName", - zoneId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - installationPoints = - listOf( - UUID.fromString("720eb694-a085-47e8-8f18-512aa1a63bef"), - UUID.fromString("c457a028-dd08-4040-a1bb-17767e2b2c28"), - ), - ) - .await() - result.name.shouldBeEqual("zoneName") - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteAuthorizationProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteAuthorizationProfileTest.kt deleted file mode 100644 index 38e481c3..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteAuthorizationProfileTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -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.deleteAuthorizationProfileAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.AuthorizationProfileDeleted -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.booleans.shouldBeFalse -import io.kotest.matchers.equals.shouldBeEqual -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class DeleteAuthorizationProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("delete authorization profile") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.DELETE_AUTHORIZATION_PROFILE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - AuthorizationProfileDeleted( - individual = false, - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync( - Topics.Event.AUTHORIZATION_PROFILE_DELETED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.AUTHORIZATION_PROFILE_DELETED)).await() - val result = - api.deleteAuthorizationProfileAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.individual.shouldBeFalse() - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteAuthorizationTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteAuthorizationTimeProfileTest.kt deleted file mode 100644 index fef6e170..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteAuthorizationTimeProfileTest.kt +++ /dev/null @@ -1,84 +0,0 @@ -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.deleteAuthorizationTimeProfileAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.AuthorizationTimeProfileDeleted -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class DeleteAuthorizationTimeProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("create authorization time profile") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.DELETE_AUTHORIZATION_TIME_PROFILE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - AuthorizationTimeProfileDeleted( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ), - ) - - client - .publishAsync( - Topics.Event.AUTHORIZATION_TIME_PROFILE_DELETED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.AUTHORIZATION_TIME_PROFILE_DELETED)) - .await() - val result = - api.deleteAuthorizationTimeProfileAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteCalendarTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteCalendarTest.kt deleted file mode 100644 index e780729c..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteCalendarTest.kt +++ /dev/null @@ -1,81 +0,0 @@ -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.deleteCalendarAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.CalendarDeleted -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class DeleteCalendarTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("delete calendar") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.DELETE_CALENDAR -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - CalendarDeleted( - 123, - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync(Topics.Event.CALENDAR_DELETED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.CALENDAR_DELETED)).await() - val result = - api.deleteCalendarAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteCodingStationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteCodingStationTest.kt deleted file mode 100644 index 110a0158..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteCodingStationTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.deleteCodingStationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.CodingStationDeleted -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class DeleteCodingStationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("delete coding station") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.DELETE_CODING_STATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - CodingStationDeleted( - LocalDateTime.parse("2023-07-05T15:22:13.509825"), - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync( - Topics.Event.CODING_STATION_DELETED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.CODING_STATION_DELETED)).await() - val result = - api.deleteCodingStationAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteEntityMetadataDefinitionTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteEntityMetadataDefinitionTest.kt deleted file mode 100644 index 8b6c6480..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteEntityMetadataDefinitionTest.kt +++ /dev/null @@ -1,105 +0,0 @@ -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.deleteEntityMetadataDefinitionAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.EntityMetadata -import com.open200.xesar.connect.messages.EntityType -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class DeleteEntityMetadataDefinitionTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("delete entity metadata definition") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.DELETE_ENTITY_METADATA_DEFINITION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"entityType\":\"PERSON\",\"names\":[\"department\"],\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - entityMetadataDefinitions = - PartitionChanged.EntityMetadataDefinitions( - authorizationProfiles = emptyList(), - identificationMedia = emptyList(), - installationPoints = emptyList(), - persons = - listOf( - EntityMetadata( - id = - UUID.fromString( - "aaaaaaaa-0000-0000-0000-000000000001" - ), - name = "nickname", - ) - ), - zones = emptyList(), - ), - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - - val result = - api.deleteEntityMetadataDefinitionAsync(EntityType.PERSON, "department") - .await() - - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.entityMetadataDefinitions!! - .persons - .map { it.name } - .shouldBeEqual(listOf("nickname")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteInstallationPointTest.kt deleted file mode 100644 index 10f9609b..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteInstallationPointTest.kt +++ /dev/null @@ -1,90 +0,0 @@ -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.deleteInstallationPointAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointDeleted -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class DeleteInstallationPointTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("delete installation point") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.DELETE_INSTALLATION_POINT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointDeleted( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - linkedInstallationPoints = - listOf( - UUID.fromString("dc6f8102-af8f-4e8d-afd4-2d6ed1f5722d") - ), - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINT_DELETED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINT_DELETED)).await() - val result = - api.deleteInstallationPointAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.linkedInstallationPoints.shouldBeEqual( - listOf(UUID.fromString("dc6f8102-af8f-4e8d-afd4-2d6ed1f5722d")) - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteOfficeModeTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteOfficeModeTimeProfileTest.kt deleted file mode 100644 index f8fd5160..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteOfficeModeTimeProfileTest.kt +++ /dev/null @@ -1,84 +0,0 @@ -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.deleteOfficeModeTimeProfileAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.OfficeModeTimeProfileDeleted -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class DeleteOfficeModeTimeProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("delete office mode time profile") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.DELETE_OFFICE_MODE_TIME_PROFILE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - OfficeModeTimeProfileDeleted( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ), - ) - - client - .publishAsync( - Topics.Event.OFFICE_MODE_TIME_PROFILE_DELETED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.OFFICE_MODE_TIME_PROFILE_DELETED)) - .await() - val result = - api.deleteOfficeModeTimeProfileAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeletePersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeletePersonTest.kt deleted file mode 100644 index fe18ad27..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeletePersonTest.kt +++ /dev/null @@ -1,77 +0,0 @@ -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.deletePersonAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PersonDeleted -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class DeletePersonTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("delete person") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.DELETE_PERSON -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"externalId\":\"EXT-123\",\"id\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PersonDeleted( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ), - ) - - client - .publishAsync(Topics.Event.PERSON_DELETED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PERSON_DELETED)).await() - val result = api.deletePersonAsync("EXT-123").await() - - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteZoneTest.kt deleted file mode 100644 index 40ffda9b..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/DeleteZoneTest.kt +++ /dev/null @@ -1,80 +0,0 @@ -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.deleteZoneAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.ZoneDeleted -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class DeleteZoneTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("delete zone") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.DELETE_ZONE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - ZoneDeleted( - deletedAt = LocalDateTime.parse("2023-06-15T16:25:52.225991"), - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync(Topics.Event.ZONE_DELETED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.ZONE_DELETED)).await() - val result = - api.deleteZoneAsync(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/FindComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/FindComponentTest.kt deleted file mode 100644 index 71356b88..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/FindComponentTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.findComponentAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.FindComponentPerformed -import com.open200.xesar.connect.messages.event.encodeEvent -import com.open200.xesar.connect.util.fixture.InstallationPointFixture -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.ktor.http.* -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class FindComponentTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("find Component with success") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.FIND_COMPONENT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"${InstallationPointFixture.installationPointFixture.id}\",\"enable\":true,\"token\":\"${MosquittoContainer.TOKEN}\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - FindComponentPerformed("ok"), - ) - - client - .publishAsync( - Topics.Event.FIND_COMPONENT_PERFORMED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.FIND_COMPONENT_PERFORMED)).await() - val result = - api.findComponentAsync( - InstallationPointFixture.installationPointFixture.id, - true, - ) - .await() - - result.ok.shouldBeEqual("ok") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ForceRemoveEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ForceRemoveEvvaComponentTest.kt deleted file mode 100644 index a17e67d4..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ForceRemoveEvvaComponentTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -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.forceRemoveEvvaComponentAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.EvvaComponentRemoved -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ForceRemoveEvvaComponentTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("force remove evva component") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.FORCE_REMOVE_EVVA_COMPONENT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - EvvaComponentRemoved( - accessId = 123, - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - useOddKey = true, - forced = true, - stateChangedAt = - LocalDateTime.parse("2023-06-15T16:23:25.229593"), - nonce = 1, - ), - ) - - client - .publishAsync( - Topics.Event.EVVA_COMPONENT_REMOVED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.EVVA_COMPONENT_REMOVED)).await() - val result = - api.forceRemoveEvvaComponentAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - result.aggregateId.shouldBeEqual( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - result.accessId.shouldBeEqual(123) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/PrepareRemovalOfEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/PrepareRemovalOfEvvaComponentTest.kt deleted file mode 100644 index ebb477ea..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/PrepareRemovalOfEvvaComponentTest.kt +++ /dev/null @@ -1,90 +0,0 @@ -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.prepareRemovalOfEvvaComponentAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.EvvaComponentRemovalPrepared -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class PrepareRemovalOfEvvaComponentTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("prepare removal of evva component") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.PREPARE_REMOVAL_OF_EVVA_COMPONENT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - EvvaComponentRemovalPrepared( - stateChangeAt = - LocalDateTime.parse("2023-06-15T16:25:52.225991"), - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync( - Topics.Event.EVVA_COMPONENT_REMOVAL_PREPARED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.EVVA_COMPONENT_REMOVAL_PREPARED)).await() - - val result = - api.prepareRemovalOfEvvaComponentAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - result.aggregateId.shouldBeEqual( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoteDisengagePermanentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoteDisengagePermanentTest.kt deleted file mode 100644 index dd782ad8..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoteDisengagePermanentTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -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.executeRemoteDisengagePermanentAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.RemoteDisengagePerformed -import com.open200.xesar.connect.messages.event.encodeEvent -import com.open200.xesar.connect.util.fixture.InstallationPointFixture -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.ktor.http.* -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RemoteDisengagePermanentTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("remote disengage permanent with success") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.REMOTE_DISENGAGE_PERMANENT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"${InstallationPointFixture.installationPointFixture.id}\",\"enable\":true,\"token\":\"${MosquittoContainer.TOKEN}\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - RemoteDisengagePerformed("ok"), - ) - - client - .publishAsync( - Topics.Event.REMOTE_DISENGAGE_PERMANENT_PERFORMED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.REMOTE_DISENGAGE_PERMANENT_PERFORMED)) - .await() - val result = - api.executeRemoteDisengagePermanentAsync( - InstallationPointFixture.installationPointFixture.id, - true, - ) - .await() - - result.ok.shouldBeEqual("ok") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoteDisengageTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoteDisengageTest.kt deleted file mode 100644 index 870a90cb..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoteDisengageTest.kt +++ /dev/null @@ -1,84 +0,0 @@ -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.executeRemoteDisengageAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.* -import com.open200.xesar.connect.util.fixture.InstallationPointFixture -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.ktor.http.* -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RemoteDisengageTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("remote disengage with success") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.REMOTE_DISENGAGE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"${InstallationPointFixture.installationPointFixture.id}\",\"extended\":true,\"token\":\"${MosquittoContainer.TOKEN}\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - RemoteDisengagePerformed("ok"), - ) - val remoteDisengagePerformed = encodeEvent(apiEvent) - - client - .publishAsync( - Topics.Event.REMOTE_DISENGAGE_PERFORMED, - remoteDisengagePerformed, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.REMOTE_DISENGAGE_PERFORMED)).await() - val result = - api.executeRemoteDisengageAsync( - InstallationPointFixture.installationPointFixture.id, - true, - ) - .await() - - result.ok.shouldBeEqual("ok") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveInstallationPointAuthorizationFromMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveInstallationPointAuthorizationFromMediumTest.kt deleted file mode 100644 index ccd6f02e..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveInstallationPointAuthorizationFromMediumTest.kt +++ /dev/null @@ -1,90 +0,0 @@ -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.removeInstallationPointAuthorizationFromMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.IndividualAuthorizationsDeleted -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RemoveInstallationPointAuthorizationFromMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("remove installation point authorization from medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command - .REMOVE_INSTALLATION_POINT_AUTHORIZATION_FROM_MEDIUM -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"authorization\":\"8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - IndividualAuthorizationsDeleted( - listOf(UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f")), - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync( - Topics.Event.INDIVIDUAL_AUTHORIZATIONS_DELETED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INDIVIDUAL_AUTHORIZATIONS_DELETED)) - .await() - - val result = - api.removeInstallationPointAuthorizationFromMediumAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f"), - ) - .await() - result.mediumId.shouldBeEqual( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveInstallationPointFromZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveInstallationPointFromZoneTest.kt deleted file mode 100644 index cfe71e17..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveInstallationPointFromZoneTest.kt +++ /dev/null @@ -1,96 +0,0 @@ -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.removeInstallationPointFromZoneAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointsInZoneChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RemoveInstallationPointFromZoneTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("remove installation point from zone") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.REMOVE_INSTALLATION_POINT_FROM_ZONE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"installationPointId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"id\":\"8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointsInZoneChanged( - accessId = 123, - removedInstallationPoints = - listOf( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ), - aggregateId = - UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f"), - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINTS_IN_ZONE_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINTS_IN_ZONE_CHANGED)) - .await() - val result = - api.removeInstallationPointFromZoneAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f"), - ) - .await() - result.aggregateId.shouldBeEqual( - UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f") - ) - result.removedInstallationPoints.shouldBeEqual( - listOf(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveZoneAuthorizationFromMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveZoneAuthorizationFromMediumTest.kt deleted file mode 100644 index ca57b296..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RemoveZoneAuthorizationFromMediumTest.kt +++ /dev/null @@ -1,91 +0,0 @@ -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.removeZoneAuthorizationFromMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.IndividualAuthorizationsDeleted -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RemoveZoneAuthorizationFromMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("remove zone authorization from medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.REMOVE_ZONE_AUTHORIZATION_FROM_MEDIUM -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"authorization\":\"8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - IndividualAuthorizationsDeleted( - listOf(UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f")), - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync( - Topics.Event.INDIVIDUAL_AUTHORIZATIONS_DELETED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INDIVIDUAL_AUTHORIZATIONS_DELETED)) - .await() - val result = - api.removeZoneAuthorizationFromMediumAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f"), - ) - .await() - result.mediumId.shouldBeEqual( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - result.individualAuthorizations.shouldBeEqual( - listOf(UUID.fromString("8c7128d4-a30f-4aad-b5d2-d7b975c5cf8f")) - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RenameEntityMetadataDefinitionTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RenameEntityMetadataDefinitionTest.kt deleted file mode 100644 index 39c90ac3..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RenameEntityMetadataDefinitionTest.kt +++ /dev/null @@ -1,108 +0,0 @@ -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.renameEntityMetadataDefinitionAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.EntityMetadata -import com.open200.xesar.connect.messages.EntityType -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RenameEntityMetadataDefinitionTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("rename entity metadata definition") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val targetId = UUID.fromString("aaaaaaaa-0000-0000-0000-000000000001") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.RENAME_ENTITY_METADATA_DEFINITION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"entityType\":\"PERSON\",\"metadataDefinitionId\":\"$targetId\",\"name\":\"team\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - entityMetadataDefinitions = - PartitionChanged.EntityMetadataDefinitions( - authorizationProfiles = emptyList(), - identificationMedia = emptyList(), - installationPoints = emptyList(), - persons = - listOf( - EntityMetadata(id = targetId, name = "team"), - EntityMetadata( - id = - UUID.fromString( - "bbbbbbbb-0000-0000-0000-000000000002" - ), - name = "department", - ), - ), - zones = emptyList(), - ), - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - - val result = - api.renameEntityMetadataDefinitionAsync(EntityType.PERSON, targetId, "team") - .await() - - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.entityMetadataDefinitions!! - .persons - .map { it.name } - .shouldBeEqual(listOf("team", "department")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RequestAddMediumToInstallationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RequestAddMediumToInstallationTest.kt deleted file mode 100644 index 654bc9bb..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RequestAddMediumToInstallationTest.kt +++ /dev/null @@ -1,119 +0,0 @@ -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.requestToAddMediumToInstallationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.* -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RequestAddMediumToInstallationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("request add medium to installation returning both events") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.REQUEST_ADD_MEDIUM_TO_INSTALLATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"hardwareId\":\"hardwareId\",\"id\":\"2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be\",\"terminalId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"label\":null,\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - AddMediumToInstallationRequested( - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - hardwareId = "hardwareId", - ), - ) - - val apiEvent2 = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - MediumAddedToInstallation( - aggregateId = - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), - "hardwareId", - ), - ) - - client - .publishAsync( - Topics.Event.ADD_MEDIUM_TO_INSTALLATION_REQUESTED, - encodeEvent(apiEvent), - ) - .await() - - client - .publishAsync( - Topics.Event.MEDIUM_ADDED_TO_INSTALLATION, - encodeEvent(apiEvent2), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync( - Topics( - Topics.Event.ADD_MEDIUM_TO_INSTALLATION_REQUESTED, - Topics.Event.MEDIUM_ADDED_TO_INSTALLATION, - ) - ) - .await() - - val requestToAddMediumToInstallationResult = - api.requestToAddMediumToInstallationAsync( - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be"), - "hardwareId", - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ) - val mediumAddedToInstallation = - requestToAddMediumToInstallationResult.mediumAddedToInstallationDeferred - .await() - mediumAddedToInstallation.aggregateId.shouldBe( - UUID.fromString("2d52bd95-18ba-4e46-8f00-0fc4c1e3f9be") - ) - val addMediumToInstallationRequested = - requestToAddMediumToInstallationResult - .addMediumToInstallationRequestedDeferred - .await() - addMediumToInstallationRequested.hardwareId.shouldBe("hardwareId") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RequestNewRegistrationCodeMapi.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RequestNewRegistrationCodeMapi.kt deleted file mode 100644 index 7e7736d5..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RequestNewRegistrationCodeMapi.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.requestNewRegistrationCodeAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.* -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RequestNewRegistrationCodeMapi : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("request new registration code for a smartphone media") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.REQUEST_NEW_REGISTRATION_CODE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - NewRegistrationCodeRequested( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ), - ) - - client - .publishAsync( - Topics.Event.NEW_REGISTRATION_CODE_REQUESTED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.NEW_REGISTRATION_CODE_REQUESTED)).await() - - val requestNewRegistrationCodeResult = - api.requestNewRegistrationCodeAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - - requestNewRegistrationCodeResult.id.shouldBe( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ResendSmartphoneAuthorizationsTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ResendSmartphoneAuthorizationsTest.kt deleted file mode 100644 index 760cf326..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/ResendSmartphoneAuthorizationsTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -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.resendSmartphoneAuthorizationsAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.SmartphoneUnregistered -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class ResendSmartphoneAuthorizationsTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("resend smartphone authorizations") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.RESEND_SMARTPHONE_AUTHORIZATIONS -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - SmartphoneUnregistered( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ), - ) - - client - .publishAsync( - Topics.Event.SMARTPHONE_AUTHORIZATIONS_RESENT, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.SMARTPHONE_AUTHORIZATIONS_RESENT)) - .await() - val result = - api.resendSmartphoneAuthorizationsAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - - result.id!!.shouldBeEqual( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RevertPrepareRemovalOfEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RevertPrepareRemovalOfEvvaComponentTest.kt deleted file mode 100644 index ff974cb7..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RevertPrepareRemovalOfEvvaComponentTest.kt +++ /dev/null @@ -1,89 +0,0 @@ -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.revertPrepareRemovalOfEvvaComponentAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PrepareEvvaComponentRemovalReverted -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RevertPrepareRemovalOfEvvaComponentTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("revert prepare removal of evva component") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.REVERT_PREPARE_REMOVAL_OF_EVVA_COMPONENT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PrepareEvvaComponentRemovalReverted( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - LocalDateTime.parse("2023-07-05T15:22:38.230076"), - ), - ) - - client - .publishAsync( - Topics.Event.PREPARE_EVVA_COMPONENT_REMOVAL_REVERTED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PREPARE_EVVA_COMPONENT_REMOVAL_REVERTED)) - .await() - val result = - api.revertPrepareRemovalOfEvvaComponentAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.stateChangedAt.shouldBeEqual( - LocalDateTime.parse("2023-07-05T15:22:38.230076") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RevokeSmartphoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RevokeSmartphoneTest.kt deleted file mode 100644 index 3f106dac..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/RevokeSmartphoneTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.revokeSmartphoneAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.MediumRevoked -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.util.UUID -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class RevokeSmartphoneTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("revoke smartphone medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val smartphoneId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.REVOKE_SMARTPHONE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - MediumRevoked( - aggregateId = smartphoneId, - mediumIdentifier = 123456L, - hasMasterKeyAccess = false, - ), - ) - - client - .publishAsync(Topics.Event.MEDIUM_REVOKED, encodeEvent(apiEvent)) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.MEDIUM_REVOKED)).await() - - val result = api.revokeSmartphoneAsync(smartphoneId).await() - - result.aggregateId.shouldBeEqual(smartphoneId) - result.mediumIdentifier.shouldBeEqual(123456L) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetAccessBeginAtTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetAccessBeginAtTest.kt deleted file mode 100644 index f076d928..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetAccessBeginAtTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.setAccessBeginAtAsync -import com.open200.xesar.connect.it.MosquittoContainer -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetAccessBeginAtTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set access begin at") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_ACCESS_BEGIN_AT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"accessBeginAt\":\"2023-08-24T16:25:52.225991\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - 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() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.MEDIUM_CHANGED)).await() - val result = - api.setAccessBeginAtAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - LocalDateTime.parse("2023-08-24T16:25:52.225991"), - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetAccessEndAtTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetAccessEndAtTest.kt deleted file mode 100644 index 0aca5743..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetAccessEndAtTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.setAccessEndAtAsync -import com.open200.xesar.connect.it.MosquittoContainer -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetAccessEndAtTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set access end at") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_ACCESS_END_AT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"accessEndAt\":\"2023-08-24T16:25:52.225991\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - 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() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.MEDIUM_CHANGED)).await() - val result = - api.setAccessEndAtAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - LocalDateTime.parse("2023-08-24T16:25:52.225991"), - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDailySchedulerExecutionTimeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDailySchedulerExecutionTimeTest.kt deleted file mode 100644 index 8a04ccb1..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDailySchedulerExecutionTimeTest.kt +++ /dev/null @@ -1,81 +0,0 @@ -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.setDailySchedulerExecutionTimeAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -import com.open200.xesar.connect.messages.event.encodeEvent -import com.open200.xesar.connect.util.fixture.TimeProfileFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetDailySchedulerExecutionTimeTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set daily scheduler execution time") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_DAILY_SCHEDULER_EXECUTION_TIME -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"dailySchedulerExecutionTime\":\"14:15:00\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - dailySchedulerExecutionTime = TimeProfileFixture.localTime, - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - val result = - api.setDailySchedulerExecutionTimeAsync(TimeProfileFixture.localTime) - .await() - result.dailySchedulerExecutionTime.shouldBe(TimeProfileFixture.localTime) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultAuthorizationProfileForPersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultAuthorizationProfileForPersonTest.kt deleted file mode 100644 index 1e53fef4..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultAuthorizationProfileForPersonTest.kt +++ /dev/null @@ -1,79 +0,0 @@ -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.setDefaultAuthorizationProfileForPersonAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PersonChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetDefaultAuthorizationProfileForPersonTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set default authorization profile for a person") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_DEFAULT_AUTHORIZATION_PROFILE_FOR_PERSON -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"externalId\":\"EXT-123\",\"id\":null,\"defaultAuthorizationProfileName\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PersonChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - firstName = "firstName", - lastName = "lastName", - ), - ) - - client - .publishAsync(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PERSON_CHANGED)).await() - val result = - api.setDefaultAuthorizationProfileForPersonAsync("EXT-123", null).await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultDisengagePeriodForPersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultDisengagePeriodForPersonTest.kt deleted file mode 100644 index 1642cc49..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultDisengagePeriodForPersonTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -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.setDefaultDisengagePeriodForPersonAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.DisengagePeriod -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PersonChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetDefaultDisengagePeriodForPersonTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set default disengage period for a person") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_DEFAULT_DISENGAGE_PERIOD_FOR_PERSON -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"disengagePeriod\":\"SHORT\",\"externalId\":\"EXT-123\",\"id\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PersonChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - firstName = "firstName", - lastName = "lastName", - disengagePeriod = DisengagePeriod.SHORT, - ), - ) - - client - .publishAsync(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PERSON_CHANGED)).await() - val result = - api.setDefaultDisengagePeriodForPersonAsync( - "EXT-123", - disengagePeriod = DisengagePeriod.SHORT, - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.disengagePeriod?.shouldBeEqual(DisengagePeriod.SHORT) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultSmartphoneValidityDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultSmartphoneValidityDurationTest.kt deleted file mode 100644 index 5c349001..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultSmartphoneValidityDurationTest.kt +++ /dev/null @@ -1,76 +0,0 @@ -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.setDefaultSmartphoneValidityDurationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetDefaultSmartphoneValidityDurationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set default smartphone validity duration for all smartphones") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_DEFAULT_SMARTPHONE_VALIDITIY_DURATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"validityDuration\":10,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - smartphoneValidityDuration = 10, - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - val result = api.setDefaultSmartphoneValidityDurationAsync(10).await() - result.smartphoneValidityDuration!!.shouldBeEqual(10) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultValidityDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultValidityDurationTest.kt deleted file mode 100644 index acaece8b..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDefaultValidityDurationTest.kt +++ /dev/null @@ -1,78 +0,0 @@ -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.setDefaultValidityDurationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetDefaultValidityDurationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set default validity duration") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_DEFAULT_VALIDITY_DURATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"validityDuration\":0,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - validityDuration = 0, - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - val result = api.setDefaultValidityDurationAsync(0).await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.validityDuration?.shouldBeEqual(0) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDisengagePeriodOnMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDisengagePeriodOnMediumTest.kt deleted file mode 100644 index adcc5931..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetDisengagePeriodOnMediumTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -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.setDisengagePeriodOnMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.DisengagePeriod -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetDisengagePeriodOnMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set disengage period on medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_DISENGAGE_PERIOD_ON_MEDIUM -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"disengagePeriod\":\"LONG\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - MediumChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"), - disengagePeriod = DisengagePeriod.LONG, - ), - ) - - 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.setDisengagePeriodOnMediumAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - DisengagePeriod.LONG, - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.disengagePeriod?.shouldBeEqual(DisengagePeriod.LONG) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetInstallationPointPersonalReferenceDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetInstallationPointPersonalReferenceDurationTest.kt deleted file mode 100644 index 80195251..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetInstallationPointPersonalReferenceDurationTest.kt +++ /dev/null @@ -1,87 +0,0 @@ -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.setInstallationPointPersonalReferenceDurationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.PersonalLog -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetInstallationPointPersonalReferenceDurationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set installation point personal reference duration") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command - .SET_INSTALLATION_POINT_PERSONAL_REFERENCE_DURATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"personalReferenceDuration\":{\"logMode\":null,\"days\":30},\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - installationPointDefaultPersonalReferenceDuration = - PersonalLog(days = 30), - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - val result = - api.setInstallationPointPersonalReferenceDurationAsync( - PersonalLog(days = 30) - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.installationPointDefaultPersonalReferenceDuration - ?.days - ?.shouldBeEqual(30) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetLabelOnMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetLabelOnMediumTest.kt deleted file mode 100644 index 910c5a15..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetLabelOnMediumTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.setLabelOnMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetLabelOnMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set label on medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_LABEL_ON_MEDIUM -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"label\":\"label\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - MediumChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"), - label = "label", - ), - ) - - 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.setLabelOnMediumAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - "label", - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.label?.shouldBeEqual("label") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetMessageLanguageOnSmartphoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetMessageLanguageOnSmartphoneTest.kt deleted file mode 100644 index d43b863c..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetMessageLanguageOnSmartphoneTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.setMessageLanguageOnSmartphoneAsync -import com.open200.xesar.connect.it.MosquittoContainer -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetMessageLanguageOnSmartphoneTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set message language on smartphone media") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_MESSAGE_LANGUAGE_ON_SMARTPHONE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"messageLanguage\":\"en\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - MediumChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"), - messageLanguage = "en", - ), - ) - - 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.setMessageLanguageOnSmartphoneAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - "en", - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.messageLanguage?.shouldBeEqual("en") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetMobileServiceModeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetMobileServiceModeTest.kt deleted file mode 100644 index c1c94a00..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetMobileServiceModeTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.setMobileServiceModeAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.MobileServiceMode -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.UUID -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetMobileServiceModeTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set mobile service mode to SELF_SERVICE") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_MOBILE_SERVICE_MODE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - // Enums are serialized using @SerialName -> "xms" - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"mobileServiceMode\":\"self-service\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - mobileServiceMode = MobileServiceMode.SELF_SERVICE, - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - - val result = - api.setMobileServiceModeAsync(MobileServiceMode.SELF_SERVICE).await() - - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.mobileServiceMode?.shouldBeEqual(MobileServiceMode.SELF_SERVICE) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonPersonalReferenceDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonPersonalReferenceDurationTest.kt deleted file mode 100644 index e36e6e3e..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonPersonalReferenceDurationTest.kt +++ /dev/null @@ -1,80 +0,0 @@ -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.setPersonPersonalReferenceDurationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.PersonalLog -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetPersonPersonalReferenceDurationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set person personal reference duration") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_PERSON_PERSONAL_REFERENCE_DURATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"personalReferenceDuration\":{\"logMode\":null,\"days\":30},\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - personDefaultPersonalReferenceDuration = PersonalLog(days = 30), - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - val result = - api.setPersonPersonalReferenceDurationAsync(PersonalLog(days = 30)).await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.personDefaultPersonalReferenceDuration?.days?.shouldBeEqual(30) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonalReferenceDurationForInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonalReferenceDurationForInstallationPointTest.kt deleted file mode 100644 index 56c12cf5..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonalReferenceDurationForInstallationPointTest.kt +++ /dev/null @@ -1,100 +0,0 @@ -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.setPersonalReferenceDurationForInstallationPointAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.PersonalLog -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.InstallationPointChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetPersonalReferenceDurationForInstallationPointTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set personal reference duration for installation point") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command - .SET_PERSONAL_REFERENCE_DURATION_FOR_INSTALLATION_POINT -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"personalReferenceDuration\":{\"logMode\":\"saveForDays\",\"days\":30},\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - InstallationPointChanged( - aggregateId = - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - personalReferenceDuration = - PersonalLog( - days = 30, - logMode = PersonalLog.PersonalLogModes.saveForDays, - ), - ), - ) - - client - .publishAsync( - Topics.Event.INSTALLATION_POINT_CHANGED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.INSTALLATION_POINT_CHANGED)).await() - val result = - api.setPersonalReferenceDurationForInstallationPointAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - PersonalLog( - days = 30, - logMode = PersonalLog.PersonalLogModes.saveForDays, - ), - ) - .await() - result.aggregateId.shouldBeEqual( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - result.personalReferenceDuration?.shouldBeEqual( - PersonalLog(days = 30, logMode = PersonalLog.PersonalLogModes.saveForDays) - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonalReferenceDurationInPersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonalReferenceDurationInPersonTest.kt deleted file mode 100644 index bee4afd9..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPersonalReferenceDurationInPersonTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -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.setPersonalReferenceDurationInPersonAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.PersonalLog -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PersonChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetPersonalReferenceDurationInPersonTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set personal reference duration in person") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_PERSONAL_REFERENCE_DURATION_IN_PERSON -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"newValue\":{\"logMode\":null,\"days\":30},\"externalId\":\"EXT-123\",\"id\":null,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PersonChanged( - firstName = "firstName", - lastName = "lastName", - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - personalReferenceDuration = PersonalLog(days = 30), - ), - ) - - client - .publishAsync(Topics.Event.PERSON_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PERSON_CHANGED)).await() - val result = - api.setPersonalReferenceDurationInPersonAsync( - "EXT-123", - personalReferenceDuration = PersonalLog(days = 30), - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.personalReferenceDuration?.shouldBeEqual(PersonalLog(days = 30)) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPhoneNumberOnSmartphoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPhoneNumberOnSmartphoneTest.kt deleted file mode 100644 index f37b2297..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetPhoneNumberOnSmartphoneTest.kt +++ /dev/null @@ -1,97 +0,0 @@ -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.setPhoneNumberOnSmartphoneAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.DisengagePeriod -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetPhoneNumberOnSmartphoneTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set phone number on smartphone media") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val smartphoneMediaId = UUID.fromString("7b21f75f-3fa6-41c8-acff-a14839331b25") - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_PHONE_NUMBER_ON_SMARTPHONE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"7b21f75f-3fa6-41c8-acff-a14839331b25\",\"phoneNumber\":\"+0123456789\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - MediumChanged( - accessBeginAt = LocalDateTime.parse("2024-08-04T10:05"), - disengagePeriod = DisengagePeriod.SHORT, - authorizationProfileId = - UUID.fromString("00000000-0000-0000-0000-000000000001"), - validityDuration = null, - validUntil = null, - changedAt = - LocalDateTime.parse("2024-08-08T08:00:40.671784826"), - id = UUID.fromString("16ea9a30-bc2a-4b99-b3d8-73981f01e2d2"), - label = "Test12348", - validFrom = null, - accessEndAt = LocalDateTime.parse("2079-12-31T23:50"), - phoneNumber = "+0123456789", - ), - ) - - client - .publishAsync(Topics.Event.MEDIUM_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync( - Topics(Topics.Event.PHONE_NUMBER_CHANGED, Topics.Event.MEDIUM_CHANGED) - ) - .await() - val result = - api.setPhoneNumberOnSmartphoneAsync("+0123456789", smartphoneMediaId) - .mediumChangedDeferred - .await() - result.phoneNumber!!.shouldBeEqual("+0123456789") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetReplacementMediumDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetReplacementMediumDurationTest.kt deleted file mode 100644 index 8b17adad..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetReplacementMediumDurationTest.kt +++ /dev/null @@ -1,78 +0,0 @@ -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.setReplacementMediumDurationAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetReplacementMediumDurationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set replacement medium duration") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_REPLACEMENT_MEDIUM_DURATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"replacementMediumDuration\":123,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - replacementMediumDuration = 123, - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - val result = api.setReplacementMediumDurationAsync(123).await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.replacementMediumDuration?.shouldBeEqual(123) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetValidityDurationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetValidityDurationTest.kt deleted file mode 100644 index 12addab9..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetValidityDurationTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.setValidityDurationAsync -import com.open200.xesar.connect.it.MosquittoContainer -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetValidityDurationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set validity duration") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_VALIDITY_DURATION -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"validityDuration\":123,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - MediumChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - changedAt = LocalDateTime.parse("2023-08-23T16:25:52.225991"), - validityDuration = 123, - ), - ) - - 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.setValidityDurationAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - 123, - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.validityDuration?.shouldBeEqual(123) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetValidityThresholdTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetValidityThresholdTest.kt deleted file mode 100644 index 1db7afcd..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/SetValidityThresholdTest.kt +++ /dev/null @@ -1,78 +0,0 @@ -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.setValidityThresholdAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.PartitionChanged -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class SetValidityThresholdTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("set validity threshold") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.SET_VALIDITY_THRESHOLD -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"validityThreshold\":123,\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - PartitionChanged( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - validityDuration = 123, - ), - ) - - client - .publishAsync(Topics.Event.PARTITION_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.PARTITION_CHANGED)).await() - val result = api.setValidityThresholdAsync(123).await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.validityDuration?.shouldBeEqual(123) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/UnassignPersonFromMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/UnassignPersonFromMediumTest.kt deleted file mode 100644 index 69847d5d..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/UnassignPersonFromMediumTest.kt +++ /dev/null @@ -1,86 +0,0 @@ -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.unassignPersonFromMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.MediumPersonChanged -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.kotest.matchers.nulls.shouldBeNull -import io.mockk.coEvery -import java.util.UUID -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class UnassignPersonFromMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("unassign person from medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - - val mediumId = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.UNASSIGN_PERSON_FROM_MEDIUM -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"mediumId\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - MediumPersonChanged( - oldPersonId = null, - newPersonId = null, - id = mediumId, - ), - ) - - client - .publishAsync(Topics.Event.MEDIUM_PERSON_CHANGED, encodeEvent(apiEvent)) - .await() - } - } - - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.MEDIUM_PERSON_CHANGED)).await() - - val result = api.unassignPersonFromMediumAsync(mediumId).await() - - result.id.shouldBeEqual(mediumId) - result.newPersonId.shouldBeNull() - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/UnregisterSmartphoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/UnregisterSmartphoneTest.kt deleted file mode 100644 index 45409ad1..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/UnregisterSmartphoneTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -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.unregisterSmartphoneAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.SmartphoneUnregistered -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class UnregisterSmartphoneTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("Unregister smartphone") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.UNREGISTER_SMARTPHONE -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - SmartphoneUnregistered( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ), - ) - - client - .publishAsync( - Topics.Event.SMARTPHONE_UNREGISTERED, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Event.SMARTPHONE_UNREGISTERED)).await() - val result = - api.unregisterSmartphoneAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - .await() - - result.id!!.shouldBeEqual( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/WithdrawAuthorizationProfileFromMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/WithdrawAuthorizationProfileFromMediumTest.kt deleted file mode 100644 index fe24facb..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/command/WithdrawAuthorizationProfileFromMediumTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -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.withdrawAuthorizationProfileFromMediumAsync -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.event.ApiEvent -import com.open200.xesar.connect.messages.event.AuthorizationProfileWithdrawnFromMedium -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.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class WithdrawAuthorizationProfileFromMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("withdraw authorization profile from medium") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val commandReceived = CompletableDeferred() - - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Command.WITHDRAW_AUTHORIZATION_PROFILE_FROM_MEDIUM -> { - commandReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val commandContent = commandReceived.await() - - commandContent.shouldBeEqual( - "{\"commandId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"authorizationProfileId\":null,\"id\":\"43edc7cf-80ab-4486-86db-41cda2c7a2cd\",\"token\":\"JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx\"}" - ) - - val apiEvent = - ApiEvent( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - AuthorizationProfileWithdrawnFromMedium( - id = UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - withdrawnAt = LocalDateTime.parse("2023-08-24T16:25:52.225991"), - authorizationProfileId = - UUID.fromString("00000000-0000-0000-0000-000000000001"), - ), - ) - - client - .publishAsync( - Topics.Event.AUTHORIZATION_PROFILE_WITHDRAWN_FROM_MEDIUM, - encodeEvent(apiEvent), - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync( - Topics(Topics.Event.AUTHORIZATION_PROFILE_WITHDRAWN_FROM_MEDIUM) - ) - .await() - val result = - api.withdrawAuthorizationProfileFromMediumAsync( - UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd"), - null, - ) - .await() - result.id.shouldBeEqual(UUID.fromString("43edc7cf-80ab-4486-86db-41cda2c7a2cd")) - result.authorizationProfileId?.shouldBeEqual( - UUID.fromString("00000000-0000-0000-0000-000000000001") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryAccessProtocolEventTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryAccessProtocolEventTest.kt deleted file mode 100644 index a0250d8c..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryAccessProtocolEventTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryAccessProtocolEvents -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.QueryList -import com.open200.xesar.connect.messages.query.encodeQueryList -import com.open200.xesar.connect.util.fixture.AccessProtocolEventFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryAccessProtocolEventTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryAccessProtocolEventList without params") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - "{\"resource\":\"access-protocol\",\"requestId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"${MosquittoContainer.TOKEN}\",\"id\":null,\"params\":null}" - ) - - val person = - encodeQueryList( - QueryList( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - QueryList.Response( - listOf( - AccessProtocolEventFixture.accessProtocolEvent, - AccessProtocolEventFixture.accessProtocolEvent.copy( - id = - UUID.fromString( - "4509ca29-9fd3-454f-9c98-fc0967fe3f66" - ) - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync(Topics.Query.result(config.apiProperties.userId), person) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryAccessProtocolEvents() - result.totalCount.shouldBeEqual(2) - result.data[0] - .id - .shouldBeEqual(UUID.fromString("0f0f5120-098c-4d8f-92f3-2a073b85ef8a")) - result.data[1] - .id - .shouldBeEqual(UUID.fromString("4509ca29-9fd3-454f-9c98-fc0967fe3f66")) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryAuthorizationProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryAuthorizationProfileTest.kt deleted file mode 100644 index b364abf1..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryAuthorizationProfileTest.kt +++ /dev/null @@ -1,154 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryAuthorizationProfileById -import com.open200.xesar.connect.extension.queryAuthorizationProfiles -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.* -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.AuthorizationProfileFixture.authorizationProfileFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryAuthorizationProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryAuthorizationProfileList without params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - AuthorizationProfile.QUERY_RESOURCE, - requestId, - ) - ) - - val authorizationProfiles = - encodeQueryList( - QueryList( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - QueryList.Response( - listOf( - authorizationProfileFixture, - authorizationProfileFixture.copy( - id = - UUID.fromString( - "894852cf-ca33-4734-a4a9-008eeeaeb005" - ), - name = "authorization profile 2", - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - authorizationProfiles, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryAuthorizationProfiles() - result.totalCount.shouldBeEqual(2) - result.data[0].name.shouldBeEqual("authorization profile 1 String") - result.data[1].name.shouldBeEqual("authorization profile 2") - } - } - } - - test("queryAuthorizationProfileById") { - val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - AuthorizationProfile.QUERY_RESOURCE, - requestId, - authorizationProfileFixture.id, - ) - ) - - val person = - encodeQueryElement( - QueryElement( - UUID.fromString("00000000-1281-42c0-9a15-c5844850c748"), - authorizationProfileFixture, - ) - ) - - client - .publishAsync(Topics.Query.result(config.apiProperties.userId), person) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryAuthorizationProfileById(authorizationProfileFixture.id) - result!!.id.shouldBeEqual(authorizationProfileFixture.id) - result.name.shouldBeEqual("authorization profile 1 String") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryCodingStationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryCodingStationTest.kt deleted file mode 100644 index 9d2a91fd..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryCodingStationTest.kt +++ /dev/null @@ -1,158 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryCodingStationById -import com.open200.xesar.connect.extension.queryCodingStations -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.* -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.CodingStationFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryCodingStationTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryCodingStationList without params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - CodingStation.QUERY_RESOURCE, - requestId, - ) - ) - - val codingStation = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - CodingStationFixture.codingStationFixture, - CodingStationFixture.codingStationFixture.copy( - id = - UUID.fromString( - "4509ca29-9fd3-454f-9c98-fc0967fe3f66" - ), - partitionId = - UUID.fromString( - "6b4399a0-21ce-4bee-ba43-e06e291248d2" - ), - online = false, - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - codingStation, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryCodingStations() - result.totalCount.shouldBeEqual(2) - result.data[0].online?.shouldBeEqual(true) - result.data[1].online?.shouldBeEqual(false) - } - } - } - - test("queryCodingStationById") { - val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - CodingStation.QUERY_RESOURCE, - requestId, - CodingStationFixture.codingStationFixture.id, - ) - ) - - val codingStation = - encodeQueryElement( - QueryElement(requestId, CodingStationFixture.codingStationFixture) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - codingStation, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = - api.queryCodingStationById(CodingStationFixture.codingStationFixture.id) - result!!.id.shouldBeEqual(CodingStationFixture.codingStationFixture.id) - result.online?.shouldBeEqual(true) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryEvvaComponentTest.kt deleted file mode 100644 index 32a45a22..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryEvvaComponentTest.kt +++ /dev/null @@ -1,156 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryEvvaComponentById -import com.open200.xesar.connect.extension.queryEvvaComponents -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.* -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.EvvaComponentFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryEvvaComponentTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryEvvaComponentList with params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - EvvaComponent.QUERY_RESOURCE, - requestId, - ) - ) - - val evvaComponentList = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - EvvaComponentFixture.evvaComponentFixture, - EvvaComponentFixture.evvaComponentFixture.copy( - id = - UUID.fromString( - "f7019248-f7f9-4138-9af7-119e2e251408" - ), - status = ComponentStatus.NotSynced, - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - evvaComponentList, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryEvvaComponents() - result.totalCount.shouldBeEqual(2) - result.data[0].status?.shouldBeEqual(ComponentStatus.Synced) - result.data[1].status?.shouldBeEqual(ComponentStatus.NotSynced) - } - } - } - - test("queryEvvaComponentById") { - val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") - - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - EvvaComponent.QUERY_RESOURCE, - requestId, - EvvaComponentFixture.evvaComponentFixture.id, - ) - ) - - val evvaComponent = - encodeQueryElement( - QueryElement(requestId, EvvaComponentFixture.evvaComponentFixture) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - evvaComponent, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = - api.queryEvvaComponentById(EvvaComponentFixture.evvaComponentFixture.id) - result!!.id.shouldBeEqual(EvvaComponentFixture.evvaComponentFixture.id) - result.status?.shouldBeEqual(ComponentStatus.Synced) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryIdentificationMediumAccessDataTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryIdentificationMediumAccessDataTest.kt deleted file mode 100644 index f6bfefed..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryIdentificationMediumAccessDataTest.kt +++ /dev/null @@ -1,204 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryIdentificationMediumAccessData -import com.open200.xesar.connect.extension.queryIdentificationMediumAccessDataById -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.IdentificationMediumAccessData -import com.open200.xesar.connect.messages.query.QueryElement -import com.open200.xesar.connect.messages.query.QueryList -import com.open200.xesar.connect.messages.query.encodeQueryElement -import com.open200.xesar.connect.messages.query.encodeQueryList -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.IdentificationMediumAccessDataFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryIdentificationMediumAccessDataTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryIdentificationMediaAccessDataList without params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - IdentificationMediumAccessData.QUERY_RESOURCE, - requestId, - ) - ) - - val IdentificationMediumAccessData = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - IdentificationMediumAccessDataFixture - .identificationMediumAccessData, - IdentificationMediumAccessDataFixture - .identificationMediumAccessData - .copy( - identificationMedium = - IdentificationMediumAccessDataFixture - .identificationMediumAccessData - .identificationMedium - .copy( - xsMediumId = - UUID.fromString( - "8d8347ba-e8f9-40ed-af7d-f08d9290b3db" - ), - xsMobileId = - UUID.fromString( - "df2e491a-aa69-4488-905f-3ea48fd5c5b0" - ), - ) - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - IdentificationMediumAccessData, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryIdentificationMediumAccessData() - result.totalCount.shouldBeEqual(2) - result.data[0] - .identificationMedium - .xsMediumId - .shouldBeEqual( - IdentificationMediumAccessDataFixture.identificationMediumAccessData - .identificationMedium - .xsMediumId - ) - result.data[1] - .identificationMedium - .xsMediumId - .shouldBeEqual(UUID.fromString("8d8347ba-e8f9-40ed-af7d-f08d9290b3db")) - - result.data[0] - .identificationMedium - .xsMobileId - ?.shouldBeEqual( - IdentificationMediumAccessDataFixture.identificationMediumAccessData - .identificationMedium - .xsMobileId as UUID - ) - result.data[1] - .identificationMedium - .xsMobileId - ?.shouldBeEqual(UUID.fromString("df2e491a-aa69-4488-905f-3ea48fd5c5b0")) - } - } - } - - test("queryIdentificationMediumAccessDataById without params") { - val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - - val id = - IdentificationMediumAccessDataFixture.identificationMediumAccessData - .identificationMedium - .xsMediumId - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - IdentificationMediumAccessData.QUERY_RESOURCE, - requestId, - id, - ) - ) - - val identificationMediumAccessData = - encodeQueryElement( - QueryElement( - requestId, - IdentificationMediumAccessDataFixture - .identificationMediumAccessData, - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - identificationMediumAccessData, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryIdentificationMediumAccessDataById(id) - result!!.identificationMedium.xsMediumId.shouldBeEqual(id) - result.identificationMedium.metadata.accessPoints - ?.get(1) - ?.bleMac - ?.shouldBeEqual("00:1B:44:11:3A:B7") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryIdentificationMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryIdentificationMediumTest.kt deleted file mode 100644 index d15da2f0..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryIdentificationMediumTest.kt +++ /dev/null @@ -1,360 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.* -import com.open200.xesar.connect.exception.MediumListSizeException -import com.open200.xesar.connect.extension.queryIdentificationMediumById -import com.open200.xesar.connect.extension.queryIdentificationMediumByMediumIdentifier -import com.open200.xesar.connect.extension.queryIdentificationMediums -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.* -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.IdentificationMediumFixture -import io.kotest.assertions.throwables.shouldThrow -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.nulls.shouldBeNull -import io.mockk.coEvery -import java.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryIdentificationMediumTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryIdentificationMediaList without params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - IdentificationMedium.QUERY_RESOURCE, - requestId, - ) - ) - - val identificationMedium = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - IdentificationMediumFixture.identificationMediumFixture, - IdentificationMediumFixture.identificationMediumFixture - .copy( - id = - UUID.fromString( - "a4c838a8-f6be-49e0-abee-c1d3b2897279" - ), - label = "test door 2", - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - identificationMedium, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryIdentificationMediums() - result.totalCount.shouldBeEqual(2) - result.data[0].label.shouldBeEqual("test door") - result.data[1].label.shouldBeEqual("test door 2") - } - } - } - - test( - "queryIdentificationMediumByMediumIdentifierAsync without params should return an element" - ) { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - "{\"resource\":\"identification-media\",\"requestId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"${MosquittoContainer.TOKEN}\",\"id\":null,\"params\":{\"pageOffset\":null,\"pageLimit\":null,\"sort\":null,\"language\":null,\"filters\":[{\"field\":\"mediumIdentifier\",\"type\":\"eq\",\"value\":\"1\"}]}}" - ) - - val identificationMedium = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - IdentificationMediumFixture.identificationMediumFixture - ), - 1, - 1, - ), - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - identificationMedium, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = - api.queryIdentificationMediumByMediumIdentifier(mediumIdentifierValue = 1) - - result?.label?.shouldBeEqual("test door") - } - } - } - - test( - "queryIdentificationMediumByMediumIdentifierAsync without params should return null when no result" - ) { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, _ -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(null) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeNull() - - val identificationMedium = - encodeQueryList( - QueryList(requestId, QueryList.Response(listOf(), 1, 1)) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - identificationMedium, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = - api.queryIdentificationMediumByMediumIdentifier( - mediumIdentifierValue = 9999 - ) - - result.shouldBeNull() - } - } - } - - test( - "queryIdentificationMediumByMediumIdentifierAsync should throw an exception if the results is returning 2 values" - ) { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - "{\"resource\":\"identification-media\",\"requestId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"${MosquittoContainer.TOKEN}\",\"id\":null,\"params\":{\"pageOffset\":null,\"pageLimit\":null,\"sort\":null,\"language\":null,\"filters\":[{\"field\":\"mediumIdentifier\",\"type\":\"eq\",\"value\":\"1\"}]}}" - ) - - val identificationMedium = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - IdentificationMediumFixture.identificationMediumFixture, - IdentificationMediumFixture.identificationMediumFixture - .copy( - id = - UUID.fromString( - "a4c838a8-f6be-49e0-abee-c1d3b2897279" - ), - label = "test door 2", - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - identificationMedium, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - - val result = - shouldThrow { - api.queryIdentificationMediumByMediumIdentifier( - mediumIdentifierValue = 1 - ) - } - - result.message?.shouldBeEqual( - "Expected exactly one element in the list with mediumIdentifier 1, but found 2 elements" - ) - } - } - } - - test("queryIdentificationMediumById") { - val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - - val id = IdentificationMediumFixture.identificationMediumFixture.id - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - IdentificationMedium.QUERY_RESOURCE, - requestId, - id, - ) - ) - - val identificationMedium = - encodeQueryElement( - QueryElement( - requestId, - IdentificationMediumFixture.identificationMediumFixture, - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - identificationMedium, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryIdentificationMediumById(id) - result!!.id.shouldBeEqual(id) - result.label.shouldBeEqual("test door") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryInstallationPointTest.kt deleted file mode 100644 index 4d12ee69..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryInstallationPointTest.kt +++ /dev/null @@ -1,156 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryInstallationPointById -import com.open200.xesar.connect.extension.queryInstallationPoints -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.* -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.InstallationPointFixture.installationPointFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryInstallationPointTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryInstallationPointList without params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - InstallationPoint.QUERY_RESOURCE, - requestId, - ) - ) - - val installationPoint = - encodeQueryList( - QueryList( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - QueryList.Response( - listOf( - installationPointFixture, - installationPointFixture.copy( - id = - UUID.fromString( - "a4c838a8-f6be-49e0-abee-c1d3b2897279" - ), - name = "door 2 entry point", - description = "door 2", - installationId = - "0cefd48b-969e-43eb-aad6-98553288eb4d", - installationType = "door 2", - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - installationPoint, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryInstallationPoints() - result.totalCount.shouldBeEqual(2) - result.data[0].name.shouldBeEqual("door 1 entry point") - result.data[1].name.shouldBeEqual("door 2 entry point") - } - } - } - - test("queryInstallationPointById") { - val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - InstallationPoint.QUERY_RESOURCE, - requestId, - installationPointFixture.id, - ) - ) - - val installationPoint = - encodeQueryElement(QueryElement(requestId, installationPointFixture)) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - installationPoint, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryInstallationPointById(installationPointFixture.id) - result!!.id.shouldBeEqual(installationPointFixture.id) - result.name.shouldBeEqual("door 1 entry point") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryOfficeModeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryOfficeModeTest.kt deleted file mode 100644 index 21cb1ad0..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryOfficeModeTest.kt +++ /dev/null @@ -1,153 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryOfficeModeById -import com.open200.xesar.connect.extension.queryOfficeModes -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.* -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.OfficeModeFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryOfficeModeTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryOfficeModeList without params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest(OfficeMode.QUERY_RESOURCE, requestId) - ) - - val officeModes = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - OfficeModeFixture.officeModeFixture, - OfficeModeFixture.officeModeFixture.copy( - id = - UUID.fromString( - "894852cf-ca33-4734-a4a9-008eeeaeb005" - ), - timeProfileName = "timeProfileName2", - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - officeModes, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryOfficeModes() - result.totalCount.shouldBeEqual(2) - result.data[0].timeProfileName.shouldBeEqual("timeProfileName") - result.data[1].timeProfileName.shouldBeEqual("timeProfileName2") - } - } - } - - test("queryOfficeModeById") { - val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - OfficeMode.QUERY_RESOURCE, - requestId, - OfficeModeFixture.officeModeFixture.id, - ) - ) - - val officeMode = - encodeQueryElement( - QueryElement(requestId, OfficeModeFixture.officeModeFixture) - ) - - client - .publishAsync( - Topics.Query.result(config.apiProperties.userId), - officeMode, - ) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryOfficeModeById(OfficeModeFixture.officeModeFixture.id) - result!!.id.shouldBeEqual(OfficeModeFixture.officeModeFixture.id) - result.installationPointId.shouldBeEqual( - UUID.fromString("39b25462-2580-44dc-b0a8-22fd6c03a023") - ) - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryPersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryPersonTest.kt deleted file mode 100644 index a894db16..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryPersonTest.kt +++ /dev/null @@ -1,162 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryPersonById -import com.open200.xesar.connect.extension.queryPersons -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.command.FilterType -import com.open200.xesar.connect.messages.command.Query -import com.open200.xesar.connect.messages.query.QueryElement -import com.open200.xesar.connect.messages.query.QueryList -import com.open200.xesar.connect.messages.query.encodeQueryElement -import com.open200.xesar.connect.messages.query.encodeQueryList -import com.open200.xesar.connect.util.fixture.PersonFixture.personFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryPersonTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryPersonList with params") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757")) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - "{\"resource\":\"persons\",\"requestId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"${MosquittoContainer.TOKEN}\",\"id\":null," + - "\"params\":{\"pageOffset\":0,\"pageLimit\":3,\"sort\":\"firstName\",\"language\":null,\"filters\":[{\"field\":\"firstName\",\"type\":\"contains\",\"value\":\"filtered first name\"}]}}" - ) - - val person = - encodeQueryList( - QueryList( - UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), - QueryList.Response( - listOf( - personFixture, - personFixture.copy( - id = - UUID.fromString( - "f7019248-f7f9-4138-9af7-119e2e251408" - ), - firstName = "firstname 2 String", - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync(Topics.Query.result(config.apiProperties.userId), person) - .await() - } - } - launch { - simulatedBackendReady.await() - val params = - Query.Params( - 0, - 3, - "firstName", - null, - listOf( - Query.Params.Filter( - "firstName", - FilterType.CONTAINS, - "filtered first name", - ) - ), - ) - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryPersons(params) - result.totalCount.shouldBeEqual(2) - result.data[0].firstName.shouldBeEqual("firstname String") - result.data[1].firstName.shouldBeEqual("firstname 2 String") - } - } - } - - test("queryPersonById") { - coEvery { config.uuidGenerator.generateId() } - .returns(UUID.fromString("00000000-1281-42c0-9a15-c5844850c748")) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - "{\"resource\":\"persons\",\"requestId\":\"00000000-1281-42c0-9a15-c5844850c748\",\"token\":\"${MosquittoContainer.TOKEN}\",\"id\":\"${personFixture.id}\",\"params\":null}" - ) - - val person = - encodeQueryElement( - QueryElement( - UUID.fromString("00000000-1281-42c0-9a15-c5844850c748"), - personFixture, - ) - ) - - client - .publishAsync(Topics.Query.result(config.apiProperties.userId), person) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryPersonById(personFixture.id) - result!!.id.shouldBeEqual(personFixture.id) - result.firstName.shouldBeEqual("firstname String") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryTimeProfileTest.kt deleted file mode 100644 index f334038b..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryTimeProfileTest.kt +++ /dev/null @@ -1,149 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryTimeProfileById -import com.open200.xesar.connect.extension.queryTimeProfiles -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.* -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.TimeProfileFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryTimeProfileTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryTimeProfileList without params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - TimeProfile.QUERY_RESOURCE, - requestId, - ) - ) - - val person = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - TimeProfileFixture.timeProfileFixture, - TimeProfileFixture.timeProfileFixture.copy( - id = - UUID.fromString( - "4509ca29-9fd3-454f-9c98-fc0967fe3f66" - ), - name = "name 2", - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync(Topics.Query.result(config.apiProperties.userId), person) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryTimeProfiles() - result.totalCount.shouldBeEqual(2) - result.data[0].name?.shouldBeEqual("name") - result.data[1].name?.shouldBeEqual("name 2") - } - } - } - - test("queryTimeProfileById") { - val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - TimeProfile.QUERY_RESOURCE, - requestId, - TimeProfileFixture.timeProfileFixture.id!!, - ) - ) - - val person = - encodeQueryElement( - QueryElement(requestId, TimeProfileFixture.timeProfileFixture) - ) - - client - .publishAsync(Topics.Query.result(config.apiProperties.userId), person) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = - api.queryTimeProfileById(TimeProfileFixture.timeProfileFixture.id!!) - result!!.id?.shouldBeEqual(TimeProfileFixture.timeProfileFixture.id!!) - result.name?.shouldBeEqual("name") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryUserTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryUserTest.kt deleted file mode 100644 index 968edbf5..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryUserTest.kt +++ /dev/null @@ -1,93 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryUsers -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.QueryList -import com.open200.xesar.connect.messages.query.User -import com.open200.xesar.connect.messages.query.encodeQueryList -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.UserFixture.userFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryUserTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryUserList without params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest(User.QUERY_RESOURCE, requestId) - ) - - val person = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - userFixture, - userFixture.copy( - id = - UUID.fromString( - "4509ca29-9fd3-454f-9c98-fc0967fe3f66" - ), - name = "lastname 2 String", - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync(Topics.Query.result(config.apiProperties.userId), person) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryUsers() - result.totalCount.shouldBeEqual(2) - result.data[0].name.shouldBeEqual("lastname String") - result.data[1].name.shouldBeEqual("lastname 2 String") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryZoneTest.kt deleted file mode 100644 index 98dfe3a3..00000000 --- a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/it/query/QueryZoneTest.kt +++ /dev/null @@ -1,143 +0,0 @@ -package com.open200.xesar.connect.it.query - -import com.open200.xesar.connect.Topics -import com.open200.xesar.connect.XesarConnect -import com.open200.xesar.connect.XesarMqttClient -import com.open200.xesar.connect.extension.queryZoneById -import com.open200.xesar.connect.extension.queryZones -import com.open200.xesar.connect.it.MosquittoContainer -import com.open200.xesar.connect.messages.query.* -import com.open200.xesar.connect.util.QueryTestHelper -import com.open200.xesar.connect.util.fixture.ZoneFixture -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.util.* -import kotlinx.coroutines.CompletableDeferred -import kotlinx.coroutines.launch - -class QueryZoneTest : - FunSpec({ - val container = MosquittoContainer.container() - val config = MosquittoContainer.config(container) - listener(container.perProject()) - - test("queryZoneList without params") { - val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest(Zone.QUERY_RESOURCE, requestId) - ) - - val zones = - encodeQueryList( - QueryList( - requestId, - QueryList.Response( - listOf( - ZoneFixture.zoneFixture, - ZoneFixture.zoneFixture.copy( - id = - UUID.fromString( - "4509ca29-9fd3-454f-9c98-fc0967fe3f66" - ), - name = "zone name2", - ), - ), - 2, - 2, - ), - ) - ) - - client - .publishAsync(Topics.Query.result(config.apiProperties.userId), zones) - .await() - } - } - launch { - simulatedBackendReady.await() - - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryZones() - result.totalCount.shouldBeEqual(2) - result.data[0].name.shouldBeEqual("zone name") - result.data[1].name.shouldBeEqual("zone name2") - } - } - } - - test("queryZoneById") { - val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") - coEvery { config.uuidGenerator.generateId() }.returns(requestId) - - runBlocking { - val simulatedBackendReady = CompletableDeferred() - val queryReceived = CompletableDeferred() - launch { - XesarMqttClient.connectAsync(config).await().use { client -> - client.subscribeAsync(arrayOf(Topics.ALL_TOPICS)).await() - - client.onMessage = { topic, payload -> - when (topic) { - Topics.Query.REQUEST -> { - queryReceived.complete(payload.decodeToString()) - } - } - } - - simulatedBackendReady.complete(Unit) - - val queryContent = queryReceived.await() - - queryContent.shouldBeEqual( - QueryTestHelper.createQueryRequest( - Zone.QUERY_RESOURCE, - requestId, - ZoneFixture.zoneFixture.id, - ) - ) - - val zone = - encodeQueryElement(QueryElement(requestId, ZoneFixture.zoneFixture)) - - client - .publishAsync(Topics.Query.result(config.apiProperties.userId), zone) - .await() - } - } - launch { - simulatedBackendReady.await() - val api = XesarConnect.connectAndLoginAsync(config).await() - api.subscribeAsync(Topics(Topics.Query.result(config.apiProperties.userId))) - .await() - val result = api.queryZoneById(ZoneFixture.zoneFixture.id) - result!!.id.shouldBeEqual(ZoneFixture.zoneFixture.id) - result.name.shouldBeEqual("zone name") - } - } - } - }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryAccessProtocolEventTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryAccessProtocolEventTest.kt new file mode 100644 index 00000000..d22dbbe3 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryAccessProtocolEventTest.kt @@ -0,0 +1,60 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryAccessProtocolEvents +import com.open200.xesar.connect.messages.query.QueryList +import com.open200.xesar.connect.messages.query.encodeQueryList +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.AccessProtocolEventFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryAccessProtocolEventTest : + FunSpec({ + test("queryAccessProtocolEventList without params") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Query.REQUEST) { + val person = + encodeQueryList( + QueryList( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + QueryList.Response( + listOf( + AccessProtocolEventFixture.accessProtocolEvent, + AccessProtocolEventFixture.accessProtocolEvent.copy( + id = + UUID.fromString( + "4509ca29-9fd3-454f-9c98-fc0967fe3f66" + ) + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), person) + } + + val api = harness.api + val result = api.queryAccessProtocolEvents() + result.totalCount.shouldBeEqual(2) + result.data[0] + .id + .shouldBeEqual(UUID.fromString("0f0f5120-098c-4d8f-92f3-2a073b85ef8a")) + result.data[1] + .id + .shouldBeEqual(UUID.fromString("4509ca29-9fd3-454f-9c98-fc0967fe3f66")) + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + "{\"resource\":\"access-protocol\",\"requestId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"${MockedXesarConnect.TOKEN}\",\"id\":null,\"params\":null}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryAuthorizationProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryAuthorizationProfileTest.kt new file mode 100644 index 00000000..371c7221 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryAuthorizationProfileTest.kt @@ -0,0 +1,95 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryAuthorizationProfileById +import com.open200.xesar.connect.extension.queryAuthorizationProfiles +import com.open200.xesar.connect.messages.query.* +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.AuthorizationProfileFixture.authorizationProfileFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryAuthorizationProfileTest : + FunSpec({ + test("queryAuthorizationProfileList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val authorizationProfiles = + encodeQueryList( + QueryList( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + QueryList.Response( + listOf( + authorizationProfileFixture, + authorizationProfileFixture.copy( + id = + UUID.fromString( + "894852cf-ca33-4734-a4a9-008eeeaeb005" + ), + name = "authorization profile 2", + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), authorizationProfiles) + } + + val api = harness.api + val result = api.queryAuthorizationProfiles() + result.totalCount.shouldBeEqual(2) + result.data[0].name.shouldBeEqual("authorization profile 1 String") + result.data[1].name.shouldBeEqual("authorization profile 2") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + AuthorizationProfile.QUERY_RESOURCE, + requestId, + ) + ) + } + } + + test("queryAuthorizationProfileById") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val person = + encodeQueryElement( + QueryElement( + UUID.fromString("00000000-1281-42c0-9a15-c5844850c748"), + authorizationProfileFixture, + ) + ) + + emitMessage(Topics.Query.result(userId), person) + } + + val api = harness.api + val result = api.queryAuthorizationProfileById(authorizationProfileFixture.id) + result!!.id.shouldBeEqual(authorizationProfileFixture.id) + result.name.shouldBeEqual("authorization profile 1 String") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + AuthorizationProfile.QUERY_RESOURCE, + requestId, + authorizationProfileFixture.id, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryCalendarTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryCalendarTest.kt new file mode 100644 index 00000000..df9bdc94 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryCalendarTest.kt @@ -0,0 +1,95 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryCalendarById +import com.open200.xesar.connect.extension.queryCalendars +import com.open200.xesar.connect.messages.query.* +import com.open200.xesar.connect.messages.query.Calendar +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.CalendarFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryCalendarTest : + FunSpec({ + test("queryCalendarList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val calendar = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + CalendarFixture.calendarFixture, + CalendarFixture.calendarFixture.copy( + id = + UUID.fromString( + "4509ca29-9fd3-454f-9c98-fc0967fe3f66" + ), + partitionId = + UUID.fromString( + "6b4399a0-21ce-4bee-ba43-e06e291248d2" + ), + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), calendar) + } + + val api = harness.api + val result = api.queryCalendars() + result.totalCount.shouldBeEqual(2) + result.data[0] + .partitionId + .shouldBeEqual(UUID.fromString("7b4399a0-21ce-4bee-ba43-e06e291248d2")) + result.data[1] + .partitionId + .shouldBeEqual(UUID.fromString("6b4399a0-21ce-4bee-ba43-e06e291248d2")) + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest(Calendar.QUERY_RESOURCE, requestId) + ) + } + } + + test("queryCalendarById") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val calendar = + encodeQueryElement(QueryElement(requestId, CalendarFixture.calendarFixture)) + + emitMessage(Topics.Query.result(userId), calendar) + } + + val api = harness.api + val result = api.queryCalendarById(CalendarFixture.calendarFixture.id) + result!!.id.shouldBeEqual(CalendarFixture.calendarFixture.id) + result.name.shouldBeEqual("string") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + Calendar.QUERY_RESOURCE, + requestId, + CalendarFixture.calendarFixture.id, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryCodingStationTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryCodingStationTest.kt new file mode 100644 index 00000000..c885d729 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryCodingStationTest.kt @@ -0,0 +1,94 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryCodingStationById +import com.open200.xesar.connect.extension.queryCodingStations +import com.open200.xesar.connect.messages.query.* +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.CodingStationFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryCodingStationTest : + FunSpec({ + test("queryCodingStationList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val codingStation = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + CodingStationFixture.codingStationFixture, + CodingStationFixture.codingStationFixture.copy( + id = + UUID.fromString( + "4509ca29-9fd3-454f-9c98-fc0967fe3f66" + ), + partitionId = + UUID.fromString( + "6b4399a0-21ce-4bee-ba43-e06e291248d2" + ), + online = false, + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), codingStation) + } + + val api = harness.api + val result = api.queryCodingStations() + result.totalCount.shouldBeEqual(2) + result.data[0].online?.shouldBeEqual(true) + result.data[1].online?.shouldBeEqual(false) + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest(CodingStation.QUERY_RESOURCE, requestId) + ) + } + } + + test("queryCodingStationById") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val codingStation = + encodeQueryElement( + QueryElement(requestId, CodingStationFixture.codingStationFixture) + ) + + emitMessage(Topics.Query.result(userId), codingStation) + } + + val api = harness.api + val result = + api.queryCodingStationById(CodingStationFixture.codingStationFixture.id) + result!!.id.shouldBeEqual(CodingStationFixture.codingStationFixture.id) + result.online?.shouldBeEqual(true) + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + CodingStation.QUERY_RESOURCE, + requestId, + CodingStationFixture.codingStationFixture.id, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryEvvaComponentTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryEvvaComponentTest.kt new file mode 100644 index 00000000..ceb36be2 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryEvvaComponentTest.kt @@ -0,0 +1,90 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryEvvaComponentById +import com.open200.xesar.connect.extension.queryEvvaComponents +import com.open200.xesar.connect.messages.query.* +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.EvvaComponentFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryEvvaComponentTest : + FunSpec({ + test("queryEvvaComponentList with params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val evvaComponentList = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + EvvaComponentFixture.evvaComponentFixture, + EvvaComponentFixture.evvaComponentFixture.copy( + id = + UUID.fromString( + "f7019248-f7f9-4138-9af7-119e2e251408" + ), + status = ComponentStatus.NotSynced, + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), evvaComponentList) + } + + val api = harness.api + val result = api.queryEvvaComponents() + result.totalCount.shouldBeEqual(2) + result.data[0].status?.shouldBeEqual(ComponentStatus.Synced) + result.data[1].status?.shouldBeEqual(ComponentStatus.NotSynced) + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest(EvvaComponent.QUERY_RESOURCE, requestId) + ) + } + } + + test("queryEvvaComponentById") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val evvaComponent = + encodeQueryElement( + QueryElement(requestId, EvvaComponentFixture.evvaComponentFixture) + ) + + emitMessage(Topics.Query.result(userId), evvaComponent) + } + + val api = harness.api + val result = + api.queryEvvaComponentById(EvvaComponentFixture.evvaComponentFixture.id) + result!!.id.shouldBeEqual(EvvaComponentFixture.evvaComponentFixture.id) + result.status?.shouldBeEqual(ComponentStatus.Synced) + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + EvvaComponent.QUERY_RESOURCE, + requestId, + EvvaComponentFixture.evvaComponentFixture.id, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryIdentificationMediumAccessDataTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryIdentificationMediumAccessDataTest.kt new file mode 100644 index 00000000..5f191371 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryIdentificationMediumAccessDataTest.kt @@ -0,0 +1,142 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryIdentificationMediumAccessData +import com.open200.xesar.connect.extension.queryIdentificationMediumAccessDataById +import com.open200.xesar.connect.messages.query.IdentificationMediumAccessData +import com.open200.xesar.connect.messages.query.QueryElement +import com.open200.xesar.connect.messages.query.QueryList +import com.open200.xesar.connect.messages.query.encodeQueryElement +import com.open200.xesar.connect.messages.query.encodeQueryList +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.IdentificationMediumAccessDataFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryIdentificationMediumAccessDataTest : + FunSpec({ + test("queryIdentificationMediaAccessDataList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val IdentificationMediumAccessData = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + IdentificationMediumAccessDataFixture + .identificationMediumAccessData, + IdentificationMediumAccessDataFixture + .identificationMediumAccessData + .copy( + identificationMedium = + IdentificationMediumAccessDataFixture + .identificationMediumAccessData + .identificationMedium + .copy( + xsMediumId = + UUID.fromString( + "8d8347ba-e8f9-40ed-af7d-f08d9290b3db" + ), + xsMobileId = + UUID.fromString( + "df2e491a-aa69-4488-905f-3ea48fd5c5b0" + ), + ) + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), IdentificationMediumAccessData) + } + + val api = harness.api + val result = api.queryIdentificationMediumAccessData() + result.totalCount.shouldBeEqual(2) + result.data[0] + .identificationMedium + .xsMediumId + .shouldBeEqual( + IdentificationMediumAccessDataFixture.identificationMediumAccessData + .identificationMedium + .xsMediumId + ) + result.data[1] + .identificationMedium + .xsMediumId + .shouldBeEqual(UUID.fromString("8d8347ba-e8f9-40ed-af7d-f08d9290b3db")) + + result.data[0] + .identificationMedium + .xsMobileId + ?.shouldBeEqual( + IdentificationMediumAccessDataFixture.identificationMediumAccessData + .identificationMedium + .xsMobileId as UUID + ) + result.data[1] + .identificationMedium + .xsMobileId + ?.shouldBeEqual(UUID.fromString("df2e491a-aa69-4488-905f-3ea48fd5c5b0")) + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + IdentificationMediumAccessData.QUERY_RESOURCE, + requestId, + ) + ) + } + } + + test("queryIdentificationMediumAccessDataById without params") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + + val id = + IdentificationMediumAccessDataFixture.identificationMediumAccessData + .identificationMedium + .xsMediumId + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val identificationMediumAccessData = + encodeQueryElement( + QueryElement( + requestId, + IdentificationMediumAccessDataFixture.identificationMediumAccessData, + ) + ) + + emitMessage(Topics.Query.result(userId), identificationMediumAccessData) + } + + val api = harness.api + val result = api.queryIdentificationMediumAccessDataById(id) + result!!.identificationMedium.xsMediumId.shouldBeEqual(id) + result.identificationMedium.metadata.accessPoints + ?.get(1) + ?.bleMac + ?.shouldBeEqual("00:1B:44:11:3A:B7") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + IdentificationMediumAccessData.QUERY_RESOURCE, + requestId, + id, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryIdentificationMediumTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryIdentificationMediumTest.kt new file mode 100644 index 00000000..110ede6d --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryIdentificationMediumTest.kt @@ -0,0 +1,215 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.* +import com.open200.xesar.connect.exception.MediumListSizeException +import com.open200.xesar.connect.extension.queryIdentificationMediumById +import com.open200.xesar.connect.extension.queryIdentificationMediumByMediumIdentifier +import com.open200.xesar.connect.extension.queryIdentificationMediums +import com.open200.xesar.connect.messages.query.* +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.IdentificationMediumFixture +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.nulls.shouldBeNull +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryIdentificationMediumTest : + FunSpec({ + test("queryIdentificationMediaList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val identificationMedium = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + IdentificationMediumFixture.identificationMediumFixture, + IdentificationMediumFixture.identificationMediumFixture + .copy( + id = + UUID.fromString( + "a4c838a8-f6be-49e0-abee-c1d3b2897279" + ), + label = "test door 2", + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), identificationMedium) + } + + val api = harness.api + val result = api.queryIdentificationMediums() + result.totalCount.shouldBeEqual(2) + result.data[0].label.shouldBeEqual("test door") + result.data[1].label.shouldBeEqual("test door 2") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + IdentificationMedium.QUERY_RESOURCE, + requestId, + ) + ) + } + } + + test( + "queryIdentificationMediumByMediumIdentifierAsync without params should return an element" + ) { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val identificationMedium = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf(IdentificationMediumFixture.identificationMediumFixture), + 1, + 1, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), identificationMedium) + } + + val api = harness.api + val result = + api.queryIdentificationMediumByMediumIdentifier(mediumIdentifierValue = 1) + + result?.label?.shouldBeEqual("test door") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + "{\"resource\":\"identification-media\",\"requestId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"${MockedXesarConnect.TOKEN}\",\"id\":null,\"params\":{\"pageOffset\":null,\"pageLimit\":null,\"sort\":null,\"language\":null,\"filters\":[{\"field\":\"mediumIdentifier\",\"type\":\"eq\",\"value\":\"1\"}]}}" + ) + } + } + + test( + "queryIdentificationMediumByMediumIdentifierAsync without params should return null when no result" + ) { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val identificationMedium = + encodeQueryList(QueryList(requestId, QueryList.Response(listOf(), 1, 1))) + + emitMessage(Topics.Query.result(userId), identificationMedium) + } + + val api = harness.api + val result = + api.queryIdentificationMediumByMediumIdentifier(mediumIdentifierValue = 9999) + + result.shouldBeNull() + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + "{\"resource\":\"identification-media\",\"requestId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"${MockedXesarConnect.TOKEN}\",\"id\":null,\"params\":{\"pageOffset\":null,\"pageLimit\":null,\"sort\":null,\"language\":null,\"filters\":[{\"field\":\"mediumIdentifier\",\"type\":\"eq\",\"value\":\"9999\"}]}}" + ) + } + } + + test( + "queryIdentificationMediumByMediumIdentifierAsync should throw an exception if the results is returning 2 values" + ) { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val identificationMedium = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + IdentificationMediumFixture.identificationMediumFixture, + IdentificationMediumFixture.identificationMediumFixture + .copy( + id = + UUID.fromString( + "a4c838a8-f6be-49e0-abee-c1d3b2897279" + ), + label = "test door 2", + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), identificationMedium) + } + + val api = harness.api + val result = + shouldThrow { + api.queryIdentificationMediumByMediumIdentifier(mediumIdentifierValue = 1) + } + + result.message?.shouldBeEqual( + "Expected exactly one element in the list with mediumIdentifier 1, but found 2 elements" + ) + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + "{\"resource\":\"identification-media\",\"requestId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"${MockedXesarConnect.TOKEN}\",\"id\":null,\"params\":{\"pageOffset\":null,\"pageLimit\":null,\"sort\":null,\"language\":null,\"filters\":[{\"field\":\"mediumIdentifier\",\"type\":\"eq\",\"value\":\"1\"}]}}" + ) + } + } + + test("queryIdentificationMediumById") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + + val id = IdentificationMediumFixture.identificationMediumFixture.id + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val identificationMedium = + encodeQueryElement( + QueryElement( + requestId, + IdentificationMediumFixture.identificationMediumFixture, + ) + ) + + emitMessage(Topics.Query.result(userId), identificationMedium) + } + + val api = harness.api + val result = api.queryIdentificationMediumById(id) + result!!.id.shouldBeEqual(id) + result.label.shouldBeEqual("test door") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + IdentificationMedium.QUERY_RESOURCE, + requestId, + id, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryInstallationPointTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryInstallationPointTest.kt new file mode 100644 index 00000000..5d6a0ac2 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryInstallationPointTest.kt @@ -0,0 +1,93 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryInstallationPointById +import com.open200.xesar.connect.extension.queryInstallationPoints +import com.open200.xesar.connect.messages.query.* +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.InstallationPointFixture.installationPointFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryInstallationPointTest : + FunSpec({ + test("queryInstallationPointList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val installationPoint = + encodeQueryList( + QueryList( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + QueryList.Response( + listOf( + installationPointFixture, + installationPointFixture.copy( + id = + UUID.fromString( + "a4c838a8-f6be-49e0-abee-c1d3b2897279" + ), + name = "door 2 entry point", + description = "door 2", + installationId = "0cefd48b-969e-43eb-aad6-98553288eb4d", + installationType = "door 2", + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), installationPoint) + } + + val api = harness.api + val result = api.queryInstallationPoints() + result.totalCount.shouldBeEqual(2) + result.data[0].name.shouldBeEqual("door 1 entry point") + result.data[1].name.shouldBeEqual("door 2 entry point") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + InstallationPoint.QUERY_RESOURCE, + requestId, + ) + ) + } + } + + test("queryInstallationPointById") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val installationPoint = + encodeQueryElement(QueryElement(requestId, installationPointFixture)) + + emitMessage(Topics.Query.result(userId), installationPoint) + } + + val api = harness.api + val result = api.queryInstallationPointById(installationPointFixture.id) + result!!.id.shouldBeEqual(installationPointFixture.id) + result.name.shouldBeEqual("door 1 entry point") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + InstallationPoint.QUERY_RESOURCE, + requestId, + installationPointFixture.id, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryOfficeModeTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryOfficeModeTest.kt new file mode 100644 index 00000000..e4864bd3 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryOfficeModeTest.kt @@ -0,0 +1,91 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryOfficeModeById +import com.open200.xesar.connect.extension.queryOfficeModes +import com.open200.xesar.connect.messages.query.* +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.OfficeModeFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryOfficeModeTest : + FunSpec({ + test("queryOfficeModeList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val officeModes = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + OfficeModeFixture.officeModeFixture, + OfficeModeFixture.officeModeFixture.copy( + id = + UUID.fromString( + "894852cf-ca33-4734-a4a9-008eeeaeb005" + ), + timeProfileName = "timeProfileName2", + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), officeModes) + } + + val api = harness.api + val result = api.queryOfficeModes() + result.totalCount.shouldBeEqual(2) + result.data[0].timeProfileName.shouldBeEqual("timeProfileName") + result.data[1].timeProfileName.shouldBeEqual("timeProfileName2") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest(OfficeMode.QUERY_RESOURCE, requestId) + ) + } + } + + test("queryOfficeModeById") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val officeMode = + encodeQueryElement( + QueryElement(requestId, OfficeModeFixture.officeModeFixture) + ) + + emitMessage(Topics.Query.result(userId), officeMode) + } + + val api = harness.api + val result = api.queryOfficeModeById(OfficeModeFixture.officeModeFixture.id) + result!!.id.shouldBeEqual(OfficeModeFixture.officeModeFixture.id) + result.installationPointId.shouldBeEqual( + UUID.fromString("39b25462-2580-44dc-b0a8-22fd6c03a023") + ) + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + OfficeMode.QUERY_RESOURCE, + requestId, + OfficeModeFixture.officeModeFixture.id, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryPersonTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryPersonTest.kt new file mode 100644 index 00000000..c2950458 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryPersonTest.kt @@ -0,0 +1,109 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryPersonById +import com.open200.xesar.connect.extension.queryPersons +import com.open200.xesar.connect.messages.command.FilterType +import com.open200.xesar.connect.messages.command.Query +import com.open200.xesar.connect.messages.query.QueryElement +import com.open200.xesar.connect.messages.query.QueryList +import com.open200.xesar.connect.messages.query.encodeQueryElement +import com.open200.xesar.connect.messages.query.encodeQueryList +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.fixture.PersonFixture.personFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryPersonTest : + FunSpec({ + test("queryPersonList with params") { + runTest { + val harness = MockedXesarConnect(this) + harness.respondTo(Topics.Query.REQUEST) { + val person = + encodeQueryList( + QueryList( + UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), + QueryList.Response( + listOf( + personFixture, + personFixture.copy( + id = + UUID.fromString( + "f7019248-f7f9-4138-9af7-119e2e251408" + ), + firstName = "firstname 2 String", + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), person) + } + + val params = + Query.Params( + 0, + 3, + "firstName", + null, + listOf( + Query.Params.Filter( + "firstName", + FilterType.CONTAINS, + "filtered first name", + ) + ), + ) + val api = harness.api + val result = api.queryPersons(params) + result.totalCount.shouldBeEqual(2) + result.data[0].firstName.shouldBeEqual("firstname String") + result.data[1].firstName.shouldBeEqual("firstname 2 String") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + "{\"resource\":\"persons\",\"requestId\":\"00000000-1281-40ae-89d7-5c541d77a757\",\"token\":\"${MockedXesarConnect.TOKEN}\",\"id\":null," + + "\"params\":{\"pageOffset\":0,\"pageLimit\":3,\"sort\":\"firstName\",\"language\":null,\"filters\":[{\"field\":\"firstName\",\"type\":\"contains\",\"value\":\"filtered first name\"}]}}" + ) + } + } + + test("queryPersonById") { + runTest { + val harness = + MockedXesarConnect( + this, + UUID.fromString("00000000-1281-42c0-9a15-c5844850c748"), + ) + harness.respondTo(Topics.Query.REQUEST) { + val person = + encodeQueryElement( + QueryElement( + UUID.fromString("00000000-1281-42c0-9a15-c5844850c748"), + personFixture, + ) + ) + + emitMessage(Topics.Query.result(userId), person) + } + + val api = harness.api + val result = api.queryPersonById(personFixture.id) + result!!.id.shouldBeEqual(personFixture.id) + result.firstName.shouldBeEqual("firstname String") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + "{\"resource\":\"persons\",\"requestId\":\"00000000-1281-42c0-9a15-c5844850c748\",\"token\":\"${MockedXesarConnect.TOKEN}\",\"id\":\"${personFixture.id}\",\"params\":null}" + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryTimeProfileTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryTimeProfileTest.kt new file mode 100644 index 00000000..a5d7fc5a --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryTimeProfileTest.kt @@ -0,0 +1,89 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryTimeProfileById +import com.open200.xesar.connect.extension.queryTimeProfiles +import com.open200.xesar.connect.messages.query.* +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.TimeProfileFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryTimeProfileTest : + FunSpec({ + test("queryTimeProfileList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val person = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + TimeProfileFixture.timeProfileFixture, + TimeProfileFixture.timeProfileFixture.copy( + id = + UUID.fromString( + "4509ca29-9fd3-454f-9c98-fc0967fe3f66" + ), + name = "name 2", + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), person) + } + + val api = harness.api + val result = api.queryTimeProfiles() + result.totalCount.shouldBeEqual(2) + result.data[0].name?.shouldBeEqual("name") + result.data[1].name?.shouldBeEqual("name 2") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest(TimeProfile.QUERY_RESOURCE, requestId) + ) + } + } + + test("queryTimeProfileById") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val person = + encodeQueryElement( + QueryElement(requestId, TimeProfileFixture.timeProfileFixture) + ) + + emitMessage(Topics.Query.result(userId), person) + } + + val api = harness.api + val result = api.queryTimeProfileById(TimeProfileFixture.timeProfileFixture.id!!) + result!!.id?.shouldBeEqual(TimeProfileFixture.timeProfileFixture.id!!) + result.name?.shouldBeEqual("name") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + TimeProfile.QUERY_RESOURCE, + requestId, + TimeProfileFixture.timeProfileFixture.id!!, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryUserTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryUserTest.kt new file mode 100644 index 00000000..afc38516 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryUserTest.kt @@ -0,0 +1,60 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryUsers +import com.open200.xesar.connect.messages.query.QueryList +import com.open200.xesar.connect.messages.query.User +import com.open200.xesar.connect.messages.query.encodeQueryList +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.UserFixture.userFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryUserTest : + FunSpec({ + test("queryUserList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val person = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + userFixture, + userFixture.copy( + id = + UUID.fromString( + "4509ca29-9fd3-454f-9c98-fc0967fe3f66" + ), + name = "lastname 2 String", + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), person) + } + + val api = harness.api + val result = api.queryUsers() + result.totalCount.shouldBeEqual(2) + result.data[0].name.shouldBeEqual("lastname String") + result.data[1].name.shouldBeEqual("lastname 2 String") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest(User.QUERY_RESOURCE, requestId) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryZoneTest.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryZoneTest.kt new file mode 100644 index 00000000..e8ba097f --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/query/QueryZoneTest.kt @@ -0,0 +1,86 @@ +package com.open200.xesar.connect.query + +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.extension.queryZoneById +import com.open200.xesar.connect.extension.queryZones +import com.open200.xesar.connect.messages.query.* +import com.open200.xesar.connect.util.MockedXesarConnect +import com.open200.xesar.connect.util.QueryTestHelper +import com.open200.xesar.connect.util.fixture.ZoneFixture +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.equals.shouldBeEqual +import java.util.* +import kotlinx.coroutines.test.runTest + +class QueryZoneTest : + FunSpec({ + test("queryZoneList without params") { + val requestId = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val zones = + encodeQueryList( + QueryList( + requestId, + QueryList.Response( + listOf( + ZoneFixture.zoneFixture, + ZoneFixture.zoneFixture.copy( + id = + UUID.fromString( + "4509ca29-9fd3-454f-9c98-fc0967fe3f66" + ), + name = "zone name2", + ), + ), + 2, + 2, + ), + ) + ) + + emitMessage(Topics.Query.result(userId), zones) + } + + val api = harness.api + val result = api.queryZones() + result.totalCount.shouldBeEqual(2) + result.data[0].name.shouldBeEqual("zone name") + result.data[1].name.shouldBeEqual("zone name2") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest(Zone.QUERY_RESOURCE, requestId) + ) + } + } + + test("queryZoneById") { + val requestId = UUID.fromString("00000000-1281-42c0-9a15-c5844850c748") + runTest { + val harness = MockedXesarConnect(this, requestId) + harness.respondTo(Topics.Query.REQUEST) { + val zone = encodeQueryElement(QueryElement(requestId, ZoneFixture.zoneFixture)) + + emitMessage(Topics.Query.result(userId), zone) + } + + val api = harness.api + val result = api.queryZoneById(ZoneFixture.zoneFixture.id) + result!!.id.shouldBeEqual(ZoneFixture.zoneFixture.id) + result.name.shouldBeEqual("zone name") + + harness + .publishedPayload(Topics.Query.REQUEST) + .shouldBeEqual( + QueryTestHelper.createQueryRequest( + Zone.QUERY_RESOURCE, + requestId, + ZoneFixture.zoneFixture.id, + ) + ) + } + } + }) diff --git a/xesar-connect/src/test/kotlin/com/open200/xesar/connect/util/MockedXesarConnect.kt b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/util/MockedXesarConnect.kt new file mode 100644 index 00000000..c4c33458 --- /dev/null +++ b/xesar-connect/src/test/kotlin/com/open200/xesar/connect/util/MockedXesarConnect.kt @@ -0,0 +1,113 @@ +package com.open200.xesar.connect.util + +import com.open200.xesar.connect.Config +import com.open200.xesar.connect.Topics +import com.open200.xesar.connect.XesarConnect +import com.open200.xesar.connect.XesarMqttClient +import com.open200.xesar.connect.messages.event.ApiEvent +import com.open200.xesar.connect.messages.event.Event +import com.open200.xesar.connect.messages.event.encodeEvent +import io.kotest.assertions.fail +import io.mockk.Runs +import io.mockk.every +import io.mockk.just +import io.mockk.mockk +import io.mockk.spyk +import java.util.* +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CopyOnWriteArrayList +import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.test.StandardTestDispatcher +import kotlinx.coroutines.test.TestScope +import org.eclipse.paho.client.mqttv3.MqttAsyncClient + +/* + * Test harness which creates a XesarConnect instance without a MQTT broker. + * - the MqttAsyncClient is mocked and published messages are recorded instead of being sent + * - the backend is simulated with responders which are called when a message is published on a topic + * - incoming messages from the broker are simulated by calling onMessage of the XesarMqttClient + * - login is not needed, the token is initialized directly + * + * Usage: + * val harness = MockedXesarConnect(this) + * harness.respondTo(Topics.Command.LOCK_MEDIUM) { emitEvent(Topics.Event.MEDIUM_LOCKED, event) } + * val result = harness.api.lockMediumAsync(mediumId).await() + * harness.publishedPayload(Topics.Command.LOCK_MEDIUM).shouldBeEqual("...") + */ +class MockedXesarConnect( + scope: TestScope, + val commandId: UUID = UUID.fromString("00000000-1281-40ae-89d7-5c541d77a757"), +) { + val userId: UUID = UUID.fromString("faf3d0c4-1281-40ae-89d7-5c541d77a757") + val token = TOKEN + + val client: XesarMqttClient = + spyk(XesarMqttClient(mockk { every { setCallback(any()) } just Runs })) + + private val published = CopyOnWriteArrayList>() + private val responders = ConcurrentHashMap Unit>() + + val api: XesarConnect + + init { + every { client.publishAsync(any(), any(), any()) } answers + { + val topic = firstArg() + val payload = secondArg() + published.add(topic to payload) + responders[topic]?.invoke(this@MockedXesarConnect, payload) + CompletableDeferred(Unit) + } + + val config = + mockk { + every { dispatcherForCommandsAndCleanUp } returns + StandardTestDispatcher(scope.testScheduler) + every { uuidGenerator.generateId() } returns commandId + every { apiProperties } returns + Config.ApiProperties( + hostname = "hostname", + port = "1883", + userId = userId, + token = token, + ) + } + + api = XesarConnect(client, config).also { it.token = token } + } + + /** + * Simulates the backend: [responder] is called with the payload whenever a message is published + * on [topic]. Don't assert inside the responder, use [publishedPayload] after the call instead. + */ + fun respondTo(topic: String, responder: MockedXesarConnect.(payload: String) -> Unit) { + responders[topic] = responder + } + + /** Simulates an event for [commandId] received from the broker on [topic]. */ + inline fun emitEvent(topic: String, event: E) { + emitMessage(topic, encodeEvent(ApiEvent(commandId, event))) + } + + /** Simulates an encoded query result received from the broker. */ + fun emitQueryResult(payload: String) { + emitMessage(Topics.Query.result(userId), payload) + } + + /** Simulates a raw message received from the broker on [topic]. */ + fun emitMessage(topic: String, payload: String) { + client.onMessage(topic, payload.encodeToByteArray()) + } + + /** Returns the last payload published on [topic] or fails if nothing was published there. */ + fun publishedPayload(topic: String): String = + published.lastOrNull { it.first == topic }?.second + ?: fail( + "nothing published on topic $topic, published topics: ${published.map { it.first }}" + ) + + companion object { + const val TOKEN = + "JDJhJDEwJDFSNEljZ2FaRUNXUXBTQ25XN05KbE9qRzFHQ1VjMzkvWTBVcFpZb1M4Vmt0dnJYZ0tJVFBx" + } +}