44import static org .hamcrest .Matchers .greaterThan ;
55import static org .hamcrest .Matchers .is ;
66import static org .junit .jupiter .api .Assertions .assertEquals ;
7+ import static org .springframework .security .test .web .servlet .request .SecurityMockMvcRequestPostProcessors .csrf ;
78import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .delete ;
89import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
910import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .put ;
@@ -105,6 +106,7 @@ void put_persistsRecomputesBumpsRevision_ignoresDerived_leavesItemizedRows() thr
105106 mockMvc .perform (put (ENDPOINT )
106107 .param ("millId" , "518" ).param ("year" , "2021" )
107108 .contentType (MediaType .APPLICATION_JSON ).content (body )
109+ .with (csrf ())
108110 .accept (MediaType .APPLICATION_JSON ))
109111 .andExpect (status ().isOk ())
110112 .andExpect (content ().contentTypeCompatibleWith (MediaType .APPLICATION_JSON ))
@@ -203,7 +205,8 @@ private void expect400NothingPersisted(String body, String verbatimDetail) throw
203205 int before = revisionOf (1018 );
204206 mockMvc .perform (put (ENDPOINT )
205207 .param ("millId" , "518" ).param ("year" , "2021" )
206- .contentType (MediaType .APPLICATION_JSON ).content (body ))
208+ .contentType (MediaType .APPLICATION_JSON ).content (body )
209+ .with (csrf ()))
207210 .andExpect (status ().isBadRequest ())
208211 .andExpect (content ().contentTypeCompatibleWith ("application/problem+json" ))
209212 .andExpect (jsonPath ("$.detail" , is (verbatimDetail )));
@@ -218,7 +221,8 @@ void put_nonDraft_returns409() throws Exception {
218221 int before = revisionOf (1017 );
219222 mockMvc .perform (put (ENDPOINT )
220223 .param ("millId" , "517" ).param ("year" , "2021" )
221- .contentType (MediaType .APPLICATION_JSON ).content (validBody (before )))
224+ .contentType (MediaType .APPLICATION_JSON ).content (validBody (before ))
225+ .with (csrf ()))
222226 .andExpect (status ().isConflict ())
223227 .andExpect (content ().contentTypeCompatibleWith ("application/problem+json" ))
224228 .andExpect (jsonPath ("$.detail" , is ("This schedule cannot be edited in its current status." )));
@@ -228,7 +232,8 @@ void put_nonDraft_returns409() throws Exception {
228232 @ Test
229233 @ DisplayName ("S22-write — DELETE against non-Draft (mill 517, track S) -> 409, row survives" )
230234 void delete_nonDraft_returns409 () throws Exception {
231- mockMvc .perform (delete (ENDPOINT ).param ("millId" , "517" ).param ("year" , "2021" ))
235+ mockMvc .perform (delete (ENDPOINT ).param ("millId" , "517" ).param ("year" , "2021" )
236+ .with (csrf ()))
232237 .andExpect (status ().isConflict ())
233238 .andExpect (jsonPath ("$.detail" , is ("This schedule cannot be edited in its current status." )));
234239 assertEquals (1 , JdbcTestUtils .countRowsInTableWhere (jdbcTemplate , SUMMARY ,
@@ -240,7 +245,8 @@ void delete_nonDraft_returns409() throws Exception {
240245 @ Test
241246 @ DisplayName ("S13 — 519 Draft DELETE 200 (SUC-002) removes summary + all details; re-GET 404" )
242247 void delete_removesWholeSchedule () throws Exception {
243- mockMvc .perform (delete (ENDPOINT ).param ("millId" , "519" ).param ("year" , "2021" ))
248+ mockMvc .perform (delete (ENDPOINT ).param ("millId" , "519" ).param ("year" , "2021" )
249+ .with (csrf ()))
244250 .andExpect (status ().isOk ())
245251 .andExpect (jsonPath ("$.message.text" , is ("Data deleted successfully" )));
246252 assertEquals (0 , JdbcTestUtils .countRowsInTableWhere (jdbcTemplate , SUMMARY ,
@@ -263,21 +269,24 @@ void put_staleRevision_returns409_thenRetrySucceeds() throws Exception {
263269 // First writer wins (N -> N+1).
264270 mockMvc .perform (put (ENDPOINT )
265271 .param ("millId" , "520" ).param ("year" , "2021" )
266- .contentType (MediaType .APPLICATION_JSON ).content (validBody (n )))
272+ .contentType (MediaType .APPLICATION_JSON ).content (validBody (n ))
273+ .with (csrf ()))
267274 .andExpect (status ().isOk ())
268275 .andExpect (jsonPath ("$.revisionCount" , is (n + 1 )));
269276 // Second writer still holds the stale token N -> rejected, no overwrite.
270277 mockMvc .perform (put (ENDPOINT )
271278 .param ("millId" , "520" ).param ("year" , "2021" )
272- .contentType (MediaType .APPLICATION_JSON ).content (validBody (n )))
279+ .contentType (MediaType .APPLICATION_JSON ).content (validBody (n ))
280+ .with (csrf ()))
273281 .andExpect (status ().isConflict ())
274282 .andExpect (content ().contentTypeCompatibleWith ("application/problem+json" ))
275283 .andExpect (jsonPath ("$.detail" , is ("This schedule was changed by another user. Please reload and try again." )));
276284 assertEquals (n + 1 , revisionOf (1020 ), "the stale PUT must not overwrite" );
277285 // Reload the fresh token and retry -> succeeds.
278286 mockMvc .perform (put (ENDPOINT )
279287 .param ("millId" , "520" ).param ("year" , "2021" )
280- .contentType (MediaType .APPLICATION_JSON ).content (validBody (n + 1 )))
288+ .contentType (MediaType .APPLICATION_JSON ).content (validBody (n + 1 ))
289+ .with (csrf ()))
281290 .andExpect (status ().isOk ())
282291 .andExpect (jsonPath ("$.revisionCount" , is (greaterThan (n + 1 ))));
283292 }
0 commit comments