Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected ResponseEntity <Set<FindAllBooksDTO>> findAllBooks () {
@GetMapping("/search")
protected ResponseEntity <List<Object>> searchBooks (@RequestBody @Valid SearchBooksDTO books) {

List <Object> result = openLibraryService.search(books);
var result = openLibraryService.search(books);

return ResponseEntity.status(HttpStatus.OK).body(result);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.book.store.athena.controllers;

import com.book.store.athena.api.OpenLibraryService;
import com.book.store.athena.model.dto.books.SearchBooksDTO;
import com.book.store.athena.model.dto.books.UpdateBooksDTO;
import com.book.store.athena.services.BooksService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -14,7 +16,6 @@
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;


import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand Down Expand Up @@ -66,6 +67,22 @@ void getAllBooks_Test () throws Exception {

}

@Test
void searchBooks_Test () throws Exception {

SearchBooksDTO searchBooksDTO = new SearchBooksDTO("Tolkien");

Mockito.when(openLibraryService.search(searchBooksDTO)).thenReturn(Mockito.anyList());

mockMvc.perform(get("/books/search")
.content(new ObjectMapper().writeValueAsString(searchBooksDTO))
.contentType("application/json"))
.andExpect(status().isOk());

Mockito.verify(openLibraryService, Mockito.times(1)).search(searchBooksDTO);

}

@Test
void updateBookById_Test () throws Exception {

Expand Down