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

@@ -41,8 +41,8 @@ public class AuctionParsingTest {
System.out.println("\n=== Auction Parsing Test ===");
System.out.println("Found " + auctionLinks.size() + " auction links");
List<TroostwijkScraper.AuctionInfo> auctions = new ArrayList<>();
int count = 0;
List<AuctionInfo> auctions = new ArrayList<>();
int count = 0;
for (Element link : auctionLinks) {
String href = link.attr("href");
@@ -59,7 +59,7 @@ public class AuctionParsingTest {
int auctionId = Integer.parseInt(matcher.group(2));
// Extract auction info using IMPROVED text-based method
TroostwijkScraper.AuctionInfo auction = extractAuctionInfoFromText(link, href, auctionId, "A" + typeNum);
AuctionInfo auction = extractAuctionInfoFromText(link, href, auctionId, "A" + typeNum);
auctions.add(auction);
// Print the first 10 auctions for verification
@@ -101,7 +101,7 @@ public class AuctionParsingTest {
assertTrue(auctions.size() > 0, "Should find at least one auction");
// Verify all auctions have basic info
for (TroostwijkScraper.AuctionInfo auction : auctions) {
for (AuctionInfo auction : auctions) {
assertNotNull(auction.title, "Title should not be null for auction " + auction.auctionId);
assertTrue(auction.title.length() > 0, "Title should not be empty for auction " + auction.auctionId);
assertNotNull(auction.url, "URL should not be null for auction " + auction.auctionId);
@@ -119,8 +119,8 @@ public class AuctionParsingTest {
* Expected format: "[day] om [time] [lot_count] [title] [city], [CC]"
* Example: "woensdag om 18:00 1 Vrachtwagens voor bedrijfsvoertuigen Loßburg, DE"
*/
private TroostwijkScraper.AuctionInfo extractAuctionInfoFromText(Element link, String href, int auctionId, String type) {
TroostwijkScraper.AuctionInfo auction = new TroostwijkScraper.AuctionInfo();
private AuctionInfo extractAuctionInfoFromText(Element link, String href, int auctionId, String type) {
AuctionInfo auction = new AuctionInfo();
auction.auctionId = auctionId;
auction.type = type;
auction.url = "https://www.troostwijkauctions.com" + href;

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");
}
}