Search in sources :

Example 1 with BookSearchResult

use of com.aidanwhiteley.books.domain.googlebooks.BookSearchResult in project books by aidanwhiteley.

the class GoogleBooksDaoSycTest method findByTitle.

@Test
public void findByTitle() {
    BookSearchResult result = theDao.searchGoogBooksByTitle("Design Patterns");
    assertNotNull(result);
    assertTrue("Should have found result items", result.getItems().size() > 0);
    assertTrue("Should have found a book id", result.getItems().get(0).getId().length() > 0);
    assertTrue("Should have found a title", result.getItems().get(0).getVolumeInfo().getTitle().length() > 0);
}
Also used : BookSearchResult(com.aidanwhiteley.books.domain.googlebooks.BookSearchResult) IntegrationTest(com.aidanwhiteley.books.util.IntegrationTest) Test(org.junit.Test)

Example 2 with BookSearchResult

use of com.aidanwhiteley.books.domain.googlebooks.BookSearchResult in project books by aidanwhiteley.

the class GoogleBooksDaoSyncTest method findByTitle.

@Test
void findByTitle() {
    BookSearchResult result = theDao.searchGoogBooksByTitle("Design Patterns");
    assertNotNull(result);
    assertEquals(NUMBER_OF_BOOKS_IN_SEARCH_RESULTS, result.getItems().size());
    assertTrue(result.getItems().get(0).getId().length() > 0, "Should have found a book id");
    assertTrue(result.getItems().get(0).getVolumeInfo().getTitle().length() > 0, "Should have found a title");
}
Also used : BookSearchResult(com.aidanwhiteley.books.domain.googlebooks.BookSearchResult) Test(org.junit.jupiter.api.Test) IntegrationTest(com.aidanwhiteley.books.util.IntegrationTest)

Example 3 with BookSearchResult

use of com.aidanwhiteley.books.domain.googlebooks.BookSearchResult in project books by aidanwhiteley.

the class GoogleBooksDaoSync method searchGoogBooksByTitle.

public BookSearchResult searchGoogBooksByTitle(String title) {
    String encodedTitle;
    encodedTitle = URLEncoder.encode(title, StandardCharsets.UTF_8);
    googleBooksRestTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
    final String searchString = googleBooksApiConfig.getSearchUrl() + encodedTitle + "&" + googleBooksApiConfig.getCountryCode() + "&" + googleBooksApiConfig.getMaxResults();
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Google Books API called with API called: {}", searchString);
    }
    BookSearchResult result = googleBooksRestTemplate.getForObject(searchString, BookSearchResult.class);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Result of Google Books API call: {}", result);
    }
    return result;
}
Also used : BookSearchResult(com.aidanwhiteley.books.domain.googlebooks.BookSearchResult) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Aggregations

BookSearchResult (com.aidanwhiteley.books.domain.googlebooks.BookSearchResult)3 IntegrationTest (com.aidanwhiteley.books.util.IntegrationTest)2 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1