@@ -722,6 +722,107 @@ public void countersTest() throws IOException
722
722
723
723
logger .info ("Counters Test OK" );
724
724
}
725
+
726
+ @ Test
727
+ public void mailboxCountersScrubTest () throws IOException
728
+ {
729
+ initAccount ();
730
+
731
+ Map <String , UUID > messages = new HashMap <String , UUID >();
732
+ LabelCounters inboxCounters = new LabelCounters ();
733
+ LabelCounters notifCounters = new LabelCounters ();
734
+ LabelCounters trashCounters = new LabelCounters ();
735
+ LabelCounters spamCounters = new LabelCounters ();
736
+
737
+ // INBOX: add 5 messages, mark 2 as unread
738
+ messages .put ("inbox1" , addMessage (EMAIL_REGULAR , ReservedLabels .INBOX .getId ()));
739
+ messages .put ("inbox2" , addMessage (EMAIL_REGULAR , ReservedLabels .INBOX .getId ()));
740
+ messages .put ("inbox3" , addMessage (EMAIL_REGULAR , ReservedLabels .INBOX .getId ()));
741
+ messages .put ("inbox4" , addMessage (EMAIL_REGULAR , ReservedLabels .INBOX .getId ()));
742
+ messages .put ("inbox5" , addMessage (EMAIL_REGULAR , ReservedLabels .INBOX .getId ()));
743
+ markAsRead (messages .get ("inbox4" ));
744
+ markAsRead (messages .get ("inbox5" ));
745
+ inboxCounters .setTotalMessages (5L );
746
+ inboxCounters .setUnreadMessages (3L );
747
+
748
+ // NOTIFICATIONS: add 3 messages, mark 1 as read
749
+ messages .put ("notif1" , addMessage (EMAIL_REGULAR , ReservedLabels .NOTIFICATIONS .getId ()));
750
+ messages .put ("notif2" , addMessage (EMAIL_REGULAR , ReservedLabels .NOTIFICATIONS .getId ()));
751
+ messages .put ("notif3" , addMessage (EMAIL_REGULAR , ReservedLabels .NOTIFICATIONS .getId ()));
752
+ markAsRead (messages .get ("notif2" ));
753
+ notifCounters .setTotalMessages (3L );
754
+ notifCounters .setUnreadMessages (2L );
755
+
756
+ // SPAM: add 5 messages, keep all unread
757
+ messages .put ("spam1" , addMessage (EMAIL_REGULAR , ReservedLabels .SPAM .getId ()));
758
+ messages .put ("spam2" , addMessage (EMAIL_REGULAR , ReservedLabels .SPAM .getId ()));
759
+ messages .put ("spam3" , addMessage (EMAIL_REGULAR , ReservedLabels .SPAM .getId ()));
760
+ messages .put ("spam4" , addMessage (EMAIL_REGULAR , ReservedLabels .SPAM .getId ()));
761
+ messages .put ("spam5" , addMessage (EMAIL_REGULAR , ReservedLabels .SPAM .getId ()));
762
+ spamCounters .setTotalMessages (5L );
763
+ spamCounters .setUnreadMessages (5L );
764
+
765
+ // TRASH: add 4 messages, mark 2 as read
766
+ messages .put ("trash1" , addMessage (EMAIL_REGULAR , ReservedLabels .TRASH .getId ()));
767
+ messages .put ("trash2" , addMessage (EMAIL_REGULAR , ReservedLabels .TRASH .getId ()));
768
+ messages .put ("trash3" , addMessage (EMAIL_REGULAR , ReservedLabels .TRASH .getId ()));
769
+ messages .put ("trash4" , addMessage (EMAIL_REGULAR , ReservedLabels .TRASH .getId ()));
770
+ markAsRead (messages .get ("trash1" ));
771
+ markAsRead (messages .get ("trash3" ));
772
+ trashCounters .setTotalMessages (4L );
773
+ trashCounters .setUnreadMessages (2L );
774
+
775
+ // check label counters
776
+ expect ().
777
+ statusCode (200 ).and ().
778
+ body ("'" + ReservedLabels .INBOX .getId () + "'.total" ,
779
+ equalTo (inboxCounters .getTotalMessages ().intValue ())).
780
+ body ("'" + ReservedLabels .INBOX .getId () + "'.unread" ,
781
+ equalTo (inboxCounters .getUnreadMessages ().intValue ())).
782
+ body ("'" + ReservedLabels .NOTIFICATIONS .getId () + "'.total" ,
783
+ equalTo (notifCounters .getTotalMessages ().intValue ())).
784
+ body ("'" + ReservedLabels .NOTIFICATIONS .getId () + "'.unread" ,
785
+ equalTo (notifCounters .getUnreadMessages ().intValue ())).
786
+ body ("'" + ReservedLabels .SPAM .getId () + "'.total" ,
787
+ equalTo (spamCounters .getTotalMessages ().intValue ())).
788
+ body ("'" + ReservedLabels .SPAM .getId () + "'.unread" ,
789
+ equalTo (spamCounters .getUnreadMessages ().intValue ())).
790
+ body ("'" + ReservedLabels .TRASH .getId () + "'.total" ,
791
+ equalTo (trashCounters .getTotalMessages ().intValue ())).
792
+ body ("'" + ReservedLabels .TRASH .getId () + "'.unread" ,
793
+ equalTo (trashCounters .getUnreadMessages ().intValue ())).
794
+ when ().
795
+ get (REST_PATH + "/mailbox?metadata=true" ).asString ();
796
+
797
+ // scrub label counters
798
+ expect ().
799
+ statusCode (204 ).
800
+ when ().
801
+ post (REST_PATH + "/mailbox/scrub/counters" );
802
+
803
+ // check label counters after scrub
804
+ expect ().
805
+ statusCode (200 ).and ().
806
+ body ("'" + ReservedLabels .INBOX .getId () + "'.total" ,
807
+ equalTo (inboxCounters .getTotalMessages ().intValue ())).
808
+ body ("'" + ReservedLabels .INBOX .getId () + "'.unread" ,
809
+ equalTo (inboxCounters .getUnreadMessages ().intValue ())).
810
+ body ("'" + ReservedLabels .NOTIFICATIONS .getId () + "'.total" ,
811
+ equalTo (notifCounters .getTotalMessages ().intValue ())).
812
+ body ("'" + ReservedLabels .NOTIFICATIONS .getId () + "'.unread" ,
813
+ equalTo (notifCounters .getUnreadMessages ().intValue ())).
814
+ body ("'" + ReservedLabels .SPAM .getId () + "'.total" ,
815
+ equalTo (spamCounters .getTotalMessages ().intValue ())).
816
+ body ("'" + ReservedLabels .SPAM .getId () + "'.unread" ,
817
+ equalTo (spamCounters .getUnreadMessages ().intValue ())).
818
+ body ("'" + ReservedLabels .TRASH .getId () + "'.total" ,
819
+ equalTo (trashCounters .getTotalMessages ().intValue ())).
820
+ body ("'" + ReservedLabels .TRASH .getId () + "'.unread" ,
821
+ equalTo (trashCounters .getUnreadMessages ().intValue ())).
822
+ when ().
823
+ get (REST_PATH + "/mailbox?metadata=true" ).asString ();
824
+
825
+ }
725
826
726
827
/**
727
828
* Adds message throught REST API and returns new message UUID
@@ -754,6 +855,23 @@ protected static UUID addMessage(String messageFile, Integer labelId) throws IOE
754
855
755
856
return UUID .fromString ( with (response .asString ()).getString ("id" ) );
756
857
}
858
+
859
+ /**
860
+ * Mark given message as read (add SEEN marker)
861
+ *
862
+ * @param messageId
863
+ */
864
+ private static void markAsRead (UUID messageId )
865
+ {
866
+ // assign labels and marker to the message
867
+ given ().
868
+ pathParam ("messageId" , messageId .toString ()).
869
+ pathParam ("seenMarker" , Marker .SEEN .toString ().toLowerCase ()).
870
+ expect ().
871
+ statusCode (204 ).
872
+ when ().
873
+ put (REST_PATH + "/mailbox/message/{messageId}?addmarker={seenMarker}" );
874
+ }
757
875
758
876
/**
759
877
* Adds labels through REST API and returns new label ID
0 commit comments