2323
2424import static org .hamcrest .CoreMatchers .*;
2525import static org .junit .jupiter .api .Assertions .assertEquals ;
26+ import static org .junit .jupiter .api .Assertions .assertTrue ;
2627
2728import org .junit .jupiter .api .AfterAll ;
2829import org .junit .jupiter .api .BeforeAll ;
@@ -195,10 +196,6 @@ public void testMoveDatasetNotification() {
195196 .statusCode (CREATED .getStatusCode ());
196197 Integer datasetId = UtilIT .getDatasetIdFromResponse (createDataset );
197198
198- // clear existing notifications (so the DATASETMOVED notification will be the only one)
199- clearNotifications (user1ApiToken );
200- clearNotifications (user2ApiToken );
201-
202199 // User1(superuser) moves the dataset from dataverse2 to dataverse1
203200 Response moveDataset = UtilIT .moveDataset (datasetId .toString (), dataverseAlias1 , user1ApiToken );
204201 moveDataset .prettyPrint ();
@@ -209,30 +206,30 @@ public void testMoveDatasetNotification() {
209206 // verify that a notification was sent to user1
210207 Response getNotifications = UtilIT .getNotifications (user1ApiToken );
211208 getNotifications .prettyPrint ();
212- getNotifications .then ().assertThat ()
213- .statusCode (OK .getStatusCode ())
214- .body ("data.notifications[0].type" , equalTo ("DATASETMOVED" ))
215- .body ("data.notifications[0].displayAsRead" , equalTo (false ))
216- .body ("data.notifications[0].subjectText" , containsString ("has been moved" ))
217- .body ("data.notifications[0].messageText" , startsWith (BundleUtil .getStringFromBundle ("notification.email.greeting" )));
209+ verifyNotification (getNotifications , dataverseAlias1 );
210+
218211 // verify that a notification was sent to user2
219212 getNotifications = UtilIT .getNotifications (user2ApiToken );
220213 getNotifications .prettyPrint ();
221- getNotifications .then ().assertThat ()
222- .statusCode (OK .getStatusCode ())
223- .body ("data.notifications[0].type" , equalTo ("DATASETMOVED" ))
224- .body ("data.notifications[0].displayAsRead" , equalTo (false ))
225- .body ("data.notifications[0].subjectText" , containsString ("has been moved" ))
226- .body ("data.notifications[0].messageText" , startsWith (BundleUtil .getStringFromBundle ("notification.email.greeting" )));
214+ verifyNotification (getNotifications , dataverseAlias1 );
227215 }
228216
229- private void clearNotifications (String apiToken ) {
230- Response getNotifications = UtilIT .getNotifications (apiToken );
231- List <Object > notifications = JsonPath .from (getNotifications .body ().asString ()).getList ("data.notifications" );
232- for (Object obj : notifications ) {
233- Object id = ((Map ) obj ).get ("id" );
234- UtilIT .deleteNotification (Long .parseLong (id .toString ()), apiToken ).prettyPrint ();
217+ private void verifyNotification (Response notificationListResponse , String dataverseAlias ) {
218+ notificationListResponse .then ().assertThat ()
219+ .statusCode (OK .getStatusCode ());
220+ boolean found = false ;
221+ List <Map <String , String >> notifications = notificationListResponse .body ().jsonPath ().getList ("data.notifications" );
222+
223+ for (Map <String , String > notification : notifications ) {
224+ if ("DATASETMOVED" .equalsIgnoreCase (notification .get ("type" ))) {
225+ if (notification .get ("messageText" ) != null && notification .get ("messageText" ).contains (dataverseAlias )) {
226+ found = true ;
227+ assertTrue (notification .get ("subjectText" ) != null && notification .get ("subjectText" ).contains ("has been moved" ));
228+ assertTrue (notification .get ("messageText" ) != null && notification .get ("messageText" ).startsWith (BundleUtil .getStringFromBundle ("notification.email.greeting" )));
229+ }
230+ }
235231 }
232+ assertTrue (found );
236233 }
237234
238235 @ Test
0 commit comments