Skip to content

Commit

Permalink
Initial commit after separation from java framework
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Sep 23, 2015
1 parent b4f54a4 commit ad6f0b7
Show file tree
Hide file tree
Showing 41 changed files with 2,330 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Eclipse
.classpath
.project
.settings/

# Intellij
.idea/
*.iml

# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties

#Vim
*~
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use docker-based infrastructure
sudo: false

language: java

jdk:
- oraclejdk8

cache:
directories:
- "$HOME/.m2/repository"

install: /bin/true

script:
- mvn -q -B -U -Pstaging,javadoc,compatibility install jacoco:report
- mvn -q -B coveralls:report -DrepoToken=$COVERALLS_TOKEN

after_success:
- echo "<settings><servers><server><id>sonatype-nexus-snapshots</id><username>\${env.SONATYPE_USER}</username><password>\${env.SONATYPE_PASS}</password></server></servers></settings>" > ~/settings.xml
- "[[ $TRAVIS_PULL_REQUEST == \"false\" && $TRAVIS_BRANCH == \"master\" ]] && mvn -q deploy --settings ~/settings.xml -DskipTests=true -Pjavadoc"
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This source code refers to The SeedStack authors for copyright purposes.
# The master list of authors is in the SeedStack meta repository,
# visible at https://github.com/seedstack/seedstack/blob/master/AUTHORS.
3 changes: 3 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This source code was written by the SeedStack contributors.
# The master list of contributors is in the SeedStack meta repository,
# visible at https://github.com/seedstack/seedstack/blob/master/CONTRIBUTORS.
373 changes: 373 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# mail-addon
# SeedStack JavaMail add-on

[![Build status](https://travis-ci.org/seedstack/javamail-addon.svg?branch=master)](https://travis-ci.org/seedstack/javamail-addon) [![Coverage Status](https://coveralls.io/repos/seedstack/javamail-addon/badge.svg?branch=master)](https://coveralls.io/r/seedstack/javamail-addon?branch=master) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.seedstack/seed-javamail/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/org.seedstack/seed-javamail)

JavaMail official integration for SeedStack.

# Copyright and license

This source code is copyrighted by [The SeedStack Authors](https://github.com/seedstack/seedstack/blob/master/AUTHORS) and
released under the terms of the [Mozilla Public License 2.0](https://www.mozilla.org/MPL/2.0/).
65 changes: 65 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
This file is part of SeedStack, An enterprise-oriented full development stack.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<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>org.seedstack</groupId>
<artifactId>seed-javamail</artifactId>
<version>2.0.1-SNAPSHOT</version>
</parent>

<artifactId>seed-javamail-core</artifactId>

<properties>
<compatibility.artifactId>seed-mail-support-core</compatibility.artifactId>
</properties>

<dependencies>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-core-support-core</artifactId>
<version>${seed.version}</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>${javamail.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-unittest-support</artifactId>
<version>${seed.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-integrationtest-support-core</artifactId>
<version>${seed.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-mail-support-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
72 changes: 72 additions & 0 deletions core/src/it/java/org/seedstack/seed/mail/ImapIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.seed.mail;

import org.seedstack.seed.core.api.Logging;
import org.seedstack.seed.it.AbstractSeedIT;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;

import javax.inject.Inject;
import javax.inject.Named;
import javax.mail.Folder;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;

import static org.assertj.core.api.Assertions.assertThat;

public class ImapIT extends AbstractSeedIT {
@Logging
Logger logger;

@Inject
@Named("imap-test")
Session imapSession;

/**
* @throws Exception
*/
@Before
public void setUp() throws Exception {
imapSession.setDebug(true);
}

/**
* just prints the configured properties for the session using IMAP protocol, these properties
* has to be configured by the user in a .props file
*/
@Test
public void test_configure_imap_session() {
Assertions.assertThat(imapSession).isNotNull();
assertThat(imapSession.getProperty("mail.imap.user")).isEqualTo("aymen.benhmida@ext.mpsa.com");
assertThat(imapSession.getProperty("mail.imap.host")).isEqualTo("testserver");
assertThat(imapSession.getProperty("mail.imap.auth.login.disable")).isEqualTo(Boolean.FALSE.toString());
assertThat(imapSession.getProperty("mail.imap.auth.plain.disable")).isEqualTo(Boolean.TRUE.toString());
}

@Test
@Ignore
public void test_read_mailbox_with_imap() throws MessagingException {
final Store store = imapSession.getStore();
store.connect(TestConstantsValues.DEFAULT_USERNAME, TestConstantsValues.DEFAULT_PASSWORD);

final Folder defaultFolder = store.getDefaultFolder();
Assertions.assertThat(defaultFolder.getFullName());

final Folder inbox = defaultFolder.getFolder("INBOX");
logger.info("Name: {} ", inbox.getName());
logger.info("Full Name: {} ", inbox.getFullName());
logger.info("URL: {} ", inbox.getURLName());
}
}
36 changes: 36 additions & 0 deletions core/src/it/java/org/seedstack/seed/mail/MailPreparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.seed.mail;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;

class MailPreparator {
private Session session;

MailPreparator(Session session) {
this.session = session;
}

Message prepareMessageToBeSent(String to, String from, String subject, String text) throws MessagingException {
Message m = new MimeMessage(session);
m.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
m.setFrom(new InternetAddress(from));
m.setSubject(subject);
m.setText(text);
// m.setContent("Test Content","plain/text");
m.setSentDate(new Date());
return m;
}
}
112 changes: 112 additions & 0 deletions core/src/it/java/org/seedstack/seed/mail/MockMailServerIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* Copyright (c) 2013-2015 by The SeedStack authors. All rights reserved.
*
* This file is part of SeedStack, An enterprise-oriented full development stack.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.seed.mail;

import com.google.common.base.Predicate;
import org.seedstack.seed.it.AbstractSeedIT;
import org.seedstack.seed.mail.api.MessageRetriever;
import org.seedstack.seed.mail.api.WithMailServer;
import org.junit.Test;
import org.seedstack.seed.mail.assertions.MockMailServerAssertions;

import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Named;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;

import static org.seedstack.seed.mail.assertions.MockMailServerAssertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

@WithMailServer(host = "localhost", port = 6457)
public class MockMailServerIT extends AbstractSeedIT {
@Inject
MessageRetriever retriever;

@Inject
@Named("smtp-test")
private Session session;

private MimeMessage createMessage() throws MessagingException {
MimeMessage message = new MimeMessage(session);

message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("test@test.com"));
message.setFrom(new InternetAddress("test@test.com"));
message.setSubject("Test Subject");
message.setText("Test Body Text");
message.setSentDate(new Date());
message.setReplyTo(InternetAddress.parse("test@test.com"));

return message;
}

@Test
public void test_sent_message_has_the_same_recipients_message_from_server() throws MessagingException {
final Message message = createMessage();
Transport transport = session.getTransport();
transport.connect(TestConstantsValues.DEFAULT_USERNAME, TestConstantsValues.DEFAULT_PASSWORD);
transport.sendMessage(message, message.getAllRecipients());

final Collection<Message> messages = retriever.getSentMessages();
for (Message message1 : messages) {
MockMailServerAssertions.assertThat(message1).hasRecipients(Message.RecipientType.TO);
MockMailServerAssertions.assertThat(message1).recipientEqualsTo(Message.RecipientType.TO, InternetAddress.parse("test@test.com"));

}

}

@Test(expected = Throwable.class)
public void test_sent_message_are_not_same_recipients_message_from_server() throws MessagingException {
final Message message = createMessage();
Transport transport = session.getTransport();
transport.connect(TestConstantsValues.DEFAULT_USERNAME, TestConstantsValues.DEFAULT_PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
MockMailServerAssertions.assertThat(message).hasRecipients(Message.RecipientType.TO);
MockMailServerAssertions.assertThat(message).recipientEqualsTo(Message.RecipientType.TO, InternetAddress.parse("test222222@test.com"));
}

@Test
public void test_sent_message_has_same_from() throws MessagingException {
final Message message = createMessage();
Transport transport = session.getTransport();
transport.connect(TestConstantsValues.DEFAULT_USERNAME, TestConstantsValues.DEFAULT_PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
MockMailServerAssertions.assertThat(message).checkByCondition(new Predicate<Message>() {
@Override
public boolean apply(@Nullable Message input) {
try {
if (input != null) {
return Arrays.equals(input.getFrom(), message.getFrom());
}
} catch (MessagingException e) {
fail("FROM section header not equal");
}
return false;
}
});
}

@Test
public void test_mock_message() throws MessagingException {
final Message message = createMessage();
Transport transport = session.getTransport();
transport.connect(TestConstantsValues.DEFAULT_USERNAME, TestConstantsValues.DEFAULT_PASSWORD);
transport.sendMessage(message, message.getAllRecipients());
MockMailServerAssertions.assertThat(message).hasSentDate();
}
}
Loading

0 comments on commit ad6f0b7

Please sign in to comment.