From dafb9cb2d7a637a0b427be70b81932dbeed2742c Mon Sep 17 00:00:00 2001 From: Aaron Corley Date: Sat, 17 May 2014 14:05:39 -0400 Subject: [PATCH] Updated to support the latest team and league resources. Also cleaned up some code and removed a lot of tests that are now redundant. --- build.gradle | 2 +- .../lol4j/client/impl/Lol4JClientImpl.java | 54 +++++- .../lol4j/protocol/dto/league/LeagueDto.java | 14 +- .../protocol/dto/league/LeagueEntryDto.java | 101 +++++++++++ .../protocol/dto/league/LeagueItemDto.java | 141 --------------- .../protocol/dto/league/MiniSeriesDto.java | 15 +- .../dto/lolstaticdata/SummonerSpellDto.java | 4 +- .../java/lol4j/protocol/dto/team/TeamDto.java | 19 +- .../protocol/resource/LeagueResource.java | 17 +- .../resource/LolStaticDataResource.java | 2 +- .../lol4j/protocol/resource/TeamResource.java | 4 +- .../resource/impl/AbstractResourceImpl.java | 39 +++- .../resource/impl/ChampionResourceImpl.java | 13 +- .../resource/impl/GameResourceImpl.java | 7 +- .../resource/impl/LeagueResourceImpl.java | 99 +++++++++-- .../impl/LolStaticDataResourceImpl.java | 113 ++++++------ .../resource/impl/ResourceFactory.java | 16 +- .../resource/impl/StatsResourceImpl.java | 11 +- .../resource/impl/SummonerResourceImpl.java | 56 +++--- .../resource/impl/TeamResourceImpl.java | 37 ++-- .../lol4j/service/impl/ApiRequestManager.java | 17 ++ src/test/java/AbstractResourceImplTest.java | 27 +++ src/test/java/ChampionResourceImplTest.java | 21 --- src/test/java/GameResourceImplTest.java | 11 -- src/test/java/LeagueResourceImplTest.java | 168 +++++++++++++++--- src/test/java/Lol4JTestClient.java | 3 +- .../java/LolStaticDataResourceImplTest.java | 113 +----------- src/test/java/StatsResourceImplTest.java | 21 --- src/test/java/SummonerResourceImplTest.java | 101 ----------- src/test/java/TeamResourceImplTest.java | 88 ++++----- 30 files changed, 647 insertions(+), 687 deletions(-) create mode 100644 src/main/java/lol4j/protocol/dto/league/LeagueEntryDto.java delete mode 100644 src/main/java/lol4j/protocol/dto/league/LeagueItemDto.java create mode 100644 src/test/java/AbstractResourceImplTest.java diff --git a/build.gradle b/build.gradle index 65c66c8..df9a871 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'java' apply plugin: 'jacoco' sourceCompatibility = 1.7 -version = '2.0' +version = '2.1' repositories { mavenCentral() diff --git a/src/main/java/lol4j/client/impl/Lol4JClientImpl.java b/src/main/java/lol4j/client/impl/Lol4JClientImpl.java index afa1396..1cccacb 100644 --- a/src/main/java/lol4j/client/impl/Lol4JClientImpl.java +++ b/src/main/java/lol4j/client/impl/Lol4JClientImpl.java @@ -5,7 +5,7 @@ import lol4j.protocol.dto.champion.ChampionDto; import lol4j.protocol.dto.game.RecentGamesDto; import lol4j.protocol.dto.league.LeagueDto; -import lol4j.protocol.dto.league.LeagueItemDto; +import lol4j.protocol.dto.league.LeagueEntryDto; import lol4j.protocol.dto.lolstaticdata.*; import lol4j.protocol.dto.stats.PlayerStatsSummaryListDto; import lol4j.protocol.dto.stats.RankedStatsDto; @@ -31,6 +31,7 @@ public class Lol4JClientImpl implements Lol4JClient { private static final String PROD_BASE = "https://prod.api.pvp.net/api/lol"; private static final String EU_BASE = "https://eu.api.pvp.net/api/lol"; private static final String ASIA_BASE = "https://asia.api.pvp.net/api/lol"; + private static final String STATIC_DATA_BASE = "https://prod.api.pvp.net/api/lol/static-data"; private ChampionResource championResource; private GameResource gameResource; private LeagueResource leagueResource; @@ -46,7 +47,8 @@ public Lol4JClientImpl(String apiKey) { prodApiRequestManager = new ApiRequestManager(apiKey, PROD_BASE); euApiRequestManager = new ApiRequestManager(apiKey, EU_BASE); asiaApiRequestManager = new ApiRequestManager(apiKey, ASIA_BASE); - ResourceFactory resourceFactory = new ResourceFactory(prodApiRequestManager, euApiRequestManager, asiaApiRequestManager); + ApiRequestManager staticDataApiRequestManager = new ApiRequestManager(apiKey, STATIC_DATA_BASE); + ResourceFactory resourceFactory = new ResourceFactory(prodApiRequestManager, euApiRequestManager, asiaApiRequestManager, staticDataApiRequestManager); championResource = resourceFactory.createChampionResource(); gameResource = resourceFactory.createGameResource(); @@ -83,13 +85,38 @@ public List getLeaguesData(long summonerId, Region region) { } @Override - public List getLeaguesEntryData(long summonerId, Region region) { + public Map> getLeaguesData(List summonerIds, Region region) { + return leagueResource.getLeaguesData(summonerIds, region); + } + + @Override + public List getLeaguesEntryData(long summonerId, Region region) { return leagueResource.getLeaguesEntryData(summonerId, region); } @Override - public PlayerStatsSummaryListDto getPlayerStatsSummaries(long summonerId, Region region, Season season) { - return statsResource.getPlayerStatsSummaries(summonerId, region, season); + public Map> getLeaguesEntryData(List summonerIds, Region region) { + return leagueResource.getLeaguesEntryData(summonerIds, region); + } + + @Override + public List getLeaguesDataByTeam(String teamId, Region region) { + return leagueResource.getLeaguesDataByTeam(teamId, region); + } + + @Override + public Map> getLeaguesDataByTeam(List teamIds, Region region) { + return leagueResource.getLeaguesDataByTeam(teamIds, region); + } + + @Override + public List getLeaguesEntryDataByTeam(String teamId, Region region) { + return leagueResource.getLeaguesEntryDataByTeam(teamId, region); + } + + @Override + public Map> getLeaguesEntryDataByTeam(List teamIds, Region region) { + return leagueResource.getLeaguesEntryDataByTeam(teamIds, region); } @Override @@ -102,6 +129,11 @@ public Map getMasteryPages(List summonerIds, Regi return summonerResource.getMasteryPages(summonerIds, region); } + @Override + public PlayerStatsSummaryListDto getPlayerStatsSummaries(long summonerId, Region region, Season season) { + return statsResource.getPlayerStatsSummaries(summonerId, region, season); + } + @Override public MasteryPagesDto getMasteryPages(long summonerId, Region region) { return summonerResource.getMasteryPages(summonerId, region); @@ -148,8 +180,13 @@ public String getSummonerName(long summonerId, Region region) { } @Override - public List getTeams(long summonerId, Region region) { - return teamResource.getTeams(summonerId, region); + public List getTeamsBySummonerId(long summonerId, Region region) { + return teamResource.getTeamsBySummonerId(summonerId, region); + } + + @Override + public Map> getTeamsBySummonerId(List summonerIds, Region region) { + return teamResource.getTeamsBySummonerId(summonerIds, region); } @Override @@ -213,7 +250,7 @@ public SummonerSpellListDto getSummonerSpellList(Region region, String locale, S } @Override - public SummonerSpellDto getSummonerSpell(String id, Region region, String locale, String version, List requestedData) { + public SummonerSpellDto getSummonerSpell(int id, Region region, String locale, String version, List requestedData) { return lolStaticDataResource.getSummonerSpell(id, region, locale, version, requestedData); } @@ -221,5 +258,6 @@ public SummonerSpellDto getSummonerSpell(String id, Region region, String locale public void setRateLimit(int perTenSeconds, int perTenMinutes) { prodApiRequestManager.setRateLimit(perTenSeconds, perTenMinutes); euApiRequestManager.setRateLimit(perTenSeconds, perTenMinutes); + asiaApiRequestManager.setRateLimit(perTenSeconds, perTenMinutes); } } diff --git a/src/main/java/lol4j/protocol/dto/league/LeagueDto.java b/src/main/java/lol4j/protocol/dto/league/LeagueDto.java index 3eda804..18f2c20 100644 --- a/src/main/java/lol4j/protocol/dto/league/LeagueDto.java +++ b/src/main/java/lol4j/protocol/dto/league/LeagueDto.java @@ -12,13 +12,13 @@ */ @JsonIgnoreProperties(ignoreUnknown = true) public class LeagueDto { - private List entries = new ArrayList<>(); + private List entries = new ArrayList<>(); private String name; private Queue queue; private Tier tier; - private long timestamp; + private String participantId; - public List getEntries() { + public List getEntries() { return entries; } @@ -46,11 +46,11 @@ public void setTier(Tier tier) { this.tier = tier; } - public long getTimestamp() { - return timestamp; + public String getParticipantId() { + return participantId; } - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; + public void setParticipantId(String participantId) { + this.participantId = participantId; } } diff --git a/src/main/java/lol4j/protocol/dto/league/LeagueEntryDto.java b/src/main/java/lol4j/protocol/dto/league/LeagueEntryDto.java new file mode 100644 index 0000000..8f4280d --- /dev/null +++ b/src/main/java/lol4j/protocol/dto/league/LeagueEntryDto.java @@ -0,0 +1,101 @@ +package lol4j.protocol.dto.league; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Created by Aaron Corley on 12/11/13. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class LeagueEntryDto { + private String division; + private boolean isFreshBlood; + private boolean isHotStreak; + private boolean isInactive; + private boolean isVeteran; + private int leaguePoints; + private MiniSeriesDto miniSeries; + private String playerOrTeamId; + private String playerOrTeamName; + private int wins; + + public String getDivision() { + return division; + } + + public void setDivision(String division) { + this.division = division; + } + + public boolean isFreshBlood() { + return isFreshBlood; + } + + public void setFreshBlood(boolean isFreshBlood) { + this.isFreshBlood = isFreshBlood; + } + + public boolean isHotStreak() { + return isHotStreak; + } + + public void setHotStreak(boolean isHotStreak) { + this.isHotStreak = isHotStreak; + } + + public boolean isInactive() { + return isInactive; + } + + public void setInactive(boolean isInactive) { + this.isInactive = isInactive; + } + + public boolean isVeteran() { + return isVeteran; + } + + public void setVeteran(boolean isVeteran) { + this.isVeteran = isVeteran; + } + + public int getLeaguePoints() { + return leaguePoints; + } + + public void setLeaguePoints(int leaguePoints) { + this.leaguePoints = leaguePoints; + } + + public MiniSeriesDto getMiniSeries() { + return miniSeries; + } + + public void setMiniSeries(MiniSeriesDto miniSeries) { + this.miniSeries = miniSeries; + } + + public String getPlayerOrTeamId() { + return playerOrTeamId; + } + + public void setPlayerOrTeamId(String playerOrTeamId) { + this.playerOrTeamId = playerOrTeamId; + } + + public String getPlayerOrTeamName() { + return playerOrTeamName; + } + + public void setPlayerOrTeamName(String playerOrTeamName) { + this.playerOrTeamName = playerOrTeamName; + } + + public int getWins() { + return wins; + } + + public void setWins(int wins) { + this.wins = wins; + } +} diff --git a/src/main/java/lol4j/protocol/dto/league/LeagueItemDto.java b/src/main/java/lol4j/protocol/dto/league/LeagueItemDto.java deleted file mode 100644 index 51f7285..0000000 --- a/src/main/java/lol4j/protocol/dto/league/LeagueItemDto.java +++ /dev/null @@ -1,141 +0,0 @@ -package lol4j.protocol.dto.league; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * Created by Aaron Corley on 12/11/13. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class LeagueItemDto { - @JsonProperty("isFreshBlood") - private boolean freshBlood; - @JsonProperty("isHotStreak") - private boolean hotStreak; - @JsonProperty("isInactive") - private boolean inactive; - @JsonProperty("isVeteran") - private boolean veteran; - private long lastPlayed; - private String leagueName; - private int leaguePoints; - private MiniSeriesDto miniSeries; - private String playerOrTeamId; - private String playerOrTeamName; - private String queueType; - private String rank; - private String tier; - private int wins; - - public boolean isFreshBlood() { - return freshBlood; - } - - public void setFreshBlood(boolean freshBlood) { - this.freshBlood = freshBlood; - } - - public boolean isHotStreak() { - return hotStreak; - } - - public void setHotStreak(boolean hotStreak) { - this.hotStreak = hotStreak; - } - - public boolean isInactive() { - return inactive; - } - - public void setInactive(boolean inactive) { - this.inactive = inactive; - } - - public boolean isVeteran() { - return veteran; - } - - public void setVeteran(boolean veteran) { - this.veteran = veteran; - } - - public long getLastPlayed() { - return lastPlayed; - } - - public void setLastPlayed(long lastPlayed) { - this.lastPlayed = lastPlayed; - } - - public String getLeagueName() { - return leagueName; - } - - public void setLeagueName(String leagueName) { - this.leagueName = leagueName; - } - - public int getLeaguePoints() { - return leaguePoints; - } - - public void setLeaguePoints(int leaguePoints) { - this.leaguePoints = leaguePoints; - } - - public MiniSeriesDto getMiniSeries() { - return miniSeries; - } - - public void setMiniSeries(MiniSeriesDto miniSeries) { - this.miniSeries = miniSeries; - } - - public String getPlayerOrTeamId() { - return playerOrTeamId; - } - - public void setPlayerOrTeamId(String playerOrTeamId) { - this.playerOrTeamId = playerOrTeamId; - } - - public String getPlayerOrTeamName() { - return playerOrTeamName; - } - - public void setPlayerOrTeamName(String playerOrTeamName) { - this.playerOrTeamName = playerOrTeamName; - } - - public String getQueueType() { - return queueType; - } - - public void setQueueType(String queueType) { - this.queueType = queueType; - } - - public String getRank() { - return rank; - } - - public void setRank(String rank) { - this.rank = rank; - } - - public String getTier() { - return tier; - } - - public void setTier(String tier) { - this.tier = tier; - } - - public int getWins() { - return wins; - } - - public void setWins(int wins) { - this.wins = wins; - } -} diff --git a/src/main/java/lol4j/protocol/dto/league/MiniSeriesDto.java b/src/main/java/lol4j/protocol/dto/league/MiniSeriesDto.java index 0934bec..8da7b9e 100644 --- a/src/main/java/lol4j/protocol/dto/league/MiniSeriesDto.java +++ b/src/main/java/lol4j/protocol/dto/league/MiniSeriesDto.java @@ -8,9 +8,8 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class MiniSeriesDto { private int losses; - private char[] progress; + private String progress; private int target; - private long timeLeftToPlayMillis; private int wins; public int getLosses() { @@ -21,11 +20,11 @@ public void setLosses(int losses) { this.losses = losses; } - public char[] getProgress() { + public String getProgress() { return progress; } - public void setProgress(char[] progress) { + public void setProgress(String progress) { this.progress = progress; } @@ -37,14 +36,6 @@ public void setTarget(int target) { this.target = target; } - public long getTimeLeftToPlayMillis() { - return timeLeftToPlayMillis; - } - - public void setTimeLeftToPlayMillis(long timeLeftToPlayMillis) { - this.timeLeftToPlayMillis = timeLeftToPlayMillis; - } - public int getWins() { return wins; } diff --git a/src/main/java/lol4j/protocol/dto/lolstaticdata/SummonerSpellDto.java b/src/main/java/lol4j/protocol/dto/lolstaticdata/SummonerSpellDto.java index f6d74c3..975797c 100644 --- a/src/main/java/lol4j/protocol/dto/lolstaticdata/SummonerSpellDto.java +++ b/src/main/java/lol4j/protocol/dto/lolstaticdata/SummonerSpellDto.java @@ -11,7 +11,7 @@ */ @JsonIgnoreProperties(ignoreUnknown = true) public class SummonerSpellDto { - private List cooldown = new ArrayList<>(); + private List cooldown = new ArrayList<>(); private String cooldownBurn; private List cost = new ArrayList<>(); private String costBurn; @@ -37,7 +37,7 @@ public class SummonerSpellDto { private String tooltip; private List vars = new ArrayList<>(); - public List getCooldown() { + public List getCooldown() { return cooldown; } diff --git a/src/main/java/lol4j/protocol/dto/team/TeamDto.java b/src/main/java/lol4j/protocol/dto/team/TeamDto.java index 9906c36..3535d91 100644 --- a/src/main/java/lol4j/protocol/dto/team/TeamDto.java +++ b/src/main/java/lol4j/protocol/dto/team/TeamDto.java @@ -17,14 +17,13 @@ public class TeamDto { private Date lastJoinDate; private Date lastJoinedRankedTeamQueueDate; private List matchHistory = new ArrayList<>(); - private MessageOfDayDto messageOfDay; private Date modifyDate; private String name; private RosterDto roster; private Date secondLastJoinDate; private String status; private String tag; - private TeamStatSummaryDto teamStatSummary; + private List teamStatDetails = new ArrayList<>(); private Date thirdLastJoinDate; public String getFullId() { @@ -51,15 +50,6 @@ public List getMatchHistory() { return matchHistory; } - public MessageOfDayDto getMessageOfDay() { - - return messageOfDay; - } - - public void setMessageOfDay(MessageOfDayDto messageOfDay) { - this.messageOfDay = messageOfDay; - } - public Date getModifyDate() { return modifyDate; } @@ -99,12 +89,9 @@ public String getStatus() { public void setStatus(String status) { this.status = status; } - public TeamStatSummaryDto getTeamStatSummary() { - return teamStatSummary; - } - public void setTeamStatSummary(TeamStatSummaryDto teamStatSummary) { - this.teamStatSummary = teamStatSummary; + public List getTeamStatDetails() { + return teamStatDetails; } public Date getThirdLastJoinDate() { diff --git a/src/main/java/lol4j/protocol/resource/LeagueResource.java b/src/main/java/lol4j/protocol/resource/LeagueResource.java index 2b2c1f1..1a9c743 100644 --- a/src/main/java/lol4j/protocol/resource/LeagueResource.java +++ b/src/main/java/lol4j/protocol/resource/LeagueResource.java @@ -1,11 +1,12 @@ package lol4j.protocol.resource; import lol4j.protocol.dto.league.LeagueDto; -import lol4j.protocol.dto.league.LeagueItemDto; +import lol4j.protocol.dto.league.LeagueEntryDto; import lol4j.util.Region; import lol4j.util.game.SubType; import java.util.List; +import java.util.Map; /** * Created by Aaron Corley on 12/11/13. @@ -15,6 +16,18 @@ public interface LeagueResource { List getLeaguesData(long summonerId, Region region); - List getLeaguesEntryData(long summonerId, Region region); + Map> getLeaguesData(List summonerIds, Region region); + + List getLeaguesEntryData(long summonerId, Region region); + + Map> getLeaguesEntryData(List summonerIds, Region region); + + List getLeaguesDataByTeam(String teamId, Region region); + + Map> getLeaguesDataByTeam(List teamIds, Region region); + + List getLeaguesEntryDataByTeam(String teamId, Region region); + + Map> getLeaguesEntryDataByTeam(List teamIds, Region region); } diff --git a/src/main/java/lol4j/protocol/resource/LolStaticDataResource.java b/src/main/java/lol4j/protocol/resource/LolStaticDataResource.java index 94ba034..7a4d02b 100644 --- a/src/main/java/lol4j/protocol/resource/LolStaticDataResource.java +++ b/src/main/java/lol4j/protocol/resource/LolStaticDataResource.java @@ -30,5 +30,5 @@ public interface LolStaticDataResource { SummonerSpellListDto getSummonerSpellList(Region region, String locale, String version, List requestedData); - SummonerSpellDto getSummonerSpell(String id, Region region, String locale, String version, List requestedData); + SummonerSpellDto getSummonerSpell(int id, Region region, String locale, String version, List requestedData); } diff --git a/src/main/java/lol4j/protocol/resource/TeamResource.java b/src/main/java/lol4j/protocol/resource/TeamResource.java index a9ece63..137f9c1 100644 --- a/src/main/java/lol4j/protocol/resource/TeamResource.java +++ b/src/main/java/lol4j/protocol/resource/TeamResource.java @@ -10,7 +10,9 @@ * Created by Aaron Corley on 12/13/13. */ public interface TeamResource { - List getTeams(long summonerId, Region region); + List getTeamsBySummonerId(long summonerId, Region region); + + Map> getTeamsBySummonerId(List summonerIds, Region region); TeamDto getTeam(String teamId, Region region); diff --git a/src/main/java/lol4j/protocol/resource/impl/AbstractResourceImpl.java b/src/main/java/lol4j/protocol/resource/impl/AbstractResourceImpl.java index e8b6cc0..cfbb1e7 100644 --- a/src/main/java/lol4j/protocol/resource/impl/AbstractResourceImpl.java +++ b/src/main/java/lol4j/protocol/resource/impl/AbstractResourceImpl.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; /** * Created by Aaron Corley on 12/11/13. @@ -21,16 +22,44 @@ public AbstractResourceImpl(Region... regions) { supportedRegions.addAll(Arrays.asList(regions)); } - public void doSupportedRegionCheck(Region region) { + public final T get(Region region, String path, Map queryParams, boolean ignoreRateLimiter, Class clazz) { + doSupportedRegionCheck(region); + ApiRequestManager requestManager = getApiRequestManager(region); + String fullPath = region.getName() + '/' + path; + + return requestManager.get(fullPath, queryParams, ignoreRateLimiter, clazz); + } + + public final Map> getMapOfLists(Region region, String path, Map queryParams, boolean ignoreRateLimiter, Class keyClass, Class listValueClass) { + doSupportedRegionCheck(region); + ApiRequestManager requestManager = getApiRequestManager(region); + String fullPath = region.getName() + '/' + path; + + return requestManager.getMapOfLists(fullPath, queryParams, ignoreRateLimiter, keyClass, listValueClass); + } + + public final Map getMap(Region region, String path, Map queryParams, boolean ignoreRateLimiter, Class keyClass, Class valueClass) { + doSupportedRegionCheck(region); + ApiRequestManager requestManager = getApiRequestManager(region); + String fullPath = region.getName() + '/' + path; + + return requestManager.getMap(fullPath, queryParams, ignoreRateLimiter, keyClass, valueClass); + } + + public final List getList(Region region, String path, Map queryParams, boolean ignoreRateLimiter, Class clazz) { + doSupportedRegionCheck(region); + ApiRequestManager requestManager = getApiRequestManager(region); + String fullPath = region.getName() + '/' + path; + + return requestManager.getList(fullPath, queryParams, ignoreRateLimiter, clazz); + } + + public final void doSupportedRegionCheck(Region region) { if (region == null || !supportedRegions.contains(region)) { throw new InvalidRegionException(region); } } - public List getSupportedRegions() { - return supportedRegions; - } - public ApiRequestManager getApiRequestManager(Region region) { ApiRequestManager requestManager = null; diff --git a/src/main/java/lol4j/protocol/resource/impl/ChampionResourceImpl.java b/src/main/java/lol4j/protocol/resource/impl/ChampionResourceImpl.java index bbd833a..76c92e6 100644 --- a/src/main/java/lol4j/protocol/resource/impl/ChampionResourceImpl.java +++ b/src/main/java/lol4j/protocol/resource/impl/ChampionResourceImpl.java @@ -3,6 +3,7 @@ import lol4j.protocol.dto.champion.ChampionDto; import lol4j.protocol.dto.champion.ChampionListDto; import lol4j.protocol.resource.ChampionResource; +import lol4j.service.impl.ApiRequestManager; import lol4j.util.Region; import java.util.HashMap; @@ -34,19 +35,17 @@ public ChampionResourceImpl() { @Override public ChampionListDto getAllChampions(Region region, boolean freeToPlay) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + RESOURCE_URI; + String path = RESOURCE_URI; Map queryParams = new HashMap<>(); queryParams.put("freeToPlay", freeToPlay); - return getApiRequestManager(region).get(path, queryParams, false, ChampionListDto.class); + return get(region, path, queryParams, false, ChampionListDto.class); } @Override - public ChampionDto getChampion(Region region, int id) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + String.valueOf(id); + public ChampionDto getChampion(Region region, int championId) { + String path = RESOURCE_URI + SLASH + String.valueOf(championId); - return getApiRequestManager(region).get(path, null, false, ChampionDto.class); + return get(region, path, null, false, ChampionDto.class); } } diff --git a/src/main/java/lol4j/protocol/resource/impl/GameResourceImpl.java b/src/main/java/lol4j/protocol/resource/impl/GameResourceImpl.java index 23bd083..f8fa7c6 100644 --- a/src/main/java/lol4j/protocol/resource/impl/GameResourceImpl.java +++ b/src/main/java/lol4j/protocol/resource/impl/GameResourceImpl.java @@ -2,6 +2,7 @@ import lol4j.protocol.dto.game.RecentGamesDto; import lol4j.protocol.resource.GameResource; +import lol4j.service.impl.ApiRequestManager; import lol4j.util.Region; /** @@ -29,10 +30,10 @@ public GameResourceImpl() { } @Override + public RecentGamesDto getRecentGames(Region region, long summonerId) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerId + SLASH + "recent"; + String path = RESOURCE_URI + SLASH + summonerId + SLASH + "recent"; - return getApiRequestManager(region).get(path, null, false, RecentGamesDto.class); + return get(region, path, null, false, RecentGamesDto.class); } } diff --git a/src/main/java/lol4j/protocol/resource/impl/LeagueResourceImpl.java b/src/main/java/lol4j/protocol/resource/impl/LeagueResourceImpl.java index 340cc25..d59d8e6 100644 --- a/src/main/java/lol4j/protocol/resource/impl/LeagueResourceImpl.java +++ b/src/main/java/lol4j/protocol/resource/impl/LeagueResourceImpl.java @@ -2,25 +2,29 @@ import lol4j.exception.SubTypeMismatchException; import lol4j.protocol.dto.league.LeagueDto; -import lol4j.protocol.dto.league.LeagueItemDto; +import lol4j.protocol.dto.league.LeagueEntryDto; import lol4j.protocol.resource.LeagueResource; import lol4j.util.Region; import lol4j.util.game.SubType; +import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.List; import java.util.Map; /** - * Compatible with league-v2.3 + * Compatible with league-v2.4 */ public class LeagueResourceImpl extends AbstractResourceImpl implements LeagueResource { private static final String SLASH = "/"; - private static final String RESOURCE_VERSION = "v2.3"; + private static final String RESOURCE_VERSION = "v2.4"; private static final String CHALLENGER_URI = RESOURCE_VERSION + SLASH + "league" + SLASH + "challenger"; private static final String LEAGUE = "league" + SLASH + "by-summoner"; private static final String LEAGUE_URI = RESOURCE_VERSION + SLASH + LEAGUE; + private static final String LEAGUE_BY_TEAM = "league" + SLASH + "by-team"; + private static final String LEAGUE_BY_TEAM_URI = RESOURCE_VERSION + SLASH + LEAGUE_BY_TEAM; private static final String ENTRY = "entry"; + public static final int MAX_LIST_SIZE = 40; public LeagueResourceImpl() { super( @@ -39,30 +43,99 @@ public LeagueResourceImpl() { @Override public LeagueDto getChallengerLeague(Region region, SubType gameType) { - doSupportedRegionCheck(region); if (gameType == null || !SubType.getChallengerSubTypes().contains(gameType)) { throw new SubTypeMismatchException(gameType); } - String path = region.getName() + SLASH + CHALLENGER_URI; + String path = CHALLENGER_URI; Map queryParams = new HashMap<>(); queryParams.put("type", gameType.getSubType()); - return getApiRequestManager(region).get(path, queryParams, false, LeagueDto.class); + return get(region, path, queryParams, false, LeagueDto.class); } @Override public List getLeaguesData(long summonerId, Region region) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + LEAGUE_URI + SLASH + summonerId; + String path = LEAGUE_URI + SLASH + summonerId; + Map> map = getMapOfLists(region, path, null, false, String.class, LeagueDto.class); - return getApiRequestManager(region).getList(path, null, false, LeagueDto.class); + return map.get(Long.toString(summonerId)); } @Override - public List getLeaguesEntryData(long summonerId, Region region) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + LEAGUE_URI + SLASH + summonerId + SLASH + ENTRY; + public Map> getLeaguesData(List summonerIds, Region region) { + if (summonerIds == null || summonerIds.size() > MAX_LIST_SIZE || summonerIds.size() == 0) { + throw new IllegalArgumentException("summonerIds list must have at least one entry and no more than " + + MAX_LIST_SIZE + " entries"); + } + String summonerIdList = StringUtils.join(summonerIds, ","); + String path = LEAGUE_URI + SLASH + summonerIdList; + + return getMapOfLists(region, path, null, false, String.class, LeagueDto.class); + } + + @Override + public List getLeaguesEntryData(long summonerId, Region region) { + String path = LEAGUE_URI + SLASH + summonerId + SLASH + ENTRY; + Map> map = getMapOfLists(region, path, null, false, String.class, LeagueEntryDto.class); + + return map.get(Long.toString(summonerId)); + } + + @Override + public Map> getLeaguesEntryData(List summonerIds, Region region) { + if (summonerIds == null || summonerIds.size() > MAX_LIST_SIZE || summonerIds.size() == 0) { + throw new IllegalArgumentException("summonerIds list must have at least one entry and no more than " + + MAX_LIST_SIZE + " entries"); + } + String summonerIdList = StringUtils.join(summonerIds, ","); + String path = LEAGUE_URI + SLASH + summonerIdList + SLASH + ENTRY; + + return getMapOfLists(region, path, null, false, String.class, LeagueEntryDto.class); + } + + @Override + public List getLeaguesEntryDataByTeam(String teamId, Region region) { + if (teamId == null || teamId.isEmpty()) { + throw new IllegalArgumentException("teamId must provided"); + } + String path = LEAGUE_BY_TEAM_URI + SLASH + teamId + SLASH + ENTRY; + Map> map = getMapOfLists(region, path, null, false, String.class, LeagueEntryDto.class); + + return map.get(teamId); + } + + @Override + public Map> getLeaguesEntryDataByTeam(List teamIds, Region region) { + if (teamIds == null || teamIds.size() > MAX_LIST_SIZE || teamIds.size() == 0) { + throw new IllegalArgumentException("teamIds list must have at least one entry and no more than " + + MAX_LIST_SIZE + " entries"); + } + String teamIdList = StringUtils.join(teamIds, ","); + String path = LEAGUE_BY_TEAM_URI + SLASH + teamIdList + SLASH + ENTRY; + + return getMapOfLists(region, path, null, false, String.class, LeagueEntryDto.class); + } + + @Override + public List getLeaguesDataByTeam(String teamId, Region region) { + if (teamId == null || teamId.isEmpty()) { + throw new IllegalArgumentException("teamId must provided"); + } + String path = LEAGUE_BY_TEAM_URI + SLASH + teamId; + Map> map = getMapOfLists(region, path, null, false, String.class, LeagueDto.class); + + return map.get(teamId); + } + + @Override + public Map> getLeaguesDataByTeam(List teamIds, Region region) { + if (teamIds == null || teamIds.size() > MAX_LIST_SIZE || teamIds.size() == 0) { + throw new IllegalArgumentException("teamIds list must have at least one entry and no more than " + + MAX_LIST_SIZE + " entries"); + } + String teamIdList = StringUtils.join(teamIds, ","); + String path = LEAGUE_BY_TEAM_URI + SLASH + teamIdList; - return getApiRequestManager(region).getList(path, null, false, LeagueItemDto.class); + return getMapOfLists(region, path, null, false, String.class, LeagueDto.class); } } diff --git a/src/main/java/lol4j/protocol/resource/impl/LolStaticDataResourceImpl.java b/src/main/java/lol4j/protocol/resource/impl/LolStaticDataResourceImpl.java index d21e372..393e3be 100644 --- a/src/main/java/lol4j/protocol/resource/impl/LolStaticDataResourceImpl.java +++ b/src/main/java/lol4j/protocol/resource/impl/LolStaticDataResourceImpl.java @@ -2,6 +2,7 @@ import lol4j.protocol.dto.lolstaticdata.*; import lol4j.protocol.resource.LolStaticDataResource; +import lol4j.service.impl.ApiRequestManager; import lol4j.util.Region; import lol4j.util.lolstaticdata.*; import org.apache.commons.lang3.StringUtils; @@ -12,18 +13,24 @@ import java.util.Map; /** - * Created by Aaron Corley on 3/9/14. + * Compatible with static-data v1.2 */ public class LolStaticDataResourceImpl extends AbstractResourceImpl implements LolStaticDataResource { - private static final String RESOURCE_VERSION = "v1.1"; - private static final String RESOURCE_PATH = "static-data"; + private static final String SLASH = "/"; + private static final String RESOURCE_VERSION = "v1.2"; private static final String CHAMPION = "champion"; + private static final String CHAMPION_URI = RESOURCE_VERSION + SLASH + CHAMPION; private static final String ITEM = "item"; + private static final String ITEM_URI = RESOURCE_VERSION + SLASH + ITEM; private static final String MASTERY = "mastery"; + private static final String MASTERY_URI = RESOURCE_VERSION + SLASH + MASTERY; private static final String REALM = "realm"; + private static final String REALM_URI = RESOURCE_VERSION + SLASH + REALM; private static final String RUNE = "rune"; + private static final String RUNE_URI = RESOURCE_VERSION + SLASH + RUNE; private static final String SUMMONER_SPELL = "summoner-spell"; - private static final String SLASH = "/"; + private static final String SUMMONER_SPELL_URI = RESOURCE_VERSION + SLASH + SUMMONER_SPELL; + private ApiRequestManager apiRequestManager; public LolStaticDataResourceImpl() { super( @@ -42,8 +49,7 @@ public LolStaticDataResourceImpl() { @Override public ChampionListDto getChampionList(Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + CHAMPION; + String path = CHAMPION_URI; Map queryParams = new HashMap<>(); if (locale != null && !locale.isEmpty()) { queryParams.put("locale", locale); @@ -59,16 +65,15 @@ public ChampionListDto getChampionList(Region region, String locale, String vers queryParams.put("champData", StringUtils.join(list, ",")); } - return getApiRequestManager(region).get(path, queryParams, true, ChampionListDto.class); + return get(region, path, queryParams, true, ChampionListDto.class); } @Override public ChampionDto getChampion(String id, Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); if (id == null || id.isEmpty()) { throw new IllegalArgumentException("id must not be null or empty"); } - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + CHAMPION + SLASH + id; + String path = CHAMPION_URI + SLASH + id; Map queryParams = new HashMap<>(); if (locale != null && !locale.isEmpty()) { queryParams.put("locale", locale); @@ -84,16 +89,15 @@ public ChampionDto getChampion(String id, Region region, String locale, String v queryParams.put("champData", StringUtils.join(list, ",")); } - return getApiRequestManager(region).get(path, queryParams, true, ChampionDto.class); + return get(region, path, queryParams, true, ChampionDto.class); } @Override public BasicDataDto getItem(String id, Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); if (id == null || id.isEmpty()) { throw new IllegalArgumentException("id must not be null or empty"); } - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + ITEM + SLASH + id; + String path = ITEM_URI + SLASH + id; Map queryParams = new HashMap<>(); if (locale != null && !locale.isEmpty()) { queryParams.put("locale", locale); @@ -109,13 +113,12 @@ public BasicDataDto getItem(String id, Region region, String locale, String vers queryParams.put("itemData", StringUtils.join(list, ",")); } - return getApiRequestManager(region).get(path, queryParams, true, BasicDataDto.class); + return get(region, path, queryParams, true, BasicDataDto.class); } @Override public ItemListDto getItemList(Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + ITEM; + String path = ITEM_URI; Map queryParams = new HashMap<>(); if (locale != null && !locale.isEmpty()) { queryParams.put("locale", locale); @@ -131,42 +134,24 @@ public ItemListDto getItemList(Region region, String locale, String version, Lis queryParams.put("itemData", StringUtils.join(list, ",")); } - return getApiRequestManager(region).get(path, queryParams, true, ItemListDto.class); + return get(region, path, queryParams, true, ItemListDto.class); } @Override public MasteryDto getMastery(String id, Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); if (id == null || id.isEmpty()) { throw new IllegalArgumentException("id must not be null or empty"); } - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + MASTERY + SLASH + id; + String path = MASTERY_URI + SLASH + id; Map queryParams = new HashMap<>(); buildQueryParams(locale, version, requestedData, queryParams); - return getApiRequestManager(region).get(path, queryParams, true, MasteryDto.class); - } - - private void buildQueryParams(String locale, String version, List requestedData, Map queryParams) { - if (locale != null && !locale.isEmpty()) { - queryParams.put("locale", locale); - } - if (version != null && !version.isEmpty()) { - queryParams.put("version", version); - } - if (requestedData != null) { - List list = new ArrayList<>(); - for (MasteryData data : requestedData) { - list.add(data.getMasteryData()); - } - queryParams.put("itemData", StringUtils.join(list, ",")); - } + return get(region, path, queryParams, true, MasteryDto.class); } @Override public MasteryListDto getMasteryList(Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + MASTERY; + String path = MASTERY_URI; Map queryParams = new HashMap<>(); if (locale != null && !locale.isEmpty()) { queryParams.put("locale", locale); @@ -182,21 +167,19 @@ public MasteryListDto getMasteryList(Region region, String locale, String versio queryParams.put("itemData", StringUtils.join(list, ",")); } - return getApiRequestManager(region).get(path, queryParams, true, MasteryListDto.class); + return get(region, path, queryParams, true, MasteryListDto.class); } @Override public RealmDto getRealm(Region region) { - doSupportedRegionCheck(region); - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + REALM; + String path = REALM_URI; - return getApiRequestManager(region).get(path, null, true, RealmDto.class); + return get(region, path, null, true, RealmDto.class); } @Override public RuneListDto getRuneList(Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + RUNE; + String path = RUNE_URI; Map queryParams = new HashMap<>(); if (locale != null && !locale.isEmpty()) { queryParams.put("locale", locale); @@ -212,13 +195,12 @@ public RuneListDto getRuneList(Region region, String locale, String version, Lis queryParams.put("itemData", StringUtils.join(list, ",")); } - return getApiRequestManager(region).get(path, queryParams, true, RuneListDto.class); + return get(region, path, queryParams, true, RuneListDto.class); } @Override public BasicDataDto getRune(String id, Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + RUNE + SLASH + id; + String path = RUNE_URI + SLASH + id; Map queryParams = new HashMap<>(); if (locale != null && !locale.isEmpty()) { queryParams.put("locale", locale); @@ -234,13 +216,12 @@ public BasicDataDto getRune(String id, Region region, String locale, String vers queryParams.put("itemData", StringUtils.join(list, ",")); } - return getApiRequestManager(region).get(path, queryParams, true, BasicDataDto.class); + return get(region, path, queryParams, true, BasicDataDto.class); } @Override public SummonerSpellListDto getSummonerSpellList(Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + SUMMONER_SPELL; + String path = SUMMONER_SPELL_URI; Map queryParams = new HashMap<>(); if (locale != null && !locale.isEmpty()) { queryParams.put("locale", locale); @@ -256,13 +237,12 @@ public SummonerSpellListDto getSummonerSpellList(Region region, String locale, S queryParams.put("itemData", StringUtils.join(list, ",")); } - return getApiRequestManager(region).get(path, queryParams, true, SummonerSpellListDto.class); + return get(region, path, queryParams, true, SummonerSpellListDto.class); } @Override - public SummonerSpellDto getSummonerSpell(String id, Region region, String locale, String version, List requestedData) { - doSupportedRegionCheck(region); - String path = RESOURCE_PATH + SLASH + region.getName() + SLASH + RESOURCE_VERSION + SLASH + SUMMONER_SPELL + SLASH + id; + public SummonerSpellDto getSummonerSpell(int id, Region region, String locale, String version, List requestedData) { + String path = SUMMONER_SPELL_URI + SLASH + id; Map queryParams = new HashMap<>(); if (locale != null && !locale.isEmpty()) { queryParams.put("locale", locale); @@ -278,6 +258,31 @@ public SummonerSpellDto getSummonerSpell(String id, Region region, String locale queryParams.put("itemData", StringUtils.join(list, ",")); } - return getApiRequestManager(region).get(path, queryParams, true, SummonerSpellDto.class); + return get(region, path, queryParams, true, SummonerSpellDto.class); + } + + public void setApiRequestManager(ApiRequestManager apiRequestManager) { + this.apiRequestManager = apiRequestManager; + } + + @Override + public ApiRequestManager getApiRequestManager(Region region) { + return apiRequestManager; + } + + private void buildQueryParams(String locale, String version, List requestedData, Map queryParams) { + if (locale != null && !locale.isEmpty()) { + queryParams.put("locale", locale); + } + if (version != null && !version.isEmpty()) { + queryParams.put("version", version); + } + if (requestedData != null) { + List list = new ArrayList<>(); + for (MasteryData data : requestedData) { + list.add(data.getMasteryData()); + } + queryParams.put("itemData", StringUtils.join(list, ",")); + } } } diff --git a/src/main/java/lol4j/protocol/resource/impl/ResourceFactory.java b/src/main/java/lol4j/protocol/resource/impl/ResourceFactory.java index 7bb4885..329e788 100644 --- a/src/main/java/lol4j/protocol/resource/impl/ResourceFactory.java +++ b/src/main/java/lol4j/protocol/resource/impl/ResourceFactory.java @@ -10,11 +10,16 @@ public class ResourceFactory { private ApiRequestManager prodApiRequestManager; private ApiRequestManager euApiRequestManager; private ApiRequestManager asiaApiRequestManager; + private ApiRequestManager staticDataApiRequestManager; - public ResourceFactory(ApiRequestManager prodApiRequestManager, ApiRequestManager euApiRequestManager, ApiRequestManager asiaApiRequestManager) { + public ResourceFactory(ApiRequestManager prodApiRequestManager, + ApiRequestManager euApiRequestManager, + ApiRequestManager asiaApiRequestManager, + ApiRequestManager staticDataApiRequestManager) { this.prodApiRequestManager = prodApiRequestManager; this.euApiRequestManager = euApiRequestManager; this.asiaApiRequestManager = asiaApiRequestManager; + this.staticDataApiRequestManager = staticDataApiRequestManager; } public ChampionResource createChampionResource() { @@ -42,7 +47,10 @@ public TeamResource createTeamResource() { } public LolStaticDataResource createLolStaticDataResource() { - return (LolStaticDataResource) createAbstractResourceImpl(LolStaticDataResourceImpl.class); + LolStaticDataResourceImpl impl = createAbstractResourceImpl(LolStaticDataResourceImpl.class); + impl.setApiRequestManager(staticDataApiRequestManager); + + return impl; } private T createAbstractResourceImpl(Class T) { @@ -53,9 +61,7 @@ private T createAbstractResourceImpl(Class queryParams = null; if (season != null) { queryParams = new HashMap<>(); queryParams.put("season", season.getName()); } - return getApiRequestManager(region).get(path, queryParams, false, PlayerStatsSummaryListDto.class); + return get(region, path, queryParams, false, PlayerStatsSummaryListDto.class); } @Override public RankedStatsDto getRankedStats(long summonerId, Region region, Season season) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerId + SLASH + "ranked"; + String path = RESOURCE_URI + SLASH + summonerId + SLASH + "ranked"; Map queryParams = null; if (season != null) { queryParams = new HashMap<>(); queryParams.put("season", season.getName()); } - return getApiRequestManager(region).get(path, queryParams, false, RankedStatsDto.class); + return get(region, path, queryParams, false, RankedStatsDto.class); } } diff --git a/src/main/java/lol4j/protocol/resource/impl/SummonerResourceImpl.java b/src/main/java/lol4j/protocol/resource/impl/SummonerResourceImpl.java index 47c73f9..a9c49a5 100644 --- a/src/main/java/lol4j/protocol/resource/impl/SummonerResourceImpl.java +++ b/src/main/java/lol4j/protocol/resource/impl/SummonerResourceImpl.java @@ -44,53 +44,46 @@ public SummonerResourceImpl() { @Override public Map getMasteryPages(List summonerIds, Region region) { - doSupportedRegionCheck(region); if (summonerIds == null || summonerIds.size() > MAX_LIST_SIZE || summonerIds.size() == 0) { throw new IllegalArgumentException("summonerIds list must have at least one entry and no more than " + MAX_LIST_SIZE + " entries"); } String summonerIdList = StringUtils.join(summonerIds, ","); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerIdList + SLASH + MASTERIES; + String path = RESOURCE_URI + SLASH + summonerIdList + SLASH + MASTERIES; - return getApiRequestManager(region).getMap(path, null, false, String.class, MasteryPagesDto.class); + return getMap(region, path, null, false, String.class, MasteryPagesDto.class); } @Override public MasteryPagesDto getMasteryPages(long summonerId, Region region) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerId + SLASH + MASTERIES; - Map result = - getApiRequestManager(region).getMap(path, null, false, String.class, MasteryPagesDto.class); + String path = RESOURCE_URI + SLASH + summonerId + SLASH + MASTERIES; + Map result = getMap(region, path, null, false, String.class, MasteryPagesDto.class); return result.get(Long.toString(summonerId)); } @Override public Map getRunePages(List summonerIds, Region region) { - doSupportedRegionCheck(region); if (summonerIds == null || summonerIds.size() > MAX_LIST_SIZE || summonerIds.size() == 0) { throw new IllegalArgumentException("summonerIds list must have at least one entry and no more than " + MAX_LIST_SIZE + " entries"); } String summonerIdList = StringUtils.join(summonerIds, ","); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerIdList + SLASH + RUNES; + String path = RESOURCE_URI + SLASH + summonerIdList + SLASH + RUNES; - return getApiRequestManager(region).getMap(path, null, false, String.class, RunePagesDto.class); + return getMap(region, path, null, false, String.class, RunePagesDto.class); } @Override public RunePagesDto getRunePages(long summonerId, Region region) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerId + SLASH + RUNES; - Map result = - getApiRequestManager(region).getMap(path, null, false, String.class, RunePagesDto.class); + String path = RESOURCE_URI + SLASH + summonerId + SLASH + RUNES; + Map result = getMap(region, path, null, false, String.class, RunePagesDto.class); return result.get(Long.toString(summonerId)); } @Override public Map getSummonersByName(List names, Region region) { - doSupportedRegionCheck(region); if (names == null || names.size() > MAX_LIST_SIZE || names.size() == 0) { throw new IllegalArgumentException("summonerIds list must have at least one entry and no more than " + MAX_LIST_SIZE + " entries"); @@ -98,75 +91,66 @@ public Map getSummonersByName(List names, Region re String summonerNameList = StringUtils.join(names, ","); String path; try { - path = region.getName() + SLASH + RESOURCE_URI + SLASH + BY_NAME + SLASH + - URLEncoder.encode(summonerNameList, ApiRequestManager.ENCODING); + path = RESOURCE_URI + SLASH + BY_NAME + SLASH + URLEncoder.encode(summonerNameList, ApiRequestManager.ENCODING); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding: " + ApiRequestManager.ENCODING); } - return getApiRequestManager(region).getMap(path, null, false, String.class, SummonerDto.class); + return getMap(region, path, null, false, String.class, SummonerDto.class); } @Override public SummonerDto getSummonerByName(String name, Region region) { - doSupportedRegionCheck(region); if (name == null || name.isEmpty()) { throw new IllegalArgumentException("name must not be null or empty"); } String path; try { - path = region.getName() + SLASH + RESOURCE_URI + SLASH + BY_NAME + SLASH + - URLEncoder.encode(name, ApiRequestManager.ENCODING); + path = RESOURCE_URI + SLASH + BY_NAME + SLASH + URLEncoder.encode(name, ApiRequestManager.ENCODING); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding: " + ApiRequestManager.ENCODING); } - Map result = - getApiRequestManager(region).getMap(path, null, false, String.class, SummonerDto.class); + Map result = getMap(region, path, null, false, String.class, SummonerDto.class); return result.get(name.toLowerCase()); } @Override public Map getSummoners(List summonerIds, Region region) { - doSupportedRegionCheck(region); if (summonerIds == null || summonerIds.size() > MAX_LIST_SIZE || summonerIds.size() == 0) { throw new IllegalArgumentException("summonerIds list must have at least one entry and no more than " + MAX_LIST_SIZE + " entries"); } String summonerIdList = StringUtils.join(summonerIds, ","); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerIdList; + String path = RESOURCE_URI + SLASH + summonerIdList; - return getApiRequestManager(region).getMap(path, null, false, String.class, SummonerDto.class); + return getMap(region, path, null, false, String.class, SummonerDto.class); } @Override public SummonerDto getSummoner(long summonerId, Region region) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerId; - Map result = - getApiRequestManager(region).getMap(path, null, false, String.class, SummonerDto.class); + String path = RESOURCE_URI + SLASH + summonerId; + Map result = getMap(region, path, null, false, String.class, SummonerDto.class); return result.get(Long.toString(summonerId)); } @Override public Map getSummonerNames(List summonerIds, Region region) { - doSupportedRegionCheck(region); if (summonerIds == null || summonerIds.size() > MAX_LIST_SIZE || summonerIds.size() == 0) { throw new IllegalArgumentException("summonerIds list must have at least one entry and no more than " + MAX_LIST_SIZE + " entries"); } String summonerIdList = StringUtils.join(summonerIds, ","); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerIdList + SLASH + NAME; + String path = RESOURCE_URI + SLASH + summonerIdList + SLASH + NAME; - return getApiRequestManager(region).getMap(path, null, false, String.class, String.class); + return getMap(region, path, null, false, String.class, String.class); } @Override public String getSummonerName(long summonerId, Region region) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + summonerId + SLASH + NAME; - Map result = getApiRequestManager(region).getMap(path, null, false, String.class, String.class); + String path = RESOURCE_URI + SLASH + summonerId + SLASH + NAME; + Map result = getMap(region, path, null, false, String.class, String.class); return result.get(Long.toString(summonerId)); } diff --git a/src/main/java/lol4j/protocol/resource/impl/TeamResourceImpl.java b/src/main/java/lol4j/protocol/resource/impl/TeamResourceImpl.java index 0198b19..e6e8bf8 100644 --- a/src/main/java/lol4j/protocol/resource/impl/TeamResourceImpl.java +++ b/src/main/java/lol4j/protocol/resource/impl/TeamResourceImpl.java @@ -2,6 +2,7 @@ import lol4j.protocol.dto.team.TeamDto; import lol4j.protocol.resource.TeamResource; +import lol4j.service.impl.ApiRequestManager; import lol4j.util.Region; import org.apache.commons.lang3.StringUtils; @@ -9,10 +10,10 @@ import java.util.Map; /** - * Compatible with team-v2.2 + * Compatible with team-v2.3 */ public class TeamResourceImpl extends AbstractResourceImpl implements TeamResource { - private static final String RESOURCE_VERSION = "v2.2"; + private static final String RESOURCE_VERSION = "v2.3"; private static final String RESOURCE_PATH = "team"; private static final String SLASH = "/"; private static final String RESOURCE_URI = RESOURCE_VERSION + SLASH + RESOURCE_PATH; @@ -35,35 +36,43 @@ public TeamResourceImpl() { } @Override - public List getTeams(long summonerId, Region region) { - doSupportedRegionCheck(region); - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + BY_SUMMONER + SLASH + summonerId; + public List getTeamsBySummonerId(long summonerId, Region region) { + String path = RESOURCE_URI + SLASH + BY_SUMMONER + SLASH + summonerId; + Map> map = getMapOfLists(region, path, null, false, String.class, TeamDto.class); - return getApiRequestManager(region).getList(path, null, false, TeamDto.class); + return map.get(Long.toString(summonerId)); + } + + @Override + public Map> getTeamsBySummonerId(List summonerIds, Region region) { + if (summonerIds == null || summonerIds.size() > MAX_LIST_SIZE || summonerIds.isEmpty()) { + throw new IllegalArgumentException("summonerIds list must have at least one entry and no more than " + + MAX_LIST_SIZE + " entries"); + } + String path = RESOURCE_URI + SLASH + BY_SUMMONER + SLASH + StringUtils.join(summonerIds, ','); + + return getMapOfLists(region, path, null, false, String.class, TeamDto.class); } @Override public TeamDto getTeam(String teamId, Region region) { - doSupportedRegionCheck(region); if (teamId == null || teamId.isEmpty()) { throw new IllegalArgumentException("team must not be null or empty"); } - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + teamId; - Map result = - getApiRequestManager(region).getMap(path, null, false, String.class, TeamDto.class); + String path = RESOURCE_URI + SLASH + teamId; + Map result = getMap(region, path, null, false, String.class, TeamDto.class); return result.get(teamId); } @Override public Map getTeams(List teamIds, Region region) { - doSupportedRegionCheck(region); - if (teamIds == null || teamIds.size() > MAX_LIST_SIZE || teamIds.size() == 0) { + if (teamIds == null || teamIds.size() > MAX_LIST_SIZE || teamIds.isEmpty()) { throw new IllegalArgumentException("teamIds list must have at least one entry and no more than " + MAX_LIST_SIZE + " entries"); } - String path = region.getName() + SLASH + RESOURCE_URI + SLASH + StringUtils.join(teamIds, ','); + String path = RESOURCE_URI + SLASH + StringUtils.join(teamIds, ','); - return getApiRequestManager(region).getMap(path, null, false, String.class, TeamDto.class); + return getMap(region, path, null, false, String.class, TeamDto.class); } } diff --git a/src/main/java/lol4j/service/impl/ApiRequestManager.java b/src/main/java/lol4j/service/impl/ApiRequestManager.java index dc3c9b2..edc7301 100644 --- a/src/main/java/lol4j/service/impl/ApiRequestManager.java +++ b/src/main/java/lol4j/service/impl/ApiRequestManager.java @@ -1,5 +1,6 @@ package lol4j.service.impl; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.TypeFactory; import lol4j.exception.TooManyRequestsException; @@ -84,6 +85,22 @@ public Map getMap(String path, Map queryParams, boo return returnObj; } + public Map> getMapOfLists(String path, Map queryParams, boolean ignoreRateLimiter, Class keyClass, Class valueClass) { + String json = doRequest(path, queryParams, ignoreRateLimiter); + TypeFactory typeFactory = TypeFactory.defaultInstance(); + JavaType keyType = typeFactory.constructType(keyClass); + JavaType valueType = typeFactory.constructCollectionType(List.class, valueClass); + Map> returnObj = null; + + try { + returnObj = objectMapper.readValue(json, typeFactory.constructMapType(Map.class, keyType, valueType)); + } catch (IOException e) { + e.printStackTrace(); + } + + return returnObj; + } + private String doRequest(String path, Map queryParams, boolean ignoreRateLimiter) { if (usingRateLimiter && !ignoreRateLimiter) { try { diff --git a/src/test/java/AbstractResourceImplTest.java b/src/test/java/AbstractResourceImplTest.java new file mode 100644 index 0000000..e051037 --- /dev/null +++ b/src/test/java/AbstractResourceImplTest.java @@ -0,0 +1,27 @@ +import lol4j.exception.InvalidRegionException; +import lol4j.protocol.resource.impl.AbstractResourceImpl; +import lol4j.util.Region; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Created by aaryn101 on 5/16/14. + */ +public class AbstractResourceImplTest { + private static AbstractResourceImpl testObj; + + @BeforeClass + public static void init() { + testObj = new AbstractResourceImpl() { }; + } + + @Test(expected = InvalidRegionException.class) + public void testSupportedRegionCheckWithNull() { + testObj.doSupportedRegionCheck(null); + } + + @Test(expected = InvalidRegionException.class) + public void testSupportedRegionCheckWithInvalidRegion() { + testObj.doSupportedRegionCheck(Region.UNKNOWN); + } +} diff --git a/src/test/java/ChampionResourceImplTest.java b/src/test/java/ChampionResourceImplTest.java index b87c113..b6d5c5a 100644 --- a/src/test/java/ChampionResourceImplTest.java +++ b/src/test/java/ChampionResourceImplTest.java @@ -1,4 +1,3 @@ -import lol4j.exception.InvalidRegionException; import lol4j.protocol.dto.champion.ChampionDto; import lol4j.protocol.dto.champion.ChampionListDto; import lol4j.util.Region; @@ -30,24 +29,4 @@ public void getChampion() { Assert.assertEquals(CHAMPION_ID, champion.getId()); } - - @Test(expected = InvalidRegionException.class) - public void getChampionWithUnsupportedRegion() { - Lol4JTestClient.getClient().getChampion(Region.UNKNOWN, CHAMPION_ID); - } - - @Test(expected = InvalidRegionException.class) - public void getChampionWithNullRegion() { - Lol4JTestClient.getClient().getChampion(null, CHAMPION_ID); - } - - @Test(expected = InvalidRegionException.class) - public void getAllChampionsWithUnsupportedRegion() { - Lol4JTestClient.getClient().getAllChampions(Region.UNKNOWN, false); - } - - @Test(expected = InvalidRegionException.class) - public void getAllChampionsWithNullRegion() { - Lol4JTestClient.getClient().getAllChampions(null, false); - } } diff --git a/src/test/java/GameResourceImplTest.java b/src/test/java/GameResourceImplTest.java index d4c10ec..7b496a5 100644 --- a/src/test/java/GameResourceImplTest.java +++ b/src/test/java/GameResourceImplTest.java @@ -1,4 +1,3 @@ -import lol4j.exception.InvalidRegionException; import lol4j.protocol.dto.game.GameDto; import lol4j.protocol.dto.game.RecentGamesDto; import lol4j.util.Region; @@ -33,14 +32,4 @@ public void getRecentGames() { Assert.assertTrue(game.getIpEarned() >= 0); } } - - @Test(expected = InvalidRegionException.class) - public void getRecentGamesWithUnsupportedRegion() { - Lol4JTestClient.getClient().getRecentGames(Region.UNKNOWN, 0L); - } - - @Test(expected = InvalidRegionException.class) - public void getRecentGamesWithNullRegion() { - Lol4JTestClient.getClient().getRecentGames(null, 0L); - } } diff --git a/src/test/java/LeagueResourceImplTest.java b/src/test/java/LeagueResourceImplTest.java index 1fd4206..e3903a9 100644 --- a/src/test/java/LeagueResourceImplTest.java +++ b/src/test/java/LeagueResourceImplTest.java @@ -1,21 +1,38 @@ -import lol4j.exception.InvalidRegionException; import lol4j.exception.SubTypeMismatchException; import lol4j.protocol.dto.league.LeagueDto; -import lol4j.protocol.dto.league.LeagueItemDto; +import lol4j.protocol.dto.league.LeagueEntryDto; +import lol4j.protocol.resource.impl.LeagueResourceImpl; import lol4j.util.Region; import lol4j.util.game.SubType; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; +import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Random; /** * Created by Aaron Corley on 12/14/13. */ public class LeagueResourceImplTest { private static final long SUMMONER_ID = 19163557; + private static final long SUMMONER_ID_TWO = 20295494; + private static final String TEAM_ID = "TEAM-898cb9e0-e9e5-11e2-ab2b-782bcb4d0bb2"; // fragile! + private static final String TEAM_ID_TWO = "TEAM-30f02cb0-c3f0-11e2-8543-782bcb4d0bb2"; // fragile! private static final Region REGION = Region.NA; private static final SubType GAME_TYPE = SubType.RANKED_SOLO_5X5; + private static final List SUMMONER_ID_LIST = new ArrayList<>(); + private static final List TEAM_ID_LIST = new ArrayList<>(); + + @BeforeClass + public static void init() { + SUMMONER_ID_LIST.add(SUMMONER_ID); + SUMMONER_ID_LIST.add(SUMMONER_ID_TWO); + TEAM_ID_LIST.add(TEAM_ID); + TEAM_ID_LIST.add(TEAM_ID_TWO); + } @Test(expected = SubTypeMismatchException.class) public void getChallengerLeagueWithInvalidGameType() { @@ -27,16 +44,6 @@ public void getChallengerLeagueWithNullGameType() { Lol4JTestClient.getClient().getChallengerLeague(REGION, null); } - @Test(expected = InvalidRegionException.class) - public void getChallengerLeagueWithNullRegion() { - Lol4JTestClient.getClient().getChallengerLeague(null, SubType.NONE); - } - - @Test(expected = InvalidRegionException.class) - public void getChallengerLeagueWithUnsupportedRegion() { - Lol4JTestClient.getClient().getChallengerLeague(Region.UNKNOWN, SubType.NONE); - } - @Test public void getChallengerLeague() { LeagueDto league = Lol4JTestClient.getClient().getChallengerLeague(REGION, GAME_TYPE); @@ -49,31 +56,40 @@ public void getChallengerLeague() { Assert.assertNotEquals(league.getEntries().size(), 0); } - @Test(expected = InvalidRegionException.class) - public void getLeaguesEntryDataWithNullRegion() { - Lol4JTestClient.getClient().getLeaguesEntryData(SUMMONER_ID, null); - } - - @Test(expected = InvalidRegionException.class) - public void getLeaguesEntryDataWithUnsupportedRegion() { - Lol4JTestClient.getClient().getLeaguesEntryData(SUMMONER_ID, Region.UNKNOWN); - } - @Test public void getLeaguesEntryData() { - List leagueItems = Lol4JTestClient.getClient().getLeaguesEntryData(SUMMONER_ID, REGION); + List leagueItems = Lol4JTestClient.getClient().getLeaguesEntryData(SUMMONER_ID, REGION); Assert.assertNotNull(leagueItems); } - @Test(expected = InvalidRegionException.class) - public void getLeaguesDataWithNullRegion() { - Lol4JTestClient.getClient().getLeaguesData(SUMMONER_ID, null); + @Test(expected = IllegalArgumentException.class) + public void getLeaguesEntryDataMapWithNullList() { + Lol4JTestClient.getClient().getLeaguesEntryData(null, REGION); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesEntryDataMapWithEmptyList() { + Lol4JTestClient.getClient().getLeaguesEntryData(new ArrayList(), REGION); } - @Test(expected = InvalidRegionException.class) - public void getLeaguesDataWithUnsupportedRegion() { - Lol4JTestClient.getClient().getLeaguesData(SUMMONER_ID, Region.UNKNOWN); + @Test(expected = IllegalArgumentException.class) + public void getLeaguesEntryDataMapWithTooBigList() { + List tooBigList = new ArrayList<>(); + Random random = new Random(); + for (int i = 0; i < LeagueResourceImpl.MAX_LIST_SIZE + 1; i++) { + tooBigList.add(random.nextLong()); + } + Lol4JTestClient.getClient().getLeaguesEntryData(tooBigList, REGION); + } + + @Test + public void getLeaguesEntryDataMap() { + Map> map = Lol4JTestClient.getClient().getLeaguesEntryData(SUMMONER_ID_LIST, REGION); + + Assert.assertNotNull(map); + Assert.assertNotNull(map.get(Long.toString(SUMMONER_ID))); + Assert.assertNotNull(map.get(Long.toString(SUMMONER_ID_TWO))); } @Test @@ -91,4 +107,98 @@ public void getLeaguesData() { Assert.assertNotEquals(leagueData.getEntries().size(), 0); } } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesDataMapWithNullList() { + Lol4JTestClient.getClient().getLeaguesData(null, REGION); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesDataMapWithEmptyList() { + Lol4JTestClient.getClient().getLeaguesData(new ArrayList(), REGION); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesDataMapWithTooBigList() { + List tooBigList = new ArrayList<>(); + Random random = new Random(); + + for (int i = 0; i < LeagueResourceImpl.MAX_LIST_SIZE + 1; i++) { + tooBigList.add(random.nextLong()); + } + + Lol4JTestClient.getClient().getLeaguesData(tooBigList, REGION); + } + + @Test + public void getLeaguesDataMap() { + Map> map = Lol4JTestClient.getClient().getLeaguesData(SUMMONER_ID_LIST, REGION); + + Assert.assertNotNull(map); + Assert.assertNotNull(map.get(Long.toString(SUMMONER_ID))); + Assert.assertNotNull(map.get(Long.toString(SUMMONER_ID_TWO))); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesDataByTeamWithNullId() { + Lol4JTestClient.getClient().getLeaguesDataByTeam((String) null, REGION); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesDataByTeamWithEmptyId() { + Lol4JTestClient.getClient().getLeaguesDataByTeam("", REGION); + } + + @Test + public void getLeaguesDataByTeam() { + List data = Lol4JTestClient.getClient().getLeaguesDataByTeam(TEAM_ID, REGION); + + Assert.assertNotNull(data); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesEntryDataByTeamWithNullId() { + Lol4JTestClient.getClient().getLeaguesEntryDataByTeam((String) null, REGION); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesEntryDataByTeamWithEmptyId() { + Lol4JTestClient.getClient().getLeaguesEntryDataByTeam("", REGION); + } + + @Test + public void getLeaguesEntryDataByTeam() { + List data = Lol4JTestClient.getClient().getLeaguesEntryDataByTeam(TEAM_ID, REGION); + + Assert.assertNotNull(data); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesEntryDataMapByTeamWithNullList() { + Lol4JTestClient.getClient().getLeaguesEntryDataByTeam((List) null, REGION); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesEntryDataMapByTeamWithEmptyList() { + Lol4JTestClient.getClient().getLeaguesEntryDataByTeam(new ArrayList(), REGION); + } + + @Test(expected = IllegalArgumentException.class) + public void getLeaguesEntryDataMapByTeamWithTooBigList() { + List tooBigList = new ArrayList<>(); + Random random = new Random(); + + for (int i = 0; i < LeagueResourceImpl.MAX_LIST_SIZE + 1; i++) { + tooBigList.add(Long.toString(random.nextLong())); + } + + Lol4JTestClient.getClient().getLeaguesEntryDataByTeam(tooBigList, REGION); + } + + @Test + public void getLeaguesEntryDataMapByTeam() { + Map> map = Lol4JTestClient.getClient().getLeaguesEntryDataByTeam(TEAM_ID_LIST, REGION); + + Assert.assertNotNull(map); + } } diff --git a/src/test/java/Lol4JTestClient.java b/src/test/java/Lol4JTestClient.java index f0d5ec8..13eee08 100644 --- a/src/test/java/Lol4JTestClient.java +++ b/src/test/java/Lol4JTestClient.java @@ -12,7 +12,6 @@ public class Lol4JTestClient { private static Lol4JTestClient instance; - private String apiKey = null; private int numPerTenSeconds; private int numPerTenMinutes; private Lol4JClientImpl client = null; @@ -21,7 +20,7 @@ private Lol4JTestClient() { Properties p = new Properties(); try { p.load(new FileReader(new File("junit.properties"))); - apiKey = p.getProperty("api.key"); + String apiKey = p.getProperty("api.key"); numPerTenMinutes = Integer.parseInt(p.getProperty("rate.per10minutes")); numPerTenSeconds = Integer.parseInt(p.getProperty("rate.per10seconds")); client = new Lol4JClientImpl(apiKey); diff --git a/src/test/java/LolStaticDataResourceImplTest.java b/src/test/java/LolStaticDataResourceImplTest.java index 2083bf4..20064a2 100644 --- a/src/test/java/LolStaticDataResourceImplTest.java +++ b/src/test/java/LolStaticDataResourceImplTest.java @@ -1,4 +1,3 @@ -import lol4j.exception.InvalidRegionException; import lol4j.protocol.dto.lolstaticdata.*; import lol4j.util.Region; import lol4j.util.lolstaticdata.*; @@ -19,7 +18,7 @@ public class LolStaticDataResourceImplTest { private static final String CHAMP_ID = "35"; private static final String ITEM_ID = "1027"; private static final String MASTERY_ID = "4353"; - private static final String SUMMONER_SPELL_ID = "SummonerSmite"; + private static final int SUMMONER_SPELL_ID = 11; // SummonerSmite private static final List CHAMP_DATA = new ArrayList<>(); private static final List ITEM_DATA = new ArrayList<>(); private static final List MASTERY_DATA = new ArrayList<>(); @@ -35,16 +34,6 @@ public static void initializeTest() { SUMMONER_SPELL_DATA.add(SummonerSpellData.ALL); } - @Test(expected = InvalidRegionException.class) - public void getRuneWithUnsupportedRegion() { - Lol4JTestClient.getClient().getRune(RUNE_ID, Region.UNKNOWN, "en_US", null, RUNE_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getRuneWithNullRegion() { - Lol4JTestClient.getClient().getRune(RUNE_ID, null, "en_US", null, RUNE_DATA); - } - @Test public void getRune() { BasicDataDto rune = Lol4JTestClient.getClient().getRune(RUNE_ID, REGION, "en_US", null, RUNE_DATA); @@ -52,16 +41,6 @@ public void getRune() { Assert.assertNotNull(rune); } - @Test(expected = InvalidRegionException.class) - public void getChampionListWithUnsupportedRegion() { - Lol4JTestClient.getClient().getChampionList(Region.UNKNOWN, "en_US", null, CHAMP_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getChampionListWithNullRegion() { - Lol4JTestClient.getClient().getChampionList(null, "en_US", null, CHAMP_DATA); - } - @Test public void getChampionList() { ChampionListDto championList = Lol4JTestClient.getClient().getChampionList(REGION, "en_US", null, CHAMP_DATA); @@ -130,16 +109,6 @@ public void getChampionList() { Assert.assertNotNull(championList.getVersion()); } - @Test(expected = InvalidRegionException.class) - public void getChampionWithUnsupportedRegion() { - Lol4JTestClient.getClient().getChampion(CHAMP_ID, Region.UNKNOWN, "en_US", null, CHAMP_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getChampionWithNullRegion() { - Lol4JTestClient.getClient().getChampion(CHAMP_ID, null, "en_US", null, CHAMP_DATA); - } - @Test(expected = IllegalArgumentException.class) public void getChampionWithNullId() { Lol4JTestClient.getClient().getChampion(null, REGION, "en_US", null, CHAMP_DATA); @@ -208,16 +177,6 @@ public void getChampion() { Assert.assertNotNull(champion.getTitle()); } - @Test(expected = InvalidRegionException.class) - public void getItemWithUnsupportedRegion() { - Lol4JTestClient.getClient().getItem(ITEM_ID, Region.UNKNOWN, "en_US", null, ITEM_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getItemWithNullRegion() { - Lol4JTestClient.getClient().getItem(ITEM_ID, null, "en_US", null, ITEM_DATA); - } - @Test(expected = IllegalArgumentException.class) public void getItemWithNullId() { Lol4JTestClient.getClient().getItem(null, REGION, "en_US", null, ITEM_DATA); @@ -241,16 +200,6 @@ public void getItem() { Assert.assertNotNull(item.getStats()); } - @Test(expected = InvalidRegionException.class) - public void getItemsWithUnsupportedRegion() { - Lol4JTestClient.getClient().getItemList(Region.UNKNOWN, "en_US", null, ITEM_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getItemsWithNullRegion() { - Lol4JTestClient.getClient().getItemList(null, "en_US", null, ITEM_DATA); - } - @Test public void getItems() { ItemListDto itemList = Lol4JTestClient.getClient().getItemList(REGION, "en_US", null, ITEM_DATA); @@ -265,16 +214,6 @@ public void getItems() { Assert.assertNotNull(item.getStats()); } - @Test(expected = InvalidRegionException.class) - public void getMasteryWithUnsupportedRegion() { - Lol4JTestClient.getClient().getMastery(MASTERY_ID, Region.UNKNOWN, "en_US", null, MASTERY_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getMasteryWithNullRegion() { - Lol4JTestClient.getClient().getMastery(MASTERY_ID, null, "en_US", null, MASTERY_DATA); - } - @Test(expected = IllegalArgumentException.class) public void getMasteryWithNullId() { Lol4JTestClient.getClient().getMastery(null, REGION, "en_US", null, MASTERY_DATA); @@ -293,16 +232,6 @@ public void getMastery() { Assert.assertNotNull(mastery.getName()); } - @Test(expected = InvalidRegionException.class) - public void getMasteriesWithUnsupportedRegion() { - Lol4JTestClient.getClient().getMasteryList(Region.UNKNOWN, "en_US", null, MASTERY_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getMasteriesWithNullRegion() { - Lol4JTestClient.getClient().getMasteryList(null, "en_US", null, MASTERY_DATA); - } - @Test public void getMasteries() { MasteryListDto masteries = Lol4JTestClient.getClient().getMasteryList(REGION, "en_US", null, MASTERY_DATA); @@ -312,16 +241,6 @@ public void getMasteries() { Assert.assertNotNull(masteries.getVersion()); } - @Test(expected = InvalidRegionException.class) - public void getRealmWithUnsupportedRegion() { - Lol4JTestClient.getClient().getRealm(Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getRealmWithNullRegion() { - Lol4JTestClient.getClient().getRealm(null); - } - @Test public void getRealm() { RealmDto realm = Lol4JTestClient.getClient().getRealm(REGION); @@ -335,16 +254,6 @@ public void getRealm() { Assert.assertNotNull(realm.getVersion()); } - @Test(expected = InvalidRegionException.class) - public void getRunesWithUnsupportedRegion() { - Lol4JTestClient.getClient().getRuneList(Region.UNKNOWN, null, null, RUNE_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getRunesWithNullRegion() { - Lol4JTestClient.getClient().getRuneList(null, null, null, RUNE_DATA); - } - @Test public void getRunes() { RuneListDto runes = Lol4JTestClient.getClient().getRuneList(REGION, null, null, RUNE_DATA); @@ -352,16 +261,6 @@ public void getRunes() { Assert.assertNotNull(runes); } - @Test(expected = InvalidRegionException.class) - public void getSummonerSpellsWithUnsupportedRegion() { - Lol4JTestClient.getClient().getSummonerSpellList(Region.UNKNOWN, null, null, SUMMONER_SPELL_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getSummonerSpellsWithNullRegion() { - Lol4JTestClient.getClient().getSummonerSpellList(null, null, null, SUMMONER_SPELL_DATA); - } - @Test public void getSummonerSpells() { SummonerSpellListDto summonerSpells = Lol4JTestClient.getClient().getSummonerSpellList(REGION, null, null, SUMMONER_SPELL_DATA); @@ -369,16 +268,6 @@ public void getSummonerSpells() { Assert.assertNotNull(summonerSpells); } - @Test(expected = InvalidRegionException.class) - public void getSummonerSpellWithUnsupportedRegion() { - Lol4JTestClient.getClient().getSummonerSpell(SUMMONER_SPELL_ID, Region.UNKNOWN, null, null, SUMMONER_SPELL_DATA); - } - - @Test(expected = InvalidRegionException.class) - public void getSummonerSpellWithNullRegion() { - Lol4JTestClient.getClient().getSummonerSpell(SUMMONER_SPELL_ID, null, null, null, SUMMONER_SPELL_DATA); - } - @Test public void getSummonerSpell() { SummonerSpellDto summonerSpell = Lol4JTestClient.getClient().getSummonerSpell(SUMMONER_SPELL_ID, REGION, null, null, SUMMONER_SPELL_DATA); diff --git a/src/test/java/StatsResourceImplTest.java b/src/test/java/StatsResourceImplTest.java index 10bc2a4..80ac61d 100644 --- a/src/test/java/StatsResourceImplTest.java +++ b/src/test/java/StatsResourceImplTest.java @@ -1,4 +1,3 @@ -import lol4j.exception.InvalidRegionException; import lol4j.protocol.dto.stats.ChampionStatsDto; import lol4j.protocol.dto.stats.PlayerStatsSummaryDto; import lol4j.protocol.dto.stats.PlayerStatsSummaryListDto; @@ -16,16 +15,6 @@ public class StatsResourceImplTest { private static final Region REGION = Region.NA; private static final Season SEASON = Season.SEASON_3; - @Test(expected = InvalidRegionException.class) - public void getPlayerStatsSummariesWithUnsupportedRegion() { - Lol4JTestClient.getClient().getPlayerStatsSummaries(0L, Region.UNKNOWN, SEASON); - } - - @Test(expected = InvalidRegionException.class) - public void getPlayerStatsSummariesWithNullRegion() { - Lol4JTestClient.getClient().getPlayerStatsSummaries(0L, null, SEASON); - } - @Test public void getPlayerStatsSummaries() { PlayerStatsSummaryListDto playerStatsSummaryList = Lol4JTestClient.getClient() @@ -59,16 +48,6 @@ public void getPlayerStatsSummaries() { } } - @Test(expected = InvalidRegionException.class) - public void getRankedStatsWithUnsupportedRegion() { - Lol4JTestClient.getClient().getRankedStats(0L, Region.UNKNOWN, SEASON); - } - - @Test(expected = InvalidRegionException.class) - public void getRankedStatsWithNullRegion() { - Lol4JTestClient.getClient().getRankedStats(0L, null, SEASON); - } - @Test public void getRankedStats() { RankedStatsDto rankedStats = Lol4JTestClient.getClient().getRankedStats(SUMMONER_ID, REGION, SEASON); diff --git a/src/test/java/SummonerResourceImplTest.java b/src/test/java/SummonerResourceImplTest.java index d867e2b..0d2ff78 100644 --- a/src/test/java/SummonerResourceImplTest.java +++ b/src/test/java/SummonerResourceImplTest.java @@ -1,4 +1,3 @@ -import lol4j.exception.InvalidRegionException; import lol4j.protocol.dto.summoner.*; import lol4j.protocol.resource.impl.SummonerResourceImpl; import lol4j.util.Region; @@ -26,16 +25,6 @@ public static void initializeTest() { SUMMONER_NAMES.add(SUMMONER_NAME); } - @Test(expected = InvalidRegionException.class) - public void getMasteryPagesWithUnsupportedRegion() { - Lol4JTestClient.getClient().getMasteryPages(SUMMONER_IDS, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getMasteryPagesWithNullRegion() { - Lol4JTestClient.getClient().getMasteryPages(SUMMONER_IDS, null); - } - @Test(expected = IllegalArgumentException.class) public void getMasteryPagesWithNullList() { Lol4JTestClient.getClient().getMasteryPages(null, REGION); @@ -76,16 +65,6 @@ public void getMasteryPages() { } } - @Test(expected = InvalidRegionException.class) - public void getMasteryPagesSingleWithUnsupportedRegion() { - Lol4JTestClient.getClient().getMasteryPages(SUMMONER_ID, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getMasteryPagesSingleWithNullRegion() { - Lol4JTestClient.getClient().getMasteryPages(SUMMONER_ID, null); - } - @Test public void getMasteryPagesSingle() { MasteryPagesDto pages = Lol4JTestClient.getClient().getMasteryPages(SUMMONER_ID, REGION); @@ -100,16 +79,6 @@ public void getMasteryPagesSingle() { } } - @Test(expected = InvalidRegionException.class) - public void getRunePagesWithUnsupportedRegion() { - Lol4JTestClient.getClient().getRunePages(SUMMONER_IDS, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getRunePagesWithNullRegion() { - Lol4JTestClient.getClient().getRunePages(SUMMONER_IDS, null); - } - @Test(expected = IllegalArgumentException.class) public void getRunePagesWithNullList() { Lol4JTestClient.getClient().getRunePages(null, REGION); @@ -145,16 +114,6 @@ public void getRunePages() { } } - @Test(expected = InvalidRegionException.class) - public void getRunePagesSingleWithUnsupportedRegion() { - Lol4JTestClient.getClient().getRunePages(SUMMONER_ID, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getRunePagesSingleWithNullRegion() { - Lol4JTestClient.getClient().getRunePages(SUMMONER_ID, null); - } - @Test public void getRunePagesSingle() { RunePagesDto pages = Lol4JTestClient.getClient().getRunePages(SUMMONER_ID, REGION); @@ -164,16 +123,6 @@ public void getRunePagesSingle() { testRunePages(pages); } - @Test(expected = InvalidRegionException.class) - public void getSummonersByNameWithUnsupportedRegion() { - Lol4JTestClient.getClient().getSummonersByName(SUMMONER_NAMES, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getSummonersByNameWithNullRegion() { - Lol4JTestClient.getClient().getSummonersByName(SUMMONER_NAMES, null); - } - @Test(expected = IllegalArgumentException.class) public void getSummonersByNameWithNullList() { Lol4JTestClient.getClient().getSummonersByName(null, REGION); @@ -208,16 +157,6 @@ public void getSummonersByName() { } } - @Test(expected = InvalidRegionException.class) - public void getSummonerByNameWithUnsupportedRegion() { - Lol4JTestClient.getClient().getSummonerByName(SUMMONER_NAME, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getSummonerByNameWithNullRegion() { - Lol4JTestClient.getClient().getSummonerByName(SUMMONER_NAME, null); - } - @Test(expected = IllegalArgumentException.class) public void getSummonerByNameWithNullName() { Lol4JTestClient.getClient().getSummonerByName(null, REGION); @@ -236,16 +175,6 @@ public void getSummonerByName() { Assert.assertNotNull(summoner.getName()); } - @Test(expected = InvalidRegionException.class) - public void getSummonersWithUnsupportedRegion() { - Lol4JTestClient.getClient().getSummoners(SUMMONER_IDS, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getSummonersWithNullRegion() { - Lol4JTestClient.getClient().getSummoners(SUMMONER_IDS, null); - } - @Test(expected = IllegalArgumentException.class) public void getSummonersWithNullList() { Lol4JTestClient.getClient().getSummoners(null, REGION); @@ -280,16 +209,6 @@ public void getSummoners() { } } - @Test(expected = InvalidRegionException.class) - public void getSummonerWithUnsupportedRegion() { - Lol4JTestClient.getClient().getSummoner(SUMMONER_ID, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getSummonerWithNullRegion() { - Lol4JTestClient.getClient().getSummoner(SUMMONER_ID, null); - } - @Test public void getSummoner() { SummonerDto summoner = Lol4JTestClient.getClient().getSummoner(SUMMONER_ID, REGION); @@ -298,16 +217,6 @@ public void getSummoner() { Assert.assertNotNull(summoner.getName()); } - @Test(expected = InvalidRegionException.class) - public void getSummonerNamesWithUnsupportedRegion() { - Lol4JTestClient.getClient().getSummonerNames(SUMMONER_IDS, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getSummonerNamesWithNullRegion() { - Lol4JTestClient.getClient().getSummonerNames(SUMMONER_IDS, null); - } - @Test(expected = IllegalArgumentException.class) public void getSummonerNamesWithNullList() { Lol4JTestClient.getClient().getSummonerNames(null, REGION); @@ -341,16 +250,6 @@ public void getSummonerNames() { } } - @Test(expected = InvalidRegionException.class) - public void getSummonerNameWithUnsupportedRegion() { - Lol4JTestClient.getClient().getSummonerName(SUMMONER_ID, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getSummonerNameWithNullRegion() { - Lol4JTestClient.getClient().getSummonerName(SUMMONER_ID, null); - } - @Test public void getSummonerName() { String summonerName = Lol4JTestClient.getClient().getSummonerName(SUMMONER_ID, REGION); diff --git a/src/test/java/TeamResourceImplTest.java b/src/test/java/TeamResourceImplTest.java index 932fe2e..ddbdf55 100644 --- a/src/test/java/TeamResourceImplTest.java +++ b/src/test/java/TeamResourceImplTest.java @@ -1,4 +1,3 @@ -import lol4j.exception.InvalidRegionException; import lol4j.protocol.dto.team.MatchHistorySummaryDto; import lol4j.protocol.dto.team.TeamDto; import lol4j.protocol.dto.team.TeamMemberInfoDto; @@ -12,34 +11,29 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Random; /** * Created by Aaron Corley on 12/16/13. */ public class TeamResourceImplTest { private static final long SUMMONER_ID = 19163557; + private static final long SUMMONER_ID_TWO = 20295494; private static final String TEAM_ID = "TEAM-898cb9e0-e9e5-11e2-ab2b-782bcb4d0bb2"; private static final Region REGION = Region.NA; private static final List TEAM_IDS = new ArrayList<>(); + private static final List SUMMONER_IDS = new ArrayList<>(); @BeforeClass public static void initializeTest() { TEAM_IDS.add(TEAM_ID); - } - - @Test(expected = InvalidRegionException.class) - public void getTeamsBySummonerWithUnsupportedRegion() { - Lol4JTestClient.getClient().getTeams(SUMMONER_ID, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getTeamsBySummonerWithNullRegion() { - Lol4JTestClient.getClient().getTeams(SUMMONER_ID, null); + SUMMONER_IDS.add(SUMMONER_ID); + SUMMONER_IDS.add(SUMMONER_ID_TWO); } @Test public void getTeamsBySummoner() { - List teams = Lol4JTestClient.getClient().getTeams(SUMMONER_ID, REGION); + List teams = Lol4JTestClient.getClient().getTeamsBySummonerId(SUMMONER_ID, REGION); Assert.assertNotNull(teams); for (TeamDto team : teams) { @@ -54,9 +48,6 @@ public void getTeamsBySummoner() { Assert.assertNotNull(summary.getMap()); Assert.assertNotNull(summary.getOpposingTeamName()); } - if (team.getMessageOfDay() != null) { - Assert.assertNotNull(team.getMessageOfDay().getMessage()); - } Assert.assertNotNull(team.getModifyDate()); Assert.assertNotNull(team.getName()); Assert.assertNotNull(team.getRoster()); @@ -68,24 +59,37 @@ public void getTeamsBySummoner() { Assert.assertNotNull(team.getSecondLastJoinDate()); Assert.assertNotNull(team.getStatus()); Assert.assertNotNull(team.getTag()); - Assert.assertNotNull(team.getTeamStatSummary()); - Assert.assertNotNull(team.getTeamStatSummary().getFullId()); - for (TeamStatDetailDto stat : team.getTeamStatSummary().getTeamStatDetails()) { - Assert.assertNotNull(stat.getFullId()); - Assert.assertNotNull(stat.getTeamStatType()); - } Assert.assertNotNull(team.getThirdLastJoinDate()); } } - - @Test(expected = InvalidRegionException.class) - public void getTeamsWithUnsupportedRegion() { - Lol4JTestClient.getClient().getTeams(TEAM_IDS, Region.UNKNOWN); + + @Test(expected = IllegalArgumentException.class) + public void getTeamsMapBySummonerWithNullList() { + Lol4JTestClient.getClient().getTeamsBySummonerId(null, REGION); } - @Test(expected = InvalidRegionException.class) - public void getTeamsWithNullRegion() { - Lol4JTestClient.getClient().getTeams(TEAM_IDS, null); + @Test(expected = IllegalArgumentException.class) + public void getTeamsMapBySummonerWithEmptyList() { + Lol4JTestClient.getClient().getTeamsBySummonerId(new ArrayList(), REGION); + } + + @Test(expected = IllegalArgumentException.class) + public void getTeamsMapBySummonerWithBigList() { + List big = new ArrayList<>(); + Random random = new Random(); + + for (int i = 0; i < TeamResourceImpl.MAX_LIST_SIZE + 1; i++) { + big.add(random.nextLong()); + } + Lol4JTestClient.getClient().getTeamsBySummonerId(big, REGION); + } + + @Test + public void getTeamsMapBySummoner() { + Map> map = Lol4JTestClient.getClient().getTeamsBySummonerId(SUMMONER_IDS, REGION); + + Assert.assertNotNull(map); + Assert.assertNotNull(map.get(Long.toString(SUMMONER_ID))); } @Test(expected = IllegalArgumentException.class) @@ -130,9 +134,6 @@ public void getTeams() { Assert.assertNotNull(summary.getMap()); Assert.assertNotNull(summary.getOpposingTeamName()); } - if (team.getMessageOfDay() != null) { - Assert.assertNotNull(team.getMessageOfDay().getMessage()); - } Assert.assertNotNull(team.getModifyDate()); Assert.assertNotNull(team.getName()); Assert.assertNotNull(team.getRoster()); @@ -144,26 +145,10 @@ public void getTeams() { Assert.assertNotNull(team.getSecondLastJoinDate()); Assert.assertNotNull(team.getStatus()); Assert.assertNotNull(team.getTag()); - Assert.assertNotNull(team.getTeamStatSummary()); - Assert.assertNotNull(team.getTeamStatSummary().getFullId()); - for (TeamStatDetailDto stat : team.getTeamStatSummary().getTeamStatDetails()) { - Assert.assertNotNull(stat.getFullId()); - Assert.assertNotNull(stat.getTeamStatType()); - } Assert.assertNotNull(team.getThirdLastJoinDate()); } } - @Test(expected = InvalidRegionException.class) - public void getTeamWithUnsupportedRegion() { - Lol4JTestClient.getClient().getTeam(TEAM_ID, Region.UNKNOWN); - } - - @Test(expected = InvalidRegionException.class) - public void getTeamWithNullRegion() { - Lol4JTestClient.getClient().getTeam(TEAM_ID, null); - } - @Test public void getTeam() { TeamDto team = Lol4JTestClient.getClient().getTeam(TEAM_ID, REGION); @@ -180,9 +165,6 @@ public void getTeam() { Assert.assertNotNull(summary.getMap()); Assert.assertNotNull(summary.getOpposingTeamName()); } - if (team.getMessageOfDay() != null) { - Assert.assertNotNull(team.getMessageOfDay().getMessage()); - } Assert.assertNotNull(team.getModifyDate()); Assert.assertNotNull(team.getName()); Assert.assertNotNull(team.getRoster()); @@ -194,12 +176,6 @@ public void getTeam() { Assert.assertNotNull(team.getSecondLastJoinDate()); Assert.assertNotNull(team.getStatus()); Assert.assertNotNull(team.getTag()); - Assert.assertNotNull(team.getTeamStatSummary()); - Assert.assertNotNull(team.getTeamStatSummary().getFullId()); - for (TeamStatDetailDto stat : team.getTeamStatSummary().getTeamStatDetails()) { - Assert.assertNotNull(stat.getFullId()); - Assert.assertNotNull(stat.getTeamStatType()); - } Assert.assertNotNull(team.getThirdLastJoinDate()); } }