Skip to content

Commit

Permalink
others(email-outbound-connector): integration tests for email outboun…
Browse files Browse the repository at this point in the history
…d connector (#3457)

* tests(email-connector): add integration tests

* tests(email-connector): add integration tests 2

* tests(email-outbound-connector): integration tests for email outbound connector

* tests(email-outbound-connector): fix
  • Loading branch information
mathias-vandaele authored Oct 9, 2024
1 parent 0c7b591 commit fb14cc5
Show file tree
Hide file tree
Showing 5 changed files with 549 additions and 0 deletions.
62 changes: 62 additions & 0 deletions connectors-e2e-test/connectors-e2e-test-mail/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.camunda.connector</groupId>
<artifactId>connectors-e2e-test-parent</artifactId>
<relativePath>../pom.xml</relativePath>
<version>8.6.0-SNAPSHOT</version>
</parent>

<description>Tests</description>
<artifactId>connectors-e2e-test-mail</artifactId>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>io.camunda.connector</groupId>
<artifactId>connector-email</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.icegreen</groupId>
<artifactId>greenmail</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>io.camunda.connector</groupId>
<artifactId>connectors-e2e-test-base</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.camunda.connector</groupId>
<artifactId>connectors-e2e-test-base</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; 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 io.camunda.connector.e2e;

import com.icegreen.greenmail.store.FolderException;
import com.icegreen.greenmail.user.GreenMailUser;
import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.GreenMailUtil;
import jakarta.mail.Address;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.io.TempDir;

public class BaseEmailTest {

protected static final String LOCALHOST = "localhost";
private static final GreenMail greenMail = new GreenMail();
@TempDir File tempDir;
private GreenMailUser greenMailUser = greenMail.setUser("[email protected]", "password");
;

@BeforeAll
static void setup() {
greenMail.start();
}

@AfterAll
static void tearDown() {
greenMail.stop();
}

protected static List<String> getSenders(Message message) {
try {
return Arrays.stream(message.getFrom()).map(Address::toString).toList();
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}

protected static List<String> getReceivers(Message message) {
try {
return Arrays.stream(message.getAllRecipients()).map(Address::toString).toList();
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}

protected static String getPlainTextBody(Message message) {
try {
return message.getContent().toString().trim();
} catch (MessagingException | IOException e) {
throw new RuntimeException(e);
}
}

protected static String getSubject(Message message) {
try {
return message.getSubject();
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}

protected Message[] getLastReceivedEmails() {
return greenMail.getReceivedMessages();
}

protected boolean waitForNewEmails(long timeout, int numberOfEmails) {
return greenMail.waitForIncomingEmail(timeout, numberOfEmails);
}

protected void sendEmail(String to, String subject, String body) {
MimeMessage mimeMessage =
GreenMailUtil.createTextEmail(
to, "[email protected]", subject, body, greenMail.getImap().getServerSetup());
greenMailUser.deliver(mimeMessage);
}

protected String getLastEmailMessageId() {
Message message = getLastReceivedEmails()[0];
try {
String messageId = message.getHeader("Message-ID")[0];
return messageId.trim().replaceAll("[<>]", "");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}

protected String getUnsecurePop3Port() {
return String.valueOf(greenMail.getPop3().getPort());
}

protected String getUnsecureImapPort() {
return String.valueOf(greenMail.getImap().getPort());
}

protected String getUnsecureSmtpPort() {
return String.valueOf(greenMail.getSmtp().getPort());
}

protected void reset() {
try {
greenMail.purgeEmailFromAllMailboxes();
} catch (FolderException e) {
throw new RuntimeException(e);
}
}
}
Loading

0 comments on commit fb14cc5

Please sign in to comment.