Skip to content

Commit

Permalink
[ISSUE-1257] Use OpenPaasAmqpForwardAttribute in MemoryCalendarEventR…
Browse files Browse the repository at this point in the history
…eplyWithAMQPWorkflowTest
  • Loading branch information
HoussemNasri authored and Arsnael committed Nov 19, 2024
1 parent cf948ed commit e068afe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import static org.apache.james.data.UsersRepositoryModuleChooser.Implementation.DEFAULT;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.io.FileInputStream;
import java.net.URI;
import java.nio.file.Path;
import java.util.Optional;
import java.util.UUID;

import jakarta.inject.Singleton;

import org.apache.commons.io.FileUtils;
import org.apache.james.JamesServerBuilder;
import org.apache.james.JamesServerExtension;
Expand All @@ -16,6 +19,12 @@
import org.junit.jupiter.api.extension.RegisterExtension;

import com.github.fge.lambdas.Throwing;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.linagora.tmail.AmqpUri;
import com.linagora.tmail.OpenPaasModule;
import com.linagora.tmail.configuration.OpenPaasConfiguration;
import com.linagora.tmail.james.app.MemoryConfiguration;
import com.linagora.tmail.james.app.MemoryServer;
import com.linagora.tmail.james.common.LinagoraCalendarEventReplyWithAMQPWorkflowContract;
Expand All @@ -38,12 +47,12 @@ public class MemoryCalendarEventReplyWithAMQPWorkflowTest implements LinagoraCal
Throwing.runnable(() -> FileUtils.copyDirectory(new File(ClassLoader.getSystemClassLoader().getResource(".").getFile()),
confPath.toFile())).run();

// Replace amqp uri in the mailetcontainer_with_amqpforward_openpass.xml and write it to mailetcontainer.xml
Throwing.runnable(() -> {
String sourceContent = FileUtils.readFileToString(confPath.resolve("mailetcontainer_with_amqpforward_openpass.xml").toFile(), StandardCharsets.UTF_8);
String newContent = sourceContent.replace("{{AmqpForwardAttribute_uri}}", amqpExtension.getAmqpUri());
FileUtils.writeStringToFile(confPath.resolve("mailetcontainer.xml").toFile(), newContent, StandardCharsets.UTF_8);
}).run();
// Write content of mailetcontainer_with_amqpforward_openpass.xml to mailetcontainer.xml.
Throwing.runnable(() ->
FileUtils.copyToFile(
new FileInputStream(confPath.resolve("mailetcontainer_with_amqpforward_openpass.xml").toFile()),
confPath.resolve("mailetcontainer.xml").toFile()
)).run();

System.out.println("confPath: " + confPath);
return MemoryConfiguration.builder()
Expand All @@ -53,7 +62,12 @@ public class MemoryCalendarEventReplyWithAMQPWorkflowTest implements LinagoraCal
.build();
})
.server(configuration -> MemoryServer.createServer(configuration)
.overrideWith(new LinagoraTestJMAPServerModule(), new DelegationProbeModule()))
.combineWith(new OpenPaasModule())
.overrideWith(
new LinagoraTestJMAPServerModule(),
new DelegationProbeModule(),
provideOpenPaasConfigurationModule(amqpExtension.getAmqpUri()))
)
.build();

@Override
Expand All @@ -65,4 +79,20 @@ public String randomBlobId() {
public Optional<String> readAMQPContent() {
return Throwing.supplier(() -> amqpExtension.readContent()).get();
}

private static Module provideOpenPaasConfigurationModule(String amqpUri) {
return new AbstractModule() {
@Provides
@Singleton
public OpenPaasConfiguration provideOpenPaasConfiguration() {
return new OpenPaasConfiguration(
AmqpUri.from(amqpUri),
URI.create("http://localhost:8081"),
"user",
"password"
);
}
};

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@
<rawSource>rawIcalendar2</rawSource>
<onMailetException>ignore</onMailetException>
</mailet>
<mailet match="SenderIsLocal" class="AmqpForwardAttribute">
<uri>{{AmqpForwardAttribute_uri}}</uri>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailet.OpenPaasAmqpForwardAttribute">
<attribute>icalendarAsJson2</attribute>
<exchange>james:events</exchange>
<exchange_type>fanout</exchange_type>
<attribute>icalendarAsJson2</attribute>
<routing_key>icalendar_routing_key2</routing_key>
<onMailetException>ignore</onMailetException>
</mailet>
<!-- End of ICAL pipeline -->
<mailet match="All" class="RecipientRewriteTable">
Expand Down

0 comments on commit e068afe

Please sign in to comment.