This is an automated email from the ASF dual-hosted git repository. chibenwa pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 1a2032dc0eba337fe6235c82cff0b812d73d9bcf Author: Quan Tran <[email protected]> AuthorDate: Thu Jun 4 15:52:48 2026 +0700 [REFACTORING] Remove IMAPServerTest --- .../james/imapserver/netty/IMAPServerTest.java | 238 --------------------- 1 file changed, 238 deletions(-) diff --git a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java b/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java deleted file mode 100644 index 6efcab8269..0000000000 --- a/server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/**************************************************************** - * 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.imapserver.netty; - -import static org.mockito.Mockito.spy; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; -import java.nio.charset.StandardCharsets; -import java.security.cert.X509Certificate; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; - -import javax.net.ssl.X509TrustManager; - -import org.apache.commons.configuration2.HierarchicalConfiguration; -import org.apache.commons.configuration2.tree.ImmutableNode; -import org.apache.commons.net.imap.AuthenticatingIMAPClient; -import org.apache.james.core.Username; -import org.apache.james.imap.api.ConnectionCheck; -import org.apache.james.imap.encode.main.DefaultImapEncoderFactory; -import org.apache.james.imap.main.DefaultImapDecoderFactory; -import org.apache.james.imap.processor.fetch.FetchProcessor; -import org.apache.james.imap.processor.main.DefaultImapProcessorFactory; -import org.apache.james.mailbox.inmemory.InMemoryMailboxManager; -import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources; -import org.apache.james.mailbox.store.FakeAuthenticator; -import org.apache.james.mailbox.store.FakeAuthorizator; -import org.apache.james.mailbox.store.StoreSubscriptionManager; -import org.apache.james.metrics.api.NoopGaugeRegistry; -import org.apache.james.metrics.tests.RecordingMetricFactory; -import org.apache.james.protocols.api.utils.BogusSslContextFactory; -import org.apache.james.protocols.api.utils.BogusTrustManagerFactory; -import org.apache.james.protocols.lib.LegacyJavaEncryptionFactory; -import org.apache.james.protocols.lib.mock.ConfigLoader; -import org.apache.james.server.core.filesystem.FileSystemImpl; -import org.apache.james.util.ClassLoaderUtils; -import org.apache.james.utils.TestIMAPClient; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - -import ch.qos.logback.classic.Logger; -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.read.ListAppender; - -@SuppressWarnings("checkstyle:membername") -class IMAPServerTest { - private static final String _129K_MESSAGE = "header: value\r\n" + "012345678\r\n".repeat(13107); - private static final String _65K_MESSAGE = "header: value\r\n" + "012345678\r\n".repeat(6553); - private static final Username USER = Username.of("[email protected]"); - private static final Username USER2 = Username.of("[email protected]"); - private static final Username USER3 = Username.of("[email protected]"); - private static final String USER_PASS = "pass"; - public static final String SMALL_MESSAGE = "header: value\r\n\r\nBODY"; - private InMemoryIntegrationResources memoryIntegrationResources; - private FakeAuthenticator authenticator; - - @RegisterExtension - public TestIMAPClient testIMAPClient = new TestIMAPClient(); - private InMemoryMailboxManager mailboxManager; - - private IMAPServer createImapServer(HierarchicalConfiguration<ImmutableNode> config, - InMemoryIntegrationResources inMemoryIntegrationResources, - FetchProcessor.LocalCacheConfiguration localCacheConfiguration) throws Exception { - memoryIntegrationResources = inMemoryIntegrationResources; - - RecordingMetricFactory metricFactory = new RecordingMetricFactory(); - Set<ConnectionCheck> connectionChecks = defaultConnectionChecks(); - mailboxManager = spy(memoryIntegrationResources.getMailboxManager()); - IMAPServer imapServer = new IMAPServer( - new DefaultImapDecoderFactory().buildImapDecoder(), - new DefaultImapEncoderFactory().buildImapEncoder(), - DefaultImapProcessorFactory.createXListSupportingProcessor( - mailboxManager, - memoryIntegrationResources.getEventBus(), - new StoreSubscriptionManager(mailboxManager.getMapperFactory(), - mailboxManager.getMapperFactory(), - mailboxManager.getEventBus()), - null, - memoryIntegrationResources.getQuotaManager(), - memoryIntegrationResources.getQuotaRootResolver(), - metricFactory, - localCacheConfiguration), - new ImapMetrics(metricFactory), - new NoopGaugeRegistry(), connectionChecks); - - FileSystemImpl fileSystem = FileSystemImpl.forTestingWithConfigurationFromClasspath(); - imapServer.setFileSystem(fileSystem); - imapServer.setEncryptionFactory(new LegacyJavaEncryptionFactory(fileSystem)); - - imapServer.configure(config); - imapServer.init(); - - return imapServer; - } - - private IMAPServer createImapServer(HierarchicalConfiguration<ImmutableNode> config, FetchProcessor.LocalCacheConfiguration localCacheConfiguration) throws Exception { - authenticator = new FakeAuthenticator(); - authenticator.addUser(USER, USER_PASS); - authenticator.addUser(USER2, USER_PASS); - authenticator.addUser(USER3, USER_PASS); - - memoryIntegrationResources = InMemoryIntegrationResources.builder() - .authenticator(authenticator) - .authorizator(FakeAuthorizator.defaultReject()) - .inVmEventBus() - .defaultAnnotationLimits() - .defaultMessageParser() - .scanningSearchIndex() - .noPreDeletionHooks() - .storeQuotaManager() - .build(); - - return createImapServer(config, memoryIntegrationResources, localCacheConfiguration); - } - - private IMAPServer createImapServer(HierarchicalConfiguration<ImmutableNode> config) throws Exception { - return createImapServer(config, FetchProcessor.LocalCacheConfiguration.DEFAULT); - } - - private IMAPServer createImapServer(String configurationFile, FetchProcessor.LocalCacheConfiguration localCacheConfiguration) throws Exception { - return createImapServer(ConfigLoader.getConfig(ClassLoaderUtils.getSystemResourceAsSharedStream(configurationFile)), localCacheConfiguration); - } - - private IMAPServer createImapServer(String configurationFile) throws Exception { - return createImapServer(configurationFile, FetchProcessor.LocalCacheConfiguration.DEFAULT); - } - - private Set<ConnectionCheck> defaultConnectionChecks() { - return ImmutableSet.of(new IpConnectionCheck()); - } - - - - - - - - public static class BlindTrustManager implements X509TrustManager { - public X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted(X509Certificate[] chain, String authType) { - - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) { - - - } - } - - public static ListAppender<ILoggingEvent> getListAppenderForClass(Class clazz) { - Logger logger = (Logger) LoggerFactory.getLogger(clazz); - - ListAppender<ILoggingEvent> loggingEventListAppender = new ListAppender<>(); - loggingEventListAppender.start(); - - logger.addAppender(loggingEventListAppender); - return loggingEventListAppender; - } - - - - - - - - - - - - - private AuthenticatingIMAPClient imapsClient(int port) throws Exception { - AuthenticatingIMAPClient client = new AuthenticatingIMAPClient(false, BogusSslContextFactory.getClientContext()); - client.setTrustManager(BogusTrustManagerFactory.getTrustManagers()[0]); - client.connect("127.0.0.1", port); - client.execTLS(); - return client; - } - - - - - - - - - private byte[] readBytes(SocketChannel channel) throws IOException { - ByteBuffer line = ByteBuffer.allocate(1024); - channel.read(line); - line.rewind(); - byte[] bline = new byte[line.remaining()]; - line.get(bline); - return bline; - } - - private List<String> readStringUntil(SocketChannel channel, Predicate<String> condition) throws IOException { - ImmutableList.Builder<String> result = ImmutableList.builder(); - while (true) { - String line = new String(readBytes(channel), StandardCharsets.US_ASCII); - result.add(line); - if (condition.test(line)) { - return result.build(); - } - } - } - - - - - - - -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
