diff --git a/README.md b/README.md index a9f0a70..fa236f1 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ To fully automate update your weekly actions on your *MPG* leagues, you can use The main output is displaying: * Injured players, to remove of your team +* Your team composition as remind * Your team line by line, ordered by efficiency score (*Eff.*), with the players quotation/prices (*Q.*): ``` @@ -90,7 +91,7 @@ The main output is displaying: Out: Aouar Houssem (M - 34.88) - INJURY_ORANGE - Inconnu (depuis 12/11) - Inconnu Out: Ambroise Oyongo (D - 11.85) - INJURY_ORANGE - Blessure au genou (depuis 04/11) - Inconnu -Optimized team: +Optimized team (Compo: 343): +---+--------------------+-------+----+ | P | Player name | Eff. | Q. | +---+--------------------+-------+----+ diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index c9279e5..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.exclusions=src/test/resources/__files/**/* \ No newline at end of file diff --git a/src/main/java/org/blondin/mpg/Games.java b/src/main/java/org/blondin/mpg/Games.java index 30caf4b..6193436 100644 --- a/src/main/java/org/blondin/mpg/Games.java +++ b/src/main/java/org/blondin/mpg/Games.java @@ -65,7 +65,7 @@ public void process(League league, ApiClients apiClients, Config config) { Comparator.comparing(Player::getPosition).thenComparing(Player::getEfficiency).thenComparing(Player::getQuotation).reversed()); // Write optimized team - writeTeamOptimized(players, config.isDebug()); + writeTeamOptimized(players, coach.getComposition(), config.isDebug()); // Auto-update team if (config.isTeampUpdate()) { @@ -104,7 +104,7 @@ public void process(League league, ApiClients apiClients, Config config) { * Teams players is only id and price paid => replace by real player * * @param teamPlayers teams - * @param pool players + * @param pool players */ static void completePlayersTeam(Map teamPlayers, PoolPlayers pool) { List players2Remove = new ArrayList<>(); @@ -266,8 +266,8 @@ static List removeOutPlayers(List players, InjuredSuspendedWrapp return players; } - private static void writeTeamOptimized(List players, boolean isDebug) { - LOG.info("\nOptimized team:"); + private static void writeTeamOptimized(List players, int composition, boolean isDebug) { + LOG.info("\nOptimized team (Compo: {}):", composition); AsciiTable at = getTable(TABLE_POSITION, TABLE_PLAYER_NAME, TABLE_EFFICIENCY, TABLE_QUOTE); Position lp = Position.G; for (Player player : players) { diff --git a/src/test/java/org/blondin/mpg/MainTest.java b/src/test/java/org/blondin/mpg/MainTest.java index 3c1086f..1940f6f 100644 --- a/src/test/java/org/blondin/mpg/MainTest.java +++ b/src/test/java/org/blondin/mpg/MainTest.java @@ -39,7 +39,8 @@ public class MainTest extends AbstractMockTestClient { public void testRealIfCredentials() { try { final String config = "src/test/resources/mpg.properties"; - if (new File(config).exists() || (StringUtils.isNoneBlank(System.getenv("MPG_EMAIL")) && StringUtils.isNoneBlank(System.getenv("MPG_PASSWORD")))) { + if (new File(config).exists() + || (StringUtils.isNoneBlank(System.getenv("MPG_EMAIL")) && StringUtils.isNoneBlank(System.getenv("MPG_PASSWORD")))) { Main.main(new String[] { config }); } } catch (ProcessingException e) { @@ -57,14 +58,18 @@ public void testRealWithBadCredentials() { Assert.assertTrue("Bad credentials", e.getMessage().contains("Forbidden URL")); } catch (ProcessingException e) { // Proxy not configured or real URL not accessible - Assert.assertTrue("No network: " + e.getMessage(), Arrays.asList("java.net.UnknownHostException: api.mpg.football", "javax.net.ssl.SSLException: Read timed out").contains(e.getMessage())); + Assert.assertTrue("No network: " + e.getMessage(), + Arrays.asList("java.net.UnknownHostException: api.mpg.football", "javax.net.ssl.SSLException: Read timed out") + .contains(e.getMessage())); } } @Test public void testFollowed() { - stubFor(post("/user/sign-in").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); - stubFor(get("/dashboard/leagues").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.only-followed.json"))); + stubFor(post("/user/sign-in") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); + stubFor(get("/dashboard/leagues") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.only-followed.json"))); Config config = spy(getConfig()); executeMainProcess(config); @@ -77,11 +82,15 @@ public void testFollowed() { public void testBonusSelectionFailWhenLastMatchAndDecatBonus() { // Old and not linked injured, not important on this use case prepareMainFrenchLigue1Mocks("20230104", "2023", "20230104", "20220327"); - stubFor(get("/division/mpg_division_PJHY1S98_1_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.PJHY1S98.20230104.json"))); - stubFor(get("/division/mpg_division_PJHY1S98_1_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.PJHY1S98.20230104.json"))); - stubFor(get("/team/mpg_team_PJHY1S98_1_1_2").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.PJHY1S98.20230104.json"))); + stubFor(get("/division/mpg_division_PJHY1S98_1_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.PJHY1S98.20230104.json"))); + stubFor(get("/division/mpg_division_PJHY1S98_1_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.PJHY1S98.20230104.json"))); + stubFor(get("/team/mpg_team_PJHY1S98_1_1_2") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.PJHY1S98.20230104.json"))); stubFor(put("/match-team-formation/mpg_match_team_formation_PJHY1S98_1_1_18_3_2") - .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json").withBody("Fake: mpg_match_team_formation_PJHY1S98_1_1_18_3_2"))); + .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json") + .withBody("Fake: mpg_match_team_formation_PJHY1S98_1_1_18_3_2"))); Config config = spy(getConfig()); doReturn(Arrays.asList("PJHY1S98")).when(config).getLeaguesInclude(); @@ -105,38 +114,62 @@ public void testMpgStatsLongAuctions() { @Test public void testMpgStatsApiV2() { prepareMainFrenchLigue1Mocks("20220327", "2022", "20220327", "20220327"); - stubFor(get("/division/mpg_division_MLAX7HMK_4_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20220327.json"))); - stubFor(get("/division/mpg_division_MLAX7HMK_4_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20220327.json"))); - stubFor(get("/team/mpg_team_MLAX7HMK_4_1_6").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20220327.json"))); + stubFor(get("/division/mpg_division_MLAX7HMK_4_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20220327.json"))); + stubFor(get("/division/mpg_division_MLAX7HMK_4_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20220327.json"))); + stubFor(get("/team/mpg_team_MLAX7HMK_4_1_6") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20220327.json"))); prepareMainFrenchLigue2Mocks("20220327", "2022", "20220327", "20220327"); - stubFor(get("/division/mpg_division_MLEFEX6G_4_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20220327.json"))); - stubFor(get("/division/mpg_division_MLEFEX6G_4_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20220327.json"))); - stubFor(get("/team/mpg_team_MLEFEX6G_4_1_2").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20220327.json"))); + stubFor(get("/division/mpg_division_MLEFEX6G_4_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20220327.json"))); + stubFor(get("/division/mpg_division_MLEFEX6G_4_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20220327.json"))); + stubFor(get("/team/mpg_team_MLEFEX6G_4_1_2") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20220327.json"))); // Liga - stubFor(get("/division/mpg_division_PYUJXJM_1_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.PYUJXJM.20220327.json"))); - stubFor(get("/team/mpg_team_PYUJXJM_1_1_3").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.PYUJXJM.20220327.json"))); - stubFor(get("/championship-players-pool/3").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.3.2022.json"))); - stubFor(get("/division/mpg_division_PYUJXJM_1_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.PYUJXJM.20220327.json"))); - stubFor(get("/leagues/Liga_v2.json").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.liga.20220327.json"))); - stubFor(get("/injuries/football/spain-la-liga/").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.liga.20220327.html"))); + stubFor(get("/division/mpg_division_PYUJXJM_1_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.PYUJXJM.20220327.json"))); + stubFor(get("/team/mpg_team_PYUJXJM_1_1_3") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.PYUJXJM.20220327.json"))); + stubFor(get("/championship-players-pool/3") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.3.2022.json"))); + stubFor(get("/division/mpg_division_PYUJXJM_1_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.PYUJXJM.20220327.json"))); + stubFor(get("/leagues/Liga_v2.json") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.liga.20220327.json"))); + stubFor(get("/injuries/football/spain-la-liga/") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.liga.20220327.html"))); // SerieA - stubFor(get("/division/mpg_division_NKCDJTKS_2_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.NKCDJTKS.20220327.json"))); - stubFor(get("/team/mpg_team_NKCDJTKS_2_1_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.NKCDJTKS.20220327.json"))); - stubFor(get("/championship-players-pool/5").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.5.2022.json"))); - stubFor(get("/division/mpg_division_NKCDJTKS_2_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.NKCDJTKS.20220327.json"))); - stubFor(get("/leagues/Serie-A_v2.json").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.serie-a.20220327.json"))); - stubFor(get("/injuries/football/italy-serie-a/").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.serie-a.20220327.html"))); + stubFor(get("/division/mpg_division_NKCDJTKS_2_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.NKCDJTKS.20220327.json"))); + stubFor(get("/team/mpg_team_NKCDJTKS_2_1_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.NKCDJTKS.20220327.json"))); + stubFor(get("/championship-players-pool/5") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.5.2022.json"))); + stubFor(get("/division/mpg_division_NKCDJTKS_2_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.NKCDJTKS.20220327.json"))); + stubFor(get("/leagues/Serie-A_v2.json") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.serie-a.20220327.json"))); + stubFor(get("/injuries/football/italy-serie-a/") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.serie-a.20220327.html"))); // PL - stubFor(get("/division/mpg_division_MLMHBPCB_4_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLMHBPCB.20220327.json"))); - stubFor(get("/team/mpg_team_MLMHBPCB_4_1_4").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLMHBPCB.20220327.json"))); - stubFor(get("/division/mpg_division_MLMHBPCB_4_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLMHBPCB.20220327.json"))); - stubFor(get("/championship-players-pool/2").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.2.2022.json"))); - stubFor(get("/leagues/Premier-League_v2.json").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.premier-league.20220327.json"))); - stubFor(get("/injuries/football/england-premier-league/").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.premier-league.20211122.html"))); + stubFor(get("/division/mpg_division_MLMHBPCB_4_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLMHBPCB.20220327.json"))); + stubFor(get("/team/mpg_team_MLMHBPCB_4_1_4") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLMHBPCB.20220327.json"))); + stubFor(get("/division/mpg_division_MLMHBPCB_4_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLMHBPCB.20220327.json"))); + stubFor(get("/championship-players-pool/2") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.2.2022.json"))); + stubFor(get("/leagues/Premier-League_v2.json") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.premier-league.20220327.json"))); + stubFor(get("/injuries/football/england-premier-league/") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.premier-league.20211122.html"))); Config config = spy(getConfig()); doReturn(false).when(config).isTeampUpdate(); @@ -149,11 +182,14 @@ public void testMpgStatsApiV2() { public void testKeepAtLeastOneGoalkeeperEvenIfAbsent() { prepareMainFrenchLigue2Mocks("MLEFEX6G-20220227", "2022", "20220227", "20220227"); // Override Mansuy user - stubFor(post("/user/sign-in") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"token\": \"token.fake\", \"userId\": \"user_953561\", \"language\": \"fr-FR\" }"))); - stubFor(get("/division/mpg_division_MLEFEX6G_4_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20220227.json"))); - stubFor(get("/team/mpg_team_MLEFEX6G_4_1_0").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20220227.json"))); - stubFor(get("/division/mpg_division_MLEFEX6G_4_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20220227.json"))); + stubFor(post("/user/sign-in").willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody("{ \"token\": \"token.fake\", \"userId\": \"user_953561\", \"language\": \"fr-FR\" }"))); + stubFor(get("/division/mpg_division_MLEFEX6G_4_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20220227.json"))); + stubFor(get("/team/mpg_team_MLEFEX6G_4_1_0") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20220227.json"))); + stubFor(get("/division/mpg_division_MLEFEX6G_4_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20220227.json"))); Config config = spy(getConfig()); doReturn(false).when(config).isTeampUpdate(); @@ -166,8 +202,10 @@ public void testKeepAtLeastOneGoalkeeperEvenIfAbsent() { @Test public void testLastLiveDay() { - stubFor(post("/user/sign-in").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); - stubFor(get("/dashboard/leagues").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.NL931FU9-noNextweek.json"))); + stubFor(post("/user/sign-in") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); + stubFor(get("/dashboard/leagues") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.NL931FU9-noNextweek.json"))); Config config = spy(getConfig()); executeMainProcess(config); @@ -177,11 +215,15 @@ public void testLastLiveDay() { @Test public void testCaptainAndBoostPlayerBonus3() { prepareMainFrenchLigue1Mocks("MLAX7HMK-20211122", "2021", "20211122", "20211122"); - stubFor(get("/division/mpg_division_MLAX7HMK_3_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20211122.json"))); - stubFor(get("/team/mpg_team_MLAX7HMK_3_1_6").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20211122.json"))); - stubFor(get("/division/mpg_division_MLAX7HMK_3_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20211122.json"))); + stubFor(get("/division/mpg_division_MLAX7HMK_3_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20211122.json"))); + stubFor(get("/team/mpg_team_MLAX7HMK_3_1_6") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20211122.json"))); + stubFor(get("/division/mpg_division_MLAX7HMK_3_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20211122.json"))); stubFor(put("/match-team-formation/mpg_match_team_formation_MLAX7HMK_3_1_14_5_6") - .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json").withBody("Fake: mpg_match_team_formation_MLAX7HMK_3_1_14_5_6"))); + .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json") + .withBody("Fake: mpg_match_team_formation_MLAX7HMK_3_1_14_5_6"))); Config config = spy(getConfig()); doReturn(true).when(config).isTeampUpdate(); @@ -195,21 +237,32 @@ public void testCaptainAndBoostPlayerBonus3() { @Test public void testCaptainAndBoostPlayerBonus2() { - stubFor(post("/user/sign-in").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); - stubFor(get("/dashboard/leagues").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.MLMHBPCB-20211122.json"))); - stubFor(get("/division/mpg_division_MLMHBPCB_3_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLMHBPCB.20211122.json"))); - stubFor(get("/team/mpg_team_MLMHBPCB_3_1_4").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLMHBPCB.20211122.json"))); - stubFor(get("/division/mpg_division_MLMHBPCB_3_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLMHBPCB.20211122.json"))); - stubFor(get("/championship-players-pool/2").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.2.2021.json"))); - stubFor(get("/championship-clubs").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.clubs.2021.json"))); - stubFor(get("/division/mpg_division_MLEFEX6G_3_1/available-players") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLMHBPCB.20211122.json"))); + stubFor(post("/user/sign-in") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); + stubFor(get("/dashboard/leagues") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.MLMHBPCB-20211122.json"))); + stubFor(get("/division/mpg_division_MLMHBPCB_3_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLMHBPCB.20211122.json"))); + stubFor(get("/team/mpg_team_MLMHBPCB_3_1_4") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLMHBPCB.20211122.json"))); + stubFor(get("/division/mpg_division_MLMHBPCB_3_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLMHBPCB.20211122.json"))); + stubFor(get("/championship-players-pool/2") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.2.2021.json"))); + stubFor(get("/championship-clubs") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.clubs.2021.json"))); + stubFor(get("/division/mpg_division_MLEFEX6G_3_1/available-players").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLMHBPCB.20211122.json"))); stubFor(put("/match-team-formation/mpg_match_team_formation_MLMHBPCB_3_1_12_5_4") - .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json").withBody("Fake: mpg_match_team_formation_MLMHBPCB_3_1_12_5_4"))); + .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json") + .withBody("Fake: mpg_match_team_formation_MLMHBPCB_3_1_12_5_4"))); - stubFor(get("/builds.json").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20211122.json"))); - stubFor(get("/leagues/Premier-League_v2.json").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.premier-league.20211122.json"))); - stubFor(get("/injuries/football/england-premier-league/").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.premier-league.20211122.html"))); + stubFor(get("/builds.json") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20211122.json"))); + stubFor(get("/leagues/Premier-League_v2.json") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.premier-league.20211122.json"))); + stubFor(get("/injuries/football/england-premier-league/") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.premier-league.20211122.html"))); Config config = spy(getConfig()); doReturn(true).when(config).isTeampUpdate(); @@ -224,11 +277,16 @@ public void testCaptainAndBoostPlayerBonus2() { @Test public void testCaptainAndBoostPlayerBonus() throws IOException { prepareMainFrenchLigue2Mocks("MLEFEX6G-20211019", "2021", "20211019", "20211019"); - stubFor(get("/division/mpg_division_MLEFEX6G_3_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20211019.json"))); - stubFor(get("/team/mpg_team_MLEFEX6G_3_1_2").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20211019.json"))); - stubFor(get("/division/mpg_division_MLEFEX6G_3_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20211019.json"))); - stubFor(put("/match-team-formation/mpg_match_team_formation_MLEFEX6G_3_1_12_5_2").withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLEFEX6G.20211019-Request.json"))) - .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json").withBody("Fake: mpg_match_team_formation_MLEFEX6G_3_1_12_5_2"))); + stubFor(get("/division/mpg_division_MLEFEX6G_3_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20211019.json"))); + stubFor(get("/team/mpg_team_MLEFEX6G_3_1_2") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20211019.json"))); + stubFor(get("/division/mpg_division_MLEFEX6G_3_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20211019.json"))); + stubFor(put("/match-team-formation/mpg_match_team_formation_MLEFEX6G_3_1_12_5_2") + .withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLEFEX6G.20211019-Request.json"))) + .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json") + .withBody("Fake: mpg_match_team_formation_MLEFEX6G_3_1_12_5_2"))); Config config = spy(getConfig()); doReturn(true).when(config).isTeampUpdate(); @@ -242,14 +300,19 @@ public void testCaptainAndBoostPlayerBonus() throws IOException { @Test public void testTransactionProposalSelling() throws IOException { prepareMainFrenchLigue2Mocks("MLEFEX6G-20211019", "2021", "20211019", "20211019"); - stubFor(get("/division/mpg_division_MLEFEX6G_3_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20211019.json"))); - stubFor(get("/team/mpg_team_MLEFEX6G_3_1_2").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20211019.json"))); - stubFor(get("/division/mpg_division_MLEFEX6G_3_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20211019.json"))); + stubFor(get("/division/mpg_division_MLEFEX6G_3_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20211019.json"))); + stubFor(get("/team/mpg_team_MLEFEX6G_3_1_2") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20211019.json"))); + stubFor(get("/division/mpg_division_MLEFEX6G_3_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20211019.json"))); // Not the same date, UT added after - stubFor(get("/division/mpg_division_MLEFEX6G_3_1/available-players") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLMHBPCB.20211122.json"))); - stubFor(put("/match-team-formation/mpg_match_team_formation_MLEFEX6G_3_1_12_5_2").withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLEFEX6G.20211019-Request.json"))) - .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json").withBody("Fake: mpg_match_team_formation_MLEFEX6G_3_1_12_5_2"))); + stubFor(get("/division/mpg_division_MLEFEX6G_3_1/available-players").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLMHBPCB.20211122.json"))); + stubFor(put("/match-team-formation/mpg_match_team_formation_MLEFEX6G_3_1_12_5_2") + .withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLEFEX6G.20211019-Request.json"))) + .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json") + .withBody("Fake: mpg_match_team_formation_MLEFEX6G_3_1_12_5_2"))); Config config = spy(getConfig()); doReturn(true).when(config).isTeampUpdate(); @@ -270,13 +333,16 @@ public void testTransactionProposalSelling() throws IOException { @Test public void testCaptainNotOnMainPitch() throws IOException { prepareMainFrenchLigue1Mocks("MLAX7HMK-status-4", "2021", "20210812", "20210812"); - stubFor(get("/division/mpg_division_MLAX7HMK_3_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20210812.json"))); - stubFor(get("/team/mpg_team_MLAX7HMK_3_1_6").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20210812.manyBonus.json"))); - stubFor(get("/division/mpg_division_MLAX7HMK_3_1/coach") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20210812.withNotOnMainPitchCaptain.json"))); + stubFor(get("/division/mpg_division_MLAX7HMK_3_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20210812.json"))); + stubFor(get("/team/mpg_team_MLAX7HMK_3_1_6") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20210812.manyBonus.json"))); + stubFor(get("/division/mpg_division_MLAX7HMK_3_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("mpg.coach.MLAX7HMK.20210812.withNotOnMainPitchCaptain.json"))); stubFor(put("/match-team-formation/mpg_match_team_formation_MLAX7HMK_3_1_1_5_6") .withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLAX7HMK.20210812.withNotOnMainPitchCaptain-Request.json"))) - .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json").withBody("Fake: mpg_match_team_formation_MLAX7HMK_3_1_1_5_6"))); + .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json") + .withBody("Fake: mpg_match_team_formation_MLAX7HMK_3_1_1_5_6"))); Config config = spy(getConfig()); doReturn(true).when(config).isTeampUpdate(); doReturn(false).when(config).isTacticalSubstitutes(); @@ -291,11 +357,16 @@ public void testCaptainNotOnMainPitch() throws IOException { @Test public void testCaptainAlreadySelected() throws IOException { prepareMainFrenchLigue1Mocks("MLAX7HMK-status-4", "2021", "20210812", "20210812"); - stubFor(get("/division/mpg_division_MLAX7HMK_3_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20210812.json"))); - stubFor(get("/team/mpg_team_MLAX7HMK_3_1_6").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20210812.json"))); - stubFor(get("/division/mpg_division_MLAX7HMK_3_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20210812.withCaptain.json"))); - stubFor(put("/match-team-formation/mpg_match_team_formation_MLAX7HMK_3_1_1_5_6").withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLAX7HMK.20210812.withCaptain-Request.json"))) - .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json").withBody("Fake: mpg_match_team_formation_MLAX7HMK_3_1_1_5_6"))); + stubFor(get("/division/mpg_division_MLAX7HMK_3_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20210812.json"))); + stubFor(get("/team/mpg_team_MLAX7HMK_3_1_6") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20210812.json"))); + stubFor(get("/division/mpg_division_MLAX7HMK_3_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20210812.withCaptain.json"))); + stubFor(put("/match-team-formation/mpg_match_team_formation_MLAX7HMK_3_1_1_5_6") + .withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLAX7HMK.20210812.withCaptain-Request.json"))) + .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json") + .withBody("Fake: mpg_match_team_formation_MLAX7HMK_3_1_1_5_6"))); Config config = spy(getConfig()); doReturn(true).when(config).isTeampUpdate(); doReturn(false).when(config).isTacticalSubstitutes(); @@ -310,11 +381,16 @@ public void testCaptainAlreadySelected() throws IOException { @Test public void testCaptainAdd() throws IOException { prepareMainFrenchLigue1Mocks("MLAX7HMK-status-4", "2021", "20210812", "20210812"); - stubFor(get("/division/mpg_division_MLAX7HMK_3_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20210812.json"))); - stubFor(get("/team/mpg_team_MLAX7HMK_3_1_6").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20210812.json"))); - stubFor(get("/division/mpg_division_MLAX7HMK_3_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20210812.withNoCaptain.json"))); - stubFor(put("/match-team-formation/mpg_match_team_formation_MLAX7HMK_3_1_1_5_6").withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLAX7HMK.20210812.withNoCaptain-Request.json"))) - .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json").withBody("Fake: mpg_match_team_formation_MLAX7HMK_3_1_1_5_6"))); + stubFor(get("/division/mpg_division_MLAX7HMK_3_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLAX7HMK.20210812.json"))); + stubFor(get("/team/mpg_team_MLAX7HMK_3_1_6") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLAX7HMK.20210812.json"))); + stubFor(get("/division/mpg_division_MLAX7HMK_3_1/coach").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLAX7HMK.20210812.withNoCaptain.json"))); + stubFor(put("/match-team-formation/mpg_match_team_formation_MLAX7HMK_3_1_1_5_6") + .withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLAX7HMK.20210812.withNoCaptain-Request.json"))) + .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json") + .withBody("Fake: mpg_match_team_formation_MLAX7HMK_3_1_1_5_6"))); Config config = spy(getConfig()); doReturn(true).when(config).isTeampUpdate(); doReturn(false).when(config).isTacticalSubstitutes(); @@ -325,14 +401,20 @@ public void testCaptainAdd() throws IOException { Assert.assertTrue(getLogOut(), getLogOut().contains("Updating team ...")); Assert.assertTrue(getLogOut(), getLogOut().contains(" Captain: Bamba Jonathan")); + // Test formation display + Assert.assertTrue(getLogOut(), getLogOut().contains("Optimized team (Compo: 343):")); + // UT player remove from pool - Assert.assertTrue(getLogOut(), getLogOut().contains("Some player in your team removed because doesn't exist in league pool players: mpg_championship_player_482549")); + Assert.assertTrue(getLogOut(), getLogOut() + .contains("Some player in your team removed because doesn't exist in league pool players: mpg_championship_player_482549")); } @Test public void testMercatoEnd() { - stubFor(post("/user/sign-in").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); - stubFor(get("/dashboard/leagues").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.MLAX7HMK-status-3-mercatoEnd.json"))); + stubFor(post("/user/sign-in") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); + stubFor(get("/dashboard/leagues").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.MLAX7HMK-status-3-mercatoEnd.json"))); Config config = spy(getConfig()); executeMainProcess(config); doReturn(false).when(config).isEfficiencyRecentFocus(); @@ -343,12 +425,15 @@ public void testMercatoEnd() { public void testWaitMercatoNextTurnWithConnectionReset() { // CONNECTION_RESET_BY_PEER doesn't work on Windows (block response), EMPTY_RESPONSE throws a SocketException too final String scenario = "Retry Scenario Connection Reset"; - stubFor(post("/user/sign-in").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); - stubFor(get("/dashboard/leagues").inScenario(scenario).whenScenarioStateIs(Scenario.STARTED).willSetStateTo("SocketException").willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); + stubFor(post("/user/sign-in") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); + stubFor(get("/dashboard/leagues").inScenario(scenario).whenScenarioStateIs(Scenario.STARTED).willSetStateTo("SocketException") + .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); // Don't understand why too fault request necessary to have only one :/ - stubFor(get("/dashboard/leagues").inScenario(scenario).whenScenarioStateIs("SocketException").willSetStateTo("ValidResponse").willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); - stubFor(get("/dashboard/leagues").inScenario(scenario).whenScenarioStateIs("ValidResponse") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.MLAX7HMK-status-3-waitMercatoNextTurn.json"))); + stubFor(get("/dashboard/leagues").inScenario(scenario).whenScenarioStateIs("SocketException").willSetStateTo("ValidResponse") + .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); + stubFor(get("/dashboard/leagues").inScenario(scenario).whenScenarioStateIs("ValidResponse").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.MLAX7HMK-status-3-waitMercatoNextTurn.json"))); Config config = spy(getConfig()); doReturn(Arrays.asList("MLAX7HMK")).when(config).getLeaguesInclude(); doReturn(false).when(config).isEfficiencyRecentFocus(); @@ -358,18 +443,28 @@ public void testWaitMercatoNextTurnWithConnectionReset() { @Test public void testPrepareMercatoTurn0Day0EnglishSerieARecentFocusEnabled() { - stubFor(post("/user/sign-in").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); - stubFor(get("/dashboard/leagues").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.NKCDJTKS.MLMHBPCB-status-3.json"))); - stubFor(get("/championship-players-pool/2").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.2.2021.json"))); - stubFor(get("/championship-players-pool/5").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.5.2021.json"))); - stubFor(get("/championship-clubs").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.clubs.2021.json"))); - stubFor(get("/division/mpg_division_MLMHBPCB_3_1/available-players") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLMHBPCB.20210813.json"))); - stubFor(get("/builds.json").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20210813.json"))); - stubFor(get("/leagues/Serie-A_v2.json").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.serie-a.20210813.json"))); - stubFor(get("/leagues/Premier-League_v2.json").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.premier-league.20210813.json"))); - stubFor(get("/injuries/football/italy-serie-a/").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.serie-a.20210224.html"))); - stubFor(get("/injuries/football/england-premier-league/").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.premier-league.20210224.html"))); + stubFor(post("/user/sign-in") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); + stubFor(get("/dashboard/leagues").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard.NKCDJTKS.MLMHBPCB-status-3.json"))); + stubFor(get("/championship-players-pool/2") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.2.2021.json"))); + stubFor(get("/championship-players-pool/5") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers.5.2021.json"))); + stubFor(get("/championship-clubs") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.clubs.2021.json"))); + stubFor(get("/division/mpg_division_MLMHBPCB_3_1/available-players").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLMHBPCB.20210813.json"))); + stubFor(get("/builds.json") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds.20210813.json"))); + stubFor(get("/leagues/Serie-A_v2.json") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.serie-a.20210813.json"))); + stubFor(get("/leagues/Premier-League_v2.json") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.premier-league.20210813.json"))); + stubFor(get("/injuries/football/italy-serie-a/") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.serie-a.20210224.html"))); + stubFor(get("/injuries/football/england-premier-league/") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.premier-league.20210224.html"))); Config config = spy(getConfig()); executeMainProcess(config); Assert.assertTrue(getLogOut(), getLogOut().contains("| A | Cristiano Ronaldo | 313.12 | 44 |")); @@ -398,13 +493,18 @@ public void testProcessFromEmptyCoach() throws IOException { doReturn(true).when(config).isTransactionsProposal(); doReturn(false).when(config).isEfficiencyRecentFocus(); doReturn(true).when(config).isDebug(); - stubFor(get("/division/mpg_division_MLEFEX6G_3_1").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20210804.json"))); - stubFor(get("/team/mpg_team_MLEFEX6G_3_1_2").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20210804.json"))); - stubFor(get("/division/mpg_division_MLEFEX6G_3_1/coach").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20210804.empty.json"))); - stubFor(get("/division/mpg_division_MLEFEX6G_3_1/available-players") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLEFEX6G.20210804.json"))); - stubFor(put("/match-team-formation/mpg_match_team_formation_MLEFEX6G_3_1_2_2_2").withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLEFEX6G.20210804-Request.json"))) - .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json").withBody("Fake: mpg_match_team_formation_MLEFEX6G_3_1_2_2_2"))); + stubFor(get("/division/mpg_division_MLEFEX6G_3_1") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.MLEFEX6G.20210804.json"))); + stubFor(get("/team/mpg_team_MLEFEX6G_3_1_2") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.team.MLEFEX6G.20210804.json"))); + stubFor(get("/division/mpg_division_MLEFEX6G_3_1/coach") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.coach.MLEFEX6G.20210804.empty.json"))); + stubFor(get("/division/mpg_division_MLEFEX6G_3_1/available-players").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.division.available.players.MLEFEX6G.20210804.json"))); + stubFor(put("/match-team-formation/mpg_match_team_formation_MLEFEX6G_3_1_2_2_2") + .withRequestBody(equalToJson(getTestFileToString("mpg.coach.MLEFEX6G.20210804-Request.json"))) + .willReturn(aResponse().withStatus(Response.Status.OK.getStatusCode()).withHeader("Content-Type", "application/json") + .withBody("Fake: mpg_match_team_formation_MLEFEX6G_3_1_2_2_2"))); executeMainProcess(config); Assert.assertTrue(getLogOut(), getLogOut().contains("Ligue 2 Fous")); Assert.assertTrue(getLogOut(), getLogOut().contains("Ba")); @@ -419,7 +519,8 @@ private void executeMainProcess(Config config) { executeMainProcess(null, null, null, config); } - private void executeMainProcess(MpgClient mpgClient, MpgStatsClient mpgStatsClient, InjuredSuspendedWrapperClient injuredSuspendedClient, Config config) { + private void executeMainProcess(MpgClient mpgClient, MpgStatsClient mpgStatsClient, InjuredSuspendedWrapperClient injuredSuspendedClient, + Config config) { Config c = ObjectUtils.defaultIfNull(config, getConfig()); // ObjectUtils.defaultIfNull could not be used for other, the builders of client should not be called MpgClient mpgClientLocal = mpgClient; @@ -450,34 +551,41 @@ private static void prepareMainFrenchLigue2Mocks(String dashboard, String poolPl prepareMainFrenchLigueMocks(dashboard, 2, poolPlayerYear, statsLeaguesDate, null, maLigue2Date); } - private static void prepareMainFrenchLigueMocks(String dashboard, int frenchLigue, String poolPlayerYear, String statsLeaguesDate, String sportsGamblerDate, String maLigue2Date) { + private static void prepareMainFrenchLigueMocks(String dashboard, int frenchLigue, String poolPlayerYear, String statsLeaguesDate, + String sportsGamblerDate, String maLigue2Date) { try { SimpleDateFormat dateDayFormat = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat dateYearFormat = new SimpleDateFormat("yyyy"); - stubFor(post("/user/sign-in").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); + stubFor(post("/user/sign-in") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.user-signIn.fake.json"))); if (StringUtils.isNotBlank(dashboard)) { - stubFor(get("/dashboard/leagues").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard." + dashboard + ".json"))); + stubFor(get("/dashboard/leagues") + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.dashboard." + dashboard + ".json"))); } if (StringUtils.isNotBlank(poolPlayerYear)) { dateYearFormat.parse(poolPlayerYear); stubFor(get("/championship-players-pool/" + (frenchLigue == 1 ? 1 : 4)) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.poolPlayers." + (frenchLigue == 1 ? 1 : 4) + "." + poolPlayerYear + ".json"))); - stubFor(get("/championship-clubs").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.clubs." + poolPlayerYear + ".json"))); + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("mpg.poolPlayers." + (frenchLigue == 1 ? 1 : 4) + "." + poolPlayerYear + ".json"))); + stubFor(get("/championship-clubs").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mpg.clubs." + poolPlayerYear + ".json"))); } if (StringUtils.isNotBlank(statsLeaguesDate)) { dateDayFormat.parse(statsLeaguesDate); - stubFor(get("/builds.json").willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds." + statsLeaguesDate + ".json"))); - stubFor(get("/leagues/Ligue-" + frenchLigue + "_v2.json") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.ligue-" + frenchLigue + "." + statsLeaguesDate + ".json"))); + stubFor(get("/builds.json").willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("mlnstats.builds." + statsLeaguesDate + ".json"))); + stubFor(get("/leagues/Ligue-" + frenchLigue + "_v2.json").willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("mlnstats.ligue-" + frenchLigue + "." + statsLeaguesDate + ".json"))); } if (StringUtils.isNotBlank(sportsGamblerDate)) { dateDayFormat.parse(sportsGamblerDate); stubFor(get("/injuries/football/france-ligue-" + frenchLigue + "/") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("sportsgambler.ligue-" + frenchLigue + "." + sportsGamblerDate + ".html"))); + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("sportsgambler.ligue-" + frenchLigue + "." + sportsGamblerDate + ".html"))); } if (StringUtils.isNotBlank(maLigue2Date)) { - stubFor(get("/2020/08/20/joueurs-blesses-et-suspendus/") - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("maligue2.joueurs-blesses-et-suspendus." + maLigue2Date + ".html"))); + stubFor(get("/2020/08/20/joueurs-blesses-et-suspendus/").willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("maligue2.joueurs-blesses-et-suspendus." + maLigue2Date + ".html"))); } } catch (ParseException e) { throw new UnsupportedOperationException("Input is not in correct date format: " + e.getMessage(), e);