|
22 | 22 | import java.util.ArrayList;
|
23 | 23 | import java.util.HashMap;
|
24 | 24 | import java.util.List;
|
| 25 | +import java.util.Locale; |
25 | 26 | import java.util.Map;
|
26 | 27 | import java.util.function.BiConsumer;
|
27 | 28 | import java.util.function.Supplier;
|
@@ -323,31 +324,76 @@ public void testExecute_MLClientAccessorThrowFail_handlerFailure() {
|
323 | 324 | }
|
324 | 325 |
|
325 | 326 | public void testExecute_mapHasNonStringValue_throwIllegalArgumentException() {
|
326 |
| - Map<String, String> map1 = ImmutableMap.of("test1", "test2"); |
327 |
| - Map<String, Double> map2 = ImmutableMap.of("test3", 209.3D); |
328 | 327 | Map<String, Object> sourceAndMetadata = new HashMap<>();
|
329 |
| - sourceAndMetadata.put("key1", map1); |
330 |
| - sourceAndMetadata.put("my_text_field", map2); |
| 328 | + sourceAndMetadata.put("key1", "test2"); |
| 329 | + sourceAndMetadata.put("my_text_field", 209.3D); |
331 | 330 | sourceAndMetadata.put(IndexFieldMapper.NAME, "my_index");
|
332 | 331 | IngestDocument ingestDocument = new IngestDocument(sourceAndMetadata, new HashMap<>());
|
333 | 332 | TextImageEmbeddingProcessor processor = createInstance(false);
|
334 | 333 | BiConsumer handler = mock(BiConsumer.class);
|
335 | 334 | processor.execute(ingestDocument, handler);
|
336 |
| - verify(handler).accept(isNull(), any(IllegalArgumentException.class)); |
| 335 | + |
| 336 | + ArgumentCaptor<Throwable> argumentCaptor = ArgumentCaptor.forClass(Throwable.class); |
| 337 | + verify(handler).accept(isNull(), argumentCaptor.capture()); |
| 338 | + |
| 339 | + Throwable capturedException = argumentCaptor.getValue(); |
| 340 | + assertTrue(capturedException instanceof IllegalArgumentException); |
| 341 | + final String desiredExceptionMessage = String.format( |
| 342 | + Locale.getDefault(), |
| 343 | + "Unsupported format of the field in the document, %s value must be a non-empty string. Currently it is '%s'. Type is %s", |
| 344 | + "my_text_field", |
| 345 | + 209.3D, |
| 346 | + Double.class |
| 347 | + ); |
| 348 | + assertEquals(desiredExceptionMessage, capturedException.getMessage()); |
337 | 349 | }
|
338 | 350 |
|
339 | 351 | public void testExecute_mapHasEmptyStringValue_throwIllegalArgumentException() {
|
340 |
| - Map<String, String> map1 = ImmutableMap.of("test1", "test2"); |
341 |
| - Map<String, String> map2 = ImmutableMap.of("test3", " "); |
342 | 352 | Map<String, Object> sourceAndMetadata = new HashMap<>();
|
343 |
| - sourceAndMetadata.put("key1", map1); |
344 |
| - sourceAndMetadata.put("my_text_field", map2); |
| 353 | + sourceAndMetadata.put("key1", "test2"); |
| 354 | + sourceAndMetadata.put("my_text_field", ""); |
345 | 355 | sourceAndMetadata.put(IndexFieldMapper.NAME, "my_index");
|
346 | 356 | IngestDocument ingestDocument = new IngestDocument(sourceAndMetadata, new HashMap<>());
|
347 | 357 | TextImageEmbeddingProcessor processor = createInstance(false);
|
348 | 358 | BiConsumer handler = mock(BiConsumer.class);
|
349 | 359 | processor.execute(ingestDocument, handler);
|
350 |
| - verify(handler).accept(isNull(), any(IllegalArgumentException.class)); |
| 360 | + |
| 361 | + ArgumentCaptor<Throwable> argumentCaptor = ArgumentCaptor.forClass(Throwable.class); |
| 362 | + verify(handler).accept(isNull(), argumentCaptor.capture()); |
| 363 | + |
| 364 | + Throwable capturedException = argumentCaptor.getValue(); |
| 365 | + assertTrue(capturedException instanceof IllegalArgumentException); |
| 366 | + final String desiredExceptionMessage = String.format( |
| 367 | + Locale.getDefault(), |
| 368 | + "Unsupported format of the field in the document, %s value must be a non-empty string. Currently it is '%s'. Type is %s", |
| 369 | + "my_text_field", |
| 370 | + "", |
| 371 | + "".getClass() |
| 372 | + ); |
| 373 | + assertEquals(desiredExceptionMessage, capturedException.getMessage()); |
| 374 | + } |
| 375 | + |
| 376 | + public void testExecute_mapHasNullValue_throwIllegalArgumentException() { |
| 377 | + Map<String, Object> sourceAndMetadata = new HashMap<>(); |
| 378 | + sourceAndMetadata.put("key1", "test2"); |
| 379 | + sourceAndMetadata.put("my_text_field", null); |
| 380 | + sourceAndMetadata.put(IndexFieldMapper.NAME, "my_index"); |
| 381 | + IngestDocument ingestDocument = new IngestDocument(sourceAndMetadata, new HashMap<>()); |
| 382 | + TextImageEmbeddingProcessor processor = createInstance(false); |
| 383 | + BiConsumer handler = mock(BiConsumer.class); |
| 384 | + processor.execute(ingestDocument, handler); |
| 385 | + |
| 386 | + ArgumentCaptor<Throwable> argumentCaptor = ArgumentCaptor.forClass(Throwable.class); |
| 387 | + verify(handler).accept(isNull(), argumentCaptor.capture()); |
| 388 | + |
| 389 | + Throwable capturedException = argumentCaptor.getValue(); |
| 390 | + assertTrue(capturedException instanceof IllegalArgumentException); |
| 391 | + final String desiredExceptionMessage = String.format( |
| 392 | + Locale.getDefault(), |
| 393 | + "Unsupported format of the field in the document, %s value must be a non-empty string. Currently it is null", |
| 394 | + "my_text_field" |
| 395 | + ); |
| 396 | + assertEquals(desiredExceptionMessage, capturedException.getMessage()); |
351 | 397 | }
|
352 | 398 |
|
353 | 399 | public void testExecute_hybridTypeInput_successful() throws Exception {
|
|
0 commit comments