2525@ TestInstance (Lifecycle .PER_CLASS )
2626class TaskServiceIT {
2727
28- private Integer taskListId ;
28+ private Integer taskListId ;
2929
30- private Integer taskItemId ;
30+ private Integer taskItemId ;
3131
32- private String token ;
32+ private String token ;
3333
34- @ BeforeAll
35- void getJwt (){
36- token = KeycloakTokenProvider .getAccessTokenWithAdmin ();
37- }
34+ @ BeforeAll
35+ void getJwt () {
36+ token = KeycloakTokenProvider .getAccessTokenWithAdmin ();
37+ }
3838
39- @ Test
40- @ Order (1 )
41- void shouldAllowCreatingANewTaskList () {
42-
43- Response response = given ().when ().header ("Authorization" , token ).body ("{ \" title\" : \" Shopping List\" }" ).contentType (ContentType .JSON )
44- .post ("/task/list" );
45- response .then ().statusCode (201 ).header ("Location" , not (emptyString ()));
46-
47- this .taskListId = Integer .parseInt (response .header ("Location" ).replaceAll (".*?/task/list/" , "" ));
48- }
49-
50- @ Test
51- @ Order (2 )
52- void shouldAllowAddingATaskToATaskList () {
53-
54- Response response = given ().when ().header ("Authorization" , token ).body ("{ \" title\" : \" Buy Milk\" , \" taskListId\" : " + this .taskListId + " }" )
55- .contentType (ContentType .JSON ).post ("/task/item" );
56-
57- response .then ().statusCode (201 ).header ("Location" , not (emptyString ()));
58-
59- this .taskItemId = Integer .parseInt (response .header ("Location" ).replaceAll (".*?/task/item/" , "" ));
60- }
61-
62- @ Test
63- @ Order (3 )
64- void shouldAllowRetrievingATaskListWithTaskItems () {
65-
66- given ().when ().header ("Authorization" , token ).get ("/task/list-with-items/{taskListId}" , this .taskListId ).then ().statusCode (200 )
67- .body ("list.title" , Matchers .equalTo ("Shopping List" )).and ().body ("list.id" , Matchers .equalTo (this .taskListId ))
68- .and ().body ("items[0].title" , Matchers .equalTo ("Buy Milk" ));
69- }
70-
71- @ Test
72- @ Order (4 )
73- void shouldAllowDeletingATaskListCompletely () {
74-
75- given ().when ().header ("Authorization" , token ).delete ("/task/list/{taskListId}" , this .taskListId ).then ().statusCode (204 );
76- given ().when ().header ("Authorization" , token ).get ("/task/list/{taskListId}" , this .taskListId ).then ().statusCode (404 );
77- given ().when ().header ("Authorization" , token ).get ("/task/item/{itemId}" , this .taskItemId ).then ().statusCode (404 );
78-
79- }
8039}
0 commit comments