Skip to content

Commit

Permalink
#16: Enable profile for the integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgroup committed Mar 30, 2019
1 parent dd90849 commit 72a86c2
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 48 deletions.
6 changes: 1 addition & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
# Environment variables: https://circleci.com/docs/2.0/env-vars
# Verify circleci *.yml: https://circleci.com/docs/2.0/local-cli
#
# @todo #/DEV Enable profile for the integration tests
# The expected configuration is
# `mvn -X -P integration-tests,qulice clean install -DLL.gmail.user=${GMAIL_USER} -DLL.gmail.pass=${GMAIL_PASS} -DLL.gmail.to.user=${GMAIL_TO}`
#
version: 2
jobs:
assemble_jar:
Expand All @@ -24,7 +20,7 @@ jobs:
- run:
name: Build java sources (including integration tests)
command: |
mvn -X -P qulice clean install
mvn -X -P integration-tests,qulice clean install -DLL.yandex.user=${EMAIL_USER} -DLL.yandex.pass=${EMAIL_PASS} -DLL.yandex.to.user=${EMAIL_TO}
workflows:
version: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import org.cactoos.Scalar;

/**
* Gmail SMTP properties..
* Gmail incoming/outgoing SMTP server properties.
*
* @since 0.1.0
*/
public final class GmailProperties implements Scalar<Properties> {
public final class GmailSmtpProperties implements Scalar<Properties> {

@Override
public Properties value() throws ArgNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* MIT License
*
* Copyright (c) 2019 Yurii Dubinka
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package io.github.dgroup.mbox4j;

import io.github.dgroup.term4j.arg.ArgNotFoundException;
import io.github.dgroup.term4j.arg.PropOf;
import java.util.Properties;
import org.cactoos.Scalar;

/**
* Yandex SMTP server incoming properties.
*
* @since 0.1.0
*/
public final class YandexIncomingSmtpProperties implements Scalar<Properties> {

@Override
public Properties value() throws ArgNotFoundException {
final Properties props = new Properties();
props.setProperty("mail.smtp.auth", Boolean.TRUE.toString());
props.setProperty("mail.smtp.starttls.enable", Boolean.TRUE.toString());
props.setProperty("mail.smtp.host", "imap.yandex.com");
props.setProperty("mail.smtp.port", "993");
props.setProperty("username", new PropOf("LL.yandex.user").value());
props.setProperty("password", new PropOf("LL.yandex.pass").value());
return props;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import org.cactoos.Scalar;

/**
* Gmail SMTP properties.
* Yandex SMTP server outgoing properties.
*
* @since 0.1.0
*/
public final class YandexProperties implements Scalar<Properties> {
public final class YandexOutgoingSmtpProperties implements Scalar<Properties> {

@Override
public Properties value() throws ArgNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

package io.github.dgroup.mbox4j.inbox.javax;

import io.github.dgroup.mbox4j.GmailProperties;
import io.github.dgroup.mbox4j.EmailException;
import io.github.dgroup.mbox4j.Msg;
import io.github.dgroup.mbox4j.Query;
import io.github.dgroup.mbox4j.YandexIncomingSmtpProperties;
import io.github.dgroup.mbox4j.inbox.javax.search.mode.Modes;
import io.github.dgroup.mbox4j.query.QueryOf;
import io.github.dgroup.mbox4j.query.mode.Mode;
Expand All @@ -40,6 +41,7 @@
import org.hamcrest.Matchers;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.HasValues;

/**
* Test case for {@link JavaxMailInbox}.
Expand All @@ -54,23 +56,47 @@
public final class JavaxMailInboxTestIT {

@Test
public void read() {
public void size() {
new Assertion<>(
"3 emails were read",
() -> {
final Mode mode = new ModeOf("first 3 emails");
final Query query = new QueryOf("pop3s", "INBOX", mode);
final Func<Folder, Iterable<Msg>> fnc = folder -> new ArrayList<>(
new Mapped<>(
new ToMsg(), folder.getMessages(1, 3)
)
);
return new JavaxMailInbox(
new GmailProperties(),
new Modes(new MapOf<>(new MapEntry<>(mode, fnc)))
).read(query);
},
() -> this.read(3),
Matchers.iterableWithSize(3)
).affirm();
}

@Test
public void subject() {
new Assertion<>(
"3 emails have expected subject",
() -> new Mapped<>(
msg -> msg.subject().asString(),
this.read(3)
),
new HasValues<>(
"The first email",
"The second email",
"The third email"
)
).affirm();
}

/**
* Read range of emails from the dedicated SMTP server.
* @param quantity The quantity of messages to be fetched from SMTP server.
* @return The emails.
* @throws EmailException Шn case of connectivity issues.
*/
private Iterable<Msg> read(final int quantity) throws EmailException {
final Mode mode = new ModeOf("first several emails");
final Query query = new QueryOf("imaps", "INBOX", mode);
final Func<Folder, Iterable<Msg>> fnc = folder -> new ArrayList<>(
new Mapped<>(
new ToMsg(), folder.getMessages(1, quantity)
)
);
return new JavaxMailInbox(
new YandexIncomingSmtpProperties(),
new Modes(new MapOf<>(new MapEntry<>(mode, fnc)))
).read(query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
package io.github.dgroup.mbox4j.outbox.javax;

import io.github.dgroup.mbox4j.EmailException;
import io.github.dgroup.mbox4j.GmailProperties;
import io.github.dgroup.mbox4j.YandexProperties;
import io.github.dgroup.mbox4j.YandexOutgoingSmtpProperties;
import io.github.dgroup.mbox4j.msg.MsgOf;
import io.github.dgroup.term4j.arg.ArgNotFoundException;
import io.github.dgroup.term4j.arg.PropOf;
Expand All @@ -41,27 +40,6 @@
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class JavaxMailOutboxTestIT {

/**
* Integration test for email message sending procedure.
* @throws EmailException In case issues during sending.
* @throws ArgNotFoundException In case if user credentials
* were not specified during the testing procedure.
* @todo #/DEV Enable test once the SMTP server is UP and available for sending.
*/
@Test
public void sendFromGmailAccount() throws EmailException, ArgNotFoundException {
new JavaxMailOutbox(
new GmailProperties()
).send(
new MsgOf(
new PropOf("LL.gmail.user").value(),
new PropOf("LL.gmail.to.user").value(),
"Testing subj",
"I'm simple and i know it."
)
);
}

/**
* Integration test for email message sending procedure.
* @throws EmailException In case issues during sending.
Expand All @@ -71,7 +49,7 @@ public void sendFromGmailAccount() throws EmailException, ArgNotFoundException {
@Test
public void sendFromYandexAccount() throws EmailException, ArgNotFoundException {
new JavaxMailOutbox(
new YandexProperties()
new YandexOutgoingSmtpProperties()
).send(
new MsgOf(
new PropOf("LL.yandex.user").value(),
Expand Down

2 comments on commit 72a86c2

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 72a86c2 Mar 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle DEV-87e0cae5 disappeared from src/test/java/io/github/dgroup/mbox4j/outbox/javax/JavaxMailOutboxTest.java, that's why I closed #12. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 72a86c2 Mar 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle DEV-8299728c disappeared from .circleci/config.yml, that's why I closed #16. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.