71 lines
2.2 KiB
Java
71 lines
2.2 KiB
Java
package com.auction;
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.opencv.core.Core;
|
|
|
|
import java.io.File;
|
|
import java.sql.SQLException;
|
|
import java.util.List;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
/**
|
|
* Test case for TroostwijkScraper that verifies auction discovery and data persistence.
|
|
* Uses a temporary test database to verify that:
|
|
* 1. Dutch auctions are correctly discovered from the live page
|
|
* 2. Auction properties (sale IDs, titles, etc.) are valid
|
|
* 3. Data is correctly persisted to the database
|
|
*/
|
|
public class TroostwijkScraperTest {
|
|
|
|
private TroostwijkScraper scraper;
|
|
private String testDatabasePath;
|
|
|
|
@BeforeAll
|
|
public static void loadOpenCV() {
|
|
// Load native OpenCV library before any tests run
|
|
try {
|
|
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
|
IO.println("✓ OpenCV native library loaded successfully");
|
|
} catch (UnsatisfiedLinkError e) {
|
|
System.err.println("⚠️ Warning: Could not load OpenCV native library");
|
|
System.err.println(" Tests will run without object detection support");
|
|
}
|
|
}
|
|
|
|
@BeforeEach
|
|
public void setUp() throws SQLException, java.io.IOException {
|
|
// Create temporary test database
|
|
testDatabasePath = "test_auctions_" + System.currentTimeMillis() + ".db";
|
|
|
|
// Initialize scraper with test database (no YOLO models needed for this test)
|
|
// Using non-existent paths for YOLO files will disable object detection
|
|
scraper = new TroostwijkScraper(
|
|
testDatabasePath,
|
|
"desktop",
|
|
"",
|
|
"nonexistent/yolov4.cfg",
|
|
"nonexistent/yolov4.weights",
|
|
"nonexistent/coco.names"
|
|
);
|
|
}
|
|
|
|
@AfterEach
|
|
public void tearDown() {
|
|
// Clean up browser and cache
|
|
if (scraper != null) {
|
|
scraper.close();
|
|
}
|
|
|
|
// Clean up test database
|
|
var dbFile = new File(testDatabasePath);
|
|
if (dbFile.exists()) {
|
|
dbFile.delete();
|
|
}
|
|
}
|
|
|
|
}
|