11package app .softnetwork .notification .scalatest
22
33import 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
611import app .softnetwork .notification .model .Notification
712import app .softnetwork .notification .persistence .query .{
813 NotificationCommandProcessorStream ,
914 Scheduler2NotificationProcessorStream
1015}
1116import app .softnetwork .notification .persistence .typed .{
12- MockAllNotificationsBehavior ,
17+ AllNotificationsBehavior ,
1318 NotificationBehavior
1419}
20+ import app .softnetwork .notification .spi .FcmMockProvider
1521import app .softnetwork .persistence .query .InMemoryJournalProvider
22+ import com .typesafe .config .Config
1623import 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}
0 commit comments