@@ -11,6 +11,9 @@ import org.junit.jupiter.api.BeforeEach
11
11
import org.junit.jupiter.api.Test
12
12
import org.junit.jupiter.params.ParameterizedTest
13
13
import org.junit.jupiter.params.provider.MethodSource
14
+ import org.mockito.kotlin.any
15
+ import org.mockito.kotlin.eq
16
+ import org.mockito.kotlin.verify
14
17
import org.opensearch.action.admin.indices.alias.Alias
15
18
import org.opensearch.action.admin.indices.delete.DeleteIndexRequest
16
19
import org.opensearch.client.RequestOptions
@@ -22,11 +25,13 @@ import org.opensearch.data.client.orhlc.OpenSearchRestTemplate
22
25
import org.springframework.beans.factory.annotation.Autowired
23
26
import org.springframework.beans.factory.annotation.Value
24
27
import org.springframework.boot.test.context.SpringBootTest
28
+ import org.springframework.boot.test.mock.mockito.MockBean
25
29
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates
26
30
import org.springframework.data.elasticsearch.core.query.Query
27
31
import org.springframework.http.MediaType
28
32
import org.springframework.test.context.ActiveProfiles
29
33
import org.springframework.util.ResourceUtils
34
+ import uk.gov.justice.digital.hmpps.hmppsauditsdk.AuditService
30
35
import uk.gov.justice.hmpps.probationsearch.contactsearch.ContactGenerator.contacts
31
36
import uk.gov.justice.hmpps.probationsearch.util.JwtAuthenticationHelper
32
37
@@ -43,6 +48,9 @@ class ContactSearchIntegrationTest {
43
48
@Value(" \$ {local.server.port}" )
44
49
internal val port: Int = 0
45
50
51
+ @MockBean
52
+ internal lateinit var auditService: AuditService
53
+
46
54
@BeforeEach
47
55
internal fun before () {
48
56
RestAssured .port = port
@@ -87,6 +95,8 @@ class ContactSearchIntegrationTest {
87
95
.map { it.id }
88
96
.take(3 ),
89
97
)
98
+
99
+ verify(auditService).publishEvent(eq(" Search Contacts" ), any(), eq(crn), eq(" CRN" ), any(), " probation-search" )
90
100
}
91
101
92
102
@ParameterizedTest
@@ -102,6 +112,8 @@ class ContactSearchIntegrationTest {
102
112
val found = results.results.first()
103
113
assertThat(found.crn).isEqualTo(crn)
104
114
assertThat(found.highlights).containsExactlyInAnyOrderEntriesOf(mapOf (" type" to listOf (" <em>FIND_ME</em>" )))
115
+
116
+ verify(auditService).publishEvent(eq(" Search Contacts" ), any(), eq(crn), eq(" CRN" ), any(), " probation-search" )
105
117
}
106
118
107
119
@Test
@@ -122,6 +134,8 @@ class ContactSearchIntegrationTest {
122
134
.map { it.id }
123
135
.take(4 ),
124
136
)
137
+
138
+ verify(auditService).publishEvent(eq(" Search Contacts" ), any(), eq(crn), eq(" CRN" ), any(), " probation-search" )
125
139
}
126
140
127
141
@Test
@@ -142,6 +156,8 @@ class ContactSearchIntegrationTest {
142
156
.map { it.id }
143
157
.take(4 ),
144
158
)
159
+
160
+ verify(auditService).publishEvent(eq(" Search Contacts" ), any(), eq(crn), eq(" CRN" ), any(), " probation-search" )
145
161
}
146
162
147
163
@Test
@@ -162,6 +178,8 @@ class ContactSearchIntegrationTest {
162
178
.map { it.id }
163
179
.take(4 ),
164
180
)
181
+
182
+ verify(auditService).publishEvent(eq(" Search Contacts" ), any(), eq(crn), eq(" CRN" ), any(), " probation-search" )
165
183
}
166
184
167
185
@ParameterizedTest
@@ -176,6 +194,8 @@ class ContactSearchIntegrationTest {
176
194
177
195
assertThat(results.size).isEqualTo(1 )
178
196
assertThat(results.results.first().crn).isEqualTo(crn)
197
+
198
+ verify(auditService).publishEvent(eq(" Search Contacts" ), any(), eq(crn), eq(" CRN" ), any(), " probation-search" )
179
199
}
180
200
181
201
@Test
@@ -196,6 +216,8 @@ class ContactSearchIntegrationTest {
196
216
" outcome" to listOf (" Matches were <em>highlighted</em>" ),
197
217
),
198
218
)
219
+
220
+ verify(auditService).publishEvent(eq(" Search Contacts" ), any(), eq(crn), eq(" CRN" ), any(), " probation-search" )
199
221
}
200
222
201
223
companion object {
0 commit comments