Skip to content

Commit c1349f9

Browse files
committed
to fix duplication code
1 parent acff51e commit c1349f9

14 files changed

+58
-202
lines changed

testkit/src/main/scala/app/softnetwork/notification/scalatest/AllNotificationsRouteTestKit.scala

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

testkit/src/main/scala/app/softnetwork/notification/scalatest/AllNotificationsTestKit.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ trait AllNotificationsTestKit
2727
with NotificationGrpcServer[Notification]
2828
with ApnsToken { _: Suite =>
2929

30-
implicit lazy val system: ActorSystem[_] = typedSystem()
31-
3230
lazy val apnsPort: Int = availablePort
3331

3432
lazy val smsPort: Int = availablePort
@@ -47,7 +45,7 @@ trait AllNotificationsTestKit
4745
super.beforeAll()
4846
assert(
4947
new ApnsMockServer with InternalConfig {
50-
override implicit def system: ActorSystem[_] = typedSystem()
48+
override implicit def system: ActorSystem[_] = asystem
5149

5250
override def serverPort: Int = apnsPort
5351

@@ -56,7 +54,7 @@ trait AllNotificationsTestKit
5654
)
5755
assert(
5856
new SMSMockServer with InternalConfig {
59-
override implicit def system: ActorSystem[_] = typedSystem()
57+
override implicit def system: ActorSystem[_] = asystem
6058

6159
override def serverPort: Int = smsPort
6260

@@ -65,7 +63,7 @@ trait AllNotificationsTestKit
6563
)
6664
assert(
6765
new SmtpMockServer with InternalConfig {
68-
override implicit def system: ActorSystem[_] = typedSystem()
66+
override implicit def system: ActorSystem[_] = asystem
6967

7068
override def serverPort: Int = smtpPort
7169

testkit/src/main/scala/app/softnetwork/notification/scalatest/ApnsNotificationsTestKit.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ trait ApnsNotificationsTestKit
2626
with NotificationGrpcServer[Push]
2727
with ApnsToken { _: Suite =>
2828

29-
implicit lazy val system: ActorSystem[_] = typedSystem()
30-
3129
lazy val apnsPort: Int = availablePort
3230

3331
override lazy val additionalConfig: String = grpcConfig +
@@ -39,7 +37,7 @@ trait ApnsNotificationsTestKit
3937
super.beforeAll()
4038
assert(
4139
new ApnsMockServer with InternalConfig {
42-
override implicit def system: ActorSystem[_] = typedSystem()
40+
override implicit def system: ActorSystem[_] = asystem
4341

4442
override def serverPort: Int = apnsPort
4543

testkit/src/main/scala/app/softnetwork/notification/scalatest/FcmAndApnsNotificationsTestKit.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ trait FcmAndApnsNotificationsTestKit
2727
with NotificationGrpcServer[Push]
2828
with ApnsToken { _: Suite =>
2929

30-
implicit lazy val system: ActorSystem[_] = typedSystem()
31-
3230
lazy val apnsPort: Int = availablePort
3331

3432
override lazy val additionalConfig: String = grpcConfig +
@@ -40,7 +38,7 @@ trait FcmAndApnsNotificationsTestKit
4038
super.beforeAll()
4139
assert(
4240
new ApnsMockServer with InternalConfig {
43-
override implicit def system: ActorSystem[_] = typedSystem()
41+
override implicit def system: ActorSystem[_] = asystem
4442

4543
override def serverPort: Int = apnsPort
4644

testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationRouteTestKit.scala

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

testkit/src/main/scala/app/softnetwork/notification/scalatest/NotificationTestKit.scala

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
package app.softnetwork.notification.scalatest
22

3+
import akka.actor.testkit.typed.scaladsl.TestProbe
4+
import akka.actor.typed.ActorSystem
5+
import akka.actor.typed.eventstream.EventStream.Subscribe
6+
import app.softnetwork.notification.api.NotificationClient
7+
import app.softnetwork.notification.config.MailSettings
38
import app.softnetwork.notification.config.NotificationSettings.NotificationConfig
49
import app.softnetwork.notification.launch.NotificationGuardian
10+
import app.softnetwork.notification.message.Schedule4NotificationTriggered
511
import app.softnetwork.notification.model.Notification
612
import app.softnetwork.scheduler.scalatest.SchedulerTestKit
713
import com.typesafe.config.Config
814
import org.scalatest.Suite
15+
import org.softnetwork.notification.model.{BasicDevice, From, Mail, Platform, Push, SMS}
916

1017
import java.net.ServerSocket
1118

12-
trait NotificationTestKit[T <: Notification] extends SchedulerTestKit with NotificationGuardian[T] {
19+
trait NotificationTestKit[T <: Notification]
20+
extends SchedulerTestKit
21+
with NotificationGuardian[T]
22+
with ApnsToken {
1323
_: Suite =>
1424

25+
implicit lazy val asystem: ActorSystem[_] = typedSystem()
26+
1527
/** @return
1628
* roles associated with this node
1729
*/
@@ -26,4 +38,39 @@ trait NotificationTestKit[T <: Notification] extends SchedulerTestKit with Notif
2638
port
2739
}
2840

41+
val subject = "test"
42+
val message = "message"
43+
44+
protected def generateMail(uuid: String): Mail =
45+
Mail.defaultInstance
46+
.withUuid(uuid)
47+
.withFrom(From(MailSettings.MailConfig.username, None))
48+
.withTo(Seq("nobody@gmail.com"))
49+
.withSubject(subject)
50+
.withMessage(message)
51+
52+
protected def generateSMS(uuid: String): SMS =
53+
SMS.defaultInstance
54+
.withUuid(uuid)
55+
.withSubject(subject)
56+
.withMessage(message)
57+
.withTo(Seq(uuid))
58+
59+
protected def generatePush(uuid: String, devices: BasicDevice*): Push =
60+
Push.defaultInstance
61+
.withUuid(uuid)
62+
.withSubject(subject)
63+
.withMessage(message)
64+
.withDevices(devices)
65+
.withApp("mock")
66+
67+
val iosDevice: BasicDevice = BasicDevice(generateRandomDeviceToken, Platform.IOS)
68+
69+
val androidDevice: BasicDevice = BasicDevice("test-token-android", Platform.ANDROID)
70+
71+
val probe: TestProbe[Schedule4NotificationTriggered] =
72+
createTestProbe[Schedule4NotificationTriggered]()
73+
asystem.eventStream.tell(Subscribe(probe.ref))
74+
75+
lazy val client: NotificationClient = NotificationClient(asystem)
2976
}

testkit/src/main/scala/app/softnetwork/notification/scalatest/SMSModeNotificationsTestKit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ trait SMSModeNotificationsTestKit
3636
super.beforeAll()
3737
assert(
3838
new SMSMockServer with InternalConfig {
39-
override implicit def system: ActorSystem[_] = typedSystem()
39+
override implicit def system: ActorSystem[_] = asystem
4040

4141
override def serverPort: Int = smsPort
4242

testkit/src/main/scala/app/softnetwork/notification/scalatest/SimpleMailNotificationsTestKit.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ trait SimpleMailNotificationsTestKit
2525
extends NotificationTestKit[Mail]
2626
with NotificationGrpcServer[Mail] { _: Suite =>
2727

28-
implicit lazy val system: ActorSystem[Nothing] = typedSystem()
29-
3028
lazy val smtpPort: Int = availablePort
3129

3230
override lazy val additionalConfig: String = grpcConfig +
@@ -39,7 +37,7 @@ trait SimpleMailNotificationsTestKit
3937
super.beforeAll()
4038
assert(
4139
new SmtpMockServer with InternalConfig {
42-
override implicit def system: ActorSystem[_] = typedSystem()
40+
override implicit def system: ActorSystem[_] = asystem
4341

4442
override def serverPort: Int = smtpPort
4543

testkit/src/test/scala/app/softnetwork/notification/handlers/AllNotificationsHandlerSpec.scala

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package app.softnetwork.notification.handlers
22

3-
import akka.actor.testkit.typed.scaladsl.TestProbe
4-
import akka.actor.typed.eventstream.EventStream.Subscribe
5-
import app.softnetwork.notification.api.NotificationClient
63
import org.scalatest.wordspec.AnyWordSpecLike
7-
import app.softnetwork.notification.config.MailSettings
84
import app.softnetwork.notification.message._
9-
import org.softnetwork.notification.model.{From, Mail, Push, SMS}
105
import app.softnetwork.notification.scalatest.AllNotificationsTestKit
116

127
/** Created by smanciot on 14/04/2020.
@@ -16,37 +11,6 @@ class AllNotificationsHandlerSpec
1611
with AnyWordSpecLike
1712
with AllNotificationsTestKit {
1813

19-
lazy val from: String = MailSettings.MailConfig.username
20-
val to = Seq("nobody@gmail.com")
21-
val subject = "test"
22-
val message = "message"
23-
24-
private[this] def generateMail(uuid: String): Mail =
25-
Mail.defaultInstance
26-
.withUuid(uuid)
27-
.withFrom(From(from, None))
28-
.withTo(to)
29-
.withSubject(subject)
30-
.withMessage(message)
31-
32-
private[this] def generateSMS(uuid: String): SMS =
33-
SMS.defaultInstance
34-
.withUuid(uuid)
35-
.withSubject(subject)
36-
.withMessage(message)
37-
38-
private[this] def generatePush(uuid: String): Push =
39-
Push.defaultInstance
40-
.withUuid(uuid)
41-
.withSubject(subject)
42-
.withMessage(message)
43-
44-
val probe: TestProbe[Schedule4NotificationTriggered] =
45-
createTestProbe[Schedule4NotificationTriggered]()
46-
system.eventStream.tell(Subscribe(probe.ref))
47-
48-
lazy val client: NotificationClient = NotificationClient(system)
49-
5014
"Notification handler" must {
5115

5216
"add notification" in {

testkit/src/test/scala/app/softnetwork/notification/handlers/ApnsNotificationsHandlerSpec.scala

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package app.softnetwork.notification.handlers
22

3-
import akka.actor.testkit.typed.scaladsl.TestProbe
4-
import akka.actor.typed.eventstream.EventStream.Subscribe
5-
import app.softnetwork.notification.api.NotificationClient
63
import app.softnetwork.notification.message._
74
import app.softnetwork.notification.scalatest.ApnsNotificationsTestKit
85
import org.scalatest.wordspec.AnyWordSpecLike
9-
import org.softnetwork.notification.model.{BasicDevice, NotificationStatus, Platform, Push}
6+
import org.softnetwork.notification.model.NotificationStatus
107

118
/** Created by smanciot on 07/12/2022.
129
*/
@@ -15,27 +12,6 @@ class ApnsNotificationsHandlerSpec
1512
with AnyWordSpecLike
1613
with ApnsNotificationsTestKit {
1714

18-
val subject = "test"
19-
val message = "message"
20-
21-
protected def generatePush(uuid: String, devices: BasicDevice*): Push =
22-
Push.defaultInstance
23-
.withUuid(uuid)
24-
.withSubject(subject)
25-
.withMessage(message)
26-
.withDevices(devices)
27-
.withApp("mock")
28-
29-
val iosDevice: BasicDevice = BasicDevice(generateRandomDeviceToken, Platform.IOS)
30-
31-
val androidDevice: BasicDevice = BasicDevice("test-token-android", Platform.ANDROID)
32-
33-
val probe: TestProbe[Schedule4NotificationTriggered] =
34-
createTestProbe[Schedule4NotificationTriggered]()
35-
system.eventStream.tell(Subscribe(probe.ref))
36-
37-
lazy val client: NotificationClient = NotificationClient(system)
38-
3915
"Apns Notification handler" must {
4016

4117
"add notification" in {

0 commit comments

Comments
 (0)