Got the first tests for mark passing update from race log changes running

Change-Id: I857191e67ae8e408670832d02f1e1caab42d10a9
This commit is contained in:
Axel Uhl committed 2016-01-22 15:15:03 +01:00
1 parent 09f92c97da
commit 35af1394c6
13 files changed
+432 -19

No files matched your search

@@ -0,0 +1,126 @@
package com.sap.sailing.domain.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.ParseException;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import com.sap.sailing.domain.abstractlog.AbstractLogEventAuthor;
import com.sap.sailing.domain.abstractlog.impl.LogEventAuthorImpl;
import com.sap.sailing.domain.abstractlog.race.CompetitorResult;
import com.sap.sailing.domain.abstractlog.race.CompetitorResults;
import com.sap.sailing.domain.abstractlog.race.RaceLog;
import com.sap.sailing.domain.abstractlog.race.RaceLogFinishPositioningConfirmedEvent;
import com.sap.sailing.domain.abstractlog.race.impl.CompetitorResultImpl;
import com.sap.sailing.domain.abstractlog.race.impl.CompetitorResultsImpl;
import com.sap.sailing.domain.abstractlog.race.impl.RaceLogFinishPositioningConfirmedEventImpl;
import com.sap.sailing.domain.abstractlog.race.impl.RaceLogPassChangeEventImpl;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.RaceColumn;
import com.sap.sailing.domain.base.impl.CourseAreaImpl;
import com.sap.sailing.domain.common.NoWindException;
import com.sap.sailing.domain.common.WindSourceType;
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl;
import com.sap.sailing.domain.common.impl.WindImpl;
import com.sap.sailing.domain.common.impl.WindSourceImpl;
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
import com.sap.sailing.domain.leaderboard.impl.FlexibleLeaderboardImpl;
import com.sap.sailing.domain.leaderboard.impl.LowPoint;
import com.sap.sailing.domain.leaderboard.impl.ThresholdBasedResultDiscardingRuleImpl;
import com.sap.sailing.domain.tracking.MarkPassing;
import com.sap.sailing.domain.tractracadapter.ReceiverType;
import com.sap.sse.common.Duration;
import com.sap.sse.common.TimePoint;
import com.sap.sse.common.Util;
import com.sap.sse.common.Util.Pair;
import com.sap.sse.common.impl.MillisecondsTimePoint;
import com.tractrac.model.lib.api.event.CreateModelException;
import com.tractrac.subscription.lib.api.SubscriberInitializationException;
/**
* Tests the implementation for bug3420: when a {@link RaceLogFinishPositioningConfirmedEvent} is found in a race log
* that has a valid {@link CompetitorResult#getFinishingTime()} defined for a competitor, a wrapper mark passing is
* expected to be generated with that time point for the finish waypoint. When the event is invalidated, e.g., by
* detaching the race log or by starting a new pass or by sending a newer {@link RaceLogFinishPositioningConfirmedEvent}
* or one that has higher priority, the finish mark passings need to be updated accordingly. This can mean that entirely
* artificial mark passings need to be removed entirely; mark passings that only replaced an original mark passing by
* one with a modified finish time need to be reverted back to the original mark passing.
*
* @author Axel Uhl (D043530)
*
*/
public class MarkPassingUpdateFromRaceLogFinishPositioingListTest extends AbstractManeuverDetectionTestCase {
private FlexibleLeaderboard leaderboard;
private RaceLog raceLog;
private final AbstractLogEventAuthor author;
public MarkPassingUpdateFromRaceLogFinishPositioingListTest() throws MalformedURLException, URISyntaxException {
super();
author = new LogEventAuthorImpl("Me", 0);
}
@Override
protected String getExpectedEventName() {
return "ESS Qingdao 2014";
}
@Before
public void setUp() throws URISyntaxException, IOException, InterruptedException, ParseException, SubscriberInitializationException, CreateModelException {
super.setUp();
URI storedUri = new URI("file:///"+new File("resources/event_20140429_ESSQingdao-Race_4.mtb").getCanonicalPath().replace('\\', '/'));
super.setUp(
new URL("file:///" + new File("resources/event_20140429_ESSQingdao-Race_4.txt").getCanonicalPath()),
/* liveUri */null, /* storedUri */storedUri, new ReceiverType[] { ReceiverType.MARKPASSINGS,
ReceiverType.MARKPOSITIONS, ReceiverType.RACECOURSE, ReceiverType.RAWPOSITIONS });
getTrackedRace().recordWind(
new WindImpl(/* position */null, new MillisecondsTimePoint(dateFormat.parse("05/01/2014-09:02:00")),
new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(269))),
new WindSourceImpl(WindSourceType.WEB));
leaderboard = new FlexibleLeaderboardImpl("Test", new ThresholdBasedResultDiscardingRuleImpl(new int[0]), new LowPoint(), new CourseAreaImpl("Here", UUID.randomUUID()));
final RaceColumn raceColumn = leaderboard.addRace(getTrackedRace(), "R", /* medalRace */ false);
raceLog = raceColumn.getRaceLog(raceColumn.getFleets().iterator().next());
}
/**
* Tests the Race 4 for competitor "Alinghi" at a time where the maneuver detection test is likely to compute
* a penalty although between the jibe and the tack there is a mark passing
*/
@Test
public void testOriginalFinishMarkPassingTime() throws ParseException, NoWindException {
Competitor alinghi = getCompetitorByName("Alinghi");
final MarkPassing alinghiOriginalFinish = getTrackedRace().getMarkPassing(alinghi, getTrackedRace().getRace().getCourse().getLastWaypoint());
final TimePoint alinghiOriginalFinishingTime = alinghiOriginalFinish.getTimePoint();
assertNotNull(alinghiOriginalFinish.getTimePoint());
final TimePoint now = MillisecondsTimePoint.now();
final CompetitorResults alinghiFinishesNow = createCompetitorResults(new Util.Pair<>(alinghi, now));
raceLog.add(new RaceLogFinishPositioningConfirmedEventImpl(now, author, /* pPassId */ 0, alinghiFinishesNow));
final MarkPassing alinghiCorrectedFinishMarkPassing = getTrackedRace().getMarkPassing(alinghi, getTrackedRace().getRace().getCourse().getLastWaypoint());
assertEquals(now, alinghiCorrectedFinishMarkPassing.getTimePoint());
raceLog.add(new RaceLogPassChangeEventImpl(now.plus(Duration.ONE_SECOND), author, /* pass */ 1)); // this should invalidate the previously edited result
assertEquals(alinghiOriginalFinishingTime, getTrackedRace().getMarkPassing(alinghi, getTrackedRace().getRace().getCourse().getLastWaypoint()).getTimePoint());
// TODO now eliminate the original finish mark passing, then set a finishing time in the race log to see how the synthetic mark passing is created and then again removed
}
@SafeVarargs
private final CompetitorResults createCompetitorResults(Pair<Competitor, TimePoint>... finishingTimes) {
final CompetitorResults results = new CompetitorResultsImpl();
int rank = 1;
for (Pair<Competitor, TimePoint> finishingTime : finishingTimes) {
results.add(new CompetitorResultImpl(finishingTime.getA().getId(), finishingTime.getA().getName(), rank++, /* maxPointsReason */
null, /* score */null, finishingTime.getB(), /* comment */null));
}
return results;
}
}
@@ -7,6 +7,7 @@ import java.util.NavigableSet;
import java.util.Set;
import java.util.TreeSet;
import com.sap.sailing.domain.abstractlog.race.CompetitorResults;
import com.sap.sailing.domain.abstractlog.race.RaceLog;
import com.sap.sailing.domain.abstractlog.race.analyzing.impl.RaceLogResolver;
import com.sap.sailing.domain.abstractlog.regatta.RegattaLog;
@@ -1008,4 +1009,12 @@ public class MockedTrackedRace implements DynamicTrackedRace {
public IsManagedByCache<SharedDomainFactory> resolve(SharedDomainFactory domainFactory) {
return this;
}
@Override
public void updateFinishingTimesFromRaceLog(CompetitorResults event) {
}
@Override
public void updateMarkPassingsAfterRaceLogChanges() {
}
}