ComicApiClient extends MarvelApiClient { public MarvelResponse<ComicsDto> getAll(int offset, int limit) throws MarvelApiException { ComicsQuery query = ComicsQuery.Builder.create().withOffset(offset).withLimit(limit).build(); return getAll(query); } ComicApiClient(MarvelApiConfig marvelApiConfig); MarvelResponse<ComicsDto> getAll(int offset, int limit); MarvelResponse<ComicsDto> getAll(ComicsQuery comicsQuery); MarvelResponse<ComicDto> getComic(String comicId);  }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenLimitIsZero() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse(); comicApiClient.getAll(ANY_OFFSET, INVALID_LIMIT); }
@Test public void shouldUseAllTheRequestParamsAddedFromQueryWhenSendIt() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse(); ComicsQuery query = ComicsQuery.Builder.create() .withFormat(Format.COMIC) .withFormatType(ComicsQuery.FormatType.COLLECTION) .withNoVariants() .withDateDescriptor(ComicsQuery.DateDescriptor.LAST_WEEK) .withDateRange(getAnyDate()) .withTitle(ANY_TITLE) .withTitleStartsWith(ANY_START_TITLE) .withStartYear(ANY_START_YEAR) .withIssueNumber(ANY_ISSUE_NUMBER) .withDiamondCode(ANY_DIAMOND_CODE) .withUpc(ANY_UPC) .withIsbn(ANY_ISBN) .withEan(ANY_EAN) .withIssn(ANY_ISSN) .withHasDigitalIssue() .withLimit(ANY_LIMIT) .withOffset(ANY_OFFSET) .addCreator(ANY_CREATOR) .addCharacter(ANY_CHARACTER) .withModifiedSince(getAnyDate()) .withOrderBy(OrderBy.NAME, false) .addEvent(getAnyEvents()) .addSerie(ANY_SERIE) .addStory(ANY_STORY) .addSharedAppearance(ANY_SHARED_APPEARANCES) .addCollaborator(getAnyCollaborators()) .build(); comicApiClient.getAll(query); assertRequestSentToContains("format=" + Format.COMIC.toString(), "formatType=" + ComicsQuery.FormatType.COLLECTION, "noVariants=true", "dateDescriptor=" + LAST_WEEK_REQUEST, "dateRange=" + ANY_DATE_RANGE, "startYear=" + ANY_START_YEAR, "issueNumber=" + ANY_ISSUE_NUMBER, "diamondCode=" + ANY_DIAMOND_CODE, "upc=" + ANY_UPC, "isbn=" + ANY_ISBN, "ean=" + ANY_EAN, "issn=" + ANY_ISSN, "hasDigitalIssue=true", "creators=" + ANY_CREATOR, "characters=" + ANY_CHARACTER, "offset=" + ANY_OFFSET, "appearances=" + ANY_SHARED_APPEARANCES, "collaborators=" + COLLABORATORS_REQUEST, "limit=" + ANY_LIMIT, "title=" + ANY_TITLE, "titleStartsWith=" + ANY_START_TITLE, "modifiedSince=" + ANY_MODIFIED_SINCE, "orderBy=" + ORDER_NAME_DESCEDANT_VALUE, "events=" + EVENTS_REQUEST, "series=" + ANY_SERIE, "stories=" + ANY_STORY); }
@Test(expected = MarvelAuthApiException.class) public void shouldThrowMarvelApiExceptionOnAuthHttpError() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse(401, "{\"code\":\"InvalidCredentials\",\"message\":\"That hash, timestamp and key " + "combination is invalid.\"}"); try { comicApiClient.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 shouldParseGetAllComicsResponse() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse("getComics.json"); MarvelResponse<ComicsDto> comics = comicApiClient.getAll(0, ANY_LIMIT); assertBasicMarvelResponse(comics); assertGetAllComicsResponseIsProperlyParsed(comics); }
@Test public void shouldRequestComicsByOffsetAndLimitWithAsParams() throws Exception { ComicApiClient comicApiClient = givenComicApiClient(); enqueueMockResponse(); comicApiClient.getAll(ANY_OFFSET, ANY_LIMIT); assertRequestSentToContains("offset=" + ANY_OFFSET, "limit=" + ANY_LIMIT); }