mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-10 04:51:07 +00:00
Bug 5173: allow updating the leaderboard display name
This commit is contained in:
1 parent
f2a0906c6c
commit
d470b4e52d
4 files changed
+50
-16
No files matched your search
+4
-2
@@ -27,8 +27,9 @@ public class LeaderboardApi {
|
||||
+ "/{leaderboardname}/settrackingtimes";
|
||||
private static final String START_TRACKING_URL = LEADERBOARDS_V1_RESOURCE_URL + "/{leaderboardname}/starttracking";
|
||||
private static final String UPDATE_LEADERBOARD_URL = LEADERBOARDS_V1_RESOURCE_URL + "/{leaderboardname}/update";
|
||||
|
||||
|
||||
private static final String PARAM_RESULT_DISCARDING_THRESHOLDS = "resultDiscardingThresholds";
|
||||
private static final String PARAM_LEADERBOARD_DISPLAY_NAME = "leaderboardDisplayName";
|
||||
|
||||
public JSONArray getLeaderboards(ApiContext ctx) {
|
||||
return ctx.get(LEADERBOARDS_LIST_URL);
|
||||
@@ -42,7 +43,7 @@ public class LeaderboardApi {
|
||||
return new DeviceMappingRequest(ctx, leaderboardName);
|
||||
}
|
||||
|
||||
public void updateLeaderboard(ApiContext ctx, String leaderboardName, int[] resultDiscardingThresholds) {
|
||||
public void updateLeaderboard(ApiContext ctx, String leaderboardName, String leaderboardDisplayName, int[] resultDiscardingThresholds) {
|
||||
JSONObject requestJson = new JSONObject();
|
||||
JSONArray resultDiscardingThresholdsJsonArray = new JSONArray();
|
||||
if (resultDiscardingThresholds != null) {
|
||||
@@ -52,6 +53,7 @@ public class LeaderboardApi {
|
||||
}
|
||||
requestJson.put(PARAM_RESULT_DISCARDING_THRESHOLDS,
|
||||
resultDiscardingThresholds != null ? resultDiscardingThresholdsJsonArray : null);
|
||||
requestJson.put(PARAM_LEADERBOARD_DISPLAY_NAME, leaderboardDisplayName);
|
||||
System.out.println(requestJson.toJSONString());
|
||||
ctx.post(toUrl(UPDATE_LEADERBOARD_URL, leaderboardName), null, requestJson);
|
||||
}
|
||||
|
||||
+25
-5
@@ -64,14 +64,15 @@ public class LeaderboardApiTest extends AbstractSeleniumTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatingResultDiscardingThresholds() {
|
||||
public void testUpdatingLeaderboard() {
|
||||
final ApiContext ctx = createAdminApiContext(getContextRoot(), SERVER_CONTEXT);
|
||||
eventApi.createEvent(ctx, LEADERBOARD_NAME, BOATCLASSNAME, CLOSED, "default");
|
||||
final Leaderboard leaderboardOriginal = leaderboardApi.getLeaderboard(ctx, LEADERBOARD_NAME);
|
||||
|
||||
// updating
|
||||
final int[] newResultDiscardingThresholds = new int[] { 1, 2, 3, 4, 5 };
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, newResultDiscardingThresholds);
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, /* leaderboardDisplayName */ null,
|
||||
newResultDiscardingThresholds);
|
||||
|
||||
// reloading and check if updated
|
||||
Leaderboard leaderboardReloaded = leaderboardApi.getLeaderboard(ctx, LEADERBOARD_NAME);
|
||||
@@ -80,23 +81,42 @@ public class LeaderboardApiTest extends AbstractSeleniumTest {
|
||||
|
||||
// remove and check again
|
||||
final int[] newEmptyResultDiscardingThresholds = new int[] {};
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, newEmptyResultDiscardingThresholds);
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, /* leaderboardDisplayName */ null,
|
||||
newEmptyResultDiscardingThresholds);
|
||||
leaderboardReloaded = leaderboardApi.getLeaderboard(ctx, LEADERBOARD_NAME);
|
||||
assertArrayEquals(newEmptyResultDiscardingThresholds,
|
||||
leaderboardReloaded.getDiscardIndexResultsStartingWithHowManyRaces());
|
||||
|
||||
// passing null should not change anything
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, newResultDiscardingThresholds);
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, /* leaderboardDisplayName */ null,
|
||||
newResultDiscardingThresholds);
|
||||
leaderboardReloaded = leaderboardApi.getLeaderboard(ctx, LEADERBOARD_NAME);
|
||||
assertArrayEquals(newResultDiscardingThresholds,
|
||||
leaderboardReloaded.getDiscardIndexResultsStartingWithHowManyRaces());
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, null);
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, /* leaderboardDisplayName */ null, null);
|
||||
assertArrayEquals(newResultDiscardingThresholds,
|
||||
leaderboardReloaded.getDiscardIndexResultsStartingWithHowManyRaces());
|
||||
|
||||
// check that no other atributes have been changed
|
||||
assertEquals(leaderboardOriginal.getName(), leaderboardReloaded.getName());
|
||||
assertEquals(leaderboardOriginal.getDisplayName(), leaderboardReloaded.getDisplayName());
|
||||
|
||||
// update leaderboardDisplayName
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, "another display name", null);
|
||||
leaderboardReloaded = leaderboardApi.getLeaderboard(ctx, LEADERBOARD_NAME);
|
||||
assertEquals("another display name", leaderboardReloaded.getDisplayName());
|
||||
|
||||
// check that no other atributes have been changed
|
||||
assertEquals(leaderboardOriginal.getName(), leaderboardReloaded.getName());
|
||||
assertArrayEquals(newResultDiscardingThresholds,
|
||||
leaderboardReloaded.getDiscardIndexResultsStartingWithHowManyRaces());
|
||||
|
||||
// update leaderboardDisplayName and resultDiscardingThresholds
|
||||
final int[] newResultDiscardingThresholds2 = new int[] {7, 8};
|
||||
leaderboardApi.updateLeaderboard(ctx, LEADERBOARD_NAME, "another display name 2", newResultDiscardingThresholds2);
|
||||
leaderboardReloaded = leaderboardApi.getLeaderboard(ctx, LEADERBOARD_NAME);
|
||||
assertEquals("another display name 2", leaderboardReloaded.getDisplayName());
|
||||
assertArrayEquals(newResultDiscardingThresholds2, newResultDiscardingThresholds2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user