@@ -36,7 +36,7 @@ public void shouldShowPostsPage() throws Exception {
3636 @ Test
3737 @ ExpectedDatabase ("data.xml" )
3838 public void shouldShowPostPage () throws Exception {
39- mockMvc .perform (get ("/post?id= 1" ))
39+ mockMvc .perform (get ("/posts/ 1" ))
4040 .andExpect (status ().isOk ())
4141 .andExpect (view ().name ("post" ))
4242 .andExpect (model ().attributeDoesNotExist ("comment" ));
@@ -45,7 +45,7 @@ public void shouldShowPostPage() throws Exception {
4545 @ Test
4646 @ ExpectedDatabase ("data.xml" )
4747 public void shouldShowCommentFormWhenAuthorized () throws Exception {
48- mockMvc .perform (get ("/post?id= 1" ).with (userBob ()))
48+ mockMvc .perform (get ("/posts/ 1" ).with (userBob ()))
4949 .andExpect (status ().isOk ())
5050 .andExpect (view ().name ("post" ))
5151 .andExpect (model ().attribute ("comment" , instanceOf (Comment .class )));
@@ -54,14 +54,14 @@ public void shouldShowCommentFormWhenAuthorized() throws Exception {
5454 @ Test
5555 @ ExpectedDatabase ("data.xml" )
5656 public void shouldReturn404WhenPostNotExists () throws Exception {
57- mockMvc .perform (get ("/post?id= 999" ))
57+ mockMvc .perform (get ("/posts/ 999" ))
5858 .andExpect (status ().isNotFound ());
5959 }
6060
6161 @ Test
6262 @ ExpectedDatabase ("data.xml" )
6363 public void shouldShowCreatePostPageIfAdmin () throws Exception {
64- mockMvc .perform (get ("/post /create" ).with (userAdmin ()))
64+ mockMvc .perform (get ("/posts /create" ).with (userAdmin ()))
6565 .andExpect (status ().isOk ())
6666 .andExpect (view ().name ("editpost" ))
6767 .andExpect (model ().attribute ("post" , instanceOf (PostEditDto .class )))
@@ -71,21 +71,21 @@ public void shouldShowCreatePostPageIfAdmin() throws Exception {
7171 @ Test
7272 @ ExpectedDatabase ("data.xml" )
7373 public void shouldDenyCreatePostIfNotAdmin () throws Exception {
74- mockMvc .perform (get ("/post /create" ))
74+ mockMvc .perform (get ("/posts /create" ))
7575 .andExpect (status ().isFound ())
7676 .andExpect (redirectedUrlPattern ("**/login" ));
7777
78- mockMvc .perform (get ("/post /create" ).with (userBob ()))
78+ mockMvc .perform (get ("/posts /create" ).with (userBob ()))
7979 .andExpect (status ().isForbidden ());
8080
81- mockMvc .perform (post ("/post /create" ).with (userBob ()).with (csrf ()))
81+ mockMvc .perform (post ("/posts /create" ).with (userBob ()).with (csrf ()))
8282 .andExpect (status ().isForbidden ());
8383 }
8484
8585 @ Test
8686 @ ExpectedDatabase ("data.xml" )
8787 public void shouldReturnAddPostFormWithErrorsWhenSubmittedInvalidPost () throws Exception {
88- mockMvc .perform (post ("/post /create" ).with (userAdmin ()).with (csrf ())
88+ mockMvc .perform (post ("/posts /create" ).with (userAdmin ()).with (csrf ())
8989 .contentType (MediaType .APPLICATION_FORM_URLENCODED ))
9090 .andExpect (status ().isOk ())
9191 .andExpect (model ().attributeHasFieldErrors ("post" , "title" ))
@@ -95,7 +95,7 @@ public void shouldReturnAddPostFormWithErrorsWhenSubmittedInvalidPost() throws E
9595 String title = "post title" ;
9696 String text = "too short" ;
9797
98- mockMvc .perform (post ("/post /create" ).with (userAdmin ()).with (csrf ())
98+ mockMvc .perform (post ("/posts /create" ).with (userAdmin ()).with (csrf ())
9999 .contentType (MediaType .APPLICATION_FORM_URLENCODED )
100100 .param ("title" , title )
101101 .param ("text" , text ))
@@ -114,7 +114,7 @@ public void shouldAddPosts() throws Exception {
114114 String text = "new post short text===cut===new post full text Lorem ipsum" ;
115115 String tags = "c++, java, hello world" ;
116116
117- mockMvc .perform (post ("/post /create" ).with (userAdmin ()).with (csrf ())
117+ mockMvc .perform (post ("/posts /create" ).with (userAdmin ()).with (csrf ())
118118 .contentType (MediaType .APPLICATION_FORM_URLENCODED )
119119 .param ("title" , title )
120120 .param ("text" , text )
@@ -126,7 +126,7 @@ public void shouldAddPosts() throws Exception {
126126 String text2 = "new post 2 text Lorem ipsum dolor sit amet, consectetur adipiscing elit" ;
127127 String tags2 = "java" ;
128128
129- mockMvc .perform (post ("/post /create" ).with (userAdmin ()).with (csrf ())
129+ mockMvc .perform (post ("/posts /create" ).with (userAdmin ()).with (csrf ())
130130 .contentType (MediaType .APPLICATION_FORM_URLENCODED )
131131 .param ("title" , title )
132132 .param ("text" , text2 )
@@ -139,7 +139,7 @@ public void shouldAddPosts() throws Exception {
139139 @ Test
140140 @ ExpectedDatabase ("data.xml" )
141141 public void shouldShowEditPostPageIfAdmin () throws Exception {
142- mockMvc .perform (get ("/post/edit?id=1 " ).with (userAdmin ()))
142+ mockMvc .perform (get ("/posts/1/edit " ).with (userAdmin ()))
143143 .andExpect (status ().isOk ())
144144 .andExpect (view ().name ("editpost" ))
145145 .andExpect (model ().attribute ("post" , hasProperty ("id" , is (Matchers .equalTo (1L )))))
@@ -149,21 +149,21 @@ public void shouldShowEditPostPageIfAdmin() throws Exception {
149149 @ Test
150150 @ ExpectedDatabase ("data.xml" )
151151 public void shouldDenyEditPostIfNotAdmin () throws Exception {
152- mockMvc .perform (get ("/post/edit?id=1 " ))
152+ mockMvc .perform (get ("/posts/1/edit " ))
153153 .andExpect (status ().isFound ())
154154 .andExpect (redirectedUrlPattern ("**/login" ));
155155
156- mockMvc .perform (get ("/post/edit?id=1 " ).with (userBob ()))
156+ mockMvc .perform (get ("/posts/1/edit " ).with (userBob ()))
157157 .andExpect (status ().isForbidden ());
158158
159- mockMvc .perform (post ("/post/edit?id=1 " ).with (userBob ()).with (csrf ()))
159+ mockMvc .perform (post ("/posts/1/edit " ).with (userBob ()).with (csrf ()))
160160 .andExpect (status ().isForbidden ());
161161 }
162162
163163 @ Test
164164 @ ExpectedDatabase ("data.xml" )
165165 public void shouldReturnEditPostFormWithErrorsWhenSubmittedInvalidPost () throws Exception {
166- mockMvc .perform (post ("/post/edit?id=1 " ).with (userAdmin ()).with (csrf ())
166+ mockMvc .perform (post ("/posts/1/edit " ).with (userAdmin ()).with (csrf ())
167167 .contentType (MediaType .APPLICATION_FORM_URLENCODED ))
168168 .andExpect (status ().isOk ())
169169 .andExpect (model ().attributeHasFieldErrors ("post" , "title" ))
@@ -174,7 +174,7 @@ public void shouldReturnEditPostFormWithErrorsWhenSubmittedInvalidPost() throws
174174 String title = "post title" ;
175175 String text = "too short" ;
176176
177- mockMvc .perform (post ("/post/edit?id=1 " ).with (userAdmin ()).with (csrf ())
177+ mockMvc .perform (post ("/posts/1/edit " ).with (userAdmin ()).with (csrf ())
178178 .contentType (MediaType .APPLICATION_FORM_URLENCODED )
179179 .param ("title" , title )
180180 .param ("text" , text ))
@@ -194,25 +194,25 @@ public void shouldEditPosts() throws Exception {
194194 String text = "edited Lorem ipsum dolor sit amet, consectetur adipiscing elit" ;
195195 String tags = "c, c++, c#" ;
196196
197- mockMvc .perform (post ("/post/edit?id=1 " ).with (userAdmin ()).with (csrf ())
197+ mockMvc .perform (post ("/posts/1/edit " ).with (userAdmin ()).with (csrf ())
198198 .contentType (MediaType .APPLICATION_FORM_URLENCODED )
199199 .param ("title" , title )
200200 .param ("text" , text )
201201 .param ("tags" , tags ))
202202 .andExpect (status ().isFound ())
203203 .andExpect (model ().hasNoErrors ())
204- .andExpect (view ().name ("redirect:/post?id= 1" ));
204+ .andExpect (view ().name ("redirect:/posts/ 1" ));
205205
206206 String text2 = "edited short===cut===edited Lorem ipsum dolor sit amet, consectetur adipiscing elit" ;
207207 String tags2 = "c++, meow" ;
208208
209- mockMvc .perform (post ("/post/edit?id=2 " ).with (userAdmin ()).with (csrf ())
209+ mockMvc .perform (post ("/posts/2/edit " ).with (userAdmin ()).with (csrf ())
210210 .contentType (MediaType .APPLICATION_FORM_URLENCODED )
211211 .param ("title" , title )
212212 .param ("text" , text2 )
213213 .param ("tags" , tags2 ))
214214 .andExpect (status ().isFound ())
215215 .andExpect (model ().hasNoErrors ())
216- .andExpect (view ().name ("redirect:/post?id= 2" ));
216+ .andExpect (view ().name ("redirect:/posts/ 2" ));
217217 }
218218}
0 commit comments