mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-03 10:53:49 +00:00
fixed tracked leg update after addWaypoint
This commit is contained in:
1 parent
18c49c62e5
commit
aa1aed9a81
3 files changed
+59
-4
No files matched your search
+50
-1
@@ -2,12 +2,14 @@ package com.sap.sailing.domain.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -15,15 +17,20 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.ControlPoint;
|
||||
import com.sap.sailing.domain.base.Course;
|
||||
import com.sap.sailing.domain.base.CourseListener;
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.domain.base.Leg;
|
||||
import com.sap.sailing.domain.base.RaceDefinition;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.domain.base.impl.BuoyImpl;
|
||||
import com.sap.sailing.domain.base.impl.WaypointImpl;
|
||||
import com.sap.sailing.domain.tracking.DynamicTrackedEvent;
|
||||
import com.sap.sailing.domain.tracking.TrackedLeg;
|
||||
import com.sap.sailing.domain.tracking.TrackedLegOfCompetitor;
|
||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||
import com.sap.sailing.domain.tracking.impl.EmptyWindStore;
|
||||
import com.sap.sailing.domain.tractracadapter.DomainFactory;
|
||||
import com.sap.sailing.domain.tractracadapter.Receiver;
|
||||
@@ -42,6 +49,7 @@ import difflib.Patch;
|
||||
import difflib.PatchFailedException;
|
||||
|
||||
public class CourseUpdateTest extends AbstractTracTracLiveTest {
|
||||
private RaceDefinition race;
|
||||
private Course course;
|
||||
private Event domainEvent;
|
||||
private DynamicTrackedEvent trackedEvent;
|
||||
@@ -73,7 +81,7 @@ public class CourseUpdateTest extends AbstractTracTracLiveTest {
|
||||
}
|
||||
});
|
||||
addListenersForStoredDataAndStartController(receivers);
|
||||
RaceDefinition race = domainFactory.getRaceDefinition(getEvent().getRaceList().iterator().next());
|
||||
race = domainFactory.getRaceDefinition(getEvent().getRaceList().iterator().next());
|
||||
course = race.getCourse();
|
||||
assertNotNull(course);
|
||||
assertEquals(3, Util.size(course.getWaypoints()));
|
||||
@@ -193,6 +201,47 @@ public class CourseUpdateTest extends AbstractTracTracLiveTest {
|
||||
assertTrue(result[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrackedRacesTrackedLegsUpdatedProperly() throws InterruptedException, PatchFailedException {
|
||||
final boolean[] result = new boolean[1];
|
||||
final com.tractrac.clientmodule.ControlPoint cp1 = new com.tractrac.clientmodule.ControlPoint(
|
||||
UUID.randomUUID(), "CP1", /* hasTwo */false) {
|
||||
};
|
||||
waitForRouteData();
|
||||
final List<com.tractrac.clientmodule.ControlPoint> controlPoints = new ArrayList<com.tractrac.clientmodule.ControlPoint>(
|
||||
routeData[0].getPoints());
|
||||
controlPoints.add(cp1);
|
||||
course.addCourseListener(new CourseListener() {
|
||||
@Override
|
||||
public void waypointAdded(int zeroBasedIndex, Waypoint waypointThatGotAdded) {
|
||||
System.out.println("waypointAdded " + zeroBasedIndex + " / " + waypointThatGotAdded);
|
||||
ControlPoint cp = domainFactory.getControlPoint(cp1);
|
||||
result[0] = zeroBasedIndex == controlPoints.size() - 1 && waypointThatGotAdded.getControlPoint() == cp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waypointRemoved(int zeroBasedIndex, Waypoint waypointThatGotRemoved) {
|
||||
System.out.println("waypointRemoved " + zeroBasedIndex + " / " + waypointThatGotRemoved);
|
||||
}
|
||||
});
|
||||
domainFactory.updateCourseWaypoints(course, controlPoints);
|
||||
assertTrue(result[0]);
|
||||
TrackedRace trackedRace = trackedEvent.getTrackedRace(race);
|
||||
Iterator<Leg> legIter = course.getLegs().iterator();
|
||||
for (TrackedLeg trackedLeg : trackedRace.getTrackedLegs()) {
|
||||
assertTrue(legIter.hasNext());
|
||||
Leg leg = legIter.next();
|
||||
assertSame(leg, trackedLeg.getLeg());
|
||||
}
|
||||
// and again, this time for the TrackedLegOfCompetitors
|
||||
for (Leg leg : course.getLegs()) {
|
||||
for (Competitor competitor : race.getCompetitors()) {
|
||||
TrackedLegOfCompetitor trackedLegOfCompetitor = trackedRace.getTrackedLeg(competitor, leg);
|
||||
assertSame(leg, trackedLegOfCompetitor.getLeg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
routeData[0] = null;
|
||||
|
||||
@@ -61,7 +61,13 @@ public class CourseImpl extends NamedImpl implements Course {
|
||||
@Override
|
||||
public void addWaypoint(int zeroBasedPosition, Waypoint waypointToAdd) {
|
||||
waypoints.add(zeroBasedPosition, waypointToAdd);
|
||||
legs.add(new LegImpl(this, zeroBasedPosition));
|
||||
int legStartWaypointIndex;
|
||||
if (zeroBasedPosition == waypoints.size()-1) { // added to end
|
||||
legStartWaypointIndex = zeroBasedPosition-1;
|
||||
} else {
|
||||
legStartWaypointIndex = zeroBasedPosition;
|
||||
}
|
||||
legs.add(new LegImpl(this, legStartWaypointIndex));
|
||||
notifyListenersWaypointAdded(zeroBasedPosition, waypointToAdd);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -182,7 +182,7 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
|
||||
|
||||
|
||||
@Override
|
||||
protected TrackedLeg createTrackedLeg(RaceDefinition race, Leg leg) {
|
||||
return new TrackedLegImpl(this, leg, race.getCompetitors());
|
||||
protected TrackedLeg createTrackedLeg(Leg leg) {
|
||||
return new TrackedLegImpl(this, leg, getRace().getCompetitors());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user