mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-25 06:58:39 +00:00
Normalized line endings
This commit is contained in:
+89
-89
@@ -1,90 +1,90 @@
|
||||
package com.sap.sailing.mongodb.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mongodb.MongoException;
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.base.Series;
|
||||
import com.sap.sailing.domain.base.impl.CourseAreaImpl;
|
||||
import com.sap.sailing.domain.base.impl.FleetImpl;
|
||||
import com.sap.sailing.domain.base.impl.SeriesImpl;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.NotDenotableForRaceLogTrackingException;
|
||||
import com.sap.sailing.domain.leaderboard.RegattaLeaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.impl.LowPoint;
|
||||
import com.sap.sailing.domain.racelogtracking.RaceLogTrackingAdapterFactory;
|
||||
import com.sap.sailing.domain.racelogtracking.impl.RaceLogConnectivityParams;
|
||||
import com.sap.sailing.domain.ranking.OneDesignRankingMetric;
|
||||
import com.sap.sailing.domain.tracking.RaceTrackingConnectivityParameters;
|
||||
import com.sap.sse.common.Duration;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
public class RaceLogConnectivityParamsLoadAndStoreTest extends AbstractConnectivityParamsLoadAndStoreTest {
|
||||
public RaceLogConnectivityParamsLoadAndStoreTest() throws UnknownHostException, MongoException {
|
||||
super();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreAndLoadRaceLogTrackingParams() throws MalformedURLException, URISyntaxException, NotDenotableForRaceLogTrackingException, InterruptedException, ExecutionException {
|
||||
// set up
|
||||
final long delayToLiveInMillis = 3000;
|
||||
final boolean trackWind = true;
|
||||
final boolean correctWindDirectionByMagneticDeclination = true;
|
||||
final FleetImpl fleet = new FleetImpl("Default");
|
||||
final SeriesImpl theSeries = new SeriesImpl("Default", /* isMedal */ false, /* isFleetsCanRunInParallel */ true,
|
||||
Arrays.<Fleet>asList(fleet), Collections.emptyList(), racingEventService);
|
||||
final Iterable<? extends Series> series = Arrays.<Series>asList(theSeries);
|
||||
final Regatta regatta = racingEventService.createRegatta("My Regatta", "12mR", true, MillisecondsTimePoint.now(), MillisecondsTimePoint.now().plus(Duration.ONE_DAY),
|
||||
UUID.randomUUID(), series, /* persistent */ true, new LowPoint(), new CourseAreaImpl("Default", UUID.randomUUID()),
|
||||
package com.sap.sailing.mongodb.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mongodb.MongoException;
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.base.Series;
|
||||
import com.sap.sailing.domain.base.impl.CourseAreaImpl;
|
||||
import com.sap.sailing.domain.base.impl.FleetImpl;
|
||||
import com.sap.sailing.domain.base.impl.SeriesImpl;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.NotDenotableForRaceLogTrackingException;
|
||||
import com.sap.sailing.domain.leaderboard.RegattaLeaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.impl.LowPoint;
|
||||
import com.sap.sailing.domain.racelogtracking.RaceLogTrackingAdapterFactory;
|
||||
import com.sap.sailing.domain.racelogtracking.impl.RaceLogConnectivityParams;
|
||||
import com.sap.sailing.domain.ranking.OneDesignRankingMetric;
|
||||
import com.sap.sailing.domain.tracking.RaceTrackingConnectivityParameters;
|
||||
import com.sap.sse.common.Duration;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
public class RaceLogConnectivityParamsLoadAndStoreTest extends AbstractConnectivityParamsLoadAndStoreTest {
|
||||
public RaceLogConnectivityParamsLoadAndStoreTest() throws UnknownHostException, MongoException {
|
||||
super();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreAndLoadRaceLogTrackingParams() throws MalformedURLException, URISyntaxException, NotDenotableForRaceLogTrackingException, InterruptedException, ExecutionException {
|
||||
// set up
|
||||
final long delayToLiveInMillis = 3000;
|
||||
final boolean trackWind = true;
|
||||
final boolean correctWindDirectionByMagneticDeclination = true;
|
||||
final FleetImpl fleet = new FleetImpl("Default");
|
||||
final SeriesImpl theSeries = new SeriesImpl("Default", /* isMedal */ false, /* isFleetsCanRunInParallel */ true,
|
||||
Arrays.<Fleet>asList(fleet), Collections.emptyList(), racingEventService);
|
||||
final Iterable<? extends Series> series = Arrays.<Series>asList(theSeries);
|
||||
final Regatta regatta = racingEventService.createRegatta("My Regatta", "12mR", true, MillisecondsTimePoint.now(), MillisecondsTimePoint.now().plus(Duration.ONE_DAY),
|
||||
UUID.randomUUID(), series, /* persistent */ true, new LowPoint(), new CourseAreaImpl("Default", UUID.randomUUID()),
|
||||
/* buoyZoneRadiusInHullLengths */ 2.0, /* useStartTimeInference */ true, /* controlTrackingFromStartAndFinishTimes */ false,
|
||||
OneDesignRankingMetric::new);
|
||||
theSeries.addRaceColumn("R1", racingEventService);
|
||||
theSeries.addRaceColumn("R2", racingEventService);
|
||||
theSeries.addRaceColumn("R3", racingEventService);
|
||||
final RegattaLeaderboard leaderboard = racingEventService.addRegattaLeaderboard(regatta.getRegattaIdentifier(), /* leaderboardDisplayName */ null, new int[] { 5, 9 });
|
||||
RaceLogTrackingAdapterFactory.INSTANCE.getAdapter(domainObjectFactory.getBaseDomainFactory()).denoteAllRacesForRaceLogTracking(racingEventService, leaderboard);
|
||||
final RaceLogConnectivityParams rlParams = new RaceLogConnectivityParams(
|
||||
racingEventService, regatta, leaderboard.getRaceColumnByName("R2"), fleet, leaderboard,
|
||||
delayToLiveInMillis, domainObjectFactory.getBaseDomainFactory(), trackWind,
|
||||
correctWindDirectionByMagneticDeclination);
|
||||
// store
|
||||
mongoObjectFactory.addConnectivityParametersForRaceToRestore(rlParams);
|
||||
// load
|
||||
final Set<RaceTrackingConnectivityParameters> connectivityParametersForRacesToRestore = new HashSet<>();
|
||||
domainObjectFactory.loadConnectivityParametersForRacesToRestore(params -> connectivityParametersForRacesToRestore.add(params))
|
||||
.waitForCompletionOfCallbacksForAllParameters();
|
||||
// compare
|
||||
assertEquals(1, Util.size(connectivityParametersForRacesToRestore));
|
||||
final RaceTrackingConnectivityParameters paramsReadFromDB = connectivityParametersForRacesToRestore.iterator().next();
|
||||
assertTrue(paramsReadFromDB instanceof RaceLogConnectivityParams);
|
||||
RaceLogConnectivityParams raceLogParamsReadFromDB = (RaceLogConnectivityParams) paramsReadFromDB;
|
||||
assertEquals(delayToLiveInMillis, raceLogParamsReadFromDB.getDelayToLiveInMillis());
|
||||
assertSame(leaderboard, raceLogParamsReadFromDB.getLeaderboard());
|
||||
assertSame(theSeries.getRaceColumnByName("R2"), raceLogParamsReadFromDB.getRaceColumn());
|
||||
assertSame(fleet, raceLogParamsReadFromDB.getFleet());
|
||||
assertEquals(rlParams.getTrackerID(), raceLogParamsReadFromDB.getTrackerID());
|
||||
assertEquals(rlParams.isTrackWind(), raceLogParamsReadFromDB.isTrackWind());
|
||||
assertEquals(rlParams.isCorrectWindDirectionByMagneticDeclination(), raceLogParamsReadFromDB.isCorrectWindDirectionByMagneticDeclination());
|
||||
// remove again
|
||||
mongoObjectFactory.removeConnectivityParametersForRaceToRestore(rlParams);
|
||||
final Set<RaceTrackingConnectivityParameters> connectivityParametersForRacesToRestore2 = new HashSet<>();
|
||||
domainObjectFactory.loadConnectivityParametersForRacesToRestore(params->connectivityParametersForRacesToRestore2.add(params))
|
||||
.waitForCompletionOfCallbacksForAllParameters();
|
||||
assertTrue(connectivityParametersForRacesToRestore2.isEmpty());
|
||||
}
|
||||
}
|
||||
OneDesignRankingMetric::new);
|
||||
theSeries.addRaceColumn("R1", racingEventService);
|
||||
theSeries.addRaceColumn("R2", racingEventService);
|
||||
theSeries.addRaceColumn("R3", racingEventService);
|
||||
final RegattaLeaderboard leaderboard = racingEventService.addRegattaLeaderboard(regatta.getRegattaIdentifier(), /* leaderboardDisplayName */ null, new int[] { 5, 9 });
|
||||
RaceLogTrackingAdapterFactory.INSTANCE.getAdapter(domainObjectFactory.getBaseDomainFactory()).denoteAllRacesForRaceLogTracking(racingEventService, leaderboard);
|
||||
final RaceLogConnectivityParams rlParams = new RaceLogConnectivityParams(
|
||||
racingEventService, regatta, leaderboard.getRaceColumnByName("R2"), fleet, leaderboard,
|
||||
delayToLiveInMillis, domainObjectFactory.getBaseDomainFactory(), trackWind,
|
||||
correctWindDirectionByMagneticDeclination);
|
||||
// store
|
||||
mongoObjectFactory.addConnectivityParametersForRaceToRestore(rlParams);
|
||||
// load
|
||||
final Set<RaceTrackingConnectivityParameters> connectivityParametersForRacesToRestore = new HashSet<>();
|
||||
domainObjectFactory.loadConnectivityParametersForRacesToRestore(params -> connectivityParametersForRacesToRestore.add(params))
|
||||
.waitForCompletionOfCallbacksForAllParameters();
|
||||
// compare
|
||||
assertEquals(1, Util.size(connectivityParametersForRacesToRestore));
|
||||
final RaceTrackingConnectivityParameters paramsReadFromDB = connectivityParametersForRacesToRestore.iterator().next();
|
||||
assertTrue(paramsReadFromDB instanceof RaceLogConnectivityParams);
|
||||
RaceLogConnectivityParams raceLogParamsReadFromDB = (RaceLogConnectivityParams) paramsReadFromDB;
|
||||
assertEquals(delayToLiveInMillis, raceLogParamsReadFromDB.getDelayToLiveInMillis());
|
||||
assertSame(leaderboard, raceLogParamsReadFromDB.getLeaderboard());
|
||||
assertSame(theSeries.getRaceColumnByName("R2"), raceLogParamsReadFromDB.getRaceColumn());
|
||||
assertSame(fleet, raceLogParamsReadFromDB.getFleet());
|
||||
assertEquals(rlParams.getTrackerID(), raceLogParamsReadFromDB.getTrackerID());
|
||||
assertEquals(rlParams.isTrackWind(), raceLogParamsReadFromDB.isTrackWind());
|
||||
assertEquals(rlParams.isCorrectWindDirectionByMagneticDeclination(), raceLogParamsReadFromDB.isCorrectWindDirectionByMagneticDeclination());
|
||||
// remove again
|
||||
mongoObjectFactory.removeConnectivityParametersForRaceToRestore(rlParams);
|
||||
final Set<RaceTrackingConnectivityParameters> connectivityParametersForRacesToRestore2 = new HashSet<>();
|
||||
domainObjectFactory.loadConnectivityParametersForRacesToRestore(params->connectivityParametersForRacesToRestore2.add(params))
|
||||
.waitForCompletionOfCallbacksForAllParameters();
|
||||
assertTrue(connectivityParametersForRacesToRestore2.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
+484
-484
@@ -1,484 +1,484 @@
|
||||
package com.sap.sailing.mongodb.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mongodb.MongoException;
|
||||
import com.sap.sailing.domain.base.Boat;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.base.impl.BoatClassImpl;
|
||||
import com.sap.sailing.domain.base.impl.BoatImpl;
|
||||
import com.sap.sailing.domain.base.impl.CompetitorAndBoatImpl;
|
||||
import com.sap.sailing.domain.base.impl.CompetitorImpl;
|
||||
import com.sap.sailing.domain.base.impl.NationalityImpl;
|
||||
import com.sap.sailing.domain.base.impl.PersonImpl;
|
||||
import com.sap.sailing.domain.base.impl.TeamImpl;
|
||||
import com.sap.sailing.domain.common.NoWindException;
|
||||
import com.sap.sailing.domain.common.RaceIdentifier;
|
||||
import com.sap.sailing.domain.common.RegattaNameAndRaceName;
|
||||
import com.sap.sailing.domain.common.ScoringSchemeType;
|
||||
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
|
||||
import com.sap.sailing.domain.leaderboard.impl.FlexibleLeaderboardImpl;
|
||||
import com.sap.sailing.domain.leaderboard.impl.HighPointExtremeSailingSeriesOverall;
|
||||
import com.sap.sailing.domain.leaderboard.impl.LeaderboardGroupImpl;
|
||||
import com.sap.sailing.domain.leaderboard.impl.LowPoint;
|
||||
import com.sap.sailing.domain.leaderboard.impl.ThresholdBasedResultDiscardingRuleImpl;
|
||||
import com.sap.sailing.domain.leaderboard.meta.LeaderboardGroupMetaLeaderboard;
|
||||
import com.sap.sailing.domain.persistence.DomainObjectFactory;
|
||||
import com.sap.sailing.domain.persistence.MongoObjectFactory;
|
||||
import com.sap.sailing.domain.persistence.PersistenceFactory;
|
||||
import com.sap.sailing.domain.persistence.impl.DomainObjectFactoryImpl;
|
||||
import com.sap.sailing.domain.persistence.impl.MongoObjectFactoryImpl;
|
||||
import com.sap.sailing.domain.persistence.media.MediaDBFactory;
|
||||
import com.sap.sailing.domain.racelog.tracking.EmptySensorFixStore;
|
||||
import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRankAndManyCompetitors;
|
||||
import com.sap.sailing.domain.tracking.impl.EmptyWindStore;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.impl.RacingEventServiceImpl;
|
||||
import com.sap.sailing.server.operationaltransformation.UpdateLeaderboardScoreCorrection;
|
||||
import com.sap.sse.common.Color;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sse.mongodb.MongoDBService;
|
||||
|
||||
public class TestStoringAndRetrievingLeaderboardGroups extends AbstractMongoDBTest {
|
||||
private MongoObjectFactory mongoObjectFactory = null;
|
||||
private DomainObjectFactory domainObjectFactory = null;
|
||||
|
||||
|
||||
public TestStoringAndRetrievingLeaderboardGroups() throws UnknownHostException, MongoException {
|
||||
super();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DomainFactory.INSTANCE.getCompetitorStore().clearCompetitors();
|
||||
mongoObjectFactory = new MongoObjectFactoryImpl(db);
|
||||
domainObjectFactory = new DomainObjectFactoryImpl(db, DomainFactory.INSTANCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingLeaderboardGroupWithOverallLeaderboard() {
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
Leaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
final Leaderboard overallLeaderboard = new LeaderboardGroupMetaLeaderboard(leaderboardGroup,
|
||||
new HighPointExtremeSailingSeriesOverall(), new ThresholdBasedResultDiscardingRuleImpl(new int[0]));
|
||||
leaderboardGroup.setOverallLeaderboard(overallLeaderboard);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
assertNotNull(loadedLeaderboardGroup.getOverallLeaderboard());
|
||||
assertEquals(leaderboardGroup.getId(), loadedLeaderboardGroup.getId());
|
||||
assertNotSame(leaderboardGroup.getOverallLeaderboard(), loadedLeaderboardGroup.getOverallLeaderboard());
|
||||
assertSame(ScoringSchemeType.HIGH_POINT_ESS_OVERALL, loadedLeaderboardGroup.getOverallLeaderboard().getScoringScheme().getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingLeaderboardGroupWithOverallLeaderboardWithScoreCorrection() throws NoWindException {
|
||||
RacingEventService racingEventService = new RacingEventServiceImpl();
|
||||
Competitor wolfgang = new CompetitorImpl(123, "$$$Dr. Wolfgang+Hunger$$$", "KYC", Color.RED, null, null, new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("$$$Dr. Wolfgang+Hunger$$$", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Wolfgang Hunger")), new PersonImpl("Rigo van Maas", new NationalityImpl("NED"),
|
||||
/* dateOfBirth */ null, "This is Rigo, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat wolfgangsBoat = new BoatImpl("123", "Dr. Wolfgang Hunger's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
Competitor hasso = new CompetitorImpl(234, "Hasso Plattner", "KYC", Color.RED, null, null,
|
||||
new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("Hasso Plattner", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Hasso Plattner")), new PersonImpl("Lutz Patrunky", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is Patty, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat hassosBoat = new BoatImpl("456", "Dr. Hasso Plattner's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
final String raceColumnName1 = "My First Race 1";
|
||||
MockedTrackedRaceWithFixedRankAndManyCompetitors raceWithTwoCompetitors = new MockedTrackedRaceWithFixedRankAndManyCompetitors(
|
||||
new CompetitorAndBoatImpl(wolfgang,wolfgangsBoat), /* rank */ 1, /* started */ true);
|
||||
raceWithTwoCompetitors.addCompetitorAndBoat(new CompetitorAndBoatImpl(hasso,hassosBoat));
|
||||
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
|
||||
FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
racingEventService.addLeaderboard(leaderboard);
|
||||
leaderboard.addRace(raceWithTwoCompetitors, raceColumnName1, /* medalRace */false);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
racingEventService.addLeaderboard(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
racingEventService.addLeaderboard(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
racingEventService.addLeaderboard(leaderboard);
|
||||
|
||||
LeaderboardGroup leaderboardGroup = racingEventService.addLeaderboardGroup(UUID.randomUUID(), groupName, groupDescription,
|
||||
"The LG Display Name", false,
|
||||
Arrays.asList(leaderboardNames), new int[0], ScoringSchemeType.HIGH_POINT_ESS_OVERALL);
|
||||
final Leaderboard overallLeaderboard = leaderboardGroup.getOverallLeaderboard();
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
racingEventService.apply(new UpdateLeaderboardScoreCorrection(overallLeaderboard.getName(), "Leaderboard 3",
|
||||
wolfgang.getId().toString(), 99.9, MillisecondsTimePoint.now()));
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getRaceColumnByName(raceColumnName1).setTrackedRace(
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getFleet(null), raceWithTwoCompetitors);
|
||||
Leaderboard loadedOverallLeaderboard = loadedLeaderboardGroup.getOverallLeaderboard();
|
||||
final RaceColumn leaderboard3Column = loadedOverallLeaderboard.getRaceColumnByName("Leaderboard 3");
|
||||
assertTrue(loadedOverallLeaderboard.getScoreCorrection().hasCorrectionFor(leaderboard3Column));
|
||||
final Double netPoints = loadedOverallLeaderboard.getNetPoints(wolfgang, leaderboard3Column,
|
||||
MillisecondsTimePoint.now());
|
||||
assertNotNull(netPoints);
|
||||
assertEquals(99.9, netPoints, 0.00000000001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingLeaderboardGroupWithSuppressedCompetitorsInOverallLeaderboard() {
|
||||
Competitor wolfgang = new CompetitorImpl(123, "$$$Dr. Wolfgang+Hunger$$$", "KYC", Color.RED, null, null, new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("$$$Dr. Wolfgang+Hunger$$$", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Wolfgang Hunger")), new PersonImpl("Rigo van Maas", new NationalityImpl("NED"),
|
||||
/* dateOfBirth */ null, "This is Rigo, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat wolfgangsBoat = new BoatImpl("123", "Dr. Wolfgang Hunger's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
Competitor hasso = new CompetitorImpl(234, "Hasso Plattner", "KYC", Color.RED, null, null,
|
||||
new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("Hasso Plattner", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Hasso Plattner")), new PersonImpl("Lutz Patrunky", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is Patty, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat hassosBoat = new BoatImpl("456", "Dr. Hasso Plattner's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
final String raceColumnName1 = "My First Race 1";
|
||||
MockedTrackedRaceWithFixedRankAndManyCompetitors raceWithTwoCompetitors = new MockedTrackedRaceWithFixedRankAndManyCompetitors(
|
||||
new CompetitorAndBoatImpl(wolfgang,wolfgangsBoat), /* rank */ 1, /* started */ true);
|
||||
raceWithTwoCompetitors.addCompetitorAndBoat(new CompetitorAndBoatImpl(hasso,hassosBoat));
|
||||
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard.addRace(raceWithTwoCompetitors, raceColumnName1, /* medalRace */false);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
final Leaderboard overallLeaderboard = new LeaderboardGroupMetaLeaderboard(leaderboardGroup,
|
||||
new HighPointExtremeSailingSeriesOverall(), new ThresholdBasedResultDiscardingRuleImpl(new int[0]));
|
||||
leaderboardGroup.setOverallLeaderboard(overallLeaderboard);
|
||||
overallLeaderboard.setSuppressed(wolfgang, true);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
// ensure that with no tracked races associated, suppressed competitors are not yet resolved:
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), wolfgang));
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), hasso));
|
||||
// now add tracked race to one of the group's leaderboards:
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getRaceColumnByName(raceColumnName1).setTrackedRace(
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getFleet(null), raceWithTwoCompetitors);
|
||||
// ensure that with no tracked races associated, suppressed competitors are not yet resolved:
|
||||
assertTrue(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), wolfgang));
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), hasso));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingLeaderboardGroupWithTwoSuppressedCompetitorsInOverallLeaderboard() {
|
||||
Competitor wolfgang = new CompetitorImpl(123, "$$$Dr. Wolfgang+Hunger$$$", "KYC", Color.RED, null, null, new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("$$$Dr. Wolfgang+Hunger$$$", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Wolfgang Hunger")), new PersonImpl("Rigo van Maas", new NationalityImpl("NED"),
|
||||
/* dateOfBirth */ null, "This is Rigo, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat wolfgangsBoat = new BoatImpl("123", "Dr. Wolfgang Hunger's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
Competitor hasso = new CompetitorImpl(234, "Hasso Plattner", "KYC", Color.RED, null,null,
|
||||
new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("Hasso Plattner", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Hasso Plattner")), new PersonImpl("Lutz Patrunky", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is Patty, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat hassosBoat = new BoatImpl("456", "Dr. Hasso Plattner's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
final String raceColumnName1 = "My First Race 1";
|
||||
MockedTrackedRaceWithFixedRankAndManyCompetitors raceWithTwoCompetitors = new MockedTrackedRaceWithFixedRankAndManyCompetitors(
|
||||
new CompetitorAndBoatImpl(wolfgang,wolfgangsBoat), /* rank */ 1, /* started */ true);
|
||||
raceWithTwoCompetitors.addCompetitorAndBoat(new CompetitorAndBoatImpl(hasso,hassosBoat));
|
||||
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard.addRace(raceWithTwoCompetitors, raceColumnName1, /* medalRace */false);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
final Leaderboard overallLeaderboard = new LeaderboardGroupMetaLeaderboard(leaderboardGroup,
|
||||
new HighPointExtremeSailingSeriesOverall(), new ThresholdBasedResultDiscardingRuleImpl(new int[0]));
|
||||
leaderboardGroup.setOverallLeaderboard(overallLeaderboard);
|
||||
overallLeaderboard.setSuppressed(wolfgang, true);
|
||||
overallLeaderboard.setSuppressed(hasso, true);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
// ensure that with no tracked races associated, suppressed competitors are not yet resolved:
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), wolfgang));
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), hasso));
|
||||
// now add tracked race to one of the group's leaderboards:
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getRaceColumnByName(raceColumnName1).setTrackedRace(
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getFleet(null), raceWithTwoCompetitors);
|
||||
// ensure that with no tracked races associated, suppressed competitors are not yet resolved:
|
||||
assertTrue(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), wolfgang));
|
||||
assertTrue(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), hasso));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 908: asserting that after loading two leaderboard groups referencing the same leaderbard the leaderboard is
|
||||
* loaded only once
|
||||
*/
|
||||
@Test
|
||||
public void testStoringAndRetrievingTwoLeaderboardGroupsReferencingTheSameLeaderboard() {
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName1 = "Leaderboard Group 1";
|
||||
final String groupDescription1 = "A leaderboard group 1";
|
||||
final ArrayList<Leaderboard> leaderboards1 = new ArrayList<>();
|
||||
Leaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards1.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards1.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards1.add(leaderboard);
|
||||
final LeaderboardGroup leaderboardGroup1 = new LeaderboardGroupImpl(groupName1, groupDescription1, /* displayName */ null, false, leaderboards1);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup1);
|
||||
|
||||
final String groupName2 = "Leaderboard Group 2";
|
||||
final String groupDescription2= "A leaderboard group 2";
|
||||
final ArrayList<Leaderboard> leaderboards2 = new ArrayList<>();
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards2.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards2.add(leaderboard);
|
||||
final LeaderboardGroup leaderboardGroup2 = new LeaderboardGroupImpl(groupName2, groupDescription2, /* displayName */ null, false, leaderboards2);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup2);
|
||||
|
||||
// the leaderboard named leaderboardNames[2] occurs in both groups
|
||||
RacingEventService racingEventService = new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(MongoDBService.INSTANCE, DomainFactory.INSTANCE), PersistenceFactory.INSTANCE
|
||||
.getMongoObjectFactory(MongoDBService.INSTANCE), MediaDBFactory.INSTANCE.getMediaDB(MongoDBService.INSTANCE), EmptyWindStore.INSTANCE, EmptySensorFixStore.INSTANCE, /* restoreTrackedRaces */ false); // expected to load leaderboard groups
|
||||
final LeaderboardGroup loadedLeaderboardGroup1 = racingEventService.getLeaderboardGroupByName(groupName1);
|
||||
final LeaderboardGroup loadedLeaderboardGroup2 = racingEventService.getLeaderboardGroupByName(groupName2);
|
||||
|
||||
assertEquals(groupName1, loadedLeaderboardGroup1.getName());
|
||||
assertEquals(groupDescription1, loadedLeaderboardGroup1.getDescription());
|
||||
assertEquals(groupName2, loadedLeaderboardGroup2.getName());
|
||||
assertEquals(groupDescription2, loadedLeaderboardGroup2.getDescription());
|
||||
assertSame(Util.get(loadedLeaderboardGroup1.getLeaderboards(), 2), Util.get(loadedLeaderboardGroup2.getLeaderboards(), 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingSimpleLeaderboardGroup() {
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final String groupDisplayName = "Some short name";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
Leaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, groupDisplayName, false, leaderboards);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
|
||||
Assert.assertEquals(groupName, loadedLeaderboardGroup.getName());
|
||||
Assert.assertEquals(groupDescription, loadedLeaderboardGroup.getDescription());
|
||||
Assert.assertEquals(groupDisplayName, loadedLeaderboardGroup.getDisplayName());
|
||||
|
||||
int c = 0;
|
||||
for (Leaderboard board : leaderboardGroup.getLeaderboards()) {
|
||||
Assert.assertEquals(leaderboardNames[c], board.getName());
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLeaderboardsNotInGroup() {
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
Leaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final String[] ungroupedLeaderboardNames = {"Ungrouped Leaderboard 0", "Ungrouped Leaderboard 1", "Ungrouped Leaderboard 2"};
|
||||
|
||||
final FlexibleLeaderboard[] ungroupedLeaderboards = {
|
||||
new FlexibleLeaderboardImpl(ungroupedLeaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null),
|
||||
new FlexibleLeaderboardImpl(ungroupedLeaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null),
|
||||
new FlexibleLeaderboardImpl(ungroupedLeaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null) };
|
||||
mongoObjectFactory.storeLeaderboard(ungroupedLeaderboards[0]);
|
||||
mongoObjectFactory.storeLeaderboard(ungroupedLeaderboards[1]);
|
||||
mongoObjectFactory.storeLeaderboard(ungroupedLeaderboards[2]);
|
||||
|
||||
Iterable<Leaderboard> loadedUngroupedLeaderboards = domainObjectFactory.getLeaderboardsNotInGroup(/* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
|
||||
Assert.assertTrue(loadedUngroupedLeaderboards.iterator().hasNext());
|
||||
|
||||
int c = 0;
|
||||
for (int i = 0; i < ungroupedLeaderboardNames.length; i++) {
|
||||
boolean loadedBoardsContainsName = false;
|
||||
for (Leaderboard board : loadedUngroupedLeaderboards) {
|
||||
if (ungroupedLeaderboardNames[i].equals(board.getName())) {
|
||||
loadedBoardsContainsName = true;
|
||||
c++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(loadedBoardsContainsName);
|
||||
}
|
||||
|
||||
Assert.assertTrue(c == ungroupedLeaderboards.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLeaderboardReferenceBreak() {
|
||||
//Set up
|
||||
final String leaderboardName = "Leaderboard 0";
|
||||
final String columnName = "Column";
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
final FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardName, new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces), new LowPoint(), null);
|
||||
final Fleet fleet = leaderboard.getFleet(null);
|
||||
final RaceColumn race = leaderboard.addRaceColumn(columnName, false);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup group = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
mongoObjectFactory.storeLeaderboardGroup(group);
|
||||
|
||||
//Name change test
|
||||
final String newLeaderboardName = "Leaderboard ChangedName";
|
||||
mongoObjectFactory.renameLeaderboard(leaderboardName, newLeaderboardName);
|
||||
leaderboard.setName(newLeaderboardName);
|
||||
|
||||
LeaderboardGroup loadedGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null, /* leaderboardRegistry */ null);
|
||||
String loadedLeaderboardName = loadedGroup.getLeaderboards().iterator().next().getName();
|
||||
Assert.assertEquals(newLeaderboardName, loadedLeaderboardName);
|
||||
|
||||
//RaceIdentifier change test
|
||||
final String regattaName = "Event";
|
||||
final String raceName = "Race";
|
||||
leaderboard.getRaceColumnByName(columnName).setRaceIdentifier(fleet, new RegattaNameAndRaceName(regattaName, raceName));
|
||||
mongoObjectFactory.storeLeaderboard(leaderboard);
|
||||
|
||||
//Check if the leaderboard updated correctly
|
||||
final Leaderboard loadedLeaderboard = domainObjectFactory.loadLeaderboard(leaderboard.getName(), /* regattaRegistry */ null);
|
||||
final RaceColumn loadedRaceColumnByName = loadedLeaderboard.getRaceColumnByName(columnName);
|
||||
Fleet loadedFleet = loadedRaceColumnByName.getFleetByName(fleet.getName());
|
||||
Assert.assertEquals(race.getRaceIdentifier(fleet), loadedRaceColumnByName.getRaceIdentifier(loadedFleet));
|
||||
|
||||
// Check if the group received the changes
|
||||
loadedGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null, /* leaderboardRegistry */ null);
|
||||
final RaceColumn loadedRaceColumnFromGroupByName = loadedGroup.getLeaderboards().iterator().next().getRaceColumnByName(columnName);
|
||||
Fleet loadedGroupFleet = loadedRaceColumnFromGroupByName.getFleetByName(fleet.getName());
|
||||
RaceIdentifier loadedIdentifier = loadedRaceColumnFromGroupByName.getRaceIdentifier(loadedGroupFleet);
|
||||
Assert.assertEquals(race.getRaceIdentifier(fleet), loadedIdentifier);
|
||||
}
|
||||
|
||||
}
|
||||
package com.sap.sailing.mongodb.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mongodb.MongoException;
|
||||
import com.sap.sailing.domain.base.Boat;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.base.impl.BoatClassImpl;
|
||||
import com.sap.sailing.domain.base.impl.BoatImpl;
|
||||
import com.sap.sailing.domain.base.impl.CompetitorAndBoatImpl;
|
||||
import com.sap.sailing.domain.base.impl.CompetitorImpl;
|
||||
import com.sap.sailing.domain.base.impl.NationalityImpl;
|
||||
import com.sap.sailing.domain.base.impl.PersonImpl;
|
||||
import com.sap.sailing.domain.base.impl.TeamImpl;
|
||||
import com.sap.sailing.domain.common.NoWindException;
|
||||
import com.sap.sailing.domain.common.RaceIdentifier;
|
||||
import com.sap.sailing.domain.common.RegattaNameAndRaceName;
|
||||
import com.sap.sailing.domain.common.ScoringSchemeType;
|
||||
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
|
||||
import com.sap.sailing.domain.leaderboard.impl.FlexibleLeaderboardImpl;
|
||||
import com.sap.sailing.domain.leaderboard.impl.HighPointExtremeSailingSeriesOverall;
|
||||
import com.sap.sailing.domain.leaderboard.impl.LeaderboardGroupImpl;
|
||||
import com.sap.sailing.domain.leaderboard.impl.LowPoint;
|
||||
import com.sap.sailing.domain.leaderboard.impl.ThresholdBasedResultDiscardingRuleImpl;
|
||||
import com.sap.sailing.domain.leaderboard.meta.LeaderboardGroupMetaLeaderboard;
|
||||
import com.sap.sailing.domain.persistence.DomainObjectFactory;
|
||||
import com.sap.sailing.domain.persistence.MongoObjectFactory;
|
||||
import com.sap.sailing.domain.persistence.PersistenceFactory;
|
||||
import com.sap.sailing.domain.persistence.impl.DomainObjectFactoryImpl;
|
||||
import com.sap.sailing.domain.persistence.impl.MongoObjectFactoryImpl;
|
||||
import com.sap.sailing.domain.persistence.media.MediaDBFactory;
|
||||
import com.sap.sailing.domain.racelog.tracking.EmptySensorFixStore;
|
||||
import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRankAndManyCompetitors;
|
||||
import com.sap.sailing.domain.tracking.impl.EmptyWindStore;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.impl.RacingEventServiceImpl;
|
||||
import com.sap.sailing.server.operationaltransformation.UpdateLeaderboardScoreCorrection;
|
||||
import com.sap.sse.common.Color;
|
||||
import com.sap.sse.common.Util;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sse.mongodb.MongoDBService;
|
||||
|
||||
public class TestStoringAndRetrievingLeaderboardGroups extends AbstractMongoDBTest {
|
||||
private MongoObjectFactory mongoObjectFactory = null;
|
||||
private DomainObjectFactory domainObjectFactory = null;
|
||||
|
||||
|
||||
public TestStoringAndRetrievingLeaderboardGroups() throws UnknownHostException, MongoException {
|
||||
super();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
DomainFactory.INSTANCE.getCompetitorStore().clearCompetitors();
|
||||
mongoObjectFactory = new MongoObjectFactoryImpl(db);
|
||||
domainObjectFactory = new DomainObjectFactoryImpl(db, DomainFactory.INSTANCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingLeaderboardGroupWithOverallLeaderboard() {
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
Leaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
final Leaderboard overallLeaderboard = new LeaderboardGroupMetaLeaderboard(leaderboardGroup,
|
||||
new HighPointExtremeSailingSeriesOverall(), new ThresholdBasedResultDiscardingRuleImpl(new int[0]));
|
||||
leaderboardGroup.setOverallLeaderboard(overallLeaderboard);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
assertNotNull(loadedLeaderboardGroup.getOverallLeaderboard());
|
||||
assertEquals(leaderboardGroup.getId(), loadedLeaderboardGroup.getId());
|
||||
assertNotSame(leaderboardGroup.getOverallLeaderboard(), loadedLeaderboardGroup.getOverallLeaderboard());
|
||||
assertSame(ScoringSchemeType.HIGH_POINT_ESS_OVERALL, loadedLeaderboardGroup.getOverallLeaderboard().getScoringScheme().getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingLeaderboardGroupWithOverallLeaderboardWithScoreCorrection() throws NoWindException {
|
||||
RacingEventService racingEventService = new RacingEventServiceImpl();
|
||||
Competitor wolfgang = new CompetitorImpl(123, "$$$Dr. Wolfgang+Hunger$$$", "KYC", Color.RED, null, null, new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("$$$Dr. Wolfgang+Hunger$$$", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Wolfgang Hunger")), new PersonImpl("Rigo van Maas", new NationalityImpl("NED"),
|
||||
/* dateOfBirth */ null, "This is Rigo, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat wolfgangsBoat = new BoatImpl("123", "Dr. Wolfgang Hunger's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
Competitor hasso = new CompetitorImpl(234, "Hasso Plattner", "KYC", Color.RED, null, null,
|
||||
new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("Hasso Plattner", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Hasso Plattner")), new PersonImpl("Lutz Patrunky", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is Patty, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat hassosBoat = new BoatImpl("456", "Dr. Hasso Plattner's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
final String raceColumnName1 = "My First Race 1";
|
||||
MockedTrackedRaceWithFixedRankAndManyCompetitors raceWithTwoCompetitors = new MockedTrackedRaceWithFixedRankAndManyCompetitors(
|
||||
new CompetitorAndBoatImpl(wolfgang,wolfgangsBoat), /* rank */ 1, /* started */ true);
|
||||
raceWithTwoCompetitors.addCompetitorAndBoat(new CompetitorAndBoatImpl(hasso,hassosBoat));
|
||||
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
|
||||
FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
racingEventService.addLeaderboard(leaderboard);
|
||||
leaderboard.addRace(raceWithTwoCompetitors, raceColumnName1, /* medalRace */false);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
racingEventService.addLeaderboard(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
racingEventService.addLeaderboard(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
racingEventService.addLeaderboard(leaderboard);
|
||||
|
||||
LeaderboardGroup leaderboardGroup = racingEventService.addLeaderboardGroup(UUID.randomUUID(), groupName, groupDescription,
|
||||
"The LG Display Name", false,
|
||||
Arrays.asList(leaderboardNames), new int[0], ScoringSchemeType.HIGH_POINT_ESS_OVERALL);
|
||||
final Leaderboard overallLeaderboard = leaderboardGroup.getOverallLeaderboard();
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
racingEventService.apply(new UpdateLeaderboardScoreCorrection(overallLeaderboard.getName(), "Leaderboard 3",
|
||||
wolfgang.getId().toString(), 99.9, MillisecondsTimePoint.now()));
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getRaceColumnByName(raceColumnName1).setTrackedRace(
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getFleet(null), raceWithTwoCompetitors);
|
||||
Leaderboard loadedOverallLeaderboard = loadedLeaderboardGroup.getOverallLeaderboard();
|
||||
final RaceColumn leaderboard3Column = loadedOverallLeaderboard.getRaceColumnByName("Leaderboard 3");
|
||||
assertTrue(loadedOverallLeaderboard.getScoreCorrection().hasCorrectionFor(leaderboard3Column));
|
||||
final Double netPoints = loadedOverallLeaderboard.getNetPoints(wolfgang, leaderboard3Column,
|
||||
MillisecondsTimePoint.now());
|
||||
assertNotNull(netPoints);
|
||||
assertEquals(99.9, netPoints, 0.00000000001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingLeaderboardGroupWithSuppressedCompetitorsInOverallLeaderboard() {
|
||||
Competitor wolfgang = new CompetitorImpl(123, "$$$Dr. Wolfgang+Hunger$$$", "KYC", Color.RED, null, null, new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("$$$Dr. Wolfgang+Hunger$$$", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Wolfgang Hunger")), new PersonImpl("Rigo van Maas", new NationalityImpl("NED"),
|
||||
/* dateOfBirth */ null, "This is Rigo, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat wolfgangsBoat = new BoatImpl("123", "Dr. Wolfgang Hunger's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
Competitor hasso = new CompetitorImpl(234, "Hasso Plattner", "KYC", Color.RED, null, null,
|
||||
new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("Hasso Plattner", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Hasso Plattner")), new PersonImpl("Lutz Patrunky", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is Patty, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat hassosBoat = new BoatImpl("456", "Dr. Hasso Plattner's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
final String raceColumnName1 = "My First Race 1";
|
||||
MockedTrackedRaceWithFixedRankAndManyCompetitors raceWithTwoCompetitors = new MockedTrackedRaceWithFixedRankAndManyCompetitors(
|
||||
new CompetitorAndBoatImpl(wolfgang,wolfgangsBoat), /* rank */ 1, /* started */ true);
|
||||
raceWithTwoCompetitors.addCompetitorAndBoat(new CompetitorAndBoatImpl(hasso,hassosBoat));
|
||||
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard.addRace(raceWithTwoCompetitors, raceColumnName1, /* medalRace */false);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
final Leaderboard overallLeaderboard = new LeaderboardGroupMetaLeaderboard(leaderboardGroup,
|
||||
new HighPointExtremeSailingSeriesOverall(), new ThresholdBasedResultDiscardingRuleImpl(new int[0]));
|
||||
leaderboardGroup.setOverallLeaderboard(overallLeaderboard);
|
||||
overallLeaderboard.setSuppressed(wolfgang, true);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
// ensure that with no tracked races associated, suppressed competitors are not yet resolved:
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), wolfgang));
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), hasso));
|
||||
// now add tracked race to one of the group's leaderboards:
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getRaceColumnByName(raceColumnName1).setTrackedRace(
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getFleet(null), raceWithTwoCompetitors);
|
||||
// ensure that with no tracked races associated, suppressed competitors are not yet resolved:
|
||||
assertTrue(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), wolfgang));
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), hasso));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingLeaderboardGroupWithTwoSuppressedCompetitorsInOverallLeaderboard() {
|
||||
Competitor wolfgang = new CompetitorImpl(123, "$$$Dr. Wolfgang+Hunger$$$", "KYC", Color.RED, null, null, new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("$$$Dr. Wolfgang+Hunger$$$", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Wolfgang Hunger")), new PersonImpl("Rigo van Maas", new NationalityImpl("NED"),
|
||||
/* dateOfBirth */ null, "This is Rigo, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat wolfgangsBoat = new BoatImpl("123", "Dr. Wolfgang Hunger's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
Competitor hasso = new CompetitorImpl(234, "Hasso Plattner", "KYC", Color.RED, null,null,
|
||||
new TeamImpl("STG", Collections.singleton(
|
||||
new PersonImpl("Hasso Plattner", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is famous Dr. Hasso Plattner")), new PersonImpl("Lutz Patrunky", new NationalityImpl("GER"),
|
||||
/* dateOfBirth */ null, "This is Patty, the coach")), /* timeOnTimeFactor */ null, /* timeOnDistanceAllowancePerNauticalMile */ null, null);
|
||||
Boat hassosBoat = new BoatImpl("456", "Dr. Hasso Plattner's boat", new BoatClassImpl("505", /* typicallyStartsUpwind */ true), null);
|
||||
final String raceColumnName1 = "My First Race 1";
|
||||
MockedTrackedRaceWithFixedRankAndManyCompetitors raceWithTwoCompetitors = new MockedTrackedRaceWithFixedRankAndManyCompetitors(
|
||||
new CompetitorAndBoatImpl(wolfgang,wolfgangsBoat), /* rank */ 1, /* started */ true);
|
||||
raceWithTwoCompetitors.addCompetitorAndBoat(new CompetitorAndBoatImpl(hasso,hassosBoat));
|
||||
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard.addRace(raceWithTwoCompetitors, raceColumnName1, /* medalRace */false);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
final Leaderboard overallLeaderboard = new LeaderboardGroupMetaLeaderboard(leaderboardGroup,
|
||||
new HighPointExtremeSailingSeriesOverall(), new ThresholdBasedResultDiscardingRuleImpl(new int[0]));
|
||||
leaderboardGroup.setOverallLeaderboard(overallLeaderboard);
|
||||
overallLeaderboard.setSuppressed(wolfgang, true);
|
||||
overallLeaderboard.setSuppressed(hasso, true);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
// ensure that with no tracked races associated, suppressed competitors are not yet resolved:
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), wolfgang));
|
||||
assertFalse(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), hasso));
|
||||
// now add tracked race to one of the group's leaderboards:
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getRaceColumnByName(raceColumnName1).setTrackedRace(
|
||||
loadedLeaderboardGroup.getLeaderboards().iterator().next().getFleet(null), raceWithTwoCompetitors);
|
||||
// ensure that with no tracked races associated, suppressed competitors are not yet resolved:
|
||||
assertTrue(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), wolfgang));
|
||||
assertTrue(Util.contains(loadedLeaderboardGroup.getOverallLeaderboard().getSuppressedCompetitors(), hasso));
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 908: asserting that after loading two leaderboard groups referencing the same leaderbard the leaderboard is
|
||||
* loaded only once
|
||||
*/
|
||||
@Test
|
||||
public void testStoringAndRetrievingTwoLeaderboardGroupsReferencingTheSameLeaderboard() {
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName1 = "Leaderboard Group 1";
|
||||
final String groupDescription1 = "A leaderboard group 1";
|
||||
final ArrayList<Leaderboard> leaderboards1 = new ArrayList<>();
|
||||
Leaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards1.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards1.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards1.add(leaderboard);
|
||||
final LeaderboardGroup leaderboardGroup1 = new LeaderboardGroupImpl(groupName1, groupDescription1, /* displayName */ null, false, leaderboards1);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup1);
|
||||
|
||||
final String groupName2 = "Leaderboard Group 2";
|
||||
final String groupDescription2= "A leaderboard group 2";
|
||||
final ArrayList<Leaderboard> leaderboards2 = new ArrayList<>();
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards2.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards2.add(leaderboard);
|
||||
final LeaderboardGroup leaderboardGroup2 = new LeaderboardGroupImpl(groupName2, groupDescription2, /* displayName */ null, false, leaderboards2);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup2);
|
||||
|
||||
// the leaderboard named leaderboardNames[2] occurs in both groups
|
||||
RacingEventService racingEventService = new RacingEventServiceImpl(PersistenceFactory.INSTANCE.getDomainObjectFactory(MongoDBService.INSTANCE, DomainFactory.INSTANCE), PersistenceFactory.INSTANCE
|
||||
.getMongoObjectFactory(MongoDBService.INSTANCE), MediaDBFactory.INSTANCE.getMediaDB(MongoDBService.INSTANCE), EmptyWindStore.INSTANCE, EmptySensorFixStore.INSTANCE, /* restoreTrackedRaces */ false); // expected to load leaderboard groups
|
||||
final LeaderboardGroup loadedLeaderboardGroup1 = racingEventService.getLeaderboardGroupByName(groupName1);
|
||||
final LeaderboardGroup loadedLeaderboardGroup2 = racingEventService.getLeaderboardGroupByName(groupName2);
|
||||
|
||||
assertEquals(groupName1, loadedLeaderboardGroup1.getName());
|
||||
assertEquals(groupDescription1, loadedLeaderboardGroup1.getDescription());
|
||||
assertEquals(groupName2, loadedLeaderboardGroup2.getName());
|
||||
assertEquals(groupDescription2, loadedLeaderboardGroup2.getDescription());
|
||||
assertSame(Util.get(loadedLeaderboardGroup1.getLeaderboards(), 2), Util.get(loadedLeaderboardGroup2.getLeaderboards(), 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoringAndRetrievingSimpleLeaderboardGroup() {
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1", "Leaderboard 2", "Leaderboard 3"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final String groupDisplayName = "Some short name";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
Leaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[3], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, groupDisplayName, false, leaderboards);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final LeaderboardGroup loadedLeaderboardGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
|
||||
Assert.assertEquals(groupName, loadedLeaderboardGroup.getName());
|
||||
Assert.assertEquals(groupDescription, loadedLeaderboardGroup.getDescription());
|
||||
Assert.assertEquals(groupDisplayName, loadedLeaderboardGroup.getDisplayName());
|
||||
|
||||
int c = 0;
|
||||
for (Leaderboard board : leaderboardGroup.getLeaderboards()) {
|
||||
Assert.assertEquals(leaderboardNames[c], board.getName());
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLeaderboardsNotInGroup() {
|
||||
final String[] leaderboardNames = {"Leaderboard 0", "Leaderboard 1"};
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
Leaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
leaderboard = new FlexibleLeaderboardImpl(leaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup leaderboardGroup = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
mongoObjectFactory.storeLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
final String[] ungroupedLeaderboardNames = {"Ungrouped Leaderboard 0", "Ungrouped Leaderboard 1", "Ungrouped Leaderboard 2"};
|
||||
|
||||
final FlexibleLeaderboard[] ungroupedLeaderboards = {
|
||||
new FlexibleLeaderboardImpl(ungroupedLeaderboardNames[0], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null),
|
||||
new FlexibleLeaderboardImpl(ungroupedLeaderboardNames[1], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null),
|
||||
new FlexibleLeaderboardImpl(ungroupedLeaderboardNames[2], new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces),
|
||||
new LowPoint(), null) };
|
||||
mongoObjectFactory.storeLeaderboard(ungroupedLeaderboards[0]);
|
||||
mongoObjectFactory.storeLeaderboard(ungroupedLeaderboards[1]);
|
||||
mongoObjectFactory.storeLeaderboard(ungroupedLeaderboards[2]);
|
||||
|
||||
Iterable<Leaderboard> loadedUngroupedLeaderboards = domainObjectFactory.getLeaderboardsNotInGroup(/* regattaRegistry */ null,
|
||||
/* leaderboardRegistry */ null);
|
||||
|
||||
Assert.assertTrue(loadedUngroupedLeaderboards.iterator().hasNext());
|
||||
|
||||
int c = 0;
|
||||
for (int i = 0; i < ungroupedLeaderboardNames.length; i++) {
|
||||
boolean loadedBoardsContainsName = false;
|
||||
for (Leaderboard board : loadedUngroupedLeaderboards) {
|
||||
if (ungroupedLeaderboardNames[i].equals(board.getName())) {
|
||||
loadedBoardsContainsName = true;
|
||||
c++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(loadedBoardsContainsName);
|
||||
}
|
||||
|
||||
Assert.assertTrue(c == ungroupedLeaderboards.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLeaderboardReferenceBreak() {
|
||||
//Set up
|
||||
final String leaderboardName = "Leaderboard 0";
|
||||
final String columnName = "Column";
|
||||
final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 };
|
||||
|
||||
final String groupName = "Leaderboard Group";
|
||||
final String groupDescription = "A leaderboard group";
|
||||
final ArrayList<Leaderboard> leaderboards = new ArrayList<>();
|
||||
|
||||
final FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardName, new ThresholdBasedResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces), new LowPoint(), null);
|
||||
final Fleet fleet = leaderboard.getFleet(null);
|
||||
final RaceColumn race = leaderboard.addRaceColumn(columnName, false);
|
||||
leaderboards.add(leaderboard);
|
||||
|
||||
final LeaderboardGroup group = new LeaderboardGroupImpl(groupName, groupDescription, /* displayName */ null, false, leaderboards);
|
||||
mongoObjectFactory.storeLeaderboardGroup(group);
|
||||
|
||||
//Name change test
|
||||
final String newLeaderboardName = "Leaderboard ChangedName";
|
||||
mongoObjectFactory.renameLeaderboard(leaderboardName, newLeaderboardName);
|
||||
leaderboard.setName(newLeaderboardName);
|
||||
|
||||
LeaderboardGroup loadedGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null, /* leaderboardRegistry */ null);
|
||||
String loadedLeaderboardName = loadedGroup.getLeaderboards().iterator().next().getName();
|
||||
Assert.assertEquals(newLeaderboardName, loadedLeaderboardName);
|
||||
|
||||
//RaceIdentifier change test
|
||||
final String regattaName = "Event";
|
||||
final String raceName = "Race";
|
||||
leaderboard.getRaceColumnByName(columnName).setRaceIdentifier(fleet, new RegattaNameAndRaceName(regattaName, raceName));
|
||||
mongoObjectFactory.storeLeaderboard(leaderboard);
|
||||
|
||||
//Check if the leaderboard updated correctly
|
||||
final Leaderboard loadedLeaderboard = domainObjectFactory.loadLeaderboard(leaderboard.getName(), /* regattaRegistry */ null);
|
||||
final RaceColumn loadedRaceColumnByName = loadedLeaderboard.getRaceColumnByName(columnName);
|
||||
Fleet loadedFleet = loadedRaceColumnByName.getFleetByName(fleet.getName());
|
||||
Assert.assertEquals(race.getRaceIdentifier(fleet), loadedRaceColumnByName.getRaceIdentifier(loadedFleet));
|
||||
|
||||
// Check if the group received the changes
|
||||
loadedGroup = domainObjectFactory.loadLeaderboardGroup(groupName, /* regattaRegistry */ null, /* leaderboardRegistry */ null);
|
||||
final RaceColumn loadedRaceColumnFromGroupByName = loadedGroup.getLeaderboards().iterator().next().getRaceColumnByName(columnName);
|
||||
Fleet loadedGroupFleet = loadedRaceColumnFromGroupByName.getFleetByName(fleet.getName());
|
||||
RaceIdentifier loadedIdentifier = loadedRaceColumnFromGroupByName.getRaceIdentifier(loadedGroupFleet);
|
||||
Assert.assertEquals(race.getRaceIdentifier(fleet), loadedIdentifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user