# Test cross-switch endpoint $apiUrl = "http://localhost:8000" Write-Host "=== Testing Cross-Switch Endpoint ===" -ForegroundColor Cyan Write-Host "" try { # Login to get token $loginBody = @{ username = "admin" password = "admin123" } | ConvertTo-Json Write-Host "1. Logging in..." -ForegroundColor Yellow $loginResponse = Invoke-RestMethod -Uri "$apiUrl/api/v1/auth/login" -Method Post -Body $loginBody -ContentType "application/json" $token = $loginResponse.access_token Write-Host " Login successful" -ForegroundColor Green Write-Host "" # Set up headers $headers = @{ "Authorization" = "Bearer $token" } # Test cross-switch: Camera 101038 to Monitor 1 Write-Host "2. Executing cross-switch: Camera 101038 -> Monitor 1" -ForegroundColor Yellow $crossswitchBody = @{ camera_id = 101038 monitor_id = 1 mode = 0 } | ConvertTo-Json $response = Invoke-RestMethod -Uri "$apiUrl/api/v1/crossswitch" -Method Post -Body $crossswitchBody -ContentType "application/json" -Headers $headers Write-Host "" Write-Host "=== CROSS-SWITCH RESULT ===" -ForegroundColor Cyan Write-Host "Success: $($response.success)" -ForegroundColor $(if ($response.success) { "Green" } else { "Red" }) Write-Host "Message: $($response.message)" -ForegroundColor White Write-Host "Camera ID: $($response.route.camera_id)" -ForegroundColor White Write-Host "Monitor ID: $($response.route.monitor_id)" -ForegroundColor White Write-Host "Executed At: $($response.route.executed_at)" -ForegroundColor Gray Write-Host "" # Get routing state to verify Write-Host "3. Verifying routing state..." -ForegroundColor Yellow $routingResponse = Invoke-RestMethod -Uri "$apiUrl/api/v1/crossswitch/routing" -Method Get -Headers $headers Write-Host "" Write-Host "=== CURRENT ROUTING STATE ===" -ForegroundColor Cyan Write-Host "Total active routes: $($routingResponse.total)" -ForegroundColor Green if ($routingResponse.routes.Count -gt 0) { Write-Host "" Write-Host "Active routes:" -ForegroundColor Yellow foreach ($route in $routingResponse.routes) { Write-Host " - Camera $($route.camera_id) ($($route.camera_name)) -> Monitor $($route.monitor_id) ($($route.monitor_name))" -ForegroundColor White } } Write-Host "" # Full JSON response Write-Host "Full Cross-Switch Response:" -ForegroundColor Yellow $response | ConvertTo-Json -Depth 5 } catch { Write-Host "" Write-Host "=== ERROR ===" -ForegroundColor Red Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red if ($_.ErrorDetails.Message) { Write-Host "Details: $($_.ErrorDetails.Message)" -ForegroundColor Red } Write-Host "" Write-Host "Stack Trace:" -ForegroundColor Yellow Write-Host $_.ScriptStackTrace -ForegroundColor Gray }