From 01de2848d1fc68ef9b23dd6095257ca10f6a6f93 Mon Sep 17 00:00:00 2001 From: andriluccahannes <lb214@hdm-stuttgart.de> Date: Thu, 22 Feb 2024 17:17:01 +0100 Subject: [PATCH] 22.02.2024 - Implement Tournament Factory to ensure expandability of project #32 --- .../controller/TournamentController.java | 184 +++++++++++++----- .../mi/sthbackend/enums/TournamentType.java | 6 + .../factory/TournamentServiceFactory.java | 47 +++++ .../service/ITournamentService.java | 70 +++++++ ...> SingleEliminationTournamentService.java} | 51 ++--- ... SingleEliminationTournamentTypeTest.java} | 26 +-- .../endpointTest/EndpointTests.java | 1 - .../serviceTests/AddPlayerToTeamTest.java | 4 +- .../serviceTests/CreateBracketTest.java | 22 +-- .../serviceTests/DetermineWinnerTest.java | 4 +- .../serviceTests/FillBracketRandomTest.java | 12 +- .../RemovePlayerFromTeamTest.java | 4 +- .../serviceTests/UpdateScoreTest.java | 20 +- 13 files changed, 328 insertions(+), 123 deletions(-) create mode 100644 sth-backend/src/main/java/hdm/mi/sthbackend/enums/TournamentType.java create mode 100644 sth-backend/src/main/java/hdm/mi/sthbackend/factory/TournamentServiceFactory.java create mode 100644 sth-backend/src/main/java/hdm/mi/sthbackend/service/ITournamentService.java rename sth-backend/src/main/java/hdm/mi/sthbackend/service/{TournamentService.java => SingleEliminationTournamentService.java} (89%) rename sth-backend/src/test/java/hdm/mi/sthbackend/{TournamentServiceTest.java => SingleEliminationTournamentTypeTest.java} (89%) diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java b/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java index 506cf29..597036c 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java @@ -1,8 +1,9 @@ package hdm.mi.sthbackend.controller; +import hdm.mi.sthbackend.enums.TournamentType; import hdm.mi.sthbackend.exeptions.*; +import hdm.mi.sthbackend.factory.TournamentServiceFactory; import hdm.mi.sthbackend.model.Tournament; -import hdm.mi.sthbackend.service.TournamentService; import hdm.mi.sthbackend.service.UserService; import hdm.mi.sthbackend.types.CreateTournament; import hdm.mi.sthbackend.types.TeamMatchScore; @@ -12,67 +13,107 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.Arrays; import java.util.List; import java.util.UUID; +import static hdm.mi.sthbackend.enums.TournamentType.SINGLE_ELIMINATION; + @RestController -@RequestMapping("/api/v1") +@RequestMapping( "/api/v1" ) @AllArgsConstructor -@CrossOrigin(origins = "*",allowedHeaders = "*") +@CrossOrigin( origins = "*", allowedHeaders = "*" ) public class TournamentController { - private final TournamentService tournamentService; + private final TournamentServiceFactory tournamentServiceFactory; private final UserService userService; /** * Player Endpoints **/ - @PatchMapping("/tournaments/{tournamentId}/teams/{teamId}/players/{playerId}/updatePlayerName") + @PatchMapping( "/tournaments/{tournamentId}/teams/{teamId}/players/{playerId}/updatePlayerName" ) public UUID updatePlayerName(@PathVariable UUID tournamentId, @PathVariable UUID teamId, @PathVariable UUID playerId, - @RequestBody String newPlayerName) throws PlayerIdNotFoundException, TeamIdNotFoundException, TournamentIdNotFoundException { - return tournamentService.updatePlayerName(tournamentId, teamId, playerId, newPlayerName); + @RequestParam( name = "tournamentType", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type, + @RequestBody String newPlayerName) throws + PlayerIdNotFoundException, + TeamIdNotFoundException, + TournamentIdNotFoundException { + + return tournamentServiceFactory + .createTournamentService( type ) + .updatePlayerName( tournamentId, teamId, playerId, newPlayerName ); } /** * Team Endpoints **/ - @PostMapping("/tournaments/{tournamentId}/teams") + @PostMapping( "/tournaments/{tournamentId}/teams" ) public UUID createTeam(@PathVariable UUID tournamentId, - @RequestBody TeamName teamName) throws TournamentIdNotFoundException { - return tournamentService.createAndAddTeamToTournament(tournamentId, teamName.getName()); + @RequestBody TeamName teamName, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + TournamentIdNotFoundException { + + return tournamentServiceFactory + .createTournamentService( type ) + .createAndAddTeamToTournament( tournamentId, teamName.getName() ); } - @DeleteMapping("/tournaments/{tournamentId}/teams/{teamId}") + @DeleteMapping( "/tournaments/{tournamentId}/teams/{teamId}" ) public UUID removeTeamFromTournament(@PathVariable UUID tournamentId, - @PathVariable UUID teamId) throws TournamentIdNotFoundException, TeamIdNotFoundException { - return tournamentService.deleteAndRemoveTeamFromTournament(tournamentId, teamId); + @PathVariable UUID teamId, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + TournamentIdNotFoundException, + TeamIdNotFoundException { + + return tournamentServiceFactory + .createTournamentService( type ) + .deleteAndRemoveTeamFromTournament( tournamentId, teamId ); } - @PostMapping("/tournaments/{tournamentId}/teams/{teamId}/addPlayer") - public UUID addPlayerToTeam(@PathVariable UUID tournamentId, @PathVariable UUID teamId, - @RequestBody String playerName) throws TeamIdNotFoundException, TournamentIdNotFoundException { - return tournamentService.addPlayerToTeam(tournamentId, teamId, playerName); + @PostMapping( "/tournaments/{tournamentId}/teams/{teamId}/addPlayer" ) + public UUID addPlayerToTeam(@PathVariable UUID tournamentId, + @PathVariable UUID teamId, + @RequestBody String playerName, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + TeamIdNotFoundException, + TournamentIdNotFoundException { + + return tournamentServiceFactory + .createTournamentService( type ) + .addPlayerToTeam( tournamentId, teamId, playerName ); } @ResponseStatus - @DeleteMapping("/tournaments/{tournamendId}/teams/{teamId}/players/{playerId}") - public ResponseEntity<String> removePlayerFromTeam(@PathVariable UUID tournamendId, @PathVariable UUID teamId, - @PathVariable UUID playerId) throws PlayerIdNotFoundException, TeamIdNotFoundException, TournamentIdNotFoundException { - tournamentService.removePlayerFromTeam(tournamendId, teamId, playerId); - return new ResponseEntity<>("Successfully deleted Player ...", HttpStatus.OK); + @DeleteMapping( "/tournaments/{tournamendId}/teams/{teamId}/players/{playerId}" ) + public ResponseEntity<String> removePlayerFromTeam(@PathVariable UUID tournamendId, + @PathVariable UUID teamId, + @PathVariable UUID playerId, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + PlayerIdNotFoundException, + TeamIdNotFoundException, + TournamentIdNotFoundException { + + tournamentServiceFactory + .createTournamentService( type ) + .removePlayerFromTeam( tournamendId, teamId, playerId ); + return new ResponseEntity<>( "Successfully deleted Player ...", HttpStatus.OK ); } - @PatchMapping("/tournaments/{tournamentId}/teams/{teamId}/updateTeamName") + @PatchMapping( "/tournaments/{tournamentId}/teams/{teamId}/updateTeamName" ) public UUID updateTeamName(@PathVariable UUID tournamentId, - @PathVariable UUID teamId, - @RequestBody TeamName newTeamName) throws TeamIdNotFoundException, TournamentIdNotFoundException { - return tournamentService.updateTeamName(tournamentId,teamId, newTeamName.getName()); + @PathVariable UUID teamId, + @RequestBody TeamName newTeamName, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + TeamIdNotFoundException, + TournamentIdNotFoundException { + + return tournamentServiceFactory + .createTournamentService( type ) + .updateTeamName( tournamentId, teamId, newTeamName.getName() ); } @@ -80,59 +121,100 @@ public class TournamentController { * Match Endpoints */ - @PatchMapping("/tournaments/{tournamentId}/bracketRounds/{bracketRound}/matches/{matchId}/teams/{teamId}/updateScore") + @PatchMapping( "/tournaments/{tournamentId}/bracketRounds/{bracketRound}/matches/{matchId}/teams/{teamId}/updateScore" ) public ResponseEntity<String> updateScore(@PathVariable UUID tournamentId, @PathVariable UUID matchId, @PathVariable int bracketRound, @PathVariable UUID teamId, - @RequestBody TeamMatchScore newScore) throws MatchIdNotFoundException, TeamIdNotFoundException, - BracketRoundNotFoundException, TournamentIdNotFoundException { - tournamentService.updateScore(tournamentId, bracketRound, matchId, teamId, newScore.getScore()); - return new ResponseEntity<>("Successfully updated Score for match " + matchId + " ...", HttpStatus.OK); + @RequestBody TeamMatchScore newScore, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + MatchIdNotFoundException, + TeamIdNotFoundException, + BracketRoundNotFoundException, + TournamentIdNotFoundException { + + tournamentServiceFactory + .createTournamentService( type ) + .updateScore( tournamentId, bracketRound, matchId, teamId, newScore.getScore() ); + return new ResponseEntity<>( "Successfully updated Score for match " + matchId + " ...", HttpStatus.OK ); } - @PatchMapping("/tournaments/{tournamentId}/bracketRounds/{bracketRound}/matches/{matchId}/handleWinner") - public UUID handleWinner(@PathVariable UUID tournamentId, @PathVariable int bracketRound, @PathVariable UUID matchId) throws MatchIdNotFoundException, WinnerNotDeterminedException, TournamentIdNotFoundException { - return tournamentService.handleWinner(tournamentId, bracketRound, matchId); + @PatchMapping( "/tournaments/{tournamentId}/bracketRounds/{bracketRound}/matches/{matchId}/handleWinner" ) + public UUID handleWinner(@PathVariable UUID tournamentId, + @PathVariable int bracketRound, + @PathVariable UUID matchId, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + MatchIdNotFoundException, + WinnerNotDeterminedException, + TournamentIdNotFoundException { + + return tournamentServiceFactory + .createTournamentService( type ) + .handleWinner( tournamentId, bracketRound, matchId ); } /** * Tournament Endpoints */ - @GetMapping("/tournaments/{tournamentId}") - public Tournament findTournamentById(@PathVariable UUID tournamentId) throws TournamentIdNotFoundException { - return tournamentService.getTournament(tournamentId); + @GetMapping( "/tournaments/{tournamentId}" ) + public Tournament findTournamentById(@PathVariable UUID tournamentId, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + TournamentIdNotFoundException { + + return tournamentServiceFactory + .createTournamentService( type ) + .getTournament( tournamentId ); } - @PostMapping("/tournaments") - public Tournament createTournament(@RequestBody CreateTournament tournament) { + @PostMapping( "/tournaments" ) + public Tournament createTournament(@RequestBody CreateTournament tournament, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) { String tournamentName = tournament.getTournamentName(); List<String> teamNames = tournament.getTeamNames(); UUID userId = tournament.getUserId(); - Tournament createdTournament = tournamentService.createTournament(new Tournament(tournamentName, teamNames)); - userService.addTournamentToUser(userId, createdTournament.getTournamentId()); + Tournament createdTournament = tournamentServiceFactory + .createTournamentService( type ) + .createTournament( new Tournament( tournamentName, teamNames ) ); + userService.addTournamentToUser( userId, createdTournament.getTournamentId() ); return createdTournament; } - @DeleteMapping("/tournaments/{tournamentId}") - public Tournament deleteTournament(@PathVariable UUID tournamentId) throws TournamentIdNotFoundException { - return tournamentService.deleteTournament(tournamentId); + @DeleteMapping( "/tournaments/{tournamentId}" ) + public Tournament deleteTournament(@PathVariable UUID tournamentId, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + TournamentIdNotFoundException { + + return tournamentServiceFactory + .createTournamentService( type ) + .deleteTournament( tournamentId ); } - @PatchMapping("/tournaments/{tournamentId}/updateName") + @PatchMapping( "/tournaments/{tournamentId}/updateName" ) public UUID updateTournamentName(@PathVariable UUID tournamentId, - @RequestBody String newTournamentName) throws TournamentIdNotFoundException { - return tournamentService.updateTournamentName(tournamentId, newTournamentName); + @RequestBody String newTournamentName, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + TournamentIdNotFoundException { + + return tournamentServiceFactory + .createTournamentService( type ) + .updateTournamentName( tournamentId, newTournamentName ); } - @PatchMapping("/tournaments/{tournamentId}/initialize") - public Tournament initializeTournament(@PathVariable UUID tournamentId) throws TournamentIdNotFoundException, InsufficientTeamsException, BracketAlreadyInitializedException { - return tournamentService.initializeTournament(tournamentId); + @PatchMapping( "/tournaments/{tournamentId}/initialize" ) + public Tournament initializeTournament(@PathVariable UUID tournamentId, + @RequestParam( name = "type", defaultValue = "SINGLE_ELIMINATION" ) TournamentType type) throws + TournamentIdNotFoundException, + InsufficientTeamsException, + BracketAlreadyInitializedException { + + return tournamentServiceFactory + .createTournamentService( type ) + .initializeTournament( tournamentId ); } } diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/enums/TournamentType.java b/sth-backend/src/main/java/hdm/mi/sthbackend/enums/TournamentType.java new file mode 100644 index 0000000..433ccd3 --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/enums/TournamentType.java @@ -0,0 +1,6 @@ +package hdm.mi.sthbackend.enums; + +public enum TournamentType { + + SINGLE_ELIMINATION, +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/factory/TournamentServiceFactory.java b/sth-backend/src/main/java/hdm/mi/sthbackend/factory/TournamentServiceFactory.java new file mode 100644 index 0000000..e809b19 --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/factory/TournamentServiceFactory.java @@ -0,0 +1,47 @@ +package hdm.mi.sthbackend.factory; + +import hdm.mi.sthbackend.enums.TournamentType; +import hdm.mi.sthbackend.service.ITournamentService; +import hdm.mi.sthbackend.service.SingleEliminationTournamentService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class TournamentServiceFactory { + + public static final Logger logger = LogManager.getLogger( TournamentServiceFactory.class ); + + private final List<ITournamentService> tournamentServices; + + public TournamentServiceFactory(List<ITournamentService> tournamentServices) { + + this.tournamentServices = tournamentServices; + } + + public ITournamentService createTournamentService(TournamentType tournamentType) { + + switch ( tournamentType ) { + case SINGLE_ELIMINATION -> { + return getTournamentService( SingleEliminationTournamentService.class ); + } + default -> { + return getTournamentService( SingleEliminationTournamentService.class ); + } + } + + } + + private ITournamentService getTournamentService(Class tournamentServiceType) { + + return tournamentServices + .stream() + .filter( tournamentServiceType::isInstance ) + .findFirst() + .orElseThrow( () -> new IllegalArgumentException( "Tournament service not found" ) ); + } + + +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/service/ITournamentService.java b/sth-backend/src/main/java/hdm/mi/sthbackend/service/ITournamentService.java new file mode 100644 index 0000000..009e2eb --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/service/ITournamentService.java @@ -0,0 +1,70 @@ +package hdm.mi.sthbackend.service; + +import hdm.mi.sthbackend.exeptions.*; +import hdm.mi.sthbackend.model.Tournament; + +import java.util.UUID; + +public interface ITournamentService { + UUID addPlayerToTeam(UUID tournamentId, UUID teamId, String playerName) throws + TournamentIdNotFoundException, + TeamIdNotFoundException; + + void removePlayerFromTeam(UUID tournamentId, UUID teamId, UUID playerId) throws + PlayerIdNotFoundException, + TeamIdNotFoundException, + TournamentIdNotFoundException; + + UUID updatePlayerName(UUID tournamentId, UUID teamId, UUID playerId, String newPlayerName) throws + PlayerIdNotFoundException, + TournamentIdNotFoundException, + TeamIdNotFoundException; + + UUID createAndAddTeamToTournament(UUID tournamentId, String teamName) throws TournamentIdNotFoundException; + + UUID deleteAndRemoveTeamFromTournament(UUID tournamentId, UUID teamId) throws + TournamentIdNotFoundException, + TeamIdNotFoundException; + + UUID updateTeamName(UUID tournamentId, UUID teamId, String newTeamName) throws + TeamIdNotFoundException, + TournamentIdNotFoundException; + + UUID handleWinner(UUID tournamentId, int bracketRound, UUID matchId) throws + MatchIdNotFoundException, + WinnerNotDeterminedException, + TournamentIdNotFoundException; + + Tournament assignTeamToMatch(Tournament tournament, int bracketRound, UUID matchId, UUID teamId) throws + MatchIdNotFoundException; + + void updateScore(UUID tournamentId, int bracketRound, UUID matchId, UUID teamId, int newScore) throws + MatchIdNotFoundException, + TeamIdNotFoundException, + TournamentIdNotFoundException, + BracketRoundNotFoundException; + + /* + * BracketRound service methods + */ + Tournament createBracket(Tournament tournament) throws + InsufficientTeamsException, + BracketAlreadyInitializedException; + + Tournament linkMatchesInNextRound(Tournament tournament); + + Tournament fillBracketRandom(Tournament tournament); + + Tournament createTournament(Tournament tournament); + + Tournament initializeTournament(UUID tournamentId) throws + TournamentIdNotFoundException, + InsufficientTeamsException, + BracketAlreadyInitializedException; + + UUID updateTournamentName(UUID tournamentId, String newTournamentName) throws TournamentIdNotFoundException; + + Tournament getTournament(UUID tournamentId) throws TournamentIdNotFoundException; + + Tournament deleteTournament(UUID tournamentId) throws TournamentIdNotFoundException; +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java b/sth-backend/src/main/java/hdm/mi/sthbackend/service/SingleEliminationTournamentService.java similarity index 89% rename from sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java rename to sth-backend/src/main/java/hdm/mi/sthbackend/service/SingleEliminationTournamentService.java index fdb7f46..38460bb 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/service/SingleEliminationTournamentService.java @@ -15,9 +15,9 @@ import java.util.*; @Service @AllArgsConstructor -public class TournamentService { +public class SingleEliminationTournamentService implements ITournamentService { - private final Logger log = LogManager.getLogger(TournamentService.class); + private final Logger log = LogManager.getLogger( SingleEliminationTournamentService.class); ITournamentRepository tournamentRepository; @@ -28,8 +28,8 @@ public class TournamentService { * Player service methods */ - public UUID addPlayerToTeam(UUID tournamentId, UUID teamId, - String playerName) throws TournamentIdNotFoundException, TeamIdNotFoundException { + @Override + public UUID addPlayerToTeam(UUID tournamentId, UUID teamId, String playerName) throws TournamentIdNotFoundException, TeamIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -46,8 +46,8 @@ public class TournamentService { return newPlayer.getPlayerId(); } - public void removePlayerFromTeam(UUID tournamentId, UUID teamId, - UUID playerId) throws PlayerIdNotFoundException, TeamIdNotFoundException, TournamentIdNotFoundException { + @Override + public void removePlayerFromTeam(UUID tournamentId, UUID teamId, UUID playerId) throws PlayerIdNotFoundException, TeamIdNotFoundException, TournamentIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -65,8 +65,8 @@ public class TournamentService { log.debug("Player " + removedPlayer.getPlayerId() + " removed from Team " + teamId); } - public UUID updatePlayerName(UUID tournamentId, UUID teamId, UUID playerId, - String newPlayerName) throws PlayerIdNotFoundException, TournamentIdNotFoundException, TeamIdNotFoundException { + @Override + public UUID updatePlayerName(UUID tournamentId, UUID teamId, UUID playerId, String newPlayerName) throws PlayerIdNotFoundException, TournamentIdNotFoundException, TeamIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -87,6 +87,7 @@ public class TournamentService { * Team service methods */ + @Override public UUID createAndAddTeamToTournament(UUID tournamentId, String teamName) throws TournamentIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -100,8 +101,8 @@ public class TournamentService { return newTeam.getTeamId(); } - public UUID deleteAndRemoveTeamFromTournament(UUID tournamentId, - UUID teamId) throws TournamentIdNotFoundException, TeamIdNotFoundException { + @Override + public UUID deleteAndRemoveTeamFromTournament(UUID tournamentId, UUID teamId) throws TournamentIdNotFoundException, TeamIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -116,9 +117,8 @@ public class TournamentService { return teamId; } - public UUID updateTeamName(UUID tournamentId, - UUID teamId, - String newTeamName) throws TeamIdNotFoundException, TournamentIdNotFoundException { + @Override + public UUID updateTeamName(UUID tournamentId, UUID teamId, String newTeamName) throws TeamIdNotFoundException, TournamentIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -136,10 +136,8 @@ public class TournamentService { * Match service methods */ - public UUID handleWinner(UUID tournamentId, - int bracketRound, - UUID matchId - ) throws MatchIdNotFoundException, WinnerNotDeterminedException, TournamentIdNotFoundException { + @Override + public UUID handleWinner(UUID tournamentId, int bracketRound, UUID matchId) throws MatchIdNotFoundException, WinnerNotDeterminedException, TournamentIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -177,10 +175,8 @@ public class TournamentService { return winnerTeamId; } - public Tournament assignTeamToMatch(Tournament tournament, - int bracketRound, - UUID matchId, - UUID teamId) throws MatchIdNotFoundException { + @Override + public Tournament assignTeamToMatch(Tournament tournament, int bracketRound, UUID matchId, UUID teamId) throws MatchIdNotFoundException { try { tournament @@ -199,9 +195,8 @@ public class TournamentService { } - public void updateScore(UUID tournamentId, int bracketRound, UUID matchId, - UUID teamId, - int newScore) throws MatchIdNotFoundException, TeamIdNotFoundException, TournamentIdNotFoundException, BracketRoundNotFoundException { + @Override + public void updateScore(UUID tournamentId, int bracketRound, UUID matchId, UUID teamId, int newScore) throws MatchIdNotFoundException, TeamIdNotFoundException, TournamentIdNotFoundException, BracketRoundNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -230,6 +225,7 @@ public class TournamentService { /* * BracketRound service methods */ + @Override public Tournament createBracket(Tournament tournament) throws InsufficientTeamsException, BracketAlreadyInitializedException { Map<UUID, Team> teams = tournament.getTeams(); @@ -267,6 +263,7 @@ public class TournamentService { return tournament; } + @Override public Tournament linkMatchesInNextRound(Tournament tournament) { int timesUsed = 0; Map<UUID, Match> nextRoundMatches; @@ -301,6 +298,7 @@ public class TournamentService { } + @Override public Tournament fillBracketRandom(Tournament tournament) { Map<UUID, Team> teams = new HashMap<>(Map.copyOf(tournament.getTeams())); @@ -332,6 +330,7 @@ public class TournamentService { * Tournament service methods */ + @Override public Tournament createTournament(Tournament tournament) { tournamentRepository.insert(tournament); @@ -339,6 +338,7 @@ public class TournamentService { return tournament; } + @Override public Tournament initializeTournament(UUID tournamentId) throws TournamentIdNotFoundException, InsufficientTeamsException, BracketAlreadyInitializedException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -351,6 +351,7 @@ public class TournamentService { return tournamentWithFilledBrackets; } + @Override public UUID updateTournamentName(UUID tournamentId, String newTournamentName) throws TournamentIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -361,6 +362,7 @@ public class TournamentService { return tournamentId; } + @Override public Tournament getTournament(UUID tournamentId) throws TournamentIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -369,6 +371,7 @@ public class TournamentService { return tournament; } + @Override public Tournament deleteTournament(UUID tournamentId) throws TournamentIdNotFoundException { Tournament tournamentToDelete = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); diff --git a/sth-backend/src/test/java/hdm/mi/sthbackend/TournamentServiceTest.java b/sth-backend/src/test/java/hdm/mi/sthbackend/SingleEliminationTournamentTypeTest.java similarity index 89% rename from sth-backend/src/test/java/hdm/mi/sthbackend/TournamentServiceTest.java rename to sth-backend/src/test/java/hdm/mi/sthbackend/SingleEliminationTournamentTypeTest.java index d7259eb..30f2593 100644 --- a/sth-backend/src/test/java/hdm/mi/sthbackend/TournamentServiceTest.java +++ b/sth-backend/src/test/java/hdm/mi/sthbackend/SingleEliminationTournamentTypeTest.java @@ -5,7 +5,7 @@ import hdm.mi.sthbackend.exeptions.PlayerIdNotFoundException; import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; import hdm.mi.sthbackend.model.*; import hdm.mi.sthbackend.repository.ITournamentRepository; -import hdm.mi.sthbackend.service.TournamentService; +import hdm.mi.sthbackend.service.SingleEliminationTournamentService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Test; @@ -25,11 +25,11 @@ import static org.mockito.Mockito.*; @SpringBootTest @ExtendWith(MockitoExtension.class) -public class TournamentServiceTest { +public class SingleEliminationTournamentTypeTest { private final Logger log = LogManager.getLogger("TournamentControllerTest"); @InjectMocks - private TournamentService tournamentService; + private SingleEliminationTournamentService singleEliminationTournamentService; @Mock ITournamentRepository tournamentRepository; @@ -51,7 +51,7 @@ public class TournamentServiceTest { when(tournamentRepository.findById(tournamentId)).thenReturn(Optional.of(tournament)); - UUID result = tournamentService.addPlayerToTeam(tournamentId, teamId, testString); + UUID result = singleEliminationTournamentService.addPlayerToTeam(tournamentId, teamId, testString); assertNotNull(result); verify(tournamentRepository, times(1)).findById(tournamentId); @@ -79,7 +79,7 @@ public class TournamentServiceTest { when(tournamentRepository.findById(tournamentId)).thenReturn(Optional.of(tournament)); - tournamentService.removePlayerFromTeam(tournamentId, teamId, playerId); + singleEliminationTournamentService.removePlayerFromTeam(tournamentId, teamId, playerId); verify(tournamentRepository, times(1)).findById(tournamentId); verify(tournamentRepository, times(1)).save(tournament); @@ -110,7 +110,7 @@ public class TournamentServiceTest { assertFalse(tournament.getBracket().get(0).getMatches().get(matchId).getTeamScores().containsKey(teamId)); - Tournament result = tournamentService.assignTeamToMatch(tournament,0,matchId,teamId); + Tournament result = singleEliminationTournamentService.assignTeamToMatch(tournament,0,matchId,teamId); assertNotNull(result); assertTrue(result.getBracket().get(0).getMatches().get(matchId).getTeamScores().containsKey(teamId)); @@ -137,7 +137,7 @@ public class TournamentServiceTest { tournament.getBracket().get(0).getMatches().put(matchId,match); assertThrows(MatchIdNotFoundException.class, () -> { - tournamentService.assignTeamToMatch(tournament,0,notCreatedMatchId,teamId); + singleEliminationTournamentService.assignTeamToMatch(tournament,0,notCreatedMatchId,teamId); }); } @@ -147,7 +147,7 @@ public class TournamentServiceTest { teamNames.add("machine"); Tournament tournament = new Tournament("testtunier",teamNames); - Tournament result = tournamentService.createTournament(tournament); + Tournament result = singleEliminationTournamentService.createTournament(tournament); assertNotNull(result); assertEquals(tournament,result); @@ -174,7 +174,7 @@ public class TournamentServiceTest { when(tournamentRepository.findById(tournamentId)).thenReturn(Optional.of(tournament)); - UUID result = tournamentService.updatePlayerName(tournamentId,teamId,playerId,testString); + UUID result = singleEliminationTournamentService.updatePlayerName(tournamentId,teamId,playerId,testString); assertNotNull(result); assertEquals(testString, player.getName()); @@ -201,7 +201,7 @@ public class TournamentServiceTest { when(tournamentRepository.findById(tournamentId)).thenReturn(Optional.of(tournament)); assertThrows(PlayerIdNotFoundException.class, () -> { - tournamentService.updatePlayerName(tournamentId, teamId, playerId, testString); + singleEliminationTournamentService.updatePlayerName(tournamentId, teamId, playerId, testString); }); verify(tournamentRepository, times(1)).findById(tournamentId); @@ -225,7 +225,7 @@ public class TournamentServiceTest { when(tournamentRepository.findById(tournamentId)).thenReturn(Optional.empty()); assertThrows(TournamentIdNotFoundException.class, () -> { - tournamentService.updatePlayerName(tournamentId, teamId, playerId, testString); + singleEliminationTournamentService.updatePlayerName(tournamentId, teamId, playerId, testString); }); verify(tournamentRepository, times(1)).findById(tournamentId); @@ -240,7 +240,7 @@ public class TournamentServiceTest { when(tournamentRepository.findById(tournamentId)).thenReturn(Optional.of(tournament)); - UUID result = tournamentService.createAndAddTeamToTournament(tournamentId, teamName); + UUID result = singleEliminationTournamentService.createAndAddTeamToTournament(tournamentId, teamName); verify(tournamentRepository, times(1)).findById(tournamentId); verify(tournamentRepository, times(1)).save(tournament); @@ -266,7 +266,7 @@ public class TournamentServiceTest { when(tournamentRepository.findById(tournamentId)).thenReturn(Optional.of(tournament)); - UUID result = tournamentService.deleteAndRemoveTeamFromTournament(tournamentId, teamId); + UUID result = singleEliminationTournamentService.deleteAndRemoveTeamFromTournament(tournamentId, teamId); verify(tournamentRepository, times(1)).findById(tournamentId); verify(tournamentRepository, times(1)).save(tournament); diff --git a/sth-backend/src/test/java/hdm/mi/sthbackend/endpointTest/EndpointTests.java b/sth-backend/src/test/java/hdm/mi/sthbackend/endpointTest/EndpointTests.java index 647344f..e219b3b 100644 --- a/sth-backend/src/test/java/hdm/mi/sthbackend/endpointTest/EndpointTests.java +++ b/sth-backend/src/test/java/hdm/mi/sthbackend/endpointTest/EndpointTests.java @@ -5,7 +5,6 @@ import com.jayway.jsonpath.JsonPath; import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; import hdm.mi.sthbackend.model.Tournament; import hdm.mi.sthbackend.repository.ITournamentRepository; -import hdm.mi.sthbackend.service.TournamentService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; diff --git a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/AddPlayerToTeamTest.java b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/AddPlayerToTeamTest.java index f38b921..58080d2 100644 --- a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/AddPlayerToTeamTest.java +++ b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/AddPlayerToTeamTest.java @@ -5,7 +5,7 @@ import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; import hdm.mi.sthbackend.model.Team; import hdm.mi.sthbackend.model.Tournament; import hdm.mi.sthbackend.repository.ITournamentRepository; -import hdm.mi.sthbackend.service.TournamentService; +import hdm.mi.sthbackend.service.SingleEliminationTournamentService; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -28,7 +28,7 @@ public class AddPlayerToTeamTest { ITournamentRepository repository; @InjectMocks - TournamentService service; + SingleEliminationTournamentService service; @Test void shouldAddPlayerToTeam() throws TeamIdNotFoundException, TournamentIdNotFoundException { diff --git a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/CreateBracketTest.java b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/CreateBracketTest.java index e1a6f4e..7a6262b 100644 --- a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/CreateBracketTest.java +++ b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/CreateBracketTest.java @@ -4,25 +4,23 @@ import hdm.mi.sthbackend.dummyObjects.DummyTournaments; import hdm.mi.sthbackend.exeptions.BracketAlreadyInitializedException; import hdm.mi.sthbackend.exeptions.InsufficientTeamsException; import hdm.mi.sthbackend.model.Tournament; -import hdm.mi.sthbackend.service.TournamentService; +import hdm.mi.sthbackend.service.SingleEliminationTournamentService; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import static hdm.mi.sthbackend.dummyObjects.DummyTournaments.*; - @SpringBootTest() class CreateBracketTest { @Autowired - TournamentService tournamentService; + SingleEliminationTournamentService singleEliminationTournamentService; DummyTournaments tournaments = new DummyTournaments(); @Test void create2TeamBracketTest() throws InsufficientTeamsException, BracketAlreadyInitializedException { - Tournament resultTournament = tournamentService.createBracket(tournaments.getDummyTournament("dummyName",2 )); + Tournament resultTournament = singleEliminationTournamentService.createBracket(tournaments.getDummyTournament("dummyName",2 )); Assertions.assertEquals(1, resultTournament.getBracket() .size()); @@ -34,7 +32,7 @@ class CreateBracketTest { @Test void create4TeamBracketTest() throws InsufficientTeamsException, BracketAlreadyInitializedException { - Tournament resultTournament = tournamentService.createBracket(tournaments.getDummyTournament("dummyName", 4)); + Tournament resultTournament = singleEliminationTournamentService.createBracket(tournaments.getDummyTournament("dummyName", 4)); Assertions.assertEquals(2, resultTournament.getBracket() .size()); @@ -50,7 +48,7 @@ class CreateBracketTest { @Test void create8TeamBracketTest() throws InsufficientTeamsException, BracketAlreadyInitializedException { - Tournament resultTournament = tournamentService.createBracket(tournaments.getDummyTournament("dummyName", 8)); + Tournament resultTournament = singleEliminationTournamentService.createBracket(tournaments.getDummyTournament("dummyName", 8)); Assertions.assertEquals(3, resultTournament.getBracket() .size()); @@ -70,7 +68,7 @@ class CreateBracketTest { @Test void create16TeamBracketTest() throws InsufficientTeamsException, BracketAlreadyInitializedException { - Tournament resultTournament = tournamentService.createBracket(tournaments.getDummyTournament("dummyName", 16)); + Tournament resultTournament = singleEliminationTournamentService.createBracket(tournaments.getDummyTournament("dummyName", 16)); Assertions.assertEquals(4, resultTournament.getBracket() .size()); @@ -94,12 +92,12 @@ class CreateBracketTest { @Test void create1TeamBracketTest() { - Assertions.assertThrows(InsufficientTeamsException.class, () -> tournamentService.createBracket(tournaments.getDummyTournament("dummyName", 1))); + Assertions.assertThrows(InsufficientTeamsException.class, () -> singleEliminationTournamentService.createBracket(tournaments.getDummyTournament("dummyName", 1))); } @Test void create3TeamBracketTest() throws InsufficientTeamsException, BracketAlreadyInitializedException { - Tournament resultTournament = tournamentService.createBracket(tournaments.getDummyTournament("dummyName", 3)); + Tournament resultTournament = singleEliminationTournamentService.createBracket(tournaments.getDummyTournament("dummyName", 3)); Assertions.assertEquals(2, resultTournament.getBracket() .size()); @@ -115,7 +113,7 @@ class CreateBracketTest { @Test void create5TeamBracketTest() throws InsufficientTeamsException, BracketAlreadyInitializedException { - Tournament resultTournament = tournamentService.createBracket(tournaments.getDummyTournament("dummyName", 5)); + Tournament resultTournament = singleEliminationTournamentService.createBracket(tournaments.getDummyTournament("dummyName", 5)); Assertions.assertEquals(3, resultTournament.getBracket() .size()); @@ -135,7 +133,7 @@ class CreateBracketTest { @Test void create15TeamBracketTest() throws InsufficientTeamsException, BracketAlreadyInitializedException { - Tournament resultTournament = tournamentService.createBracket(tournaments.getDummyTournament("dummyName", 15)); + Tournament resultTournament = singleEliminationTournamentService.createBracket(tournaments.getDummyTournament("dummyName", 15)); Assertions.assertEquals(4, resultTournament.getBracket() .size(), 4); diff --git a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/DetermineWinnerTest.java b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/DetermineWinnerTest.java index 5ac6457..2062520 100644 --- a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/DetermineWinnerTest.java +++ b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/DetermineWinnerTest.java @@ -5,7 +5,7 @@ import hdm.mi.sthbackend.exeptions.*; 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 hdm.mi.sthbackend.service.SingleEliminationTournamentService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Assertions; @@ -30,7 +30,7 @@ class DetermineWinnerTest { ITournamentRepository tournamentRepository; @InjectMocks - TournamentService service; + SingleEliminationTournamentService service; @Test void determineWinnerShouldFindWinner() throws Exception { diff --git a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/FillBracketRandomTest.java b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/FillBracketRandomTest.java index 88b9ba9..c956517 100644 --- a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/FillBracketRandomTest.java +++ b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/FillBracketRandomTest.java @@ -4,7 +4,7 @@ import hdm.mi.sthbackend.dummyObjects.DummyTournaments; import hdm.mi.sthbackend.model.BracketRound; import hdm.mi.sthbackend.model.Match; import hdm.mi.sthbackend.model.Tournament; -import hdm.mi.sthbackend.service.TournamentService; +import hdm.mi.sthbackend.service.SingleEliminationTournamentService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Test; @@ -21,7 +21,7 @@ class FillBracketRandomTest { private final Logger log = LogManager.getLogger("FillBracketTest"); @Autowired - TournamentService tournamentService; + SingleEliminationTournamentService singleEliminationTournamentService; DummyTournaments tournaments = new DummyTournaments(); @@ -50,7 +50,7 @@ class FillBracketRandomTest { @Test void fill2TeamBracketRandomTest() { Tournament t1withMatches = createDummyBracketAndMatches(1, tournaments.getDummyTournament("dummyName", 2)); - Tournament t1Filled = tournamentService.fillBracketRandom(t1withMatches); + Tournament t1Filled = singleEliminationTournamentService.fillBracketRandom(t1withMatches); int teamSum = calculateTeamSum(t1Filled); assertEquals(2,teamSum); @@ -59,7 +59,7 @@ class FillBracketRandomTest { @Test void fill4TeamBracketRandomTest() { Tournament t2withMatches = createDummyBracketAndMatches(2, tournaments.getDummyTournament("dummyName", 4)); - Tournament t2Filled = tournamentService.fillBracketRandom(t2withMatches); + Tournament t2Filled = singleEliminationTournamentService.fillBracketRandom(t2withMatches); int teamSum = calculateTeamSum(t2Filled); assertEquals(4,teamSum); @@ -68,7 +68,7 @@ class FillBracketRandomTest { @Test void fill8TeamBracketRandomTest() { Tournament t3withMatches = createDummyBracketAndMatches(3, tournaments.getDummyTournament("dummyName", 8)); - Tournament t3Filled = tournamentService.fillBracketRandom(t3withMatches); + Tournament t3Filled = singleEliminationTournamentService.fillBracketRandom(t3withMatches); int teamSum = calculateTeamSum(t3Filled); assertEquals(8,teamSum); @@ -78,7 +78,7 @@ class FillBracketRandomTest { @Test void fill16TeamBracketRandomTest() { Tournament t4withMatches = createDummyBracketAndMatches(4, tournaments.getDummyTournament("dummyName", 16)); - Tournament t4Filled = tournamentService.fillBracketRandom(t4withMatches); + Tournament t4Filled = singleEliminationTournamentService.fillBracketRandom(t4withMatches); int teamSum = calculateTeamSum(t4Filled); assertEquals(16,teamSum); diff --git a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/RemovePlayerFromTeamTest.java b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/RemovePlayerFromTeamTest.java index ad92216..856577a 100644 --- a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/RemovePlayerFromTeamTest.java +++ b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/RemovePlayerFromTeamTest.java @@ -6,7 +6,7 @@ import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; import hdm.mi.sthbackend.model.Team; import hdm.mi.sthbackend.model.Tournament; import hdm.mi.sthbackend.repository.ITournamentRepository; -import hdm.mi.sthbackend.service.TournamentService; +import hdm.mi.sthbackend.service.SingleEliminationTournamentService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Assertions; @@ -31,7 +31,7 @@ class RemovePlayerFromTeamTest { ITournamentRepository tournamentRepository; @InjectMocks - TournamentService service; + SingleEliminationTournamentService service; @Test void shouldRemovePlayerFromTeamTest() throws TeamIdNotFoundException, TournamentIdNotFoundException, PlayerIdNotFoundException { diff --git a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/UpdateScoreTest.java b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/UpdateScoreTest.java index d47991f..aa0cd23 100644 --- a/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/UpdateScoreTest.java +++ b/sth-backend/src/test/java/hdm/mi/sthbackend/serviceTests/UpdateScoreTest.java @@ -5,7 +5,7 @@ import hdm.mi.sthbackend.exeptions.*; 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 hdm.mi.sthbackend.service.SingleEliminationTournamentService; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.Assertions; @@ -31,7 +31,7 @@ class UpdateScoreTest { ITournamentRepository tournamentRepository; @InjectMocks - TournamentService tournamentService; + SingleEliminationTournamentService singleEliminationTournamentService; DummyTournaments tournaments = new DummyTournaments(); @@ -41,7 +41,7 @@ class UpdateScoreTest { Tournament tournament = tournaments.getDummyTournament("dummyName", 8); when(tournamentRepository.findById(tournament.getTournamentId())).thenReturn(Optional.of(tournament)); try { - tournamentService.initializeTournament(tournament.getTournamentId()); + singleEliminationTournamentService.initializeTournament(tournament.getTournamentId()); } catch (InsufficientTeamsException | BracketAlreadyInitializedException e) { log.error("Failed to initialize tournament"); } @@ -61,7 +61,7 @@ class UpdateScoreTest { .getTeamScores() .get(teamId)); - tournamentService.updateScore(tournament.getTournamentId(), bracketRound, match.getMatchId(), teamId, 2); + singleEliminationTournamentService.updateScore(tournament.getTournamentId(), bracketRound, match.getMatchId(), teamId, 2); Assertions.assertEquals(2, tournament.getBracket() .get(bracketRound) @@ -78,13 +78,13 @@ class UpdateScoreTest { when(tournamentRepository.findById(tournament.getTournamentId())).thenReturn(Optional.of(tournament)); try { - tournamentService.initializeTournament(tournament.getTournamentId()); + singleEliminationTournamentService.initializeTournament(tournament.getTournamentId()); } catch (InsufficientTeamsException | BracketAlreadyInitializedException | TournamentIdNotFoundException e) { log.error("Failed to initialize tournament"); } BracketRoundNotFoundException thrown = Assertions.assertThrows(BracketRoundNotFoundException.class, () -> { - tournamentService.updateScore(tournament.getTournamentId(), bracketRound, UUID.randomUUID(), UUID.randomUUID(), 3); + singleEliminationTournamentService.updateScore(tournament.getTournamentId(), bracketRound, UUID.randomUUID(), UUID.randomUUID(), 3); }); Assertions.assertEquals("Bracket round " + bracketRound + " not found", thrown.getMessage()); } @@ -96,14 +96,14 @@ class UpdateScoreTest { when(tournamentRepository.findById(tournament.getTournamentId())).thenReturn(Optional.of(tournament)); try { - tournamentService.initializeTournament(tournament.getTournamentId()); + singleEliminationTournamentService.initializeTournament(tournament.getTournamentId()); } catch (InsufficientTeamsException | BracketAlreadyInitializedException | TournamentIdNotFoundException e) { log.error("Failed to initialize tournament"); } UUID wrongMatchId = UUID.randomUUID(); MatchIdNotFoundException thrown = Assertions.assertThrows(MatchIdNotFoundException.class, () -> { - tournamentService.updateScore(tournament.getTournamentId(), bracketRound, wrongMatchId, UUID.randomUUID(), 3); + singleEliminationTournamentService.updateScore(tournament.getTournamentId(), bracketRound, wrongMatchId, UUID.randomUUID(), 3); }); Assertions.assertEquals(String.format("MatchID %s not found", wrongMatchId), thrown.getMessage()); } @@ -115,7 +115,7 @@ class UpdateScoreTest { Tournament tournament = tournaments.getDummyTournament("dummyName", 8); when(tournamentRepository.findById(tournament.getTournamentId())).thenReturn(Optional.of(tournament)); try { - tournamentService.initializeTournament(tournament.getTournamentId()); + singleEliminationTournamentService.initializeTournament(tournament.getTournamentId()); } catch (InsufficientTeamsException | BracketAlreadyInitializedException e) { log.error("Failed to initialize tournament"); } @@ -127,7 +127,7 @@ class UpdateScoreTest { UUID wrongTeamId = UUID.randomUUID(); TeamIdNotFoundException thrown = Assertions.assertThrows(TeamIdNotFoundException.class, () -> { - tournamentService.updateScore(tournament.getTournamentId(), bracketRound, match.getMatchId(), wrongTeamId, 2); + singleEliminationTournamentService.updateScore(tournament.getTournamentId(), bracketRound, match.getMatchId(), wrongTeamId, 2); }); Assertions.assertEquals(String.format("TeamId %s not found", wrongTeamId), thrown.getMessage()); } -- GitLab