Skip to content

Commit acff51e

Browse files
committed
update tests for all notifications
1 parent aa9350e commit acff51e

24 files changed

+107
-268
lines changed

testkit/src/main/scala/app/softnetwork/notification/api/MockAllNotificationsServer.scala

Lines changed: 0 additions & 14 deletions
This file was deleted.

testkit/src/main/scala/app/softnetwork/notification/handlers/MockAllNotificationsHandler.scala

Lines changed: 0 additions & 17 deletions
This file was deleted.

testkit/src/main/scala/app/softnetwork/notification/persistence/typed/MockAllNotificationsBehavior.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,93 @@
11
package app.softnetwork.notification.scalatest
22

33
import akka.actor.typed.ActorSystem
4-
import app.softnetwork.notification.api.{MockAllNotificationsServer, NotificationServer}
5-
import app.softnetwork.notification.handlers.MockAllNotificationsHandler
4+
import app.softnetwork.notification.api.{
5+
AllNotificationsServer,
6+
NotificationGrpcServer,
7+
NotificationServer
8+
}
9+
import app.softnetwork.notification.config.InternalConfig
10+
import app.softnetwork.notification.handlers.AllNotificationsHandler
611
import app.softnetwork.notification.model.Notification
712
import app.softnetwork.notification.persistence.query.{
813
NotificationCommandProcessorStream,
914
Scheduler2NotificationProcessorStream
1015
}
1116
import app.softnetwork.notification.persistence.typed.{
12-
MockAllNotificationsBehavior,
17+
AllNotificationsBehavior,
1318
NotificationBehavior
1419
}
20+
import app.softnetwork.notification.spi.FcmMockProvider
1521
import app.softnetwork.persistence.query.InMemoryJournalProvider
22+
import com.typesafe.config.Config
1623
import org.scalatest.Suite
1724

18-
trait AllNotificationsTestKit extends NotificationTestKit[Notification] {
19-
_: Suite =>
25+
trait AllNotificationsTestKit
26+
extends NotificationTestKit[Notification]
27+
with NotificationGrpcServer[Notification]
28+
with ApnsToken { _: Suite =>
29+
30+
implicit lazy val system: ActorSystem[_] = typedSystem()
31+
32+
lazy val apnsPort: Int = availablePort
33+
34+
lazy val smsPort: Int = availablePort
35+
36+
lazy val smtpPort: Int = availablePort
37+
38+
override lazy val additionalConfig: String = grpcConfig +
39+
s"""
40+
|notification.mail.host = $hostname
41+
|notification.mail.port = $smtpPort
42+
|notification.push.mock.apns.port = $apnsPort
43+
|notification.sms.mode.base-url = "http://$interface:$smsPort"
44+
|""".stripMargin
45+
46+
override def beforeAll(): Unit = {
47+
super.beforeAll()
48+
assert(
49+
new ApnsMockServer with InternalConfig {
50+
override implicit def system: ActorSystem[_] = typedSystem()
51+
52+
override def serverPort: Int = apnsPort
53+
54+
override lazy val config: Config = internalConfig
55+
}.initMockServer()
56+
)
57+
assert(
58+
new SMSMockServer with InternalConfig {
59+
override implicit def system: ActorSystem[_] = typedSystem()
60+
61+
override def serverPort: Int = smsPort
62+
63+
override def config: Config = internalConfig
64+
}.initMockServer()
65+
)
66+
assert(
67+
new SmtpMockServer with InternalConfig {
68+
override implicit def system: ActorSystem[_] = typedSystem()
69+
70+
override def serverPort: Int = smtpPort
71+
72+
override lazy val config: Config = internalConfig
73+
}.initMockServer()
74+
)
75+
}
2076

2177
override def notificationBehaviors: ActorSystem[_] => Seq[NotificationBehavior[Notification]] =
22-
_ => Seq(MockAllNotificationsBehavior)
78+
_ =>
79+
Seq(new AllNotificationsBehavior with FcmMockProvider with InternalConfig {
80+
override def config: Config = internalConfig
81+
})
2382

2483
override def scheduler2NotificationProcessorStream
2584
: ActorSystem[_] => Option[Scheduler2NotificationProcessorStream] =
2685
sys =>
2786
Some(
2887
new Scheduler2NotificationProcessorStream
29-
with MockAllNotificationsHandler
88+
with AllNotificationsHandler
3089
with InMemoryJournalProvider {
31-
override val tag: String = s"${MockAllNotificationsBehavior.persistenceId}-scheduler"
90+
override val tag: String = s"${AllNotificationsBehavior.persistenceId}-scheduler"
3291
override protected val forTests: Boolean = true
3392
override implicit def system: ActorSystem[_] = sys
3493
}
@@ -39,7 +98,7 @@ trait AllNotificationsTestKit extends NotificationTestKit[Notification] {
3998
sys =>
4099
Some(
41100
new NotificationCommandProcessorStream
42-
with MockAllNotificationsHandler
101+
with AllNotificationsHandler
43102
with InMemoryJournalProvider {
44103
override val forTests: Boolean = true
45104
override implicit def system: ActorSystem[_] = sys
@@ -49,5 +108,5 @@ trait AllNotificationsTestKit extends NotificationTestKit[Notification] {
49108
/** initialize all notification servers
50109
*/
51110
override def notificationServers: ActorSystem[_] => Seq[NotificationServer] = system =>
52-
Seq(MockAllNotificationsServer(system))
111+
Seq(AllNotificationsServer(system))
53112
}

testkit/src/main/scala/app/softnetwork/notification/spi/ApnsMockServer.scala renamed to testkit/src/main/scala/app/softnetwork/notification/scalatest/ApnsMockServer.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package app.softnetwork.notification.spi
1+
package app.softnetwork.notification.scalatest
22

33
import akka.Done
44
import app.softnetwork.notification.config.{ApnsConfig, InternalConfig, PushSettings}
@@ -9,12 +9,12 @@ import com.eatthepath.pushy.apns.server.{
99
PushNotificationHandlerFactory
1010
}
1111

12-
import scala.compat.java8.FutureConverters._
12+
import scala.compat.java8.FutureConverters.toScala
1313
import scala.concurrent.Future
14-
import scala.language.reflectiveCalls
1514
import scala.util.{Failure, Success, Try}
1615

17-
trait ApnsMockServer extends PushSettings with NotificationMockServer { _: InternalConfig =>
16+
trait ApnsMockServer extends PushSettings with NotificationMockServer {
17+
_: InternalConfig =>
1818

1919
override val name: String = "apns"
2020

@@ -24,6 +24,7 @@ trait ApnsMockServer extends PushSettings with NotificationMockServer { _: Inter
2424

2525
val SERVER_CERTIFICATES_FILENAME: String = "security/server-certs.pem"
2626
val SERVER_KEY_FILENAME: String = "security/server-key.pem"
27+
val SERVER_KEY_PASSWORD: Option[String] = None
2728

2829
def handler: PushNotificationHandlerFactory = new AcceptAllPushNotificationHandlerFactory
2930

@@ -33,7 +34,7 @@ trait ApnsMockServer extends PushSettings with NotificationMockServer { _: Inter
3334
.setServerCredentials(
3435
getClass.getClassLoader.getResourceAsStream(SERVER_CERTIFICATES_FILENAME),
3536
getClass.getClassLoader.getResourceAsStream(SERVER_KEY_FILENAME),
36-
null
37+
SERVER_KEY_PASSWORD.orNull
3738
)
3839
.setTrustedClientCertificateChain(
3940
getClass.getClassLoader.getResourceAsStream(apnsConfig.truststore.orNull)

0 commit comments

Comments
 (0)