77import static org .springframework .restdocs .hypermedia .HypermediaDocumentation .links ;
88import static org .springframework .restdocs .mockmvc .MockMvcRestDocumentation .document ;
99import static org .springframework .restdocs .mockmvc .MockMvcRestDocumentation .documentationConfiguration ;
10- import static org .springframework .restdocs .mockmvc .RestDocumentationRequestBuilders .delete ;
11- import static org .springframework .restdocs .mockmvc .RestDocumentationRequestBuilders .get ;
12- import static org .springframework .restdocs .mockmvc .RestDocumentationRequestBuilders .patch ;
13- import static org .springframework .restdocs .mockmvc .RestDocumentationRequestBuilders .post ;
14- import static org .springframework .restdocs .mockmvc .RestDocumentationRequestBuilders .put ;
10+ import static org .springframework .restdocs .mockmvc .RestDocumentationRequestBuilders .*;
1511import static org .springframework .restdocs .operation .preprocess .Preprocessors .preprocessRequest ;
1612import static org .springframework .restdocs .operation .preprocess .Preprocessors .preprocessResponse ;
1713import static org .springframework .restdocs .operation .preprocess .Preprocessors .prettyPrint ;
@@ -72,20 +68,18 @@ public void indexExample() throws Exception {
7268 @ Test
7369 public void crudGetExample () throws Exception {
7470
75- Map <String , String > tag = new HashMap <>();
76- tag .put ("name" , "GET" );
71+ Map <String , Object > crud = new HashMap <>();
72+ crud .put ("id" , 1L );
73+ crud .put ("title" , "Sample Model" );
74+ crud .put ("body" , "http://www.baeldung.com/" );
7775
7876 String tagLocation = this .mockMvc .perform (get ("/crud" ).contentType (MediaTypes .HAL_JSON )
79- .content (this .objectMapper .writeValueAsString (tag )))
77+ .content (this .objectMapper .writeValueAsString (crud )))
8078 .andExpect (status ().isOk ())
8179 .andReturn ()
8280 .getResponse ()
8381 .getHeader ("Location" );
8482
85- Map <String , Object > crud = new HashMap <>();
86- crud .put ("id" , 1L );
87- crud .put ("title" , "Sample Model" );
88- crud .put ("body" , "http://www.baeldung.com/" );
8983 crud .put ("tags" , singletonList (tagLocation ));
9084
9185 ConstraintDescriptions desc = new ConstraintDescriptions (CrudInput .class );
@@ -99,20 +93,18 @@ public void crudGetExample() throws Exception {
9993
10094 @ Test
10195 public void crudCreateExample () throws Exception {
102- Map <String , String > tag = new HashMap <>();
103- tag .put ("name" , "CREATE" );
96+ Map <String , Object > crud = new HashMap <>();
97+ crud .put ("id" , 2L );
98+ crud .put ("title" , "Sample Model" );
99+ crud .put ("body" , "http://www.baeldung.com/" );
104100
105101 String tagLocation = this .mockMvc .perform (post ("/crud" ).contentType (MediaTypes .HAL_JSON )
106- .content (this .objectMapper .writeValueAsString (tag )))
102+ .content (this .objectMapper .writeValueAsString (crud )))
107103 .andExpect (status ().isCreated ())
108104 .andReturn ()
109105 .getResponse ()
110106 .getHeader ("Location" );
111107
112- Map <String , Object > crud = new HashMap <>();
113- crud .put ("id" , 2L );
114- crud .put ("title" , "Sample Model" );
115- crud .put ("body" , "http://www.baeldung.com/" );
116108 crud .put ("tags" , singletonList (tagLocation ));
117109
118110 this .mockMvc .perform (post ("/crud" ).contentType (MediaTypes .HAL_JSON )
0 commit comments