55import io .pillopl .library .lending .LendingTestContext ;
66import io .pillopl .library .lending .book .model .BookFixture ;
77import io .pillopl .library .lending .patron .application .hold .CancelingHold ;
8+ import io .pillopl .library .lending .patron .application .hold .PlacingOnHold ;
89import io .pillopl .library .lending .patron .model .PatronFixture ;
910import io .pillopl .library .lending .patron .model .PatronId ;
1011import io .pillopl .library .lending .patronprofile .model .Checkout ;
2021import org .springframework .boot .test .autoconfigure .web .servlet .WebMvcTest ;
2122import org .springframework .boot .test .mock .mockito .MockBean ;
2223import org .springframework .hateoas .MediaTypes ;
24+ import org .springframework .http .MediaType ;
2325import org .springframework .test .context .ContextConfiguration ;
2426import org .springframework .test .context .junit4 .SpringRunner ;
2527import org .springframework .test .web .servlet .MockMvc ;
3537import static org .mockito .ArgumentMatchers .any ;
3638import static org .mockito .BDDMockito .given ;
3739import static org .springframework .http .HttpHeaders .CONTENT_TYPE ;
38- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .delete ;
39- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
40+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
4041import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .header ;
4142import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
4243import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
@@ -60,6 +61,9 @@ public class PatronProfileControllerIT {
6061 @ MockBean
6162 private PatronProfiles patronProfiles ;
6263
64+ @ MockBean
65+ private PlacingOnHold placingOnHold ;
66+
6367 @ MockBean
6468 private CancelingHold cancelingHold ;
6569
@@ -160,6 +164,33 @@ public void shouldReturnResourceForCheckout() throws Exception {
160164 .andExpect (jsonPath ("$._links.self.href" , containsString ("profiles/" + patronId .getPatronId () + "/checkouts/" + anotherBook .getBookId ())));
161165 }
162166
167+ @ Test
168+ public void shouldPlaceBookOnHold () throws Exception {
169+ given (placingOnHold .placeOnHold (any ())).willReturn (Try .success (Success ));
170+ var request = "{\" bookId\" :\" 6e1dfec5-5cfe-487e-814e-d70114f5396e\" , \" libraryBranchId\" :\" a518e2ef-5f6c-43e3-a7fc-5d895e15be3a\" ,\" numberOfDays\" :1}" ;
171+
172+ // expect
173+ mvc .perform (post ("/profiles/" + patronId .getPatronId () + "/holds" )
174+ .accept (MediaTypes .HAL_FORMS_JSON_VALUE )
175+ .contentType (MediaType .APPLICATION_JSON )
176+ .content (request ))
177+ .andExpect (status ().isOk ());
178+ }
179+
180+ @ Test
181+ public void shouldReturn500IfSomethingFailedWhileDuringPlacingOnHold () throws Exception {
182+ given (placingOnHold .placeOnHold (any ())).willReturn (Try .failure (new IllegalArgumentException ()));
183+ var request = "{\" bookId\" :\" 6e1dfec5-5cfe-487e-814e-d70114f5396e\" , \" libraryBranchId\" :\" a518e2ef-5f6c-43e3-a7fc-5d895e15be3a\" ,\" numberOfDays\" :1}" ;
184+
185+
186+ // expect
187+ mvc .perform (post ("/profiles/" + patronId .getPatronId () + "/holds" )
188+ .accept (MediaTypes .HAL_FORMS_JSON_VALUE )
189+ .contentType (MediaType .APPLICATION_JSON )
190+ .content (request ))
191+ .andExpect (status ().isInternalServerError ());
192+ }
193+
163194 @ Test
164195 public void shouldCancelExistingHold () throws Exception {
165196 given (patronProfiles .fetchFor (patronId )).willReturn (profiles ());
@@ -199,4 +230,4 @@ PatronProfile profiles() {
199230 new HoldsView (of (new Hold (bookId , anyDate ))),
200231 new CheckoutsView (of (new Checkout (anotherBook , anotherDate ))));
201232 }
202- }
233+ }
0 commit comments