-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.ps1
More file actions
240 lines (216 loc) · 9.19 KB
/
verify.ps1
File metadata and controls
240 lines (216 loc) · 9.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# HR Management System - Verification Script
# This script tests all endpoints and functionality
Write-Host "🔍 Verifying HR Management System..." -ForegroundColor Green
Write-Host ""
$serverUrl = "http://localhost:8080"
$clientUrl = "http://localhost:4200"
$results = @()
# Function to test URL
function Test-Url {
param($url, $description)
try {
$response = Invoke-WebRequest -Uri $url -TimeoutSec 10 -UseBasicParsing
if ($response.StatusCode -eq 200) {
$results += [PSCustomObject]@{
Test = $description
URL = $url
Status = "✅ PASS"
Details = "Status: $($response.StatusCode), Size: $($response.Content.Length) bytes"
}
Write-Host "✅ $description - PASS" -ForegroundColor Green
return $true
} else {
$results += [PSCustomObject]@{
Test = $description
URL = $url
Status = "❌ FAIL"
Details = "Status: $($response.StatusCode)"
}
Write-Host "❌ $description - FAIL (Status: $($response.StatusCode))" -ForegroundColor Red
return $false
}
} catch {
$results += [PSCustomObject]@{
Test = $description
URL = $url
Status = "❌ FAIL"
Details = $_.Exception.Message
}
Write-Host "❌ $description - FAIL ($($_.Exception.Message))" -ForegroundColor Red
return $false
}
}
# Function to test JSON API
function Test-JsonApi {
param($url, $description, $expectedCount = $null)
try {
$response = Invoke-RestMethod -Uri $url -TimeoutSec 10
if ($response) {
$count = if ($response.Count) { $response.Count } else { 1 }
$details = "JSON response received"
if ($expectedCount -and $count -ne $expectedCount) {
$details += " (Expected $expectedCount items, got $count)"
$status = "⚠️ PARTIAL"
Write-Host "⚠️ $description - PARTIAL ($details)" -ForegroundColor Yellow
} else {
$details += " ($count items)"
$status = "✅ PASS"
Write-Host "✅ $description - PASS ($details)" -ForegroundColor Green
}
$results += [PSCustomObject]@{
Test = $description
URL = $url
Status = $status
Details = $details
}
return $true
} else {
$results += [PSCustomObject]@{
Test = $description
URL = $url
Status = "❌ FAIL"
Details = "No response data"
}
Write-Host "❌ $description - FAIL (No response data)" -ForegroundColor Red
return $false
}
} catch {
$results += [PSCustomObject]@{
Test = $description
URL = $url
Status = "❌ FAIL"
Details = $_.Exception.Message
}
Write-Host "❌ $description - FAIL ($($_.Exception.Message))" -ForegroundColor Red
return $false
}
}
Write-Host "🔍 Testing Backend APIs..." -ForegroundColor Cyan
# Test backend APIs
Test-JsonApi "$serverUrl/api/departments" "Get All Departments" 4
Test-JsonApi "$serverUrl/api/employees" "Get All Employees" 12
Test-JsonApi "$serverUrl/api/departments/dept01/employees" "Get Engineering Employees" 4
Test-JsonApi "$serverUrl/api/employees/emp001" "Get Employee by ID"
Test-JsonApi "$serverUrl/api/reports/department-employees-map" "Department Employees Map"
# Test PDF endpoint
Write-Host ""
Write-Host "📄 Testing PDF Report..." -ForegroundColor Cyan
try {
$pdfResponse = Invoke-WebRequest -Uri "$serverUrl/api/reports/employees-by-department.pdf" -TimeoutSec 15 -UseBasicParsing
if ($pdfResponse.StatusCode -eq 200 -and $pdfResponse.Headers.'Content-Type' -match 'application/pdf') {
$pdfSize = $pdfResponse.Content.Length
if ($pdfSize -gt 1000) { # PDF should be at least 1KB
$results += [PSCustomObject]@{
Test = "PDF Report Generation"
URL = "$serverUrl/api/reports/employees-by-department.pdf"
Status = "✅ PASS"
Details = "PDF generated successfully ($pdfSize bytes)"
}
Write-Host "✅ PDF Report Generation - PASS ($pdfSize bytes)" -ForegroundColor Green
} else {
$results += [PSCustomObject]@{
Test = "PDF Report Generation"
URL = "$serverUrl/api/reports/employees-by-department.pdf"
Status = "⚠️ PARTIAL"
Details = "PDF too small ($pdfSize bytes)"
}
Write-Host "⚠️ PDF Report Generation - PARTIAL (PDF too small: $pdfSize bytes)" -ForegroundColor Yellow
}
} else {
Write-Host "❌ PDF Report Generation - FAIL (Not a PDF response)" -ForegroundColor Red
}
} catch {
Write-Host "❌ PDF Report Generation - FAIL ($($_.Exception.Message))" -ForegroundColor Red
}
# Test static content
Write-Host ""
Write-Host "🎨 Testing Static Content..." -ForegroundColor Cyan
Test-Url "$serverUrl/cards.html" "Static Cards Page"
Test-Url "$serverUrl/h2-console" "H2 Database Console"
# Test frontend
Write-Host ""
Write-Host "🌐 Testing Frontend..." -ForegroundColor Cyan
Test-Url "$clientUrl" "Angular Frontend"
# Test CRUD operations
Write-Host ""
Write-Host "📝 Testing CRUD Operations..." -ForegroundColor Cyan
try {
# Create a test employee
$testEmployee = @{
id = "emp999"
name = "Test Employee"
email = "test@example.com"
position = "Test Position"
salary = 50000
} | ConvertTo-Json
$createResponse = Invoke-RestMethod -Uri "$serverUrl/api/departments/dept01/employees" -Method POST -Body $testEmployee -ContentType "application/json" -TimeoutSec 10
if ($createResponse.id -eq "emp999") {
Write-Host "✅ Create Employee - PASS" -ForegroundColor Green
# Verify employee was created
$verifyResponse = Invoke-RestMethod -Uri "$serverUrl/api/employees/emp999" -TimeoutSec 10
if ($verifyResponse.id -eq "emp999") {
Write-Host "✅ Verify Created Employee - PASS" -ForegroundColor Green
# Delete the test employee
try {
Invoke-RestMethod -Uri "$serverUrl/api/departments/dept01/employees/emp999" -Method DELETE -TimeoutSec 10
Write-Host "✅ Delete Employee - PASS" -ForegroundColor Green
# Verify employee was deleted
try {
Invoke-RestMethod -Uri "$serverUrl/api/employees/emp999" -TimeoutSec 10
Write-Host "❌ Verify Employee Deletion - FAIL (Employee still exists)" -ForegroundColor Red
} catch {
Write-Host "✅ Verify Employee Deletion - PASS" -ForegroundColor Green
}
} catch {
Write-Host "❌ Delete Employee - FAIL ($($_.Exception.Message))" -ForegroundColor Red
}
} else {
Write-Host "❌ Verify Created Employee - FAIL" -ForegroundColor Red
}
} else {
Write-Host "❌ Create Employee - FAIL" -ForegroundColor Red
}
} catch {
Write-Host "❌ Create Employee - FAIL ($($_.Exception.Message))" -ForegroundColor Red
}
# Test transaction rollback
Write-Host ""
Write-Host "🔄 Testing Transaction Rollback..." -ForegroundColor Cyan
try {
$rollbackResponse = Invoke-RestMethod -Uri "$serverUrl/api/reports/test-rollback" -TimeoutSec 10
if ($rollbackResponse -match "rolled back successfully") {
Write-Host "✅ Transaction Rollback - PASS" -ForegroundColor Green
} else {
Write-Host "❌ Transaction Rollback - FAIL (Unexpected response)" -ForegroundColor Red
}
} catch {
Write-Host "❌ Transaction Rollback - FAIL ($($_.Exception.Message))" -ForegroundColor Red
}
# Summary
Write-Host ""
Write-Host "📊 Verification Summary:" -ForegroundColor Cyan
Write-Host "=" * 80 -ForegroundColor Gray
$passCount = ($results | Where-Object {$_.Status -eq "✅ PASS"}).Count
$failCount = ($results | Where-Object {$_.Status -eq "❌ FAIL"}).Count
$partialCount = ($results | Where-Object {$_.Status -eq "⚠️ PARTIAL"}).Count
$totalCount = $results.Count
Write-Host "Total Tests: $totalCount" -ForegroundColor White
Write-Host "Passed: $passCount" -ForegroundColor Green
Write-Host "Failed: $failCount" -ForegroundColor Red
Write-Host "Partial: $partialCount" -ForegroundColor Yellow
Write-Host ""
Write-Host "Detailed Results:" -ForegroundColor White
$results | Format-Table -AutoSize -Wrap
if ($failCount -eq 0) {
Write-Host ""
Write-Host "🎉 All critical tests passed! System is ready for demo." -ForegroundColor Green
} elseif ($failCount -le 2) {
Write-Host ""
Write-Host "⚠️ Most tests passed. System should work for demo with minor issues." -ForegroundColor Yellow
} else {
Write-Host ""
Write-Host "❌ Multiple tests failed. Please check the system before demo." -ForegroundColor Red
}
Write-Host ""
Write-Host "Press any key to exit..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")