@@ -35,26 +35,26 @@ public class AuctionParsingTest {
|
||||
System.out.println("\n=== Location Pattern Tests ===");
|
||||
|
||||
// Test different location formats
|
||||
String[] testCases = {
|
||||
var testCases = new String[]{
|
||||
"<p>Amsterdam, NL</p>",
|
||||
"<p class=\"flex truncate\"><span class=\"w-full truncate\">Sofia,<!-- --> </span>BG</p>",
|
||||
"<p>Berlin, DE</p>",
|
||||
"<span>Brussels,</span>BE"
|
||||
};
|
||||
|
||||
for (String testHtml : testCases) {
|
||||
Document doc = Jsoup.parse(testHtml);
|
||||
Element elem = doc.select("p, span").first();
|
||||
for (var testHtml : testCases) {
|
||||
var doc = Jsoup.parse(testHtml);
|
||||
var elem = doc.select("p, span").first();
|
||||
|
||||
if (elem != null) {
|
||||
String text = elem.text();
|
||||
var text = elem.text();
|
||||
System.out.println("\nTest: " + testHtml);
|
||||
System.out.println("Text: " + text);
|
||||
|
||||
// Test regex pattern
|
||||
if (text.matches(".*[A-Z]{2}$")) {
|
||||
String countryCode = text.substring(text.length() - 2);
|
||||
String cityPart = text.substring(0, text.length() - 2).trim().replaceAll("[,\\s]+$", "");
|
||||
var countryCode = text.substring(text.length() - 2);
|
||||
var cityPart = text.substring(0, text.length() - 2).trim().replaceAll("[,\\s]+$", "");
|
||||
System.out.println("→ Extracted: " + cityPart + ", " + countryCode);
|
||||
} else {
|
||||
System.out.println("→ No match");
|
||||
@@ -68,39 +68,39 @@ public class AuctionParsingTest {
|
||||
System.out.println("\n=== Full Text Pattern Tests ===");
|
||||
|
||||
// Test the complete auction text format
|
||||
String[] testCases = {
|
||||
var testCases = new String[]{
|
||||
"woensdag om 18:00 1 Vrachtwagens voor bedrijfsvoertuigen Loßburg, DE",
|
||||
"maandag om 14:30 5 Industriële machines Amsterdam, NL",
|
||||
"vrijdag om 10:00 12 Landbouwmachines Antwerpen, BE"
|
||||
};
|
||||
|
||||
for (String testText : testCases) {
|
||||
for (var testText : testCases) {
|
||||
System.out.println("\nParsing: \"" + testText + "\"");
|
||||
|
||||
// Simulated extraction
|
||||
String remaining = testText;
|
||||
var remaining = testText;
|
||||
|
||||
// Extract time
|
||||
java.util.regex.Pattern timePattern = java.util.regex.Pattern.compile("(\\w+)\\s+om\\s+(\\d{1,2}:\\d{2})");
|
||||
java.util.regex.Matcher timeMatcher = timePattern.matcher(remaining);
|
||||
var timePattern = java.util.regex.Pattern.compile("(\\w+)\\s+om\\s+(\\d{1,2}:\\d{2})");
|
||||
var timeMatcher = timePattern.matcher(remaining);
|
||||
if (timeMatcher.find()) {
|
||||
System.out.println(" Time: " + timeMatcher.group(1) + " om " + timeMatcher.group(2));
|
||||
remaining = remaining.substring(timeMatcher.end()).trim();
|
||||
}
|
||||
|
||||
// Extract location
|
||||
java.util.regex.Pattern locPattern = java.util.regex.Pattern.compile(
|
||||
var locPattern = java.util.regex.Pattern.compile(
|
||||
"([A-ZÀ-ÿa-z][A-ZÀ-ÿa-z\\s\\-'öäüßàèéêëïôùûç]+?),\\s*([A-Z]{2})\\s*$"
|
||||
);
|
||||
java.util.regex.Matcher locMatcher = locPattern.matcher(remaining);
|
||||
);
|
||||
var locMatcher = locPattern.matcher(remaining);
|
||||
if (locMatcher.find()) {
|
||||
System.out.println(" Location: " + locMatcher.group(1) + ", " + locMatcher.group(2));
|
||||
remaining = remaining.substring(0, locMatcher.start()).trim();
|
||||
}
|
||||
|
||||
// Extract lot count
|
||||
java.util.regex.Pattern lotPattern = java.util.regex.Pattern.compile("^(\\d+)\\s+");
|
||||
java.util.regex.Matcher lotMatcher = lotPattern.matcher(remaining);
|
||||
var lotPattern = java.util.regex.Pattern.compile("^(\\d+)\\s+");
|
||||
var lotMatcher = lotPattern.matcher(remaining);
|
||||
if (lotMatcher.find()) {
|
||||
System.out.println(" Lot count: " + lotMatcher.group(1));
|
||||
remaining = remaining.substring(lotMatcher.end()).trim();
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -29,7 +29,7 @@ public class TroostwijkScraperTest {
|
||||
// Load native OpenCV library before any tests run
|
||||
try {
|
||||
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
||||
System.out.println("✓ OpenCV native library loaded successfully");
|
||||
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");
|
||||
@@ -61,25 +61,10 @@ public class TroostwijkScraperTest {
|
||||
}
|
||||
|
||||
// Clean up test database
|
||||
File dbFile = new File(testDatabasePath);
|
||||
var dbFile = new File(testDatabasePath);
|
||||
if (dbFile.exists()) {
|
||||
dbFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDatabaseSchema() throws SQLException {
|
||||
// Verify that the database schema was created correctly
|
||||
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<Lot> activeLots = scraper.db.getActiveLots();
|
||||
assertNotNull(activeLots, "Should be able to query active lots");
|
||||
|
||||
System.out.println("✓ Database schema is valid and queryable");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user