16
16
import org .springframework .boot .test .autoconfigure .web .servlet .AutoConfigureMockMvc ;
17
17
import org .springframework .boot .test .context .SpringBootTest ;
18
18
import org .springframework .boot .test .mock .mockito .MockBean ;
19
+ import org .springframework .http .MediaType ;
19
20
import org .springframework .test .web .servlet .MockMvc ;
20
21
import service .Baloot ;
21
22
@@ -101,7 +102,7 @@ public void testRateCommodityApi(String rate) throws Exception {
101
102
when (baloot .getCommodityById (commodity .getId ())).thenReturn (commodity );
102
103
Map <String , String > map = Map .of ("rate" , rate , "username" , "user" );
103
104
mockMvc .perform (post ("/commodities/{id}/rate" , commodity .getId ())
104
- .contentType ("application/json" )
105
+ .contentType (MediaType . APPLICATION_JSON )
105
106
.content (objectMapper .writeValueAsString (map )))
106
107
.andExpect (status ().isOk ())
107
108
.andExpect (content ().string ("rate added successfully!" ));
@@ -113,7 +114,7 @@ public void testRateCommodityApiWithNonExistingCommodity() throws Exception {
113
114
when (baloot .getCommodityById (anyString ())).thenThrow (new NotExistentCommodity ());
114
115
Map <String , String > map = Map .of ("rate" , "5" , "username" , "user" );
115
116
mockMvc .perform (post ("/commodities/{id}/rate" , "1" )
116
- .contentType ("application/json" )
117
+ .contentType (MediaType . APPLICATION_JSON )
117
118
.content (objectMapper .writeValueAsString (map )))
118
119
.andExpect (status ().isNotFound ())
119
120
.andExpect (content ().string (NOT_EXISTENT_COMMODITY ));
@@ -129,7 +130,7 @@ public void testRateCommodityApiWithWrongRate(String rate) throws Exception {
129
130
when (baloot .getCommodityById (commodity .getId ())).thenReturn (commodity );
130
131
Map <String , String > map = Map .of ("rate" , rate , "username" , "user" );
131
132
mockMvc .perform (post ("/commodities/{id}/rate" , commodity .getId ())
132
- .contentType ("application/json" )
133
+ .contentType (MediaType . APPLICATION_JSON )
133
134
.content (objectMapper .writeValueAsString (map )))
134
135
.andExpect (status ().isBadRequest ())
135
136
.andExpect (jsonPath ("$" ).isNotEmpty ());
@@ -145,7 +146,7 @@ public void testRateCommodityApiWithWrongRateRange(String rate) throws Exception
145
146
when (baloot .getCommodityById (commodity .getId ())).thenReturn (commodity );
146
147
Map <String , String > map = Map .of ("rate" , rate , "username" , "user" );
147
148
mockMvc .perform (post ("/commodities/{id}/rate" , commodity .getId ())
148
- .contentType ("application/json" )
149
+ .contentType (MediaType . APPLICATION_JSON )
149
150
.content (objectMapper .writeValueAsString (map )))
150
151
.andExpect (status ().isBadRequest ())
151
152
.andExpect (content ().string (INVALID_RATE_RANGE ));
@@ -160,7 +161,7 @@ public void testRateCommodityApiWithNoRate() throws Exception {
160
161
when (baloot .getCommodityById (commodity .getId ())).thenReturn (commodity );
161
162
Map <String , String > map = Map .of ("username" , "user" );
162
163
mockMvc .perform (post ("/commodities/{id}/rate" , commodity .getId ())
163
- .contentType ("application/json" )
164
+ .contentType (MediaType . APPLICATION_JSON )
164
165
.content (objectMapper .writeValueAsString (map )))
165
166
.andExpect (status ().isBadRequest ())
166
167
.andExpect (jsonPath ("$" ).isNotEmpty ());
@@ -177,7 +178,7 @@ public void testAddCommodityCommentApi() throws Exception {
177
178
when (baloot .getUserById (user .getUsername ())).thenReturn (user );
178
179
Map <String , String > map = Map .of ("username" , user .getUsername (), "comment" , "comment" );
179
180
mockMvc .perform (post ("/commodities/{id}/comment" , commodity .getId ())
180
- .contentType ("application/json" )
181
+ .contentType (MediaType . APPLICATION_JSON )
181
182
.content (objectMapper .writeValueAsString (map )))
182
183
.andExpect (status ().isOk ())
183
184
.andExpect (content ().string ("comment added successfully!" ));
@@ -193,7 +194,7 @@ public void testAddCommodityCommentApiWithNonExistingUser() throws Exception {
193
194
when (baloot .getUserById (anyString ())).thenThrow (new NotExistentUser ());
194
195
Map <String , String > map = Map .of ("username" , "user" , "comment" , "comment" );
195
196
mockMvc .perform (post ("/commodities/{id}/comment" , commodity .getId ())
196
- .contentType ("application/json" )
197
+ .contentType (MediaType . APPLICATION_JSON )
197
198
.content (objectMapper .writeValueAsString (map )))
198
199
.andExpect (status ().isNotFound ())
199
200
.andExpect (content ().string (NOT_EXISTENT_USER ));
@@ -250,7 +251,7 @@ public void testSearchCommoditiesApiFilterByName() throws Exception {
250
251
when (baloot .filterCommoditiesByName ("name" )).thenReturn (commodities );
251
252
Map <String , String > map = Map .of ("searchOption" , "name" , "searchValue" , "name" );
252
253
mockMvc .perform (post ("/commodities/search" )
253
- .contentType ("application/json" )
254
+ .contentType (MediaType . APPLICATION_JSON )
254
255
.content (objectMapper .writeValueAsString (map )))
255
256
.andExpect (status ().isOk ())
256
257
.andExpect (jsonPath ("$.length()" ).value (2 ))
@@ -267,7 +268,7 @@ public void testSearchCommoditiesApiFilterByNameEmptyList() throws Exception {
267
268
when (baloot .filterCommoditiesByName ("name1" )).thenReturn (commodities );
268
269
Map <String , String > map = Map .of ("searchOption" , "name" , "searchValue" , "name1" );
269
270
mockMvc .perform (post ("/commodities/search" )
270
- .contentType ("application/json" )
271
+ .contentType (MediaType . APPLICATION_JSON )
271
272
.content (objectMapper .writeValueAsString (map )))
272
273
.andExpect (status ().isOk ())
273
274
.andExpect (jsonPath ("$" ).isEmpty ());
@@ -289,7 +290,7 @@ public void testSearchCommoditiesApiFilterByCategory() throws Exception {
289
290
when (baloot .filterCommoditiesByCategory ("category" )).thenReturn (commodities );
290
291
Map <String , String > map = Map .of ("searchOption" , "category" , "searchValue" , "category" );
291
292
mockMvc .perform (post ("/commodities/search" )
292
- .contentType ("application/json" )
293
+ .contentType (MediaType . APPLICATION_JSON )
293
294
.content (objectMapper .writeValueAsString (map )))
294
295
.andExpect (status ().isOk ())
295
296
.andExpect (jsonPath ("$.length()" ).value (2 ))
@@ -306,7 +307,7 @@ public void testSearchCommoditiesApiFilterByCategoryEmptyList() throws Exception
306
307
when (baloot .filterCommoditiesByCategory ("category1" )).thenReturn (commodities );
307
308
Map <String , String > map = Map .of ("searchOption" , "category" , "searchValue" , "category" );
308
309
mockMvc .perform (post ("/commodities/search" )
309
- .contentType ("application/json" )
310
+ .contentType (MediaType . APPLICATION_JSON )
310
311
.content (objectMapper .writeValueAsString (map )))
311
312
.andExpect (status ().isOk ())
312
313
.andExpect (jsonPath ("$" ).isEmpty ());
@@ -328,7 +329,7 @@ public void testSearchCommoditiesApiFilterByProvider() throws Exception {
328
329
when (baloot .filterCommoditiesByProviderName ("provider" )).thenReturn (commodities );
329
330
Map <String , String > map = Map .of ("searchOption" , "provider" , "searchValue" , "provider" );
330
331
mockMvc .perform (post ("/commodities/search" )
331
- .contentType ("application/json" )
332
+ .contentType (MediaType . APPLICATION_JSON )
332
333
.content (objectMapper .writeValueAsString (map )))
333
334
.andExpect (status ().isOk ())
334
335
.andExpect (jsonPath ("$.length()" ).value (2 ))
@@ -345,7 +346,7 @@ public void testSearchCommoditiesApiFilterByProviderEmptyList() throws Exception
345
346
when (baloot .filterCommoditiesByProviderName ("provider1" )).thenReturn (commodities );
346
347
Map <String , String > map = Map .of ("searchOption" , "provider" , "searchValue" , "provider1" );
347
348
mockMvc .perform (post ("/commodities/search" )
348
- .contentType ("application/json" )
349
+ .contentType (MediaType . APPLICATION_JSON )
349
350
.content (objectMapper .writeValueAsString (map )))
350
351
.andExpect (status ().isOk ())
351
352
.andExpect (jsonPath ("$" ).isEmpty ());
@@ -356,7 +357,7 @@ public void testSearchCommoditiesApiFilterByProviderEmptyList() throws Exception
356
357
public void testSearchCommoditiesApiFilterByInvalidOption () throws Exception {
357
358
Map <String , String > map = Map .of ("searchOption" , "invalid" , "searchValue" , "value" );
358
359
mockMvc .perform (post ("/commodities/search" )
359
- .contentType ("application/json" )
360
+ .contentType (MediaType . APPLICATION_JSON )
360
361
.content (objectMapper .writeValueAsString (map )))
361
362
.andExpect (status ().isOk ())
362
363
.andExpect (jsonPath ("$" ).isEmpty ());
0 commit comments