You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/09/01 09:16:39 UTC

[GitHub] [james-project] Arsnael commented on a change in pull request #629: JAMES-3642 Fix Buggy behavior with Android Email mobile application

Arsnael commented on a change in pull request #629:
URL: https://github.com/apache/james-project/pull/629#discussion_r699145607



##########
File path: protocols/imap/src/test/java/org/apache/james/imap/processor/SelectProcessorTest.java
##########
@@ -0,0 +1,173 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imap.processor;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.mail.Flags;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import org.apache.james.core.Username;
+import org.apache.james.imap.api.ImapConfiguration;
+import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.Tag;
+import org.apache.james.imap.api.message.IdRange;
+import org.apache.james.imap.api.message.UidRange;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.decode.main.OutputStreamImapResponseWriter;
+import org.apache.james.imap.encode.FakeImapSession;
+import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
+import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
+import org.apache.james.imap.encode.main.DefaultLocalizer;
+import org.apache.james.imap.main.ResponseEncoder;
+import org.apache.james.imap.message.request.AbstractMailboxSelectionRequest;
+import org.apache.james.imap.message.request.SelectRequest;
+import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.UidValidity;
+import org.apache.james.metrics.tests.RecordingMetricFactory;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.ImmutableList;
+
+class SelectProcessorTest {
+    private static final Username BOB = Username.of("bob");
+
+    private SelectProcessor testee;
+    private InMemoryMailboxManager mailboxManager;
+    private MailboxSession mailboxSession;
+    private UidValidity uidValidity;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        InMemoryIntegrationResources integrationResources = InMemoryIntegrationResources.defaultResources();
+
+        mailboxManager = integrationResources.getMailboxManager();
+        testee = new SelectProcessor(new ImapProcessor() {
+            @Override
+            public void process(ImapMessage message, Responder responder, ImapSession session) {
+
+            }
+
+            @Override
+            public void configure(ImapConfiguration imapConfiguration) {
+
+            }
+        }, mailboxManager,
+            integrationResources.getEventBus(),
+            new UnpooledStatusResponseFactory(),
+            new RecordingMetricFactory());
+
+        mailboxSession = mailboxManager.createSystemSession(Username.of("bob"));
+        mailboxManager.createMailbox(MailboxPath.inbox(BOB), mailboxSession);
+        uidValidity = mailboxManager.getMailbox(MailboxPath.inbox(BOB), mailboxSession).getMailboxEntity().getUidValidity();
+    }
+
+    @Test
+    void vanishedResponsesShouldNotBeSentWhenNoDeletes() throws Exception {
+        FakeImapSession session = new FakeImapSession();
+        session.authenticated();
+        session.setMailboxSession(mailboxSession);
+        EnableProcessor.getEnabledCapabilities(session)
+            .add(ImapConstants.SUPPORTS_QRESYNC);
+
+        MessageManager mailbox = mailboxManager.getMailbox(MailboxPath.inbox(BOB), mailboxSession);
+        MessageManager.AppendCommand appendCommand = MessageManager.AppendCommand
+            .builder()
+            .withFlags(new Flags(Flags.Flag.SEEN))
+            .notRecent()
+            .build(new SharedByteArrayInputStream("header: value\r\n\r\nbody".getBytes()));
+        mailbox.appendMessage(appendCommand, mailboxSession);
+        mailbox.appendMessage(appendCommand, mailboxSession);
+        mailbox.appendMessage(appendCommand, mailboxSession);
+        mailbox.appendMessage(appendCommand, mailboxSession);
+        mailbox.appendMessage(appendCommand, mailboxSession);
+
+        UidRange[] uidRanges = null;
+        IdRange[] sequences = null;
+        SelectRequest message = new SelectRequest("INBOX", false,
+            AbstractMailboxSelectionRequest.ClientSpecifiedUidValidity.valid(uidValidity),
+            4L, uidRanges, uidRanges, sequences, new Tag("AA"));
+
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+        testee.process(message,
+            new ResponseEncoder(
+                new DefaultImapEncoderFactory(new DefaultLocalizer(), true).buildImapEncoder(),
+                new ImapResponseComposerImpl(new OutputStreamImapResponseWriter(outputStream))),
+            session);
+
+        assertThat(new String(outputStream.toByteArray()))
+            .doesNotContain("* VANISHED (EARLIER) 1:4");
+    }
+
+    @Test
+    void vanishedResponsesShouldBeSentWheDeletes() throws Exception {

Review comment:
       ```suggestion
       void vanishedResponsesShouldBeSentWhenDeletes() throws Exception {
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org