Skip to content
Snippets Groups Projects
Commit e45c44dd authored by Jonas's avatar Jonas
Browse files

20.01.2024 - work in progress, matthis has to fix brackets #27

parent 9a83ca46
No related branches found
No related tags found
2 merge requests!7Dev in Main Merge,!1Feat/service testing
......@@ -4,16 +4,20 @@ import lombok.Getter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Getter
public class BracketRound {
private final Logger log = LogManager.getLogger("BracketRound");
@Getter
Map<UUID, Match> matches;
int round;
private final UUID bracketRoundId;
private final Map<UUID, Match> matches;
private final int round;
public BracketRound(int round){
this.bracketRoundId = UUID.randomUUID();
this.round = round;
matches = new HashMap<>();
this.matches = new HashMap<>();
}
}
......@@ -13,7 +13,6 @@ import java.util.Map;
import java.util.UUID;
@Getter
@Document("Match")
public class Match {
private static final Logger log = LogManager.getLogger(Match.class);
......
......@@ -9,7 +9,6 @@ import org.springframework.data.mongodb.core.mapping.Document;
import java.util.UUID;
@Getter
@Document("Player")
@AllArgsConstructor
public class Player {
......
......@@ -292,16 +292,13 @@ public class TournamentService {
throw new BracketAlreadyInitializedException(tournamentId);
}
linkMatchesInNextRound(tournamentId);
Tournament linkedTournament = linkMatchesInNextRound(tournament);
tournamentRepository.save(tournament);
return tournament;
tournamentRepository.save(linkedTournament);
return linkedTournament;
}
public void linkMatchesInNextRound(UUID tournamentId) throws TournamentIdNotFoundException {
Tournament tournament = tournamentRepository.findById(tournamentId)
.orElseThrow(() -> new TournamentIdNotFoundException(tournamentId));
private Tournament linkMatchesInNextRound(Tournament tournament) {
int timesUsed = 0;
Map<UUID, Match> nextRoundMatches;
......@@ -331,7 +328,7 @@ public class TournamentService {
}
}
tournamentRepository.save(tournament);
return tournament;
}
......
package hdm.mi.sthbackend.serviceTests;
import hdm.mi.sthbackend.exeptions.BracketAlreadyInitializedException;
import hdm.mi.sthbackend.exeptions.BracketRoundNotFoundException;
import hdm.mi.sthbackend.exeptions.InsufficientTeamsException;
import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException;
import hdm.mi.sthbackend.model.Match;
import hdm.mi.sthbackend.model.Tournament;
import hdm.mi.sthbackend.repository.ITournamentRepository;
import hdm.mi.sthbackend.service.TournamentService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class DetermineWinnerTest {
Logger log = LogManager.getLogger(DetermineWinnerTest.class);
@Mock
ITournamentRepository tournamentRepository;
@InjectMocks
TournamentService service;
@Test
void determineWinner() throws Exception {
int bracketRound = 0;
List<String> teamsNames = new ArrayList<>();
teamsNames.add("dummyTeam 01");
teamsNames.add("dummyTeam 02");
teamsNames.add("dummyTeam 03");
teamsNames.add("dummyTeam 04");
teamsNames.add("dummyTeam 05");
teamsNames.add("dummyTeam 06");
Tournament tournament = service.createTournament(new Tournament("dummyTournament", teamsNames));
try {
service.createBracket(tournament.getTournamentId());
} catch (TournamentIdNotFoundException | InsufficientTeamsException | BracketAlreadyInitializedException e) {
log.debug(e.getMessage());
}
try {
service.fillBracketRandom(tournament.getTournamentId());
} catch (TournamentIdNotFoundException e) {
log.debug("Error while trying to fill bracket");
}
Match match = tournament.getBracket().get(0).getMatches().entrySet().stream().findFirst().orElseThrow(Exception::new).getValue();
match.getTeamScores().keySet().forEach(System.out::println);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment