mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 05:11:04 +00:00
enable and test replication of the modification operations for Event.leaderboardGroups
This commit is contained in:
1 parent
b84ca9e0d4
commit
306ecbbe3e
7 files changed
+126
-11
No files matched your search
@@ -37,5 +37,9 @@ public interface Event extends Named, Renamable, WithID, EventBase {
|
||||
|
||||
void addLeaderboardGroup(LeaderboardGroup leaderboardGroup);
|
||||
|
||||
void removeLeaderboardGroup(LeaderboardGroup leaderboardGroup);
|
||||
/**
|
||||
* @return <code>true</code> if and only if a leaderboard group equal to <code>leaderboardGroup</code> was part of
|
||||
* {@link #getLeaderboardGroups()} and therefore was actually removed
|
||||
*/
|
||||
boolean removeLeaderboardGroup(LeaderboardGroup leaderboardGroup);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class EventImpl extends EventBaseImpl implements Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLeaderboardGroup(LeaderboardGroup leaderboardGroup) {
|
||||
leaderboardGroups.remove(leaderboardGroup);
|
||||
public boolean removeLeaderboardGroup(LeaderboardGroup leaderboardGroup) {
|
||||
return leaderboardGroups.remove(leaderboardGroup);
|
||||
}
|
||||
}
|
||||
+29
-1
@@ -3,8 +3,10 @@ package com.sap.sailing.server.replication.test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -16,6 +18,9 @@ import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util;
|
||||
import com.sap.sailing.server.operationaltransformation.AddLeaderboardGroupToEvent;
|
||||
import com.sap.sailing.server.operationaltransformation.CreateLeaderboardGroup;
|
||||
import com.sap.sailing.server.operationaltransformation.RemoveLeaderboardGroupFromEvent;
|
||||
|
||||
public class EventReplicationTest extends AbstractServerReplicationTest {
|
||||
|
||||
@@ -39,7 +44,30 @@ public class EventReplicationTest extends AbstractServerReplicationTest {
|
||||
assertEquals(replicatedEvent.getEndDate(), eventEndDate);
|
||||
assertEquals(replicatedEvent.getVenue().getName(), venueName);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddAndRemoveLeaderboardGroupToEventReplication() throws InterruptedException {
|
||||
final String eventName = "ESS Masquat";
|
||||
final String venueName = "Masquat, Oman";
|
||||
final boolean isPublic = false;
|
||||
List<String> regattas = new ArrayList<String>();
|
||||
regattas.add("Day1");
|
||||
regattas.add("Day2");
|
||||
final Event masterEvent = master.addEvent(eventName, null, null, venueName, isPublic, UUID.randomUUID());
|
||||
final String leaderboardGroupName = "LGName";
|
||||
master.apply(new CreateLeaderboardGroup(leaderboardGroupName, "LGDescription", /* displayGroupsInReverseOrder */false, /* leaderboardNames */
|
||||
Collections.<String> emptyList(), /* overallLeaderboardDiscardThresholds */null, /* overallLeaderboardScoringSchemeType */
|
||||
null));
|
||||
master.apply(new AddLeaderboardGroupToEvent(masterEvent.getId(), leaderboardGroupName));
|
||||
Thread.sleep(1000);
|
||||
Event replicatedEvent = replica.getEvent(masterEvent.getId());
|
||||
assertEquals(1, Util.size(replicatedEvent.getLeaderboardGroups()));
|
||||
assertEquals(leaderboardGroupName, replicatedEvent.getLeaderboardGroups().iterator().next().getName());
|
||||
assertTrue(master.apply(new RemoveLeaderboardGroupFromEvent(masterEvent.getId(), leaderboardGroupName)));
|
||||
Thread.sleep(1000);
|
||||
assertTrue(Util.isEmpty(replicatedEvent.getLeaderboardGroups()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventReplicationWithNullStartAndEndDate() throws InterruptedException {
|
||||
final String eventName = "ESS Masquat";
|
||||
|
||||
+11
-5
@@ -19,6 +19,7 @@ import org.junit.Test;
|
||||
import com.sap.sailing.domain.base.BoatClass;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.DomainFactory;
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.domain.base.RaceDefinition;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.base.Series;
|
||||
@@ -32,6 +33,7 @@ import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.domain.common.media.MediaTrack;
|
||||
import com.sap.sailing.domain.common.media.MediaTrack.MimeType;
|
||||
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
|
||||
import com.sap.sailing.domain.leaderboard.impl.LowPoint;
|
||||
import com.sap.sailing.domain.persistence.PersistenceFactory;
|
||||
import com.sap.sailing.domain.persistence.media.MediaDBFactory;
|
||||
@@ -83,7 +85,7 @@ public class InitialLoadReplicationObjectIdentityTest extends AbstractServerRepl
|
||||
final TimePoint eventStartDate = new MillisecondsTimePoint(new Date());
|
||||
final TimePoint eventEndDate = new MillisecondsTimePoint(new Date());
|
||||
|
||||
master.addEvent(eventName, eventStartDate, eventEndDate, venue, false, eventId);
|
||||
Event event = master.addEvent(eventName, eventStartDate, eventEndDate, venue, false, eventId);
|
||||
assertNotNull(master.getEvent(eventId));
|
||||
assertNull(replica.getEvent(eventId));
|
||||
|
||||
@@ -112,10 +114,12 @@ public class InitialLoadReplicationObjectIdentityTest extends AbstractServerRepl
|
||||
leaderboardNames.add(leaderboardName);
|
||||
int[] overallLeaderboardDiscardThresholds = new int[] {};
|
||||
ScoringSchemeType overallLeaderboardScoringSchemeType = ScoringSchemeType.HIGH_POINT;
|
||||
master.addLeaderboardGroup(leaderBoardGroupName, "Some descriptive Description", false, leaderboardNames, overallLeaderboardDiscardThresholds, overallLeaderboardScoringSchemeType);
|
||||
LeaderboardGroup leaderboardGroup = master.addLeaderboardGroup(leaderBoardGroupName, "Some descriptive Description", false, leaderboardNames, overallLeaderboardDiscardThresholds, overallLeaderboardScoringSchemeType);
|
||||
assertNotNull(master.getLeaderboardGroupByName(leaderBoardGroupName));
|
||||
assertNull(replica.getLeaderboardGroupByName(leaderBoardGroupName));
|
||||
|
||||
event.addLeaderboardGroup(leaderboardGroup);
|
||||
|
||||
/* Media Library */
|
||||
MediaTrack mediaTrack1 = new MediaTrack("title-1", "url", new Date(), 1, MimeType.mp4);
|
||||
master.mediaTrackAdded(mediaTrack1);
|
||||
@@ -136,12 +140,14 @@ public class InitialLoadReplicationObjectIdentityTest extends AbstractServerRepl
|
||||
}
|
||||
}
|
||||
|
||||
assertNotNull(replica.getEvent(eventId));
|
||||
Event replicaEvent = replica.getEvent(eventId);
|
||||
assertNotNull(replicaEvent);
|
||||
assertNotNull(replica.getRegatta(masterRegatta.getRegattaIdentifier()));
|
||||
assertNotNull(replica.getLeaderboardGroupByName(leaderBoardGroupName));
|
||||
LeaderboardGroup replicaLeaderboardGroup = replica.getLeaderboardGroupByName(leaderBoardGroupName);
|
||||
assertNotNull(replicaLeaderboardGroup);
|
||||
assertNotNull(replica.getLeaderboardByName(leaderboardName));
|
||||
assertTrue(replica.getAllRegattas().iterator().hasNext());
|
||||
|
||||
assertSame(replicaLeaderboardGroup, replicaEvent.getLeaderboardGroups().iterator().next());
|
||||
//System.out.println("InitialLoadReplicationObjectIdentityTest.testInitialLoad - replica.getAllMediaTracks: " + replica.getAllMediaTracks());
|
||||
|
||||
assertThat(replica.getAllMediaTracks().size(), is(3));
|
||||
|
||||
@@ -341,8 +341,8 @@ public interface RacingEventService extends TrackedRegattaRegistry, RegattaFetch
|
||||
Event getEvent(Serializable id);
|
||||
|
||||
/**
|
||||
* Creates a new event with the name <code>eventName</code>, the venue<code>venue</code> and the
|
||||
* regattas with the names in <code>regattaNames</code> and saves it in the database. Use for TESTING only!
|
||||
* Creates a new event with the name <code>eventName</code>, the venue<code>venue</code> and the regattas with the
|
||||
* names in <code>regattaNames</code>, saves it in the database and replicates it. Use for TESTING only!
|
||||
*
|
||||
* @param eventName
|
||||
* The name of the new event
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.RacingEventServiceOperation;
|
||||
|
||||
public class AddLeaderboardGroupToEvent extends AbstractRacingEventServiceOperation<LeaderboardGroup> {
|
||||
private static final long serialVersionUID = 5061411909275963501L;
|
||||
private final UUID eventId;
|
||||
private final String leaderboardGroupName;
|
||||
|
||||
public AddLeaderboardGroupToEvent(UUID eventId, String leaderboardGroupName) {
|
||||
super();
|
||||
this.eventId = eventId;
|
||||
this.leaderboardGroupName = leaderboardGroupName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LeaderboardGroup internalApplyTo(RacingEventService toState) throws Exception {
|
||||
LeaderboardGroup leaderboardGroup = toState.getLeaderboardGroupByName(leaderboardGroupName);
|
||||
toState.getEvent(eventId).addLeaderboardGroup(leaderboardGroup);
|
||||
return leaderboardGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.RacingEventServiceOperation;
|
||||
|
||||
public class RemoveLeaderboardGroupFromEvent extends AbstractRacingEventServiceOperation<Boolean> {
|
||||
private static final long serialVersionUID = 5061411909275963501L;
|
||||
private final UUID eventId;
|
||||
private final String leaderboardGroupName;
|
||||
|
||||
public RemoveLeaderboardGroupFromEvent(UUID eventId, String leaderboardGroupName) {
|
||||
super();
|
||||
this.eventId = eventId;
|
||||
this.leaderboardGroupName = leaderboardGroupName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean internalApplyTo(RacingEventService toState) throws Exception {
|
||||
LeaderboardGroup leaderboardGroup = toState.getLeaderboardGroupByName(leaderboardGroupName);
|
||||
return toState.getEvent(eventId).removeLeaderboardGroup(leaderboardGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user