You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
4.5 KiB
117 lines
4.5 KiB
# Simple Import/Export Test
|
|
$ErrorActionPreference = "Stop"
|
|
$env:JAVA_HOME = "C:\Program Files\Java\latest\jdk-25"
|
|
$APP_JAR = "target\datacollect-cli-0.1.0-jar-with-dependencies.jar"
|
|
$TEST_FILE = "data\sample_test.json"
|
|
$EXPORT_FILE = "data\export_result.json"
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Import/Export Feature Test" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Step 1: Import sample data
|
|
Write-Host "[TEST 1] Import sample JSON file" -ForegroundColor Yellow
|
|
Write-Host "Command: import $TEST_FILE" -ForegroundColor Gray
|
|
$result = & java -jar $APP_JAR "import $TEST_FILE" 2>&1
|
|
Write-Host $result -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Step 2: List articles
|
|
Write-Host "[TEST 2] List articles after import" -ForegroundColor Yellow
|
|
Write-Host "Command: list" -ForegroundColor Gray
|
|
$result = & java -jar $APP_JAR "list" 2>&1
|
|
Write-Host $result -ForegroundColor Green
|
|
|
|
# Extract count
|
|
$count1 = 0
|
|
$result -split "`n" | ForEach-Object {
|
|
if ($_ -match "Total: (\d+)") {
|
|
$count1 = [int]$matches[1]
|
|
}
|
|
}
|
|
Write-Host "Article count: $count1" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Step 3: Export to new file
|
|
Write-Host "[TEST 3] Export to new JSON file" -ForegroundColor Yellow
|
|
Write-Host "Command: export $EXPORT_FILE --format json" -ForegroundColor Gray
|
|
$result = & java -jar $APP_JAR "export $EXPORT_FILE --format json" 2>&1
|
|
Write-Host $result -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Step 4: Check exported file
|
|
Write-Host "[TEST 4] Verify exported JSON file" -ForegroundColor Yellow
|
|
if (Test-Path $EXPORT_FILE) {
|
|
Write-Host "[SUCCESS] Export file created" -ForegroundColor Green
|
|
$content = Get-Content $EXPORT_FILE -Raw
|
|
Write-Host "File size: $($content.Length) characters" -ForegroundColor Cyan
|
|
|
|
# Check for crawledAt
|
|
if ($content -match "crawledAt") {
|
|
Write-Host "[SUCCESS] crawledAt field found in exported JSON" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "[ERROR] crawledAt field NOT found" -ForegroundColor Red
|
|
}
|
|
|
|
# Check for metadata
|
|
if ($content -match "metadata") {
|
|
Write-Host "[SUCCESS] metadata field found" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "[ERROR] metadata field NOT found" -ForegroundColor Red
|
|
}
|
|
} else {
|
|
Write-Host "[ERROR] Export file NOT created" -ForegroundColor Red
|
|
}
|
|
Write-Host ""
|
|
|
|
# Step 5: Test duplicate import
|
|
Write-Host "[TEST 5] Test duplicate import (should skip duplicates)" -ForegroundColor Yellow
|
|
Write-Host "Command: import $TEST_FILE (again)" -ForegroundColor Gray
|
|
$result = & java -jar $APP_JAR "import $TEST_FILE" 2>&1
|
|
Write-Host $result -ForegroundColor Green
|
|
|
|
# Step 6: List and verify no duplication
|
|
Write-Host "[TEST 6] Verify no duplication" -ForegroundColor Yellow
|
|
Write-Host "Command: list" -ForegroundColor Gray
|
|
$result = & java -jar $APP_JAR "list" 2>&1
|
|
Write-Host $result -ForegroundColor Green
|
|
|
|
$count2 = 0
|
|
$result -split "`n" | ForEach-Object {
|
|
if ($_ -match "Total: (\d+)") {
|
|
$count2 = [int]$matches[1]
|
|
}
|
|
}
|
|
Write-Host "Article count after second import: $count2" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Summary
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "TEST SUMMARY" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
if ($count1 -eq 3 -and $count2 -eq 3) {
|
|
Write-Host "[SUCCESS] All tests passed!" -ForegroundColor Green
|
|
Write-Host "- Import: Successfully imported 3 articles" -ForegroundColor White
|
|
Write-Host "- Export: Successfully exported to JSON" -ForegroundColor White
|
|
Write-Host "- Duplicate: Correctly skipped duplicate articles" -ForegroundColor White
|
|
Write-Host "- crawledAt field: Present in exported JSON" -ForegroundColor White
|
|
} else {
|
|
Write-Host "[PARTIAL] Some tests may have issues" -ForegroundColor Yellow
|
|
Write-Host "First import count: $count1" -ForegroundColor White
|
|
Write-Host "Second import count: $count2" -ForegroundColor White
|
|
}
|
|
Write-Host ""
|
|
|
|
# Show exported file content
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "EXPORTED JSON CONTENT (Preview)" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
if (Test-Path $EXPORT_FILE) {
|
|
$exportContent = Get-Content $EXPORT_FILE -Raw
|
|
if ($exportContent.Length -gt 1000) {
|
|
Write-Host ($exportContent.Substring(0, 1000) + "...") -ForegroundColor White
|
|
} else {
|
|
Write-Host $exportContent -ForegroundColor White
|
|
}
|
|
}
|
|
|