added failing test case and fix for parse failure for 20% and 30% score corrections which now become ZFP

This commit is contained in:
Axel Uhl committed 2012-06-13 18:41:19 +02:00
1 parent 3e6a01b806
commit 7841243dff
6 files changed
+30 -6

No files matched your search

@@ -326,7 +326,7 @@ public interface StringMessages extends Messages {
String selectResultListToImportFrom();
String of();
String errorObtainingScoreCorrections(String scoreCorrectionProviderName, String eventName, String boatClassName,
String string);
String string, String message);
String assignRaceNumbersToRaceColumns();
String importOfficialResults();
String selectAll();
@@ -323,7 +323,7 @@ doYouReallyWantToRemoveRegatta=Do you really want to remove the regatta "{0}"?
errorLoadingScoreCorrectionProviders=Error loading score correction providers: {0}
selectResultListToImportFrom=Select result list to import from
of=of
errorObtainingScoreCorrections=Error obtaining score corrections from provider {0} and event {1} for boat class {2} published on {3}
errorObtainingScoreCorrections=Error obtaining score corrections from provider {0} and event {1} for boat class {2} published on {3}: {4}
assignRaceNumbersToRaceColumns=Assign race numbers of official results to leaderboard race columns
importOfficialResults=Import official results...
selectAll=Select all
@@ -324,7 +324,7 @@ doYouReallyWantToRemoveRegatta=Möchten Sie wirklich Regatta "{0}" löschen?
errorLoadingScoreCorrectionProviders=Fehler beim Laden der offiziellen Ergebnis-Dienste: {0}
selectResultListToImportFrom=Ergebnisliste auswählen
of=von
errorObtainingScoreCorrections=Fehler beim laden der offiziellen Ergebnisse von Dienst {0} zu Veranstaltung {1} und Bootsklasse {2} veröffentlicht {3}
errorObtainingScoreCorrections=Fehler beim laden der offiziellen Ergebnisse von Dienst {0} zu Veranstaltung {1} und Bootsklasse {2} veröffentlicht {3}: {4}
assignRaceNumbersToRaceColumns=Renn-Nummern den Ergebnisspalten zuordnen
importOfficialResults=Offizielle Ergebnisse importieren...
selectAll=Alle auswählen
@@ -73,7 +73,7 @@ public class ResultSelectionAndApplyDialog extends DataEntryDialog<Triple<String
@Override
public void onFailure(Throwable caught) {
errorReporter.reportError(stringMessages.errorObtainingScoreCorrections(scoreCorrectionProviderName,
eventName, boatClassName, timePointWhenResultPublished.toString()));
eventName, boatClassName, timePointWhenResultPublished.toString(), caught.getMessage()));
}
@Override
@@ -15,13 +15,17 @@ import javax.xml.parsers.ParserConfigurationException;
import org.junit.Test;
import org.xml.sax.SAXException;
import com.sap.sailing.domain.common.MaxPointsReason;
import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.kiworesultimport.Boat;
import com.sap.sailing.kiworesultimport.BoatResultInRace;
import com.sap.sailing.kiworesultimport.ParserFactory;
import com.sap.sailing.kiworesultimport.RegattaSummary;
import com.sap.sailing.kiworesultimport.ZipFile;
public class ZipStreamTest {
private final static String ZIP_EXAMPLE_FILE = "resources/Kieler_Woche_2011_Export.zip";
private final static String ZIP_EXAMPLE_FILE_YES = "resources/2012 Young Europeans Sailing-Export.zip";
@Test
public void testOpenZip() throws IOException {
@@ -46,4 +50,14 @@ public class ZipStreamTest {
RegattaSummary laser = zipFile.getRegattaSummary("Laser");
assertEquals(9, Util.size(laser.getRaces()));
}
@Test
public void twentyPercentTest() throws FileNotFoundException, IOException, SAXException, ParserConfigurationException {
// test GER1899 in YES 29er regatta, race number 1
ZipFile zipFile = ParserFactory.INSTANCE.createZipFileParser().parse(new FileInputStream(ZIP_EXAMPLE_FILE_YES));
RegattaSummary twentyNiner = zipFile.getRegattaSummary("29er");
Boat ger1899 = twentyNiner.getRace(1).getBoat("GER 1899");
BoatResultInRace ger1899results = ger1899.getResultsInRace(1);
assertEquals(MaxPointsReason.ZFP, ger1899results.getMaxPointsReason());
}
}
@@ -1,6 +1,7 @@
package com.sap.sailing.kiworesultimport.impl;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import org.w3c.dom.Node;
@@ -9,7 +10,8 @@ import com.sap.sailing.kiworesultimport.BoatResultInRace;
public class BoatResultsInRaceImpl extends AbstractNodeWrapper implements BoatResultInRace {
private static final Logger logger = Logger.getLogger(BoatResultsInRaceImpl.class.getName());
private static final Pattern leadingPercentagePattern = Pattern.compile("^[0-9][0-9]*%.*$");
public BoatResultsInRaceImpl(Node node) {
super(node);
}
@@ -52,13 +54,21 @@ public class BoatResultsInRaceImpl extends AbstractNodeWrapper implements BoatRe
MaxPointsReason result;
String status = getStatus();
if (status != null) {
result = MaxPointsReason.valueOf(status.substring(0, 3));
if (startsWithPercentage(status)) {
result = MaxPointsReason.ZFP;
} else {
result = MaxPointsReason.valueOf(status.substring(0, 3));
}
} else {
result = MaxPointsReason.NONE;
}
return result;
}
private boolean startsWithPercentage(String status) {
return leadingPercentagePattern.matcher(status).matches();
}
@Override
public String toString() {
return "{" + getRaceNumber() + ": " + getMaxPointsReason() + ", " + getPoints() + (isDiscarded()?", discarded":"")+"}";