SeriesApiClient extends MarvelApiClient { public MarvelResponse<SeriesCollectionDto> getAll(int offset, int limit) throws MarvelApiException { SeriesQuery query = SeriesQuery.Builder.create().withOffset(offset).withLimit(limit).build(); return getAll(query); } SeriesApiClient(MarvelApiConfig marvelApiConfig); MarvelResponse<SeriesCollectionDto> getAll(int offset, int limit); MarvelResponse<SeriesCollectionDto> getAll(SeriesQuery seriesQuery); MarvelResponse<SeriesDto> getSeriesById(String seriesId); MarvelResponse<ComicsDto> getComicsBySeries(String seriesId, int offset, int limit); MarvelResponse<ComicsDto> getComicsBySeries(String seriesId, ComicsQuery comicsQuery);  }
@Test public void shouldSendOffsetAsLimitAsParamsWhenGetAll() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(); seriesApiClient.getAll(ANY_OFFSET, ANY_LIMIT); assertRequestSentToContains("offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenLimitIsZero() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(); seriesApiClient.getAll(ANY_OFFSET, INVALID_LIMIT); }
@Test public void shouldUseAllTheRequestParamsAddedFromQueryWhenSendIt() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(); SeriesQuery query = SeriesQuery.Builder.create() .withTitle(ANY_TITLE) .withTitleStartsWith(ANY_START_TITLE) .withStartYear(ANY_START_YEAR) .withLimit(ANY_LIMIT) .withOffset(ANY_OFFSET) .addCreator(ANY_CREATOR) .addCharacter(ANY_CHARACTER) .withModifiedSince(getAnyDate()) .withOrderBy(OrderBy.NAME, false) .addEvent(getAnyEvents()) .addComic(ANY_COMIC) .addStory(ANY_STORY) .withContains(Format.COMIC) .withSeriesType(SeriesQuery.SeriesType.COLLECTION) .build(); seriesApiClient.getAll(query); assertRequestSentToContains("startYear=" + ANY_START_YEAR, "creators=" + ANY_CREATOR, "characters=" + ANY_CHARACTER, "offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT, "title=" + ANY_TITLE, "titleStartsWith=" + ANY_START_TITLE, "modifiedSince=" + ANY_MODIFIED_SINCE, "orderBy=" + ORDER_NAME_DESCEDANT_VALUE, "events=" + EVENTS_REQUEST, "comics=" + ANY_COMIC, "stories=" + ANY_STORY, "contains=" + Format.COMIC.toString(), "seriesType=" + SeriesQuery.SeriesType.COLLECTION.toString()); }
@Test(expected = MarvelAuthApiException.class) public void shouldThrowMarvelApiExceptionOnAuthHttpError() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse(401, "{\"code\":\"InvalidCredentials\",\"message\":\"That hash, timestamp and key " + "combination is invalid.\"}"); try { seriesApiClient.getAll(ANY_OFFSET, ANY_LIMIT); } catch (MarvelApiException e) { assertEquals("InvalidCredentials", e.getMarvelCode()); assertEquals("That hash, timestamp and key combination is invalid.", e.getMessage()); throw e; } }
@Test public void shouldParseGetAllSeriesResponse() throws Exception { SeriesApiClient seriesApiClient = givenSeriesApiClient(); enqueueMockResponse("getSeriesCollection.json"); MarvelResponse<SeriesCollectionDto> series = seriesApiClient.getAll(0, ANY_LIMIT); assertBasicMarvelResponse(series); assertGetAllSeriesResponseIsProperlyParsed(series); }