Search in sources :

Example 1 with NotTerm

use of jakarta.mail.search.NotTerm in project spring-integration by spring-projects.

the class ImapMailSearchTermsTests method validateSearchTermsWhenShouldMarkAsReadWithExistingFlags.

@Test
public void validateSearchTermsWhenShouldMarkAsReadWithExistingFlags() throws Exception {
    ImapMailReceiver receiver = new ImapMailReceiver();
    receiver.setShouldMarkMessagesAsRead(true);
    receiver.setBeanFactory(mock(BeanFactory.class));
    receiver.afterPropertiesSet();
    Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
    folderField.setAccessible(true);
    Folder folder = mock(Folder.class);
    when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
    folderField.set(receiver, folder);
    Method compileSearchTerms = ReflectionUtils.findMethod(receiver.getClass(), "compileSearchTerms", Flags.class);
    compileSearchTerms.setAccessible(true);
    Flags flags = new Flags();
    flags.add(Flag.ANSWERED);
    SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
    assertThat(searchTerms instanceof AndTerm).isTrue();
    AndTerm andTerm = (AndTerm) searchTerms;
    SearchTerm[] terms = andTerm.getTerms();
    assertThat(terms.length).isEqualTo(2);
    NotTerm notTerm = (NotTerm) terms[0];
    assertThat(((FlagTerm) notTerm.getTerm()).getFlags().contains(Flag.ANSWERED)).isTrue();
    notTerm = (NotTerm) terms[1];
    Flags siFlags = new Flags();
    siFlags.add(AbstractMailReceiver.DEFAULT_SI_USER_FLAG);
    assertThat(((FlagTerm) notTerm.getTerm()).getFlags().contains(siFlags)).isTrue();
}
Also used : AndTerm(jakarta.mail.search.AndTerm) Field(java.lang.reflect.Field) NotTerm(jakarta.mail.search.NotTerm) BeanFactory(org.springframework.beans.factory.BeanFactory) Flags(jakarta.mail.Flags) Method(java.lang.reflect.Method) Folder(jakarta.mail.Folder) SearchTerm(jakarta.mail.search.SearchTerm) Test(org.junit.jupiter.api.Test)

Example 2 with NotTerm

use of jakarta.mail.search.NotTerm in project spring-integration by spring-projects.

the class ImapMailSearchTermsTests method validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts.

public void validateSearchTermsWhenShouldMarkAsReadNoExistingFlagsGuts(String userFlag, ImapMailReceiver receiver) throws NoSuchFieldException, IllegalAccessException, InvocationTargetException {
    receiver.setShouldMarkMessagesAsRead(true);
    receiver.setBeanFactory(mock(BeanFactory.class));
    Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
    folderField.setAccessible(true);
    Folder folder = mock(Folder.class);
    when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
    folderField.set(receiver, folder);
    Method compileSearchTerms = ReflectionUtils.findMethod(receiver.getClass(), "compileSearchTerms", Flags.class);
    compileSearchTerms.setAccessible(true);
    Flags flags = new Flags();
    SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
    assertThat(searchTerms instanceof NotTerm).isTrue();
    NotTerm notTerm = (NotTerm) searchTerms;
    Flags siFlags = new Flags();
    siFlags.add(userFlag);
    assertThat(((FlagTerm) notTerm.getTerm()).getFlags()).isEqualTo(siFlags);
}
Also used : Field(java.lang.reflect.Field) FlagTerm(jakarta.mail.search.FlagTerm) NotTerm(jakarta.mail.search.NotTerm) BeanFactory(org.springframework.beans.factory.BeanFactory) Flags(jakarta.mail.Flags) Method(java.lang.reflect.Method) Folder(jakarta.mail.Folder) SearchTerm(jakarta.mail.search.SearchTerm)

Example 3 with NotTerm

use of jakarta.mail.search.NotTerm in project spring-integration by spring-projects.

the class ImapMailSearchTermsTests method validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags.

@Test
public void validateSearchTermsWhenShouldNotMarkAsReadNoExistingFlags() throws Exception {
    ImapMailReceiver receiver = new ImapMailReceiver();
    receiver.setShouldMarkMessagesAsRead(false);
    receiver.setBeanFactory(mock(BeanFactory.class));
    receiver.afterPropertiesSet();
    Field folderField = AbstractMailReceiver.class.getDeclaredField("folder");
    folderField.setAccessible(true);
    Folder folder = mock(Folder.class);
    when(folder.getPermanentFlags()).thenReturn(new Flags(Flags.Flag.USER));
    folderField.set(receiver, folder);
    Method compileSearchTerms = ReflectionUtils.findMethod(receiver.getClass(), "compileSearchTerms", Flags.class);
    compileSearchTerms.setAccessible(true);
    Flags flags = new Flags();
    SearchTerm searchTerms = (SearchTerm) compileSearchTerms.invoke(receiver, flags);
    assertThat(searchTerms instanceof NotTerm).isTrue();
}
Also used : Field(java.lang.reflect.Field) NotTerm(jakarta.mail.search.NotTerm) BeanFactory(org.springframework.beans.factory.BeanFactory) Flags(jakarta.mail.Flags) Method(java.lang.reflect.Method) Folder(jakarta.mail.Folder) SearchTerm(jakarta.mail.search.SearchTerm) Test(org.junit.jupiter.api.Test)

Aggregations

Flags (jakarta.mail.Flags)3 Folder (jakarta.mail.Folder)3 NotTerm (jakarta.mail.search.NotTerm)3 SearchTerm (jakarta.mail.search.SearchTerm)3 Field (java.lang.reflect.Field)3 Method (java.lang.reflect.Method)3 BeanFactory (org.springframework.beans.factory.BeanFactory)3 Test (org.junit.jupiter.api.Test)2 AndTerm (jakarta.mail.search.AndTerm)1 FlagTerm (jakarta.mail.search.FlagTerm)1