Skip to content

Commit

Permalink
[Backport 2.x] Replace the TestMailServer to GreenMail server (#807)
Browse files Browse the repository at this point in the history
* Replace the TestMailServer to GreenMail server (#801)

* Add 2.11 release notes (#774)

Signed-off-by: yuye-aws <[email protected]>
Signed-off-by: rdani <[email protected]>

* Fix integration test failure by allowing direct access to system index warning (#784)

* Fix integration test failure by allowing direct access to system index warning

Signed-off-by: gaobinlong <[email protected]>

* Fix bwc test failure of throwing direct access to system index when getting mapping

Signed-off-by: gaobinlong <[email protected]>

---------

Signed-off-by: gaobinlong <[email protected]>
Signed-off-by: rdani <[email protected]>

* Replace the TestMailServer to GreenMail server

Signed-off-by: rdani <[email protected]>

* bump bwc version to 2.12 (#793)

Signed-off-by: Hailong Cui <[email protected]>
Signed-off-by: rdani <[email protected]>

* Update dependency org.json:json to v20231013 (#795)

Signed-off-by: gaobinlong <[email protected]>
Signed-off-by: rdani <[email protected]>

* Re-enable detekt (#796)

Bumped version of `io.gitlab.arturbosch.detekt:detekt-gradle-plugin` to `1.23.0`

Signed-off-by: Aniruddh <[email protected]>
Co-authored-by: Hailong Cui <[email protected]>
Signed-off-by: rdani <[email protected]>

* Add assertion for retrieval of notification

Signed-off-by: rdani <[email protected]>

* Update to stable version

Signed-off-by: rdani <[email protected]>

* Update to stable version

Signed-off-by: rdani <[email protected]>

* Update to suggested version

Signed-off-by: rdani <[email protected]>

---------

Signed-off-by: yuye-aws <[email protected]>
Signed-off-by: rdani <[email protected]>
Signed-off-by: gaobinlong <[email protected]>
Signed-off-by: Hailong Cui <[email protected]>
Signed-off-by: Aniruddh <[email protected]>
Co-authored-by: Yuye Zhu <[email protected]>
Co-authored-by: gaobinlong <[email protected]>
Co-authored-by: rdani <[email protected]>
Co-authored-by: Hailong Cui <[email protected]>
Co-authored-by: Aniruddh <[email protected]>
(cherry picked from commit 76ddcd4)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Add slf4j-api for greenmail

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: yuye-aws <[email protected]>
Signed-off-by: rdani <[email protected]>
Signed-off-by: gaobinlong <[email protected]>
Signed-off-by: Hailong Cui <[email protected]>
Signed-off-by: Aniruddh <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Yuye Zhu <[email protected]>
Co-authored-by: gaobinlong <[email protected]>
Co-authored-by: rdani <[email protected]>
Co-authored-by: Hailong Cui <[email protected]>
Co-authored-by: Aniruddh <[email protected]>
  • Loading branch information
7 people authored Oct 24, 2023
1 parent d97a41b commit 80fce31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
3 changes: 3 additions & 0 deletions notifications/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ dependencies {
'io.mockk:mockk-agent-jvm:1.11.0',
)
testImplementation 'org.springframework.integration:spring-integration-mail:5.5.0'
// https://mvnrepository.com/artifact/com.icegreen/greenmail
testImplementation group: 'com.icegreen', name: 'greenmail', version: '1.6.14'
testImplementation "org.slf4j:slf4j-api:${versions.slf4j}"
testImplementation 'org.springframework.integration:spring-integration-test-support:5.5.0'
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.6.2')
testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

package org.opensearch.notifications.core.smtp

import org.junit.After
import com.icegreen.greenmail.util.GreenMail
import com.icegreen.greenmail.util.ServerSetupTest
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.opensearch.core.rest.RestStatus
import org.opensearch.notifications.core.NotificationCoreImpl
Expand All @@ -14,28 +17,29 @@ import org.opensearch.notifications.core.transport.SmtpDestinationTransport
import org.opensearch.notifications.spi.model.MessageContent
import org.opensearch.notifications.spi.model.destination.DestinationType
import org.opensearch.notifications.spi.model.destination.SmtpDestination
import org.springframework.integration.test.mail.TestMailServer
import kotlin.test.assertEquals

class SmtpEmailTests {

internal companion object {
private const val smtpPort = 10255 // use non-standard port > 1024 to avoid permission issue
private val smtpServer = TestMailServer.smtp(smtpPort)
private lateinit var greenMail: GreenMail

@BeforeEach
fun setUpServer() {
greenMail = GreenMail(ServerSetupTest.SMTP)
greenMail.start()
}

@After
@AfterEach
fun tearDownServer() {
smtpServer.stop()
smtpServer.resetServer()
greenMail.stop()
}

@Test
fun `test send email to one recipient over smtp server`() {
val smtpDestination = SmtpDestination(
"testAccountName",
"localhost",
smtpPort,
ServerSetupTest.SMTP.port,
"none",
"[email protected]",
"[email protected]"
Expand All @@ -53,14 +57,15 @@ class SmtpEmailTests {
val response = NotificationCoreImpl.sendMessage(smtpDestination, message, "ref")
assertEquals("Success", response.statusText)
assertEquals(RestStatus.OK.status, response.statusCode)
assertEquals(1, greenMail.receivedMessages.size) // Indicates retrieval of notification.
}

@Test
fun `test send email with non-available host`() {
val smtpDestination = SmtpDestination(
"testAccountName",
"invalidHost",
smtpPort,
ServerSetupTest.SMTP.port,
"none",
"[email protected]",
"[email protected]"
Expand All @@ -77,7 +82,7 @@ class SmtpEmailTests {
DestinationTransportProvider.destinationTransportMap = mapOf(DestinationType.SMTP to SmtpDestinationTransport())
val response = NotificationCoreImpl.sendMessage(smtpDestination, message, "ref")
assertEquals(
"sendEmail Error, status:Couldn't connect to host, port: invalidHost, $smtpPort; timeout -1",
"sendEmail Error, status:Couldn't connect to host, port: invalidHost, ${ServerSetupTest.SMTP.port}; timeout -1",
response.statusText
)
assertEquals(RestStatus.SERVICE_UNAVAILABLE.status, response.statusCode)
Expand Down

0 comments on commit 80fce31

Please sign in to comment.