This commit is contained in:
Tour
2025-12-03 15:09:39 +01:00
parent 7fa3e4a545
commit 853c3cf53e
16 changed files with 1405 additions and 2000 deletions

View File

@@ -68,71 +68,18 @@ public class TroostwijkScraperTest {
}
@Test
public void testFetchAndPersistAuctionData() throws SQLException {
// First, discover auctions
List<Integer> auctions = scraper.discoverDutchAuctions();
assertFalse(auctions.isEmpty(), "Need at least one auction to test");
// Take the first auction and fetch its lots
Integer firstSaleId = auctions.getFirst();
System.out.println("Testing with sale ID: " + firstSaleId);
scraper.fetchLotsForSale(firstSaleId);
// Verify data was persisted to database
List<TroostwijkScraper.Lot> lotsInDb = scraper.db.getAllLots();
assertNotNull(lotsInDb, "Lots list should not be null");
assertFalse(lotsInDb.isEmpty(), "Should have persisted at least one lot");
// Verify lot properties
for (TroostwijkScraper.Lot lot : lotsInDb) {
assertEquals(firstSaleId.intValue(), lot.saleId, "Lot should belong to the correct sale");
assertTrue(lot.lotId > 0, "Lot ID should be positive");
assertNotNull(lot.title, "Lot title should not be null");
assertFalse(lot.title.isEmpty(), "Lot title should not be empty");
assertNotNull(lot.url, "Lot URL should not be null");
assertTrue(lot.url.startsWith("https://"), "Lot URL should be valid");
assertTrue(lot.currentBid >= 0, "Current bid should be non-negative");
}
System.out.println("✓ Successfully persisted " + lotsInDb.size() + " lots to database");
System.out.println("✓ All lot properties are valid");
}
@Test
public void testDatabaseSchema() throws SQLException {
// Verify that the database schema was created correctly
List<TroostwijkScraper.Lot> lots = scraper.db.getAllLots();
List<Lot> lots = scraper.db.getAllLots();
assertNotNull(lots, "Should be able to query lots table");
int imageCount = scraper.db.getImageCount();
assertTrue(imageCount >= 0, "Image count should be non-negative");
List<TroostwijkScraper.Lot> activeLots = scraper.db.getActiveLots();
List<Lot> activeLots = scraper.db.getActiveLots();
assertNotNull(activeLots, "Should be able to query active lots");
System.out.println("✓ Database schema is valid and queryable");
}
@Test
public void testAuctionProperties() {
List<Integer> auctions = scraper.discoverDutchAuctions();
assertFalse(auctions.isEmpty(), "Should find auctions");
// Test that we can fetch data for multiple auctions
int auctionsToTest = Math.min(2, auctions.size());
for (int i = 0; i < auctionsToTest; i++) {
Integer saleId = auctions.get(i);
System.out.println("Testing auction " + (i + 1) + ": " + saleId);
// This should not throw an exception
assertDoesNotThrow(() -> scraper.fetchLotsForSale(saleId),
"Should be able to fetch lots for sale " + saleId);
}
System.out.println("✓ Successfully tested " + auctionsToTest + " auctions");
}
}