mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-08 20:12:23 +00:00
failing test for open ended device mapping finder
This commit is contained in:
1 parent
eb7f88ad69
commit
13da41a969
5 files changed
+79
-14
No files matched your search
-3
@@ -41,13 +41,10 @@ public class DependentStartTimeFinderTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
author = new LogEventAuthorImpl("Test", 1);
|
||||
|
||||
raceLogA = new RaceLogImpl("raceLogA");
|
||||
raceLogB = new RaceLogImpl("raceLogB");
|
||||
raceLogC = new RaceLogImpl("raceLogC");
|
||||
|
||||
nowMock = mock(TimePoint.class);
|
||||
|
||||
raceLogResolver = new RaceLogResolver() {
|
||||
@Override
|
||||
public RaceLog resolve(SimpleRaceLogIdentifier identifier) {
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.sap.sailing.domain.regattalog.tracking.analyzing.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.events.impl.RegattaLogDeviceMarkMappingEventImpl;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.impl.OpenEndedDeviceMappingFinder;
|
||||
import com.sap.sailing.domain.base.Mark;
|
||||
import com.sap.sailing.domain.base.impl.MarkImpl;
|
||||
import com.sap.sailing.domain.racelogtracking.impl.SmartphoneUUIDIdentifierImpl;
|
||||
import com.sap.sse.common.Duration;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
public class OpenEndedDeviceMappingFinderTest extends AbstractRegattaLogTrackingTest {
|
||||
private OpenEndedDeviceMappingFinder finder;
|
||||
private Mark mappedToMark;
|
||||
private UUID deviceUuid;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mappedToMark = new MarkImpl(UUID.randomUUID(), "Random Mark");
|
||||
deviceUuid = UUID.randomUUID();
|
||||
finder = new OpenEndedDeviceMappingFinder(log, mappedToMark, deviceUuid.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findNoOpenEndedMappingBecauseNoMappingExistsAtAll() {
|
||||
assertNull(finder.analyze()); // no event in the log, so result is expected to be null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findNoOpenEndedMappingBecauseAllMappingsAreClosed() {
|
||||
final RegattaLogDeviceMarkMappingEventImpl mappingEvent1 = new RegattaLogDeviceMarkMappingEventImpl(MillisecondsTimePoint.now(), author, mappedToMark,
|
||||
new SmartphoneUUIDIdentifierImpl(deviceUuid), MillisecondsTimePoint.now(), MillisecondsTimePoint.now().plus(Duration.ONE_HOUR));
|
||||
log.add(mappingEvent1);
|
||||
final RegattaLogDeviceMarkMappingEventImpl mappingEvent2 = new RegattaLogDeviceMarkMappingEventImpl(MillisecondsTimePoint.now().plus(Duration.ONE_YEAR), author, mappedToMark,
|
||||
new SmartphoneUUIDIdentifierImpl(deviceUuid), MillisecondsTimePoint.now(), MillisecondsTimePoint.now().plus(Duration.ONE_YEAR).plus(Duration.ONE_HOUR));
|
||||
log.add(mappingEvent2);
|
||||
assertNull(finder.analyze()); // both events are closed; expect result to be null
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOpenEndedMappingWhenItsLastOfSeveral() {
|
||||
final RegattaLogDeviceMarkMappingEventImpl mappingEvent1 = new RegattaLogDeviceMarkMappingEventImpl(MillisecondsTimePoint.now(), author, mappedToMark,
|
||||
new SmartphoneUUIDIdentifierImpl(deviceUuid), MillisecondsTimePoint.now(), MillisecondsTimePoint.now().plus(Duration.ONE_HOUR));
|
||||
log.add(mappingEvent1);
|
||||
final RegattaLogDeviceMarkMappingEventImpl mappingEvent2 = new RegattaLogDeviceMarkMappingEventImpl(MillisecondsTimePoint.now().plus(Duration.ONE_YEAR), author, mappedToMark,
|
||||
new SmartphoneUUIDIdentifierImpl(deviceUuid), MillisecondsTimePoint.now(), /* open end */ null);
|
||||
log.add(mappingEvent2);
|
||||
assertEquals(mappingEvent2.getId(), finder.analyze());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findOpenEndedMappingWhenItsFirstOfSeveral() {
|
||||
final RegattaLogDeviceMarkMappingEventImpl mappingEvent1 = new RegattaLogDeviceMarkMappingEventImpl(MillisecondsTimePoint.now(), author, mappedToMark,
|
||||
new SmartphoneUUIDIdentifierImpl(deviceUuid), MillisecondsTimePoint.now(), /* open end */ null);
|
||||
log.add(mappingEvent1);
|
||||
final RegattaLogDeviceMarkMappingEventImpl mappingEvent2 = new RegattaLogDeviceMarkMappingEventImpl(MillisecondsTimePoint.now().plus(Duration.ONE_YEAR), author, mappedToMark,
|
||||
new SmartphoneUUIDIdentifierImpl(deviceUuid), MillisecondsTimePoint.now(), MillisecondsTimePoint.now().plus(Duration.ONE_YEAR).plus(Duration.ONE_HOUR));
|
||||
log.add(mappingEvent1);
|
||||
assertEquals(mappingEvent2.getId(), finder.analyze());
|
||||
}
|
||||
|
||||
}
|
||||
+6
-6
@@ -12,19 +12,19 @@ import com.sap.sse.common.WithID;
|
||||
|
||||
/**
|
||||
* {@link BaseLogAnalyzer} used for finding the ID of an open ended {@link DeviceMappingEvent} to a corresponding
|
||||
* {@link RegattaLogCloseOpenEndedDeviceMappingEvent}
|
||||
* {@link RegattaLogCloseOpenEndedDeviceMappingEvent}.<p>
|
||||
*
|
||||
* If no corresponding event has been found, null is returned
|
||||
* If no corresponding event has been found, {@code null} is returned.
|
||||
*/
|
||||
public class OpenEndedDeviceMappingFinder extends BaseLogAnalyzer<RegattaLog, RegattaLogEvent, RegattaLogEventVisitor, Serializable> {
|
||||
|
||||
private final WithID mappedTo;
|
||||
private final Serializable deviceUuid;
|
||||
private final Serializable deviceUuidAsString;
|
||||
|
||||
public OpenEndedDeviceMappingFinder(RegattaLog log, WithID mappedTo, Serializable deviceUuid) {
|
||||
public OpenEndedDeviceMappingFinder(RegattaLog log, WithID mappedTo, String deviceUuidAsString) {
|
||||
super(log);
|
||||
this.mappedTo = mappedTo;
|
||||
this.deviceUuid = deviceUuid;
|
||||
this.deviceUuidAsString = deviceUuidAsString;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,7 +33,7 @@ public class OpenEndedDeviceMappingFinder extends BaseLogAnalyzer<RegattaLog, Re
|
||||
if (regattaLogEvent instanceof RegattaLogDeviceMappingEvent<?>) {
|
||||
RegattaLogDeviceMappingEvent<?> deviceMappingEvent = (RegattaLogDeviceMappingEvent<?>) regattaLogEvent;
|
||||
if (deviceMappingEvent.getMappedTo().equals(mappedTo) &&
|
||||
deviceMappingEvent.getDevice().getStringRepresentation().equals(deviceUuid)) {
|
||||
deviceMappingEvent.getDevice().getStringRepresentation().equals(deviceUuidAsString)) {
|
||||
return deviceMappingEvent.getId();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -42,8 +42,7 @@ public class RegattaLogOpenEndedDeviceMappingCloser extends
|
||||
|
||||
@Override
|
||||
protected List<RegattaLogCloseOpenEndedDeviceMappingEvent> performAnalysis() {
|
||||
List<RegattaLogCloseOpenEndedDeviceMappingEvent> result = new ArrayList<RegattaLogCloseOpenEndedDeviceMappingEvent>();
|
||||
|
||||
final List<RegattaLogCloseOpenEndedDeviceMappingEvent> result = new ArrayList<>();
|
||||
for (Serializable eventId : mapping.getOriginalRaceLogEventIds()) {
|
||||
RegattaLogDeviceMappingEvent<?> event = (RegattaLogDeviceMappingEvent<?>) getLog().getEventById(eventId);
|
||||
if (event.getFrom() == null || event.getToInclusive() == null) {
|
||||
|
||||
+3
-3
@@ -472,13 +472,13 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
String competitorId = (String) requestObject.get(DeviceMappingConstants.JSON_COMPETITOR_ID_AS_STRING);
|
||||
String boatId = (String) requestObject.get(DeviceMappingConstants.JSON_BOAT_ID_AS_STRING);
|
||||
String markId = (String) requestObject.get(DeviceMappingConstants.JSON_MARK_ID_AS_STRING);
|
||||
String deviceUuid = (String) requestObject.get(DeviceMappingConstants.JSON_DEVICE_UUID);
|
||||
String deviceUuidAsString = (String) requestObject.get(DeviceMappingConstants.JSON_DEVICE_UUID);
|
||||
String regattaSecret = (String) requestObject.get(DeviceMappingConstants.JSON_REGISTER_SECRET);
|
||||
TimePoint closingTimePointInclusive = new MillisecondsTimePoint(toMillis);
|
||||
boolean allowedViaPermission = getSecurityService().hasCurrentUserUpdatePermission(leaderboard);
|
||||
boolean allowedViaSecret = getService().skipChecksDueToCorrectSecret(leaderboardName, regattaSecret);
|
||||
if (allowedViaPermission || allowedViaSecret) {
|
||||
if (toMillis == null || deviceUuid == null || closingTimePointInclusive == null
|
||||
if (toMillis == null || deviceUuidAsString == null || closingTimePointInclusive == null
|
||||
|| (competitorId == null && boatId == null && markId == null)) {
|
||||
logger.warning("Invalid JSON body in request");
|
||||
return Response.status(Status.BAD_REQUEST).entity("Invalid JSON body in request").type(MediaType.TEXT_PLAIN)
|
||||
@@ -521,7 +521,7 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
mappedToTypeString = (markId != null) ? "mark" : "boat";
|
||||
}
|
||||
OpenEndedDeviceMappingFinder finder = new OpenEndedDeviceMappingFinder(isRegattaLike.getRegattaLog(), mappedTo,
|
||||
deviceUuid);
|
||||
deviceUuidAsString);
|
||||
Serializable deviceMappingEventId = finder.analyze();
|
||||
if (deviceMappingEventId == null) {
|
||||
logger.warning("No corresponding open " + mappedToTypeString + " to device mapping has been found");
|
||||
|
||||
Reference in new issue
Block a user