33
33
import org .mockito .Mockito ;
34
34
35
35
import java .io .File ;
36
+ import java .net .URISyntaxException ;
36
37
import java .util .LinkedHashMap ;
37
38
import java .util .List ;
38
39
import java .util .Map ;
@@ -44,13 +45,15 @@ public class PersonsV2FilterTest extends AbstractFilterTest {
44
45
45
46
private static final Logger LOGGER = LogManager .getLogger (PersonsV2FilterTest .class );
46
47
47
- private AlertService alertService = Mockito .mock (AlertService .class );
48
- private MetricsService metricsService = Mockito .mock (MetricsService .class );
48
+ private final AlertService alertService = Mockito .mock (AlertService .class );
49
+ private final MetricsService metricsService = Mockito .mock (MetricsService .class );
49
50
50
51
@ Test
51
52
@ DisabledOnOs ({WINDOWS , MAC })
52
53
public void filter1 () throws Exception {
53
54
55
+ Assertions .assertTrue (modelFilesExist ());
56
+
54
57
final FilterConfiguration filterConfiguration = new FilterConfiguration .FilterConfigurationBuilder ()
55
58
.withStrategies (List .of (new PersonsFilterStrategy ()))
56
59
.withAlertService (alertService )
@@ -84,6 +87,8 @@ public void filter1() throws Exception {
84
87
@ DisabledOnOs ({WINDOWS , MAC })
85
88
public void filter2 () throws Exception {
86
89
90
+ Assertions .assertTrue (modelFilesExist ());
91
+
87
92
final FilterConfiguration filterConfiguration = new FilterConfiguration .FilterConfigurationBuilder ()
88
93
.withStrategies (List .of (new PersonsFilterStrategy ()))
89
94
.withAlertService (alertService )
@@ -124,6 +129,8 @@ public void filter2() throws Exception {
124
129
@ DisabledOnOs ({WINDOWS , MAC })
125
130
public void filter3 () throws Exception {
126
131
132
+ Assertions .assertTrue (modelFilesExist ());
133
+
127
134
final FilterConfiguration filterConfiguration = new FilterConfiguration .FilterConfigurationBuilder ()
128
135
.withStrategies (List .of (new PersonsFilterStrategy ()))
129
136
.withAlertService (alertService )
@@ -152,16 +159,14 @@ public void filter3() throws Exception {
152
159
153
160
Assertions .assertEquals (3 , filterResult .getSpans ().size ());
154
161
155
- //Assertions.assertTrue(checkSpanInSpans(filterResult.getSpans(), 1181, 1194, FilterType.PERSON, "Reverend King", "{{{REDACTED-person}}}"));
156
- //Assertions.assertTrue(checkSpanInSpans(filterResult.getSpans(), 1154, 1175, FilterType.PERSON, "Barbara Ferrer Ferrer", "{{{REDACTED-person}}}"));
157
- //Assertions.assertTrue(checkSpanInSpans(filterResult.getSpans(), 1043, 1061, FilterType.PERSON, "Martin Luther King", "{{{REDACTED-person}}}"));
158
-
159
162
}
160
163
161
164
@ Test
162
165
@ DisabledOnOs ({WINDOWS , MAC })
163
166
public void filter4 () throws Exception {
164
167
168
+ Assertions .assertTrue (modelFilesExist ());
169
+
165
170
final FilterConfiguration filterConfiguration = new FilterConfiguration .FilterConfigurationBuilder ()
166
171
.withStrategies (List .of (new PersonsFilterStrategy ()))
167
172
.withAlertService (alertService )
@@ -196,6 +201,8 @@ public void filter4() throws Exception {
196
201
@ DisabledOnOs ({WINDOWS , MAC })
197
202
public void filter5 () throws Exception {
198
203
204
+ Assertions .assertTrue (modelFilesExist ());
205
+
199
206
final FilterConfiguration filterConfiguration = new FilterConfiguration .FilterConfigurationBuilder ()
200
207
.withStrategies (List .of (new PersonsFilterStrategy ()))
201
208
.withAlertService (alertService )
@@ -232,6 +239,8 @@ public void filter5() throws Exception {
232
239
@ DisabledOnOs ({WINDOWS , MAC })
233
240
public void filter6 () throws Exception {
234
241
242
+ Assertions .assertTrue (modelFilesExist ());
243
+
235
244
final FilterConfiguration filterConfiguration = new FilterConfiguration .FilterConfigurationBuilder ()
236
245
.withStrategies (List .of (new PersonsFilterStrategy ()))
237
246
.withAlertService (alertService )
@@ -264,4 +273,18 @@ public void filter6() throws Exception {
264
273
265
274
}
266
275
276
+ private boolean modelFilesExist () throws URISyntaxException {
277
+
278
+ try {
279
+ new File (getClass ().getClassLoader ().getResource ("models/model.onnx" ).toURI ());
280
+ new File (getClass ().getClassLoader ().getResource ("models/vocab.txt" ).toURI ());
281
+ } catch (NullPointerException ex ) {
282
+ LOGGER .warn ("Unable to read the required models/model.onnx and/or models.vocab.txt for unit test. Ensure both files exist." );
283
+ return false ;
284
+ }
285
+
286
+ return true ;
287
+
288
+ }
289
+
267
290
}
0 commit comments