@@ -19,7 +19,6 @@ import org.mockito.ArgumentMatchers.{eq => eqTo, _}
19
19
import org .mockito .Mockito ._
20
20
import org .scalatest .mockito .MockitoSugar
21
21
import org .scalatest .{AsyncFlatSpec , BeforeAndAfter , Matchers }
22
- import za .co .absa .hyperdrive .trigger .TestUtils .await
23
22
import za .co .absa .hyperdrive .trigger .models .NotificationRule
24
23
import za .co .absa .hyperdrive .trigger .models .enums .DagInstanceStatuses
25
24
import za .co .absa .hyperdrive .trigger .models .errors .{ApiException , ValidationError }
@@ -46,40 +45,40 @@ class NotificationRuleValidationServiceTest extends AsyncFlatSpec with Matchers
46
45
.thenReturn(Future (true ))
47
46
48
47
// when
49
- await( underTest.validate(notificationRule))
50
-
51
- // then
52
- verify(workflowRepository).existsProject (eqTo(notificationRule.project .get))(any[ ExecutionContext ])
53
- verify(workflowRepository).existsWorkflowWithPrefix(eqTo(notificationRule.workflowPrefix.get))(
54
- any[ ExecutionContext ]
55
- )
56
- succeed
48
+ underTest.validate(notificationRule).map { _ =>
49
+ // then
50
+ verify(workflowRepository).existsProject(eqTo(notificationRule.project.get))(any[ ExecutionContext ])
51
+ verify(workflowRepository).existsWorkflowWithPrefix (eqTo(notificationRule.workflowPrefix .get))(
52
+ any[ ExecutionContext ]
53
+ )
54
+ succeed
55
+ }
57
56
}
58
57
59
58
it should " succeed if neither project nor workflowPrefix are specified" in {
60
59
// given
61
60
val notificationRule = createNotificationRule().copy(project = None , workflowPrefix = None )
62
61
63
62
// when
64
- await( underTest.validate(notificationRule))
65
-
66
- // then
67
- verify(workflowRepository, never()).existsProject (any())(any())
68
- verify(workflowRepository, never()).existsWorkflowWithPrefix(any())(any())
69
- succeed
63
+ underTest.validate(notificationRule).map { _ =>
64
+ // then
65
+ verify(workflowRepository, never()).existsProject(any())(any())
66
+ verify(workflowRepository, never()).existsWorkflowWithPrefix (any())(any())
67
+ succeed
68
+ }
70
69
}
71
70
72
71
it should " succeed if both project and workflowPrefix are empty" in {
73
72
// given
74
73
val notificationRule = createNotificationRule().copy(project = Some (" " ), workflowPrefix = Some (" " ))
75
74
76
75
// when
77
- await( underTest.validate(notificationRule))
78
-
79
- // then
80
- verify(workflowRepository, never()).existsProject (any())(any())
81
- verify(workflowRepository, never()).existsWorkflowWithPrefix(any())(any())
82
- succeed
76
+ underTest.validate(notificationRule).map { _ =>
77
+ // then
78
+ verify(workflowRepository, never()).existsProject(any())(any())
79
+ verify(workflowRepository, never()).existsWorkflowWithPrefix (any())(any())
80
+ succeed
81
+ }
83
82
}
84
83
85
84
it should " succeed if minElapsedSeconds is > 0" in {
@@ -91,10 +90,10 @@ class NotificationRuleValidationServiceTest extends AsyncFlatSpec with Matchers
91
90
.thenReturn(Future (true ))
92
91
93
92
// when
94
- await( underTest.validate(notificationRule))
95
-
96
- // then
97
- succeed
93
+ underTest.validate(notificationRule).map { _ =>
94
+ // then
95
+ succeed
96
+ }
98
97
}
99
98
100
99
it should " fail if the project doesn't exist" in {
@@ -106,11 +105,12 @@ class NotificationRuleValidationServiceTest extends AsyncFlatSpec with Matchers
106
105
.thenReturn(Future (true ))
107
106
108
107
// when
109
- val result = the[ApiException ] thrownBy await(underTest.validate(notificationRule))
110
-
111
- // then
112
- result.apiErrors should have size 1
113
- result.apiErrors.head shouldBe ValidationError (s " No project with name ${notificationRule.project.get} exists " )
108
+ underTest.validate(notificationRule).failed.map { error =>
109
+ // then
110
+ val result = error.asInstanceOf [ApiException ]
111
+ result.apiErrors should have size 1
112
+ result.apiErrors.head shouldBe ValidationError (s " No project with name ${notificationRule.project.get} exists " )
113
+ }
114
114
}
115
115
116
116
it should " fail if the workflow prefix doesn't match any workflows" in {
@@ -122,13 +122,14 @@ class NotificationRuleValidationServiceTest extends AsyncFlatSpec with Matchers
122
122
.thenReturn(Future (false ))
123
123
124
124
// when
125
- val result = the[ApiException ] thrownBy await(underTest.validate(notificationRule))
126
-
127
- // then
128
- result.apiErrors should have size 1
129
- result.apiErrors.head shouldBe ValidationError (
130
- s " No workflow with prefix ${notificationRule.workflowPrefix.get} exists "
131
- )
125
+ underTest.validate(notificationRule).failed.map { error =>
126
+ val result = error.asInstanceOf [ApiException ]
127
+ // then
128
+ result.apiErrors should have size 1
129
+ result.apiErrors.head shouldBe ValidationError (
130
+ s " No workflow with prefix ${notificationRule.workflowPrefix.get} exists "
131
+ )
132
+ }
132
133
}
133
134
134
135
it should " fail if any email address is invalid" in {
@@ -140,14 +141,15 @@ class NotificationRuleValidationServiceTest extends AsyncFlatSpec with Matchers
140
141
.thenReturn(Future (true ))
141
142
142
143
// when
143
- val result = the[ApiException ] thrownBy await(underTest.validate(notificationRule))
144
-
145
- // then
146
- result.apiErrors should have size 2
147
- result.apiErrors should contain theSameElementsAs Seq (
148
- ValidationError (s " Recipient abc@com is not a valid e-mail address " ),
149
- ValidationError (s " Recipient abc.def.ghi is not a valid e-mail address " )
150
- )
144
+ underTest.validate(notificationRule).failed.map { error =>
145
+ val result = error.asInstanceOf [ApiException ]
146
+ // then
147
+ result.apiErrors should have size 2
148
+ result.apiErrors should contain theSameElementsAs Seq (
149
+ ValidationError (s " Recipient abc@com is not a valid e-mail address " ),
150
+ ValidationError (s " Recipient abc.def.ghi is not a valid e-mail address " )
151
+ )
152
+ }
151
153
}
152
154
153
155
it should " fail if minElapsedSeconds is < 0" in {
@@ -159,11 +161,12 @@ class NotificationRuleValidationServiceTest extends AsyncFlatSpec with Matchers
159
161
.thenReturn(Future (true ))
160
162
161
163
// when
162
- val result = the[ApiException ] thrownBy await(underTest.validate(notificationRule))
163
-
164
- // then
165
- result.apiErrors should have size 1
166
- result.apiErrors.head.message shouldBe " Min elapsed seconds since last success cannot be negative, is -1"
164
+ underTest.validate(notificationRule).failed.map { error =>
165
+ val result = error.asInstanceOf [ApiException ]
166
+ // then
167
+ result.apiErrors should have size 1
168
+ result.apiErrors.head.message shouldBe " Min elapsed seconds since last success cannot be negative, is -1"
169
+ }
167
170
}
168
171
169
172
it should " return all validation errors" in {
@@ -175,15 +178,16 @@ class NotificationRuleValidationServiceTest extends AsyncFlatSpec with Matchers
175
178
.thenReturn(Future (false ))
176
179
177
180
// when
178
- val result = the[ApiException ] thrownBy await(underTest.validate(notificationRule))
179
-
180
- // then
181
- result.apiErrors should have size 3
182
- result.apiErrors should contain theSameElementsAs Seq (
183
- ValidationError (s " No workflow with prefix ${notificationRule.workflowPrefix.get} exists " ),
184
- ValidationError (s " No project with name ${notificationRule.project.get} exists " ),
185
- ValidationError (s " Recipient abc@com is not a valid e-mail address " )
186
- )
181
+ underTest.validate(notificationRule).failed.map { error =>
182
+ val result = error.asInstanceOf [ApiException ]
183
+ // then
184
+ result.apiErrors should have size 3
185
+ result.apiErrors should contain theSameElementsAs Seq (
186
+ ValidationError (s " No workflow with prefix ${notificationRule.workflowPrefix.get} exists " ),
187
+ ValidationError (s " No project with name ${notificationRule.project.get} exists " ),
188
+ ValidationError (s " Recipient abc@com is not a valid e-mail address " )
189
+ )
190
+ }
187
191
}
188
192
189
193
private def createNotificationRule () =
0 commit comments