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 ;
3739import static org .springframework .http .HttpHeaders .CONTENT_TYPE ;
3840import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .delete ;
3941import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
42+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
4043import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .header ;
4144import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
4245import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
@@ -60,6 +63,9 @@ public class PatronProfileControllerIT {
6063 @ MockBean
6164 private PatronProfiles patronProfiles ;
6265
66+ @ MockBean
67+ private PlacingOnHold placingOnHold ;
68+
6369 @ MockBean
6470 private CancelingHold cancelingHold ;
6571
@@ -160,6 +166,32 @@ public void shouldReturnResourceForCheckout() throws Exception {
160166 .andExpect (jsonPath ("$._links.self.href" , containsString ("profiles/" + patronId .getPatronId () + "/checkouts/" + anotherBook .getBookId ())));
161167 }
162168
169+ @ Test
170+ public void shouldPlaceBookOnHold () throws Exception {
171+ given (placingOnHold .placeOnHold (any ())).willReturn (Try .success (Success ));
172+ var request = "{\" bookId\" :\" 6e1dfec5-5cfe-487e-814e-d70114f5396e\" , \" libraryBranchId\" :\" a518e2ef-5f6c-43e3-a7fc-5d895e15be3a\" ,\" numberOfDays\" :1}" ;
173+
174+ // expect
175+ mvc .perform (post ("/profiles/" + patronId .getPatronId () + "/holds" )
176+ .accept (MediaTypes .HAL_FORMS_JSON_VALUE )
177+ .contentType (MediaType .APPLICATION_JSON )
178+ .content (request ))
179+ .andExpect (status ().isOk ());
180+ }
181+
182+ @ Test
183+ public void shouldReturn500IfSomethingFailedWhileDuringPlacingOnHold () throws Exception {
184+ given (placingOnHold .placeOnHold (any ())).willReturn (Try .failure (new IllegalArgumentException ()));
185+ var request = "{\" bookId\" :\" 6e1dfec5-5cfe-487e-814e-d70114f5396e\" , \" libraryBranchId\" :\" a518e2ef-5f6c-43e3-a7fc-5d895e15be3a\" ,\" numberOfDays\" :1}" ;
186+
187+ // expect
188+ mvc .perform (post ("/profiles/" + patronId .getPatronId () + "/holds" )
189+ .accept (MediaTypes .HAL_FORMS_JSON_VALUE )
190+ .contentType (MediaType .APPLICATION_JSON )
191+ .content (request ))
192+ .andExpect (status ().isInternalServerError ());
193+ }
194+
163195 @ Test
164196 public void shouldCancelExistingHold () throws Exception {
165197 given (patronProfiles .fetchFor (patronId )).willReturn (profiles ());
@@ -199,4 +231,4 @@ PatronProfile profiles() {
199231 new HoldsView (of (new Hold (bookId , anyDate ))),
200232 new CheckoutsView (of (new Checkout (anotherBook , anotherDate ))));
201233 }
202- }
234+ }
0 commit comments