Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 1ee1e1a

Browse files
committed
Update ServerClientTest.kt
1 parent 4e7b940 commit 1ee1e1a

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

simplekotlinmail-test/src/test/kotlin/net/axay/simplekotlinmail/test/ServerClientTest.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ package net.axay.simplekotlinmail.test
22

33
import kotlinx.coroutines.runBlocking
44
import net.axay.simplekotlinmail.delivery.MailerManager
5-
import net.axay.simplekotlinmail.delivery.send
5+
import net.axay.simplekotlinmail.delivery.mailerBuilder
6+
import net.axay.simplekotlinmail.delivery.sendSync
67
import net.axay.simplekotlinmail.email.emailBuilder
78
import net.axay.simplekotlinmail.server.smtpServer
89
import net.axay.simplekotlinmail.server.start
910
import net.axay.simplekotlinmail.server.tls.TLSContext
1011
import net.axay.simplekotlinmail.server.tls.setupTLS
12+
import net.axay.simplekotlinmail.server.utils.session
13+
import net.axay.simplekotlinmail.server.utils.sslSocket
1114
import org.junit.jupiter.api.Assertions.assertEquals
1215
import org.junit.jupiter.api.Test
16+
import org.simplejavamail.api.mailer.config.TransportStrategy
1317
import java.io.File
1418

1519
class ServerClientTest {
16-
1720
private val plainText = "Hey, how are you?"
1821

1922
private val email = emailBuilder {
@@ -26,8 +29,7 @@ class ServerClientTest {
2629

2730
@Test
2831
fun testServer() = runBlocking {
29-
30-
val smtpServer = smtpServer {
32+
val smtpServer = smtpServer(2500) {
3133
mailListener {
3234
println("received email: ${it.email.plainText}")
3335
assertEquals(it.email.plainText?.trim(), plainText)
@@ -36,43 +38,43 @@ class ServerClientTest {
3638

3739
smtpServer.start(keepAlive = true)
3840

39-
email.send(awaitCompletion = true)
41+
email.sendSync(mailerBuilder(port = 2500))
4042

4143
MailerManager.shutdownMailers()
4244

4345
smtpServer.stop()
44-
4546
}
4647

4748
@Test
4849
fun testServerTLS() = runBlocking {
49-
50-
val plainText = "Hey, how are you?"
51-
52-
val smtpServer = smtpServer {
50+
val smtpServer = smtpServer(2500) {
5351
setupTLS(
5452
TLSContext(
5553
File("./src/test/resources/keystore"), "passphrase",
5654
File("./src/test/resources/truststore"), "passphrase"
5755
),
5856
true,
57+
starttlsOnly = false,
5958
requireClientAuth = false
6059
)
6160

6261
mailListener {
6362
println("received email: ${it.email.plainText}")
6463
assertEquals(it.email.plainText?.trim(), plainText)
64+
assert(it.context.session?.sslSocket != null)
6565
}
6666
}
6767

6868
smtpServer.start(keepAlive = true)
6969

70-
email.send(awaitCompletion = true)
70+
email.sendSync(mailerBuilder(port = 2500) {
71+
verifyingServerIdentity(false)
72+
trustingAllHosts(true)
73+
withTransportStrategy(TransportStrategy.SMTPS)
74+
})
7175

7276
MailerManager.shutdownMailers()
7377

7478
smtpServer.stop()
75-
7679
}
77-
7880
}

0 commit comments

Comments
 (0)