From c7976fe553fb8a791d83dcd36cc005c686b43cbd Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Mon, 3 Jun 2013 21:45:27 +0200 Subject: [PATCH] added a test case for competitor compression --- .../common/dto/IncrementalLeaderboardDTO.java | 9 +++++++-- .../common/test/LeaderboardDTODiffingTest.java | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/IncrementalLeaderboardDTO.java b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/IncrementalLeaderboardDTO.java index dceb37397cc..5a2be5402c4 100755 --- a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/IncrementalLeaderboardDTO.java +++ b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/IncrementalLeaderboardDTO.java @@ -356,11 +356,13 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme RaceColumnDTO previousRaceColumn = previousVersion.getRaceColumnByName(raceColumnNameForWhichCompetitorOrderingPerRaceUnchanged); setCompetitorsFromBestToWorst(raceColumn, previousVersion.getCompetitorsFromBestToWorst(previousRaceColumn)); } + final Set rowsUnchangedForCompetitors = new HashSet(); if (rowsUnchanged != null) { if (rows == null) { rows = new HashMap(); } for (Pair rowUnchanged : rowsUnchanged.getAllUnchangedCompetitorsAndKeys(previousVersion)) { + rowsUnchangedForCompetitors.add(rowUnchanged.getA()); rows.put(rowUnchanged.getA(), previousVersion.rows.get(rowUnchanged.getA())); } } @@ -370,8 +372,11 @@ public class IncrementalLeaderboardDTO extends LeaderboardDTO implements Increme if (unchangedLeaderboardEntries != null) { for (Pair competitorAndColumnName : allUnchangedLeaderboardEntriesAsCompetitorsAndColumnNames) { CompetitorDTO previousCompetitor = competitorAndColumnName.getA(); - LeaderboardEntryDTO previousEntry = previousVersion.rows.get(previousCompetitor).fieldsByRaceColumnName.get(competitorAndColumnName.getB()); - rows.get(previousCompetitor).fieldsByRaceColumnName.put(competitorAndColumnName.getB(), previousEntry); + if (!rowsUnchangedForCompetitors.contains(previousCompetitor)) { // only care if not the entire row was marked unchanged + LeaderboardEntryDTO previousEntry = previousVersion.rows.get(previousCompetitor).fieldsByRaceColumnName.get( + competitorAndColumnName.getB()); + rows.get(previousCompetitor).fieldsByRaceColumnName.put(competitorAndColumnName.getB(), previousEntry); + } } } if (legDetailsUnchanged != null) { diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/common/test/LeaderboardDTODiffingTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/common/test/LeaderboardDTODiffingTest.java index 15fba650823..d8d1316a4ce 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/common/test/LeaderboardDTODiffingTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/common/test/LeaderboardDTODiffingTest.java @@ -17,6 +17,7 @@ import org.junit.Before; import org.junit.Test; import com.sap.sailing.domain.common.Cloner; +import com.sap.sailing.domain.common.dto.BoatClassDTO; import com.sap.sailing.domain.common.dto.CompetitorDTO; import com.sap.sailing.domain.common.dto.IncrementalLeaderboardDTO; import com.sap.sailing.domain.common.dto.LeaderboardDTO; @@ -154,5 +155,18 @@ public class LeaderboardDTODiffingTest { assertEquals(rowsBeforeStripping, applied.rows); } - // TODO write a test where a competitor is added and where a competitor is removed to check that competitors compression works properly; ensure that all orders remain unchanged + @Test + public void testCompetitorListChange() { + CompetitorDTO somebodyNew = new CompetitorDTO("Someone New", "DE", "GER", "Germany", "GER 1234", "912p09871203987", + new BoatClassDTO("505", 5.05)); + newVersion.competitors.add(13, somebodyNew); // insert a competitor; this should mess up all others' indexes; check if this works + CompetitorDTO wolfgang = getPreviousCompetitorByName("HUNGER +JESS"); + newVersion.competitors.remove(wolfgang); + newVersion.rows.remove(wolfgang); // remove another competitor + List newCompetitorsBeforeStripping = new ArrayList(newVersion.competitors); + newVersion.strip(previousVersion); + assertNull(newVersion.competitors); // but there should be an added competitor that we can't see through the public interface + LeaderboardDTO applied = newVersion.getLeaderboardDTO(previousVersion); + assertEquals(newCompetitorsBeforeStripping, applied.competitors); + } }