mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-14 22:43:57 +00:00
bug 4942: add api wrapper for regatta get competitors and corresponding
basic test
This commit is contained in:
1 parent
1816187fe9
commit
2c3903bce3
2 files changed
+39
-2
No files matched your search
+11
@@ -16,6 +16,7 @@ public class RegattaApi {
|
||||
private static final String LIST_REGATTA_RACES = "/races";
|
||||
private static final String COMPETITOR_CREATE_AND_ADD_WITH_BOAT = "/competitors/createandadd";
|
||||
private static final String ADD_RACE_COLUMN_URL = "/addracecolumns";
|
||||
private static final String LIST_COMPETITORS = "/competitors";
|
||||
|
||||
public Regatta getRegatta(ApiContext ctx, String regattaName) {
|
||||
return new Regatta(ctx.get(REGATTAS + "/" + regattaName));
|
||||
@@ -49,6 +50,16 @@ public class RegattaApi {
|
||||
Optional.ofNullable(secret), Optional.empty());
|
||||
}
|
||||
|
||||
public Competitor[] getCompetitors(final ApiContext ctx, final String regattaName) {
|
||||
final String url = REGATTAS + "/" + regattaName + LIST_COMPETITORS;
|
||||
final JSONArray competitors = ctx.get(url);
|
||||
if (competitors != null) {
|
||||
return competitors.stream().map(c -> (JSONObject) c).map(Competitor::new).toArray(Competitor[]::new);
|
||||
} else {
|
||||
return new Competitor[] {};
|
||||
}
|
||||
}
|
||||
|
||||
private Competitor createAndAddCompetitor(ApiContext ctx, String regattaName, String boatclass,
|
||||
String competitorEmail, String competitorName, String nationalityIOC, Optional<String> secret,
|
||||
Optional<UUID> deviceUuid) {
|
||||
|
||||
+28
-2
@@ -4,8 +4,10 @@ import static com.sap.sailing.domain.common.CompetitorRegistrationType.CLOSED;
|
||||
import static com.sap.sailing.selenium.api.core.ApiContext.SERVER_CONTEXT;
|
||||
import static com.sap.sailing.selenium.api.core.ApiContext.createAdminApiContext;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -71,8 +73,8 @@ public class RegattaApiTest extends AbstractSeleniumTest {
|
||||
RegattaRaces regattaRaces = regattaApi.getRegattaRaces(ctx, EVENT_NAME);
|
||||
|
||||
assertEquals("read: regatta is different", EVENT_NAME, regattaRaces.getRegattaName());
|
||||
//assertEquals("read: reagtta.series should have 0 entries", 0, regattaRaces.getRaces().length);
|
||||
|
||||
// assertEquals("read: reagtta.series should have 0 entries", 0, regattaRaces.getRaces().length);
|
||||
|
||||
RaceColumn[] raceColumns = regattaApi.addRaceColumn(ctx, EVENT_NAME, "R", 1);
|
||||
leaderboardApi.startRaceLogTracking(ctx, EVENT_NAME, raceColumns[0].getRaceName(), "Default");
|
||||
regattaRaces = regattaApi.getRegattaRaces(ctx, EVENT_NAME);
|
||||
@@ -99,6 +101,30 @@ public class RegattaApiTest extends AbstractSeleniumTest {
|
||||
competitor.getBoat().getBoatClass().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCompetitors() {
|
||||
final String competitor1Name = "Max Mustermann";
|
||||
final String competitor2Name = "Hans Albatros";
|
||||
final String competitor1Nationality = "GER";
|
||||
final String competitor2Nationality = "USA";
|
||||
final ApiContext ctx = createAdminApiContext(getContextRoot(), SERVER_CONTEXT);
|
||||
eventApi.createEvent(ctx, EVENT_NAME, BOAT_CLASS, CLOSED, "default");
|
||||
final Competitor competitor1 = regattaApi.createAndAddCompetitor(ctx, EVENT_NAME, BOAT_CLASS, "test@de",
|
||||
competitor1Name, competitor1Nationality);
|
||||
assertNotNull("Competitor1 should not be null", competitor1);
|
||||
final Competitor competitor2 = regattaApi.createAndAddCompetitor(ctx, EVENT_NAME, BOAT_CLASS, "test@de",
|
||||
competitor2Name, competitor2Nationality);
|
||||
assertNotNull("Competitor2 should not be null", competitor2);
|
||||
final Competitor[] competitors = regattaApi.getCompetitors(ctx, EVENT_NAME);
|
||||
assertNotNull("read: list of competitors should not be null", competitors);
|
||||
assertNotEquals("read: list of competitors should not be empty", 0, competitors.length);
|
||||
assertEquals("read: list of competitors should contains 2 comeptitors", 2, competitors.length);
|
||||
for (Competitor competitor : competitors) {
|
||||
assertTrue("competitor name " + competitor.getName() + " is wrong",
|
||||
competitor1Name.equals(competitor.getName()) || competitor2Name.equals(competitor.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddRaceColumns() {
|
||||
final ApiContext ctx = createAdminApiContext(getContextRoot(), SERVER_CONTEXT);
|
||||
|
||||
Reference in new issue
Block a user