Skip to content

Commit 72a86c2

Browse files
committed
#16: Enable profile for the integration tests
1 parent dd90849 commit 72a86c2

File tree

6 files changed

+99
-48
lines changed

6 files changed

+99
-48
lines changed

.circleci/config.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
# Environment variables: https://circleci.com/docs/2.0/env-vars
55
# Verify circleci *.yml: https://circleci.com/docs/2.0/local-cli
66
#
7-
# @todo #/DEV Enable profile for the integration tests
8-
# The expected configuration is
9-
# `mvn -X -P integration-tests,qulice clean install -DLL.gmail.user=${GMAIL_USER} -DLL.gmail.pass=${GMAIL_PASS} -DLL.gmail.to.user=${GMAIL_TO}`
10-
#
117
version: 2
128
jobs:
139
assemble_jar:
@@ -24,7 +20,7 @@ jobs:
2420
- run:
2521
name: Build java sources (including integration tests)
2622
command: |
27-
mvn -X -P qulice clean install
23+
mvn -X -P integration-tests,qulice clean install -DLL.yandex.user=${EMAIL_USER} -DLL.yandex.pass=${EMAIL_PASS} -DLL.yandex.to.user=${EMAIL_TO}
2824
2925
workflows:
3026
version: 2

src/test/java/io/github/dgroup/mbox4j/GmailProperties.java renamed to src/test/java/io/github/dgroup/mbox4j/GmailSmtpProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
import org.cactoos.Scalar;
3131

3232
/**
33-
* Gmail SMTP properties..
33+
* Gmail incoming/outgoing SMTP server properties.
3434
*
3535
* @since 0.1.0
3636
*/
37-
public final class GmailProperties implements Scalar<Properties> {
37+
public final class GmailSmtpProperties implements Scalar<Properties> {
3838

3939
@Override
4040
public Properties value() throws ArgNotFoundException {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2019 Yurii Dubinka
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"),
8+
* to deal in the Software without restriction, including without limitation
9+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
* and/or sell copies of the Software, and to permit persons to whom
11+
* the Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22+
* OR OTHER DEALINGS IN THE SOFTWARE.
23+
*/
24+
25+
package io.github.dgroup.mbox4j;
26+
27+
import io.github.dgroup.term4j.arg.ArgNotFoundException;
28+
import io.github.dgroup.term4j.arg.PropOf;
29+
import java.util.Properties;
30+
import org.cactoos.Scalar;
31+
32+
/**
33+
* Yandex SMTP server incoming properties.
34+
*
35+
* @since 0.1.0
36+
*/
37+
public final class YandexIncomingSmtpProperties implements Scalar<Properties> {
38+
39+
@Override
40+
public Properties value() throws ArgNotFoundException {
41+
final Properties props = new Properties();
42+
props.setProperty("mail.smtp.auth", Boolean.TRUE.toString());
43+
props.setProperty("mail.smtp.starttls.enable", Boolean.TRUE.toString());
44+
props.setProperty("mail.smtp.host", "imap.yandex.com");
45+
props.setProperty("mail.smtp.port", "993");
46+
props.setProperty("username", new PropOf("LL.yandex.user").value());
47+
props.setProperty("password", new PropOf("LL.yandex.pass").value());
48+
return props;
49+
}
50+
51+
}

src/test/java/io/github/dgroup/mbox4j/YandexProperties.java renamed to src/test/java/io/github/dgroup/mbox4j/YandexOutgoingSmtpProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
import org.cactoos.Scalar;
3131

3232
/**
33-
* Gmail SMTP properties.
33+
* Yandex SMTP server outgoing properties.
3434
*
3535
* @since 0.1.0
3636
*/
37-
public final class YandexProperties implements Scalar<Properties> {
37+
public final class YandexOutgoingSmtpProperties implements Scalar<Properties> {
3838

3939
@Override
4040
public Properties value() throws ArgNotFoundException {

src/test/java/io/github/dgroup/mbox4j/inbox/javax/JavaxMailInboxTestIT.java

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424

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

27-
import io.github.dgroup.mbox4j.GmailProperties;
27+
import io.github.dgroup.mbox4j.EmailException;
2828
import io.github.dgroup.mbox4j.Msg;
2929
import io.github.dgroup.mbox4j.Query;
30+
import io.github.dgroup.mbox4j.YandexIncomingSmtpProperties;
3031
import io.github.dgroup.mbox4j.inbox.javax.search.mode.Modes;
3132
import io.github.dgroup.mbox4j.query.QueryOf;
3233
import io.github.dgroup.mbox4j.query.mode.Mode;
@@ -40,6 +41,7 @@
4041
import org.hamcrest.Matchers;
4142
import org.junit.Test;
4243
import org.llorllale.cactoos.matchers.Assertion;
44+
import org.llorllale.cactoos.matchers.HasValues;
4345

4446
/**
4547
* Test case for {@link JavaxMailInbox}.
@@ -54,23 +56,47 @@
5456
public final class JavaxMailInboxTestIT {
5557

5658
@Test
57-
public void read() {
59+
public void size() {
5860
new Assertion<>(
5961
"3 emails were read",
60-
() -> {
61-
final Mode mode = new ModeOf("first 3 emails");
62-
final Query query = new QueryOf("pop3s", "INBOX", mode);
63-
final Func<Folder, Iterable<Msg>> fnc = folder -> new ArrayList<>(
64-
new Mapped<>(
65-
new ToMsg(), folder.getMessages(1, 3)
66-
)
67-
);
68-
return new JavaxMailInbox(
69-
new GmailProperties(),
70-
new Modes(new MapOf<>(new MapEntry<>(mode, fnc)))
71-
).read(query);
72-
},
62+
() -> this.read(3),
7363
Matchers.iterableWithSize(3)
7464
).affirm();
7565
}
66+
67+
@Test
68+
public void subject() {
69+
new Assertion<>(
70+
"3 emails have expected subject",
71+
() -> new Mapped<>(
72+
msg -> msg.subject().asString(),
73+
this.read(3)
74+
),
75+
new HasValues<>(
76+
"The first email",
77+
"The second email",
78+
"The third email"
79+
)
80+
).affirm();
81+
}
82+
83+
/**
84+
* Read range of emails from the dedicated SMTP server.
85+
* @param quantity The quantity of messages to be fetched from SMTP server.
86+
* @return The emails.
87+
* @throws EmailException Шn case of connectivity issues.
88+
*/
89+
private Iterable<Msg> read(final int quantity) throws EmailException {
90+
final Mode mode = new ModeOf("first several emails");
91+
final Query query = new QueryOf("imaps", "INBOX", mode);
92+
final Func<Folder, Iterable<Msg>> fnc = folder -> new ArrayList<>(
93+
new Mapped<>(
94+
new ToMsg(), folder.getMessages(1, quantity)
95+
)
96+
);
97+
return new JavaxMailInbox(
98+
new YandexIncomingSmtpProperties(),
99+
new Modes(new MapOf<>(new MapEntry<>(mode, fnc)))
100+
).read(query);
101+
}
76102
}

src/test/java/io/github/dgroup/mbox4j/outbox/javax/JavaxMailOutboxTestIT.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
package io.github.dgroup.mbox4j.outbox.javax;
2626

2727
import io.github.dgroup.mbox4j.EmailException;
28-
import io.github.dgroup.mbox4j.GmailProperties;
29-
import io.github.dgroup.mbox4j.YandexProperties;
28+
import io.github.dgroup.mbox4j.YandexOutgoingSmtpProperties;
3029
import io.github.dgroup.mbox4j.msg.MsgOf;
3130
import io.github.dgroup.term4j.arg.ArgNotFoundException;
3231
import io.github.dgroup.term4j.arg.PropOf;
@@ -41,27 +40,6 @@
4140
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
4241
public final class JavaxMailOutboxTestIT {
4342

44-
/**
45-
* Integration test for email message sending procedure.
46-
* @throws EmailException In case issues during sending.
47-
* @throws ArgNotFoundException In case if user credentials
48-
* were not specified during the testing procedure.
49-
* @todo #/DEV Enable test once the SMTP server is UP and available for sending.
50-
*/
51-
@Test
52-
public void sendFromGmailAccount() throws EmailException, ArgNotFoundException {
53-
new JavaxMailOutbox(
54-
new GmailProperties()
55-
).send(
56-
new MsgOf(
57-
new PropOf("LL.gmail.user").value(),
58-
new PropOf("LL.gmail.to.user").value(),
59-
"Testing subj",
60-
"I'm simple and i know it."
61-
)
62-
);
63-
}
64-
6543
/**
6644
* Integration test for email message sending procedure.
6745
* @throws EmailException In case issues during sending.
@@ -71,7 +49,7 @@ public void sendFromGmailAccount() throws EmailException, ArgNotFoundException {
7149
@Test
7250
public void sendFromYandexAccount() throws EmailException, ArgNotFoundException {
7351
new JavaxMailOutbox(
74-
new YandexProperties()
52+
new YandexOutgoingSmtpProperties()
7553
).send(
7654
new MsgOf(
7755
new PropOf("LL.yandex.user").value(),

0 commit comments

Comments
 (0)