@@ -40,6 +40,7 @@ public class RatingControllerTest extends TestBaseController {
40
40
private final String ID = "5dc4c9734e9b1214ed7a9e8a" ;
41
41
private Rating ENTITY_01 ;
42
42
private Rating ENTITY_02 ;
43
+ private List <Rating > list ;
43
44
44
45
@ MockBean
45
46
private RatingRepository repository ;
@@ -60,13 +61,14 @@ public void setUp() {
60
61
ENTITY_01 = Rating .builder ().bookId ("kjasdh6753hsf27634" ).stars (3 ).build ();
61
62
ENTITY_02 = Rating .builder ().bookId ("asgd5555423gsdjhkk" ).stars (4 ).build ();
62
63
63
- List < Rating > list = new ArrayList <>();
64
+ list = new ArrayList <>();
64
65
list .add (ENTITY_01 );
65
66
list .add (ENTITY_02 );
66
67
67
68
when (repository .save (ArgumentMatchers .any ())).thenReturn (ENTITY_01 );
68
69
when (repository .findById (anyString ())).thenReturn (Optional .of (ENTITY_01 ));
69
70
when (repository .findAll ()).thenReturn (list );
71
+ when (repository .findByBookId (ID )).thenReturn (list );
70
72
}
71
73
72
74
@ Test
@@ -78,12 +80,15 @@ public void testContexLoads() {
78
80
@ Test
79
81
@ WithMockUser (username =ADMIN ,roles ={USER_ROLE ,ADMIN_ROLE })
80
82
public void testGetAll () throws Exception {
81
- List <Rating > list = new ArrayList <>();
82
- list .add (ENTITY_01 );
83
- list .add (ENTITY_02 );
84
83
assertEquals (getHttpServletResponse (API , status ().isOk ()).getContentAsString (), jsonList .write (list ).getJson ());
85
84
}
86
85
86
+ @ Test
87
+ @ WithMockUser (username =ADMIN ,roles ={USER_ROLE ,ADMIN_ROLE })
88
+ public void testGetAllBookId () throws Exception {
89
+ assertEquals (getHttpServletResponse (String .format ("%s?bookId=%s" , API , ID ), status ().isOk ()).getContentAsString (), jsonList .write (list ).getJson ());
90
+ }
91
+
87
92
@ Test
88
93
@ WithMockUser (username =ADMIN ,roles ={USER_ROLE ,ADMIN_ROLE })
89
94
public void testbyId () throws Exception {
@@ -161,7 +166,7 @@ public void testbyUpdateFields() throws Exception {
161
166
Map <String , String > fields = new TreeMap <String , String >();
162
167
fields .put ("bookId" , "kasdlkas63573sjd" );
163
168
fields .put ("stars" , "3" );
164
- String json = putHttpServletResponse (String .format ("%s/%s" , API , ID ), jsonEntityFields .write (fields ).getJson (), status ().isOk ()).getContentAsString ();
169
+ String json = patchHttpServletResponse (String .format ("%s/%s" , API , ID ), jsonEntityFields .write (fields ).getJson (), status ().isOk ()).getContentAsString ();
165
170
ObjectMapper mapper = new ObjectMapper ();
166
171
Rating obj = mapper .readValue (json , Rating .class );
167
172
assertEquals (obj , ENTITY_01 );
@@ -173,7 +178,7 @@ public void testbyUpdateFieldNotFound() throws Exception {
173
178
Map <String , String > fields = new TreeMap <String , String >();
174
179
fields .put ("asdas" , "newEqwe" );
175
180
fields .put ("asdasd" , "newTWER" );
176
- String json = putHttpServletResponse (String .format ("%s/%s" , API , ID ), jsonEntityFields .write (fields ).getJson (), status ().isBadRequest ()).getContentAsString ();
181
+ String json = patchHttpServletResponse (String .format ("%s/%s" , API , ID ), jsonEntityFields .write (fields ).getJson (), status ().isNotFound ()).getContentAsString ();
177
182
assertEquals (Constants .BLANK , json );
178
183
}
179
184
0 commit comments