Changes for page Entwicklung eines ACMP Connectors für die ISS
Last modified by jklein on 2025/02/13 13:15
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -279,95 +279,8 @@ 279 279 280 280 === Testen der PowerShell-Module === 281 281 282 -Die Funktionalität des erstellten Moduls können Sie mithilfe von Pester (dem Standard-Framework für Unit-Testing in PowerShell) oder eines dedizierten PowerShell Scripts verifizieren. So stellen Sie sicher, dass die Logik fehlerfrei und robust ist. In diesem Beispiel wird das Modul //ISSRestConnector.psm1// mit Pester 5.5.0 getestet. 283 - 284 -{{aagon.infobox}} 285 -Beachten Sie, dass Sie Pester für diesen Test ggf. vorher installieren oder updaten müssen. Weitere Informationen dazu finden Sie in der __[[Dokumentation von Pester>>https://pester.dev/docs/introduction/installation]]__. 286 -{{/aagon.infobox}} 287 - 288 -Sie können das PowerShell-Modul folgendermaßen testen: 289 - 290 -1. Erstellen Sie eine neue Datei mit dem Namen //ISSRestConnectorTests.ps1//. 291 -1. Fügen Sie den nachfolgenden Code in die Datei ein. 292 -1. Drücken Sie Strg + S, um die Datei zu speichern. 293 -1. Führen Sie das Script aus 294 - 295 -{{code language="PowerShell" layout="LINENUMBERS" title="**ISSRestConnectorTest.ps1**"}} 296 -Import-Module -Name Pester -MinimumVersion 5.5.0 297 -Remove-Module ".\Modules\ISSRestConnector.psm1" -Force -ErrorAction SilentlyContinue 298 -Import-Module -Name ".\Modules\ISSRestConnector.psm1" -Force 299 - 300 -Describe "Get-ISSData Function Tests" { 301 - BeforeAll { 302 - # Mock the API response 303 - $global:MockApiResponse = @{ 304 - Name = "iss" 305 - Id = 25544 306 - Latitude = 12.34 307 - Longitude = 56.78 308 - Altitude = 408.5 309 - Velocity = 27600.0 310 - Visibility = "daylight" 311 - Timestamp = [datetime]::Now.ToUniversalTime().Subtract([datetime]::UnixEpoch).TotalSeconds 312 - } 313 - } 314 - 315 - Context "When the API responds successfully" { 316 - BeforeEach { 317 - # Mock the API call 318 - Mock -CommandName Invoke-RestMethod -ParameterFilter { $Method -eq 'GET' } -MockWith { 319 - return $global:MockApiResponse 320 - } -ModuleName "ISSRestConnector" 321 - } 322 - 323 - It "Should return a PSCustomObject with expected properties" { 324 - $result = Get-ISSData 325 - $result | Should -BeOfType PSCustomObject 326 - $result.Name | Should -Not -BeNullOrEmpty 327 - $result.Latitude | Should -Not -BeNullOrEmpty 328 - $result.Longitude | Should -Not -BeNullOrEmpty 329 - $result.Altitude | Should -Not -BeNullOrEmpty 330 - $result.Velocity | Should -Not -BeNullOrEmpty 331 - } 332 - 333 - It "Should correctly map the API response to the output object" { 334 - $result = Get-ISSData 335 - $result.Name | Should -Be "iss" 336 - $result.Latitude | Should -Be 12.34 337 - $result.Longitude | Should -Be 56.78 338 - $result.Altitude | Should -Be 408.5 339 - $result.Velocity | Should -Be 27600.0 340 - } 341 - } 342 - 343 - Context "When the API fails" { 344 - 345 - It "Should log an error when the API fails" { 346 - # Mock a failure in the API call 347 - Mock -CommandName Invoke-RestMethod -ParameterFilter { $Method -eq 'GET' } -MockWith { 348 - throw "API error" 349 - } -ModuleName "ISSRestConnector" 350 - 351 - $error.Clear() # Clear any pre-existing errors 352 - Get-ISSData 353 - $error[1].Exception.Message | Should -Contain "API error" 354 - } 355 - } 356 -} 357 -{{/code}} 358 - 359 -(% class="wikigeneratedid" %) 360 -Als Ergebnis des Tests ... 361 - 362 362 === Erstellen der PowerShell-Microservices in AESB === 363 363 364 - 365 -Da die benötigten PowerShell-Module nun erstellt und getestet sind, kann mit der Erstellung der Microservices begonnen werden. 366 - 367 -1. Öffnen Sie die AESB Console und navigieren Sie zum Workspace //Creator - PowerShell//. 368 -1. Klicken Sie in der Ribbonleiste im Bereich //Ordner //auf den Button //Hinzufügen// und Erstellen Sie einen Ordner mit dem Namen// ISS_ACMP_Connector.// 369 -1. 370 - 371 371 === Integrieren der PowerShell-Module in die PowerShell-Microservices === 372 372 373 373