Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.0.x] Remove Typesafe in example/tests (backport #296) by @mkurz #297

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Create a new file named `CustomSMTPConfigurationProvider.scala`:
class CustomSMTPConfigurationProvider extends Provider[SMTPConfiguration] {
override def get() = {
// Custom configuration
new SMTPConfiguration("typesafe.org", 1234)
new SMTPConfiguration("example.org", 1234)
}
}

Expand Down Expand Up @@ -192,7 +192,7 @@ You can also use the SMTPMailer constructor to create new instances with custom

```scala
val email = Email("Simple email", "Mister FROM <[email protected]>")
new SMTPMailer(SMTPConfiguration("typesafe.org", 1234)).send(email)
new SMTPMailer(SMTPConfiguration("example.org", 1234)).send(email)
new SMTPMailer(SMTPConfiguration("playframework.com", 5678)).send(email)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MailerPluginGuiceSpec extends Specification {
import play.libs.mailer.{ MailerClient => JMailerClient }

val mockedConfigurationProvider = mock(classOf[SMTPConfigurationProvider])
when(mockedConfigurationProvider.get()).thenReturn(SMTPConfiguration("typesafe.org", 25, mock = true))
when(mockedConfigurationProvider.get()).thenReturn(SMTPConfiguration("example.org", 25, mock = true))

def createApp(additionalConfiguration: Map[String, _]): Application = {
new GuiceApplicationBuilder()
Expand All @@ -24,13 +24,13 @@ class MailerPluginGuiceSpec extends Specification {
.build()
}

val applicationWithMinimalMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "typesafe.org", "play.mailer.port" -> 25))
val applicationWithMinimalMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "example.org", "play.mailer.port" -> 25))

val applicationWithMockedConfigurationProvider = new GuiceApplicationBuilder()
.overrides(new ConfigModule) // Play 2.5.x "hack"
.overrides(bind[SMTPConfiguration].to(mockedConfigurationProvider))
.build()
val applicationWithMoreMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "typesafe.org", "play.mailer.port" -> 25, "play.mailer.user" -> "typesafe", "play.mailer.password" -> "typesafe"))
val applicationWithMoreMailerConfiguration = createApp(additionalConfiguration = Map("play.mailer.host" -> "example.org", "play.mailer.port" -> 25, "play.mailer.user" -> "johndoe", "play.mailer.password" -> "randompw"))

"provide the Scala mailer client" in new WithApplication(applicationWithMinimalMailerConfiguration) {
override def running() = {
Expand All @@ -54,16 +54,16 @@ class MailerPluginGuiceSpec extends Specification {
}
"call the configuration each time we send an email" in new WithApplication(applicationWithMockedConfigurationProvider) {
override def running() = {
val mail = Email("Test Configurable Mailer", "root@typesafe.org")
val mail = Email("Test Configurable Mailer", "root@example.org")
app.injector.instanceOf[MailerClient].send(mail)
app.injector.instanceOf[MailerClient].send(mail)
Mockito.verify(mockedConfigurationProvider, times(2)).get()
}
}
"validate the configuration" in new WithApplication(applicationWithMoreMailerConfiguration) {
override def running() = {
app.injector.instanceOf(bind[SMTPConfiguration]) must ===(SMTPConfiguration("typesafe.org", 25,
user = Some("typesafe"), password = Some("typesafe"), props = ConfigFactory.parseString("ssl.checkserveridentity=true")))
app.injector.instanceOf(bind[SMTPConfiguration]) must ===(SMTPConfiguration("example.org", 25,
user = Some("johndoe"), password = Some("randompw"), props = ConfigFactory.parseString("ssl.checkserveridentity=true")))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MailerPluginSpec extends Specification {
class MockCommonsMailerWithProps(props: Config = ConfigFactory.empty()) extends MockCommonsMailerWithTimeouts(None, None, props)

class MockCommonsMailerWithTimeouts(smtpTimeout: Option[Int], smtpConnectionTimeout: Option[Int], props: Config = ConfigFactory.empty())
extends CommonsMailer(SMTPConfiguration("typesafe.org", 1234, ssl = true, tls = false, tlsRequired = false, Some("user"), Some("password"), debugMode = false, smtpTimeout, smtpConnectionTimeout, props, mock = false)) {
extends CommonsMailer(SMTPConfiguration("example.org", 1234, ssl = true, tls = false, tlsRequired = false, Some("user"), Some("password"), debugMode = false, smtpTimeout, smtpConnectionTimeout, props, mock = false)) {
override def send(email: MultiPartEmail) = ""
override def createMultiPartEmail(): MultiPartEmail = new MockMultiPartEmail
override def createHtmlEmail(): HtmlEmail = new MockHtmlEmail
Expand All @@ -39,12 +39,12 @@ class MailerPluginSpec extends Specification {
val mailer = MockCommonsMailer
val email = mailer.createEmail(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>"
from = "John Doe <john.doe@example.com>"
))
email.getSmtpPort mustEqual "1234"
email.getSslSmtpPort mustEqual "1234"
email.getMailSession.getProperty("mail.smtp.auth") mustEqual "true"
email.getMailSession.getProperty("mail.smtp.host") mustEqual "typesafe.org"
email.getMailSession.getProperty("mail.smtp.host") mustEqual "example.org"
email.getMailSession.getProperty("mail.smtp.starttls.enable") mustEqual "false"
email.getMailSession.getProperty("mail.smtp.starttls.required") mustEqual "false"
email.getMailSession.getProperty("mail.smtp.localhost") must beNull
Expand All @@ -55,7 +55,7 @@ class MailerPluginSpec extends Specification {
val mailer = new MockCommonsMailerWithTimeouts(Some(10), Some(99))
val email = mailer.createEmail(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>"
from = "John Doe <john.doe@example.com>"
))
email.getSocketTimeout mustEqual 10
email.getSocketConnectionTimeout mustEqual 99
Expand All @@ -65,7 +65,7 @@ class MailerPluginSpec extends Specification {
val mailer = new MockCommonsMailerWithTimeouts(None, None)
val email = mailer.createEmail(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>"
from = "John Doe <john.doe@example.com>"
))
email.getSocketTimeout mustEqual EmailConstants.SOCKET_TIMEOUT_MS
email.getSocketConnectionTimeout mustEqual EmailConstants.SOCKET_TIMEOUT_MS
Expand All @@ -75,7 +75,7 @@ class MailerPluginSpec extends Specification {
val mailer = new MockCommonsMailerWithProps(ConfigFactory.parseString("localhost=127.0.0.1"))
val email = mailer.createEmail(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>"
from = "John Doe <john.doe@example.com>"
))
email.getMailSession.getProperty("mail.smtp.localhost") mustEqual "127.0.0.1"
email.getMailSession.getProperty("mail.smtps.localhost") mustEqual "127.0.0.1"
Expand All @@ -85,7 +85,7 @@ class MailerPluginSpec extends Specification {
val mailer = MockCommonsMailer
val messageId = mailer.send(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>",
from = "John Doe <john.doe@example.com>",
to = Seq("Guillaume Grossetie <[email protected]>")
))
messageId mustEqual ""
Expand All @@ -95,7 +95,7 @@ class MailerPluginSpec extends Specification {
val mailer = MockCommonsMailer
val email = mailer.createEmail(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>",
from = "John Doe <john.doe@example.com>",
to = Seq("Guillaume Grossetie <[email protected]>"),
replyTo = Seq("Aviv Shafir <[email protected]>"),
bodyText = Some("A text message"),
Expand All @@ -112,7 +112,7 @@ class MailerPluginSpec extends Specification {
val mailer = MockCommonsMailer
val email = mailer.createEmail(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>",
from = "John Doe <john.doe@example.com>",
to = Seq("Guillaume Grossetie <[email protected]>"),
replyTo = Seq("Aviv Shafir <[email protected]>"),
bodyText = Some("A text message"),
Expand All @@ -137,7 +137,7 @@ class MailerPluginSpec extends Specification {
val cid = "1234"
val email = mailer.createEmail(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>",
from = "John Doe <john.doe@example.com>",
to = Seq("Guillaume Grossetie <[email protected]>"),
replyTo = Seq("Aviv Shafir <[email protected]>"),
bodyHtml = Some(s"""<html><body><p>An <b>html</b> message with cid <img src="cid:$cid"></p></body></html>"""),
Expand All @@ -154,7 +154,7 @@ class MailerPluginSpec extends Specification {
val mailer = MockCommonsMailer
val email = mailer.createEmail(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>",
from = "John Doe <john.doe@example.com>",
to = Seq("Guillaume Grossetie <[email protected]>"),
replyTo = Seq("Aviv Shafir <[email protected]>"),
bodyText = Some("A text message"),
Expand All @@ -178,14 +178,14 @@ class MailerPluginSpec extends Specification {
val mailer = MockCommonsMailer
val email = mailer.createEmail(Email(
subject = "Subject",
from = "James Roper <jroper@typesafe.com>",
from = "John Doe <john.doe@example.com>",
to = Seq("Guillaume Grossetie <[email protected]>"),
replyTo = Seq("Aviv Shafir <[email protected]>"),
cc = Seq("Guillaume Grossetie <[email protected]>"),
bcc = Seq("Guillaume Grossetie <[email protected]>")
))
email.getFromAddress.getAddress mustEqual "jroper@typesafe.com"
email.getFromAddress.getPersonal mustEqual "James Roper"
email.getFromAddress.getAddress mustEqual "john.doe@example.com"
email.getFromAddress.getPersonal mustEqual "John Doe"
email.getToAddresses.get(0).getAddress mustEqual "[email protected]"
email.getToAddresses.get(0).getPersonal mustEqual "Guillaume Grossetie"
email.getCcAddresses.get(0).getAddress mustEqual "[email protected]"
Expand All @@ -200,13 +200,13 @@ class MailerPluginSpec extends Specification {
val mailer = MockCommonsMailer
val email = mailer.createEmail(Email(
subject = "Subject",
from = "jroper@typesafe.com",
from = "john.doe@example.com",
to = Seq("<[email protected]>"),
cc = Seq("[email protected]"),
replyTo = Seq("[email protected]"),
bcc = Seq("[email protected]")
))
email.getFromAddress.getAddress mustEqual "jroper@typesafe.com"
email.getFromAddress.getAddress mustEqual "john.doe@example.com"
email.getFromAddress.getPersonal must beNull
email.getToAddresses.get(0).getAddress mustEqual "[email protected]"
email.getToAddresses.get(0).getPersonal must beNull
Expand All @@ -223,7 +223,7 @@ class MailerPluginSpec extends Specification {
"convert email from Java to Scala" in {
val data = new play.libs.mailer.Email()
data.setSubject("Subject")
data.setFrom("James Roper <jroper@typesafe.com>")
data.setFrom("John Doe <john.doe@example.com>")
data.addTo("Guillaume Grossetie <[email protected]>")
data.addCc("Daniel Spasojevic <[email protected]>")
data.addBcc("Sparkbitpl <[email protected]>")
Expand All @@ -238,7 +238,7 @@ class MailerPluginSpec extends Specification {

val convert = SimpleMailerClient.convert(data)
convert.subject mustEqual "Subject"
convert.from mustEqual "James Roper <jroper@typesafe.com>"
convert.from mustEqual "John Doe <john.doe@example.com>"
convert.to.size mustEqual 1
convert.to.head mustEqual "Guillaume Grossetie <[email protected]>"
convert.cc.size mustEqual 1
Expand Down Expand Up @@ -272,8 +272,8 @@ class MailerPluginSpec extends Specification {

def simpleEmailMust(email: MultiPartEmail): Unit = {
email.getSubject mustEqual "Subject"
email.getFromAddress.getPersonal mustEqual "James Roper"
email.getFromAddress.getAddress mustEqual "jroper@typesafe.com"
email.getFromAddress.getPersonal mustEqual "John Doe"
email.getFromAddress.getAddress mustEqual "john.doe@example.com"
email.getToAddresses must have size 1
email.getToAddresses.get(0).getPersonal mustEqual "Guillaume Grossetie"
email.getToAddresses.get(0).getAddress mustEqual "[email protected]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ApplicationScala(mailer: MailerClient, environment: Environment, component
}

def configureAndSend = Action {
val mailer = new SMTPMailer(SMTPConfiguration("typesafe.org", 1234))
val mailer = new SMTPMailer(SMTPConfiguration("example.org", 1234))
val id = mailer.send(Email("Simple email", "Mister FROM <[email protected]>", Seq("Miss TO <[email protected]>")))
Ok(s"Email $id sent!")
}
Expand Down
2 changes: 1 addition & 1 deletion samples/runtimeDI/app/controllers/ApplicationScala.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ApplicationScala @Inject()(mailer: MailerClient, environment: Environment,
}

def sendWithCustomMailer = Action {
val mailer = new SMTPMailer(SMTPConfiguration("typesafe.org", 1234))
val mailer = new SMTPMailer(SMTPConfiguration("example.org", 1234))
val id = mailer.send(Email("Simple email", "Mister FROM <[email protected]>"))
Ok(s"Email $id sent!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import play.api.{Configuration, Environment}
import play.api.inject.Module

class CustomSMTPConfigurationProvider extends Provider[SMTPConfiguration] {
override def get() = new SMTPConfiguration("typesafe.org", 1234)
override def get() = new SMTPConfiguration("example.org", 1234)
}

class CustomMailerConfigurationModule extends Module {
Expand Down
Loading