File tree Expand file tree Collapse file tree 7 files changed +42
-10
lines changed
test/java/com/sar/sandpit Expand file tree Collapse file tree 7 files changed +42
-10
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,9 @@ public String addItem(Model model){
83
83
// return a
84
84
// }
85
85
86
+ private void test () {
87
+ // Long i =1L;
88
+ }
86
89
87
90
88
91
@@ -96,12 +99,12 @@ public String items(ModelMap modalMap){
96
99
//return "todo/items";
97
100
}
98
101
99
- @ PostMapping (value = "/deleteItem/{id}" )
102
+ @ GetMapping (value = "/deleteItem/{id}" )
100
103
public String deleteItem ( @ PathVariable Long id , ModelMap model ){
101
- itemService .delete (1L );
104
+ itemService .delete (id );
102
105
103
106
//return null;
104
107
//return "redirect:todo/items";
105
- return "todo/items" ;
108
+ return "redirect:/ todo/items" ;
106
109
}
107
110
}
Original file line number Diff line number Diff line change @@ -44,7 +44,8 @@ public List<Item> getItems() {
44
44
45
45
@ Override
46
46
public boolean delete (Long id ) {
47
- return false ;
47
+ itemStore .delete (id );
48
+ return itemStore .exists (id );
48
49
}
49
50
50
51
@ Override
Original file line number Diff line number Diff line change 13
13
< p > Message: < input type ="text " th:field ="*{details} " /> </ p >
14
14
< p > < input type ="submit " value ="Submit " /> < input type ="reset " value ="Reset " /> </ p >
15
15
</ form >
16
+
17
+ < p > < a th:href ="@{/todo/items/} "> items</ a > </ p >
16
18
</ html >
Original file line number Diff line number Diff line change 8
8
< body >
9
9
< p th:text ="'id ='+ ${item.id} + ' task = '+ ${item.details} "/>
10
10
< p th:text ="'id ='+ ${itemDto.id} + ' task = '+ ${itemDto.details} "/>
11
+ < p > < a th:href ="@{/todo/addItem/} "> Add Another</ a > </ p >
12
+ < p > < a th:href ="@{/todo/items/} "> items</ a > </ p >
11
13
</ body >
12
14
</ html >
Original file line number Diff line number Diff line change 12
12
< p th:text ="'test 2 = '+ ${test} "> not empty</ p >
13
13
< p th:text ="'items count = '+${items.size()} ">
8000
span></ p >
14
14
15
+ < p > < a th:href ="@{/todo/deleteItem/{items}/} ">
16
+ the items </ a > </ p >
15
17
< table >
16
18
< thead >
17
19
< tr >
18
20
< th > ids</ th >
19
21
< th > detail snippet </ th >
22
+ < th > actions</ th >
20
23
</ tr >
21
24
</ thead >
22
25
< tbody >
23
26
< tr th:each ="item: ${items} " >
24
27
< td th:text ="${item.id} "> </ td >
25
28
< td th:text ="${item.details} "> </ td >
29
+ < td th:href ="@{/todo/deleteItem/{item}} ">
30
+ delete2
31
+ < a th:href ="@{'/todo/deleteItem/'+${item.id}+'/'} ">
32
+ delete</ a >
33
+ </ td >
26
34
</ tr >
27
35
</ tbody >
28
36
</ table >
37
+ < p > < a th:href ="@{/todo/addItem/} "> add item</ a >
38
+ </ p >
39
+
40
+
29
41
30
42
31
43
</ body >
Original file line number Diff line number Diff line change @@ -218,8 +218,8 @@ public void deleteItemByItem_GivenItemToDelete_Success() throws Exception {
218
218
public void deleteItemById_GivenItemToDelete_Success () throws Exception {
219
219
Long id =1L ;
220
220
when (itemServiceable .delete (id )).thenReturn (true );
221
- mockMvc .perform (post (TODO_DELETE_ITEM_URL +id ))
222
- .andExpect (status ().isOk ())
221
+ mockMvc .perform (get (TODO_DELETE_ITEM_URL +id ))
222
+ .andExpect (status ().is3xxRedirection ())
223
223
.andDo (print ())
224
224
.andReturn ()
225
225
;
@@ -232,10 +232,10 @@ public void deleteItemById_GivenItemToDelete_Success() throws Exception {
232
232
@ Test
233
233
public void deleteItemById_GivenItemToDelete_ReturnsSuccessPage () throws Exception {
234
234
Long id =1L ;
235
- mockMvc .perform (post (TODO_DELETE_ITEM_URL +id ))
236
- .andExpect (status ().isOk ())
237
- .andExpect (view ().name (is ("todo/items" )))
238
- .andExpect (forwardedUrl ("todo/items" ))
235
+ mockMvc .perform (get (TODO_DELETE_ITEM_URL +id ))
236
+ .andExpect (status ().is3xxRedirection ())
237
+ // .andExpect(view().name(is("todo/items")))
238
+ // .andExpect(forwardedUrl("/ todo/items"))
239
239
.andDo (print ())
240
240
.andReturn ()
241
241
;
Original file line number Diff line number Diff line change @@ -102,6 +102,18 @@ public void deleteTaskItem_returnTrue() throws Exception {
102
102
verify (itemStorable ).exists (id );
103
103
}
104
104
105
+ @ Test
106
+ public void deleteTaskItemById_returnsTrue () throws Exception {
107
+ final Long id = 1L ;
108
+ when (itemStorable .exists (id )).thenReturn (true );
109
+ boolean res = itemService .delete (id );
110
+ assertThat ("should be true " ,res ,is (equalTo (true )));
111
+ verify (itemStorable , times (1 )).exists (idCapture .capture ());
112
+
113
+
114
+ }
115
+
116
+
105
117
//////////////////////////////
106
118
//todo update single item
107
119
/////////////////////////////
You can’t perform that action at this time.
0 commit comments