Commit 05254971 authored by Khalid Ali's avatar Khalid Ali
Browse files

Test DELETE request on controller

parent be141e7d
...@@ -25,8 +25,7 @@ import static org.hamcrest.Matchers.is; ...@@ -25,8 +25,7 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
...@@ -104,4 +103,20 @@ public class BookshareRestControllerIntegrationTest { ...@@ -104,4 +103,20 @@ public class BookshareRestControllerIntegrationTest {
.content(JsonUtil.writeValueAsString(listingDtoNotInDB))) .content(JsonUtil.writeValueAsString(listingDtoNotInDB)))
.andExpect(status().isNotFound()); .andExpect(status().isNotFound());
} }
@Test
public void givenListing_whenDeleteListing_thenReturnHttpOk() throws Exception {
ListingEntity listingInDB = new ListingEntity(123456, 3, 14.99,
new Date(), 192838079872L, 2879878394L, "Title Calc 3");
listingInDB.setId(1324L);
ListingDto listingDtoInDB = modelMapper.map(listingInDB, ListingDto.class);
given(listingService.getById(listingInDB.getId())).willReturn(listingInDB);
mvc.perform(delete("/bs/api/listing/" + listingInDB.getId())
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(JsonUtil.writeValueAsString(listingDtoInDB)))
.andExpect(status().isOk());
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment