Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HoussemNasri committed Oct 30, 2024
1 parent 71364c4 commit 7e6daf8
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 11 deletions.
13 changes: 13 additions & 0 deletions tmail-backend/apps/distributed/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@
<artifactId>tmail-openpaas</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.linagora.tmail</groupId>
<artifactId>tmail-openpaas</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-rate-limiter-cassandra</artifactId>
Expand Down Expand Up @@ -363,6 +371,11 @@
<groupId>com.linagora.tmail</groupId>
<artifactId>logback-json-classic</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.linagora.tmail.james.app;

import org.apache.james.JamesServerBuilder;
import org.apache.james.JamesServerExtension;
import org.apache.james.SearchConfiguration;
import org.apache.james.backends.redis.RedisExtension;
import org.apache.james.utils.GuiceProbe;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.google.inject.multibindings.Multibinder;

import com.linagora.tmail.OpenPaasModuleChooserConfiguration;
import com.linagora.tmail.OpenPaasRabbitMQExtension;
import com.linagora.tmail.combined.identity.LdapExtension;
import com.linagora.tmail.combined.identity.UsersRepositoryClassProbe;
import com.linagora.tmail.combined.identity.UsersRepositoryModuleChooser;
import com.linagora.tmail.module.LinagoraTestJMAPServerModule;

public class DistributedServerWithOpenPaasRabbitMqConfiguredTest {
@RegisterExtension
static JamesServerExtension
testExtension = new JamesServerBuilder<DistributedJamesConfiguration>(tmpDir ->
DistributedJamesConfiguration.builder()
.workingDirectory(tmpDir)
.configurationFromClasspath()
.searchConfiguration(SearchConfiguration.openSearch())
.usersRepository(UsersRepositoryModuleChooser.Implementation.COMBINED)
.eventBusKeysChoice(EventBusKeysChoice.REDIS)
.openPassModuleChooserConfiguration(OpenPaasModuleChooserConfiguration.ENABLED)
.build())
.server(configuration -> DistributedServer.createServer(configuration)
.overrideWith(new LinagoraTestJMAPServerModule())
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(UsersRepositoryClassProbe.class)))
.extension(new DockerOpenSearchExtension())
.extension(new CassandraExtension())
.extension(new RabbitMQExtension())
.extension(new OpenPaasRabbitMQExtension())
.extension(new LdapExtension())
.extension(new RedisExtension())
.lifeCycle(JamesServerExtension.Lifecycle.PER_CLASS)
.build();

@Test
void serverShouldStartWithOpenPaasRabbitMqConfigured() {
}

}
17 changes: 17 additions & 0 deletions tmail-backend/apps/memory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@
<artifactId>tmail-openpaas</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.linagora.tmail</groupId>
<artifactId>tmail-openpaas</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-backends-rabbitmq</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-backends-rabbitmq</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>tmail-webadmin-mailbox</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.linagora.tmail.james.app;

import static org.apache.james.data.UsersRepositoryModuleChooser.Implementation.DEFAULT;

import org.apache.james.JamesServerBuilder;
import org.apache.james.JamesServerExtension;
import org.apache.james.utils.GuiceProbe;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.google.inject.multibindings.Multibinder;
import com.linagora.tmail.OpenPaasModuleChooserConfiguration;
import com.linagora.tmail.OpenPaasRabbitMQExtension;
import com.linagora.tmail.encrypted.MailboxConfiguration;
import com.linagora.tmail.encrypted.MailboxManagerClassProbe;
import com.linagora.tmail.module.LinagoraTestJMAPServerModule;

class MemoryServerWithOpenPaasRabbitMqConfiguredTest {
@RegisterExtension
static JamesServerExtension jamesServerExtension = new JamesServerBuilder<MemoryConfiguration>(tmpDir ->
MemoryConfiguration.builder()
.workingDirectory(tmpDir)
.configurationFromClasspath()
.mailbox(new MailboxConfiguration(false))
.usersRepository(DEFAULT)
.openPaasModuleChooserConfiguration(OpenPaasModuleChooserConfiguration.ENABLED)
.build())
.server(configuration -> MemoryServer.createServer(configuration)
.overrideWith(new LinagoraTestJMAPServerModule())
.overrideWith(binder -> Multibinder.newSetBinder(binder, GuiceProbe.class).addBinding().to(MailboxManagerClassProbe.class)))
.extension(new OpenPaasRabbitMQExtension())
.build();

@Test
public void serverShouldStartWithOpenPaasRabbitMqConfigured() {

}
}
10 changes: 10 additions & 0 deletions tmail-backend/tmail-third-party/openpaas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
<groupId>${project.groupId}</groupId>
<artifactId>jmap-extensions</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-common</artifactId>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-common</artifactId>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-backends-rabbitmq</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,21 @@ public OpenPaasRestClient provideOpenPaasRestCLient(OpenPaasConfiguration openPa
@Provides
@Named(OPENPAAS_INJECTION_KEY)
@Singleton
public RabbitMQConfiguration provideRabbitMQConfiguration(OpenPaasConfiguration openPaasConfiguration, RabbitMQConfiguration fallbackRabbitMQConfiguration) {
public RabbitMQConfiguration provideRabbitMQConfiguration(OpenPaasConfiguration openPaasConfiguration) {
return openPaasConfiguration.maybeRabbitMqUri()
.map(AmqpUri::toRabbitMqConfiguration)
.orElseGet(() -> {
LOGGER.debug("RabbitMQ URI not configured correctly in openpaas.properties, falling back to rabbitmq.properties.");
return fallbackRabbitMQConfiguration;
});
.orElseThrow((() -> {
throw new IllegalStateException("RabbitMQ URI not configured correctly in openpaas.properties.");
}));
}

@Provides
@Named(OPENPAAS_INJECTION_KEY)
@Singleton
public SimpleConnectionPool provideSimpleConnectionPool(@Named(OPENPAAS_INJECTION_KEY) RabbitMQConfiguration rabbitMQConfiguration,
@Named(OPENPAAS_CONFIGURATION_NAME) Provider<Configuration> configuration) {
public SimpleConnectionPool provideSimpleConnectionPool(@Named(OPENPAAS_INJECTION_KEY) RabbitMQConfiguration rabbitMQConfiguration) {
RabbitMQConnectionFactory rabbitMQConnectionFactory = new RabbitMQConnectionFactory(rabbitMQConfiguration);
try {
return new SimpleConnectionPool(rabbitMQConnectionFactory, SimpleConnectionPool.Configuration.from(configuration.get()));
return new SimpleConnectionPool(rabbitMQConnectionFactory, SimpleConnectionPool.Configuration.DEFAULT);
} catch (Exception e) {
LOGGER.info("Error while retrieving SimpleConnectionPool.Configuration, falling back to defaults.", e);
return new SimpleConnectionPool(rabbitMQConnectionFactory, SimpleConnectionPool.Configuration.DEFAULT);
Expand All @@ -93,14 +91,12 @@ public SimpleConnectionPool provideSimpleConnectionPool(@Named(OPENPAAS_INJECTIO
@Named(OPENPAAS_INJECTION_KEY)
@Singleton
public ReactorRabbitMQChannelPool provideReactorRabbitMQChannelPool(
OpenPaasConfiguration openPaasConfiguration,
@Named(OPENPAAS_INJECTION_KEY) SimpleConnectionPool simpleConnectionPool,
ReactorRabbitMQChannelPool.Configuration configuration,
MetricFactory metricFactory, GaugeRegistry gaugeRegistry) {

ReactorRabbitMQChannelPool channelPool = new ReactorRabbitMQChannelPool(
simpleConnectionPool.getResilientConnection(),
configuration,
ReactorRabbitMQChannelPool.Configuration.DEFAULT,
metricFactory,
gaugeRegistry);
channelPool.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.linagora.tmail;

import org.apache.james.GuiceModuleTestExtension;
import org.apache.james.backends.rabbitmq.DockerRabbitMQ;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolutionException;

import com.google.inject.Module;

public class OpenPaasRabbitMQExtension implements GuiceModuleTestExtension {
private final DockerRabbitMQ dockerRabbitMQ = DockerRabbitMQ.withoutCookie();

@Override
public void afterAll(ExtensionContext extensionContext) {
dockerRabbitMQ.stop();
}

@Override
public void beforeAll(ExtensionContext extensionContext) {
dockerRabbitMQ.start();
}

@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws
ParameterResolutionException {
return parameterContext.getParameter().getType() == DockerRabbitMQ.class;
}

@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
return dockerRabbitMQ;
}

@Override
public Module getModule() {
return new TestOpenPaasRabbitMQModule(dockerRabbitMQ);
}

public DockerRabbitMQ dockerRabbitMQ() {
return dockerRabbitMQ;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.linagora.tmail;

import java.net.URI;
import java.net.URISyntaxException;

import jakarta.inject.Singleton;

import org.apache.james.backends.rabbitmq.DockerRabbitMQ;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.linagora.tmail.configuration.OpenPaasConfiguration;

public class TestOpenPaasRabbitMQModule extends AbstractModule {
private final DockerRabbitMQ dockerRabbitMQ;

public TestOpenPaasRabbitMQModule(DockerRabbitMQ dockerRabbitMQ) {
this.dockerRabbitMQ = dockerRabbitMQ;
}

@Provides
@Singleton
public OpenPaasConfiguration provideOpenPaasConfiguration() throws URISyntaxException {
return new OpenPaasConfiguration(
AmqpUri.from(dockerRabbitMQ.amqpUri()).asOptional(),
URI.create("http://localhost:8081"),
"user",
"password"
);
}
}

0 comments on commit 7e6daf8

Please sign in to comment.