fixed FREG parser to cope with multi-line TD strings

This commit is contained in:
Axel Uhl
2012-07-19 21:56:41 +02:00
parent 1b846fb5cd
commit 3d4e29bbe8
3 changed files with 1037 additions and 3 deletions
File diff suppressed because it is too large Load Diff
@@ -18,6 +18,7 @@ import org.junit.Test;
import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.freg.resultimport.CompetitorRow;
import com.sap.sailing.freg.resultimport.RegattaResults;
import com.sap.sailing.freg.resultimport.impl.FregHtmlParser;
public class SimpleHtmlParsingTest {
@@ -29,6 +30,24 @@ public class SimpleHtmlParsingTest {
br.close();
}
@Test
public void testMultiLineTD() throws IOException {
final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("Coupe-internationale-de-france.htm");
FregHtmlParser parser = new FregHtmlParser();
final RegattaResults regattaResults = parser.getRegattaResults(resourceAsStream);
List<CompetitorRow> result = regattaResults.getCompetitorResults();
assertFalse(result.isEmpty());
assertEquals(57, result.size());
assertTrue(regattaResults.getMetadata().contains("PRE- WORLD \n 2012 - COUPE INTERNATIONALE DE FRANCE 505"));
for (CompetitorRow row : result) {
if (Util.contains(row.getNames(), "MARTIN Aline")) {
assertEquals("FRA 8716", row.getSailID());
assertEquals(111, row.getScoreAfterDiscarding(), 0.000000001);
assertEquals(230.00, row.getTotalPointsBeforeDiscarding(), 0.000000001);
}
}
}
@Test
public void testEmptyAndDashedScores() throws IOException {
final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("pre_world_505_s.htm");
@@ -44,16 +44,17 @@ public class FregHtmlParser {
if (foundSlashTr) {
end = slashTrMatcher.start();
inTr = false;
trContents.append(readLine.substring(start, end));
tableRows.add(trContents.toString());
trContents.delete(0, trContents.length());
} else {
end = readLine.length();
}
trContents.append(readLine.substring(start, end));
if (!foundSlashTr) {
trContents.append('\n');
readLine = br.readLine();
start = 0;
} else {
tableRows.add(trContents.toString());
trContents.delete(0, trContents.length());
}
}
}