5
5
import io .pillopl .library .lending .LendingTestContext ;
6
6
import io .pillopl .library .lending .book .model .BookFixture ;
7
7
import io .pillopl .library .lending .patron .application .hold .CancelingHold ;
8
+ import io .pillopl .library .lending .patron .application .hold .PlacingOnHold ;
8
9
import io .pillopl .library .lending .patron .model .PatronFixture ;
9
10
import io .pillopl .library .lending .patron .model .PatronId ;
10
11
import io .pillopl .library .lending .patronprofile .model .Checkout ;
20
21
import org .springframework .boot .test .autoconfigure .web .servlet .WebMvcTest ;
21
22
import org .springframework .boot .test .mock .mockito .MockBean ;
22
23
import org .springframework .hateoas .MediaTypes ;
24
+ import org .springframework .http .MediaType ;
23
25
import org .springframework .test .context .ContextConfiguration ;
24
26
import org .springframework .test .context .junit4 .SpringRunner ;
25
27
import org .springframework .test .web .servlet .MockMvc ;
37
39
import static org .springframework .http .HttpHeaders .CONTENT_TYPE ;
38
40
import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .delete ;
39
41
import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
42
+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
40
43
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .header ;
41
44
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
42
45
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
@@ -60,6 +63,9 @@ public class PatronProfileControllerIT {
60
63
@ MockBean
61
64
private PatronProfiles patronProfiles ;
62
65
66
+ @ MockBean
67
+ private PlacingOnHold placingOnHold ;
68
+
63
69
@ MockBean
64
70
private CancelingHold cancelingHold ;
65
71
@@ -160,6 +166,32 @@ public void shouldReturnResourceForCheckout() throws Exception {
160
166
.andExpect (jsonPath ("$._links.self.href" , containsString ("profiles/" + patronId .getPatronId () + "/checkouts/" + anotherBook .getBookId ())));
161
167
}
162
168
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
+
163
195
@ Test
164
196
public void shouldCancelExistingHold () throws Exception {
165
197
given (patronProfiles .fetchFor (patronId )).willReturn (profiles ());
@@ -199,4 +231,4 @@ PatronProfile profiles() {
199
231
new HoldsView (of (new Hold (bookId , anyDate ))),
200
232
new CheckoutsView (of (new Checkout (anotherBook , anotherDate ))));
201
233
}
202
- }
234
+ }
0 commit comments