Skip to content
Snippets Groups Projects
Commit 078fbba0 authored by Jozef Bugos's avatar Jozef Bugos
Browse files

fixing integration testing

parent 4ba48f60
No related branches found
No related tags found
No related merge requests found
Pipeline #31377 passed
......@@ -12,7 +12,7 @@ variables:
stages:
- build
- test
- docker
# - docker
maven-build:
image: maven:3.6.3-jdk-11
......@@ -30,9 +30,9 @@ maven-test:
paths:
- target/*.jar
docker-build:
stage: docker
script:
- sudo docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- sudo docker build -t registry.gitlab.com/bugosjoz/lol-statistics .
- sudo docker push registry.gitlab.com/bugosjoz/lol-statistics
#docker-build:
# stage: docker
# script:
# - sudo docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
# - sudo docker build -t registry.gitlab.com/bugosjoz/lol-statistics .
# - sudo docker push registry.gitlab.com/bugosjoz/lol-statistics
......@@ -31,11 +31,12 @@ public class RiotController {
@GetMapping("/exists")
public ResponseEntity exists(@RequestParam String server, @RequestParam String username) {
try {
log.info("Checking whether account with username " + username + " exist on " + server + " server");
log.info("Checking whether account with username '" + username + "' exist on '" + server + "' server");
riotService.getAcccountId(server, username);
log.info("Account with username '" + username + "' exists on '" + server + "' server");
return new ResponseEntity(HttpStatus.OK);
} catch (HttpClientErrorException ex) {
log.warn("Account with username " + username + "does not exist on " + server + " server");
log.warn("Account with username '" + username + "' does not exist on '" + server + "' server");
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
......@@ -43,9 +44,9 @@ public class RiotController {
@GetMapping("/stats")
public MatchStats[] getStatsForMatches(@RequestParam String server, @RequestParam String username) {
log.info("Requesting statistics for account with username " + username + " on " + server + " server");
log.info("Requesting statistics for account with username '" + username + "' on '" + server + "' server");
String userId = riotService.getAcccountId(server, username);
MatchesBean matches = riotService.getMatchHistory(server, userId, 1);
MatchesBean matches = riotService.getMatchHistory(server, userId, 5);
MatchStats[] matchStats = new MatchStats[matches.getMatches().length];
int i = 0;
for (MatchBean match : matches.getMatches()) {
......
......@@ -30,7 +30,7 @@ public class RiotService implements IRiotService {
URI uriAccount = UriComponentsBuilder.fromUriString("https://" + server + ".api.riotgames.com/lol/summoner/v4/summoners/by-name/" + username)
.queryParam("api_key", key)
.build().toUri();
log.info("Getting account id for username " + username + " on server " + server);
log.info("Getting account id for username '" + username + "' on server " + server);
UserBean result = restTemplate.getForObject(uriAccount, UserBean.class);
return result.getAccountId();
}
......@@ -59,10 +59,9 @@ public class RiotService implements IRiotService {
}
URI uriHistory = uriComponentsBuilder.build().toUri();
log.info(
"Getting match history for user with id " + id + " on server " + server + " for " + matches + " matches"
"Getting match history for user with id '" + id + "' on server '" + server + "' for " + matches + " matches"
+ (beginTime >= 0 ? " from week before " + timestamp : "")
);
RestTemplate restTemplate = new RestTemplate();
try {
return restTemplate.getForObject(uriHistory, MatchesBean.class);
} catch (HttpClientErrorException ex) {
......@@ -76,8 +75,7 @@ public class RiotService implements IRiotService {
.queryParam("api_key", key)
.build().toUri();
RestTemplate restTemplate = new RestTemplate();
log.info("Getting match detail for match with id " + id + " on server " + server);
log.info("Getting match detail for match with id '" + id + "' on server " + server);
return restTemplate.getForObject(uriHistory, MatchDetailBean.class);
}
......
......@@ -18,11 +18,11 @@ public class StatsService implements IStatsService {
public StatsBean getStatsForPlayer(String server, String userId, long timestamp, String summonerName, int team) {
log.info(
"Getting statistics for player with username " + summonerName + " on server " + server + " before game that"
"Getting statistics for player with username '" + summonerName + "' on server '" + server + "' before game that"
+ " was played on time " + timestamp
);
MatchesBean matches = riotService.getMatchHistory(server, userId, 1, timestamp);
MatchesBean matches = riotService.getMatchHistory(server, userId, 5, timestamp);
int games = 0, wins = 0, streak = 0;
if (matches.getMatches() == null) {
log.warn("No matches found, returning empty statistics");
......@@ -60,7 +60,8 @@ public class StatsService implements IStatsService {
}
}
log.info(
"From last " + games + " games, player " + summonerName + " has " + wins + " wins and " + streak
"From last " + games + " game" + (games != 1 ? "s," : ",") + "player '" + summonerName
+ "' has " + wins + " win" + (wins != 1 ? "s" : "") + "and " + streak
+ (isWinStreak ? " win" : " loose") + " streak"
);
return new StatsBean(summonerName, team, games, streak, isWinStreak, games > 0 ? wins / (double) games : 0);
......
......@@ -137,7 +137,7 @@ class RiotControllerIntegrationTest {
endTime -= 180000;
String gameId = "2791181323";
String matchHistory = getResourceFileContent("getMatchHistoryResponse.json");
String gameDetail = getResourceFileContent("getGameDetail0Response.json");
String gameDetail = getResourceFileContent("getGameDetailResponse.json");
List<String> participantsIds = List.of(
"A7mZHh22sAOAvHzRi74iWV-r7Kou9TSX-6r2Ryj03zaS9ZU", "AYAppVilWC2-TtjcE-rQft8pz8TXGpB7yfappFw1-ADVnBg",
"l51Pg0EyiHhKHMYvaQC8MhlGZgak0Bhg7Xj5QnhlP5pq2edvzhsoL2Bm", "fuhJ5M-2M9LFpcpsA_oSkgwiCFtWOESYhm2szrojOHTJuA",
......@@ -160,7 +160,6 @@ class RiotControllerIntegrationTest {
gameDetails.add(getResourceFileContent("getGameDetail" + i + "Response.json"));
gameHistories.add(getResourceFileContent("getStatsMatchHistory" + i + "Response.json"));
}
riotWiremockServer.expect(
once(), requestTo("https://" + server + ".api.riotgames.com/lol/summoner/v4/summoners/by-name/" + username + "?api_key=" + key))
.andRespond(withSuccess(responseId, MediaType.APPLICATION_JSON));
......@@ -172,13 +171,12 @@ class RiotControllerIntegrationTest {
riotWiremockServer.expect(
once(), requestTo("https://" + server + ".api.riotgames.com/lol/match/v4/matches/" + gameId + "?api_key=" + key))
.andRespond(withSuccess(gameDetail, MediaType.APPLICATION_JSON));
int i = 0;
for (String participantId : participantsIds) {
riotWiremockServer.expect(
once(), requestTo("https://" + server + ".api.riotgames.com/lol/match/v4/matchlists/by-account/"
+ participantId + "?endIndex=" + endIndex + "&beginIndex=" + beginIndex + "&queue=" + queue + "?api_key="
+ key + "beginTime=" + beginTime + "&endTime=" + endTime))
+ participantId + "?endIndex=" + endIndex + "&beginIndex=" + beginIndex + "&queue=" + queue + "&api_key="
+ key + "&beginTime=" + beginTime + "&endTime=" + endTime))
.andRespond(withSuccess(gameHistories.get(i), MediaType.APPLICATION_JSON));
riotWiremockServer.expect(
once(), requestTo("https://" + server + ".api.riotgames.com/lol/match/v4/matches/" + gameIds.get(i) + "?api_key=" + key))
......@@ -202,7 +200,7 @@ class RiotControllerIntegrationTest {
JSONParser parser = new JSONParser();
JSONArray correctResponse = (JSONArray)parser.parse(getResourceFileContent("getCorrectResponse.json"));
riotWiremockServer.verify();
assertEquals(correctResponse.hashCode(), response.hashCode());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment