# DomainObjectFactory loads a default author for (old) events without author

This commit is contained in:
Lukas Niemeier
2013-11-17 19:40:03 +01:00
parent 65c0925477
commit c80f26f272
4 changed files with 25 additions and 5 deletions
@@ -1063,7 +1063,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
if (authorName != null && authorPriority != null) {
author = new RaceLogEventAuthorImpl(authorName, authorPriority.intValue());
} else {
author = null;
author = RaceLogEventAuthorImpl.createCompatibilityAuthor();
}
String eventClass = (String) dbObject.get(FieldNames.RACE_LOG_EVENT_CLASS.name());
@@ -13,12 +13,16 @@ import com.sap.sailing.domain.common.Named;
*/
public interface RaceLogEventAuthor extends Named {
public static final int PRIORITY_COMPATIBILITY = 16;
public static final String NAME_COMPATIBILITY = "Compatibility";
/**
* A lesser number represents a higher priority. Suggested priority levels:
* <ol>
* <li>Start Vessel</li>
* <li>Finish Vessel</li>
* <li>Short Control</li>
* <li>Shore Control</li>
* <li>Compatibility priority for old events</li>
* </ol>
*/
int getPriority();
@@ -7,6 +7,10 @@ public class RaceLogEventAuthorImpl extends NamedImpl implements RaceLogEventAut
private static final long serialVersionUID = -5602802911563685812L;
private final int priority;
public static RaceLogEventAuthor createCompatibilityAuthor() {
return new RaceLogEventAuthorImpl(NAME_COMPATIBILITY, PRIORITY_COMPATIBILITY);
}
public RaceLogEventAuthorImpl(String name, int priority) {
super(name);
this.priority = priority;
@@ -1,8 +1,6 @@
package com.sap.sailing.mongodb.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -74,6 +72,20 @@ public class StoreAndLoadRaceLogEventsTest extends AbstractMongoDBTest {
assertEquals(expectedEvent.getInvolvedBoats().size(), Util.size(actualEvent.getInvolvedBoats()));
assertEquals(expectedEvent.getPassId(), actualEvent.getPassId());
}
@Test
public void testStoreEventWithoutAuthorLoadsCompatibilityAuthor() {
RaceLogFlagEvent expectedEvent = eventFactory.createFlagEvent(expectedEventTime,
null, expectedId, expectedInvolvedBoats, expectedPassId, Flags.NONE, Flags.NONE, true);
DBObject dbObject = mongoFactory.storeRaceLogEntry(logIdentifier, expectedEvent);
RaceLogFlagEvent actualEvent = loadEvent(dbObject);
assertNull(expectedEvent.getAuthor());
assertNotNull(actualEvent.getAuthor());
assertEquals(RaceLogEventAuthor.PRIORITY_COMPATIBILITY, actualEvent.getAuthor().getPriority());
assertEquals(RaceLogEventAuthor.NAME_COMPATIBILITY, actualEvent.getAuthor().getName());
}
@Test
public void testStoreAndLoadFlagEvent() {