|
40 | 40 | import org.dspace.content.Collection; |
41 | 41 | import org.dspace.content.Community; |
42 | 42 | import org.dspace.content.Item; |
43 | | -import org.dspace.content.MetadataValue; |
44 | 43 | import org.dspace.content.ReportResult; |
45 | 44 | import org.dspace.content.clarin.ClarinLicense; |
46 | 45 | import org.dspace.content.clarin.ClarinLicenseLabel; |
@@ -399,108 +398,109 @@ public void testMetadataCheckWithRestrictedReportSize() throws Exception { |
399 | 398 | configurationService.setProperty("healthcheck.metadata.max-errors-to-show", 8); |
400 | 399 | configurationService.setProperty("healthcheck.metadata.error-dispersion-quota", 1); |
401 | 400 |
|
402 | | - Community community = CommunityBuilder.createCommunity(context) |
403 | | - .withName("Community") |
404 | | - .build(); |
405 | | - |
406 | | - Collection collection = CollectionBuilder.createCollection(context, community) |
407 | | - .withName("Collection") |
408 | | - .withSubmitterGroup(eperson) |
409 | | - .build(); |
410 | | - |
411 | | - Item item1 = ItemBuilder.createItem(context, collection) |
412 | | - .withTitle("Test item 1") |
413 | | - .withType("corpus") |
414 | | - .withSubject("Test subject") |
415 | | - .withMetadata("local", "branding", null, "Community") |
416 | | - .build(); |
417 | | - |
418 | | - Item item2 = ItemBuilder.createItem(context, collection) |
419 | | - .withTitle("Test item 2") |
420 | | - .withType("toolService") |
421 | | - .withSubject("Test subject") |
422 | | - .withMetadata("local", "branding", null, "Community") |
423 | | - .withMetadata("dc", "relation", "replaces", findItemUri(item1)) |
424 | | - .build(); |
| 401 | + try { |
| 402 | + Community community = CommunityBuilder.createCommunity(context) |
| 403 | + .withName("Community") |
| 404 | + .build(); |
425 | 405 |
|
426 | | - ItemBuilder.createItem(context, collection) |
427 | | - .withTitle("Test item 3") |
428 | | - .withType("toolService") |
429 | | - .withSubject("Test subject") |
430 | | - .withMetadata("local", "branding", null, "Community") |
431 | | - .withMetadata("dc", "relation", "isreplacedby", findItemUri(item2)) |
432 | | - .build(); |
| 406 | + Collection collection = CollectionBuilder.createCollection(context, community) |
| 407 | + .withName("Collection") |
| 408 | + .withSubmitterGroup(eperson) |
| 409 | + .build(); |
433 | 410 |
|
434 | | - // create 4 items with missing title |
435 | | - for (int i = 0; i < 4; i++) { |
436 | | - ItemBuilder.createItem(context, collection) |
437 | | - .withType("toolService") |
| 411 | + Item item1 = ItemBuilder.createItem(context, collection) |
| 412 | + .withTitle("Test item 1") |
| 413 | + .withType("corpus") |
438 | 414 | .withSubject("Test subject") |
439 | 415 | .withMetadata("local", "branding", null, "Community") |
440 | 416 | .build(); |
441 | | - } |
442 | 417 |
|
443 | | - // create 4 items with missing type |
444 | | - for (int i = 4; i < 8; i++) { |
445 | | - ItemBuilder.createItem(context, collection) |
446 | | - .withTitle("Test Item " + i) |
| 418 | + Item item2 = ItemBuilder.createItem(context, collection) |
| 419 | + .withTitle("Test item 2") |
| 420 | + .withType("toolService") |
447 | 421 | .withSubject("Test subject") |
448 | 422 | .withMetadata("local", "branding", null, "Community") |
| 423 | + .withMetadata("dc", "relation", "replaces", findItemUri(item1)) |
449 | 424 | .build(); |
450 | | - } |
451 | 425 |
|
452 | | - // create 4 items with duplicate type |
453 | | - for (int i = 8; i < 12; i++) { |
454 | 426 | ItemBuilder.createItem(context, collection) |
455 | | - .withTitle("Test Item " + i) |
| 427 | + .withTitle("Test item 3") |
456 | 428 | .withType("toolService") |
457 | | - .withType("corpus") |
458 | 429 | .withSubject("Test subject") |
459 | 430 | .withMetadata("local", "branding", null, "Community") |
| 431 | + .withMetadata("dc", "relation", "isreplacedby", findItemUri(item2)) |
460 | 432 | .build(); |
461 | | - } |
462 | | - |
463 | | - TestDSpaceRunnableHandler testDSpaceRunnableHandler = new TestDSpaceRunnableHandler(); |
464 | 433 |
|
465 | | - // with "health-report -c 5", only Metadata check is running |
466 | | - String[] args = new String[]{"health-report", "-c", "5"}; |
467 | | - ScriptLauncher.handleScript(args, ScriptLauncher.getConfig(kernelImpl), testDSpaceRunnableHandler, kernelImpl); |
468 | | - |
469 | | - assertThat(testDSpaceRunnableHandler.getErrorMessages(), empty()); |
470 | | - List<String> messages = testDSpaceRunnableHandler.getInfoMessages(); |
| 434 | + // create 4 items with missing title |
| 435 | + for (int i = 0; i < 4; i++) { |
| 436 | + ItemBuilder.createItem(context, collection) |
| 437 | + .withType("toolService") |
| 438 | + .withSubject("Test subject") |
| 439 | + .withMetadata("local", "branding", null, "Community") |
| 440 | + .build(); |
| 441 | + } |
471 | 442 |
|
472 | | - assertThat(messages, hasSize(1)); |
473 | | - assertThat(messages.get(0), containsString("dc.relation issues: " + " ".repeat(15) + "2")); |
474 | | - assertThat(messages.get(0), containsString("dc.title issues: " + " ".repeat(15) + "4")); |
475 | | - assertThat(messages.get(0), containsString("dc.type issues: " + " ".repeat(15) + "4")); |
476 | | - assertThat(messages.get(0), containsString("duplicate value issues:" + " ".repeat(13) + "4")); |
477 | | - assertThat(messages.get(0), containsString("Error count total: " + " ".repeat(14) + "14")); |
| 443 | + // create 4 items with missing type |
| 444 | + for (int i = 4; i < 8; i++) { |
| 445 | + ItemBuilder.createItem(context, collection) |
| 446 | + .withTitle("Test Item " + i) |
| 447 | + .withSubject("Test subject") |
| 448 | + .withMetadata("local", "branding", null, "Community") |
| 449 | + .build(); |
| 450 | + } |
478 | 451 |
|
479 | | - assertThat(messages.get(0), containsString("Errors:")); |
| 452 | + // create 4 items with duplicate type |
| 453 | + for (int i = 8; i < 12; i++) { |
| 454 | + ItemBuilder.createItem(context, collection) |
| 455 | + .withTitle("Test Item " + i) |
| 456 | + .withType("toolService") |
| 457 | + .withType("corpus") |
| 458 | + .withSubject("Test subject") |
| 459 | + .withMetadata("local", "branding", null, "Community") |
| 460 | + .build(); |
| 461 | + } |
480 | 462 |
|
481 | | - // check if dc.type error is present exactly 2 times |
482 | | - assertThat(StringUtils.countMatches(messages.get(0), "Does not have dc.type metadata"), is(2)); |
483 | | - // check if dc.title error is present exactly 2 times |
484 | | - assertThat(StringUtils.countMatches(messages.get(0), "Item has no dc.title metadata"), is(2)); |
485 | | - // check id duplicate value error is present exactly 2 times |
486 | | - assertThat(StringUtils.countMatches(messages.get(0), "value [dc.type] is present multiple times"), is(2)); |
487 | | - |
488 | | - // check if all dc.relation errors are present |
489 | | - assertThat(StringUtils.countMatches(messages.get(0), "does not refer back via dc.relation.replaces"), is(1)); |
490 | | - assertThat( |
491 | | - StringUtils.countMatches(messages.get(0), "does not refer back via dc.relation.isreplacedby"), is(1)); |
492 | | - assertThat(messages.get(0), containsString("and more...")); |
493 | | - |
494 | | - configurationService.setProperty("healthcheck.metadata.max-errors-to-show", null); |
495 | | - configurationService.setProperty("healthcheck.metadata.error-dispersion-quota", null); |
| 463 | + TestDSpaceRunnableHandler testDSpaceRunnableHandler = new TestDSpaceRunnableHandler(); |
| 464 | + |
| 465 | + // with "health-report -c 5", only Metadata check is running |
| 466 | + String[] args = new String[]{"health-report", "-c", "5"}; |
| 467 | + ScriptLauncher.handleScript(args, |
| 468 | + ScriptLauncher.getConfig(kernelImpl), testDSpaceRunnableHandler, kernelImpl); |
| 469 | + |
| 470 | + assertThat(testDSpaceRunnableHandler.getErrorMessages(), empty()); |
| 471 | + List<String> messages = testDSpaceRunnableHandler.getInfoMessages(); |
| 472 | + |
| 473 | + assertThat(messages, hasSize(1)); |
| 474 | + assertThat(messages.get(0), containsString("dc.relation issues: " + " ".repeat(15) + "2")); |
| 475 | + assertThat(messages.get(0), containsString("dc.title issues: " + " ".repeat(15) + "4")); |
| 476 | + assertThat(messages.get(0), containsString("dc.type issues: " + " ".repeat(15) + "4")); |
| 477 | + assertThat(messages.get(0), containsString("duplicate value issues:" + " ".repeat(13) + "4")); |
| 478 | + assertThat(messages.get(0), containsString("Error count total: " + " ".repeat(14) + "14")); |
| 479 | + |
| 480 | + assertThat(messages.get(0), containsString("Errors:")); |
| 481 | + |
| 482 | + // check if dc.type error is present exactly 2 times |
| 483 | + assertThat(StringUtils.countMatches(messages.get(0), "Does not have dc.type metadata"), is(2)); |
| 484 | + // check if dc.title error is present exactly 2 times |
| 485 | + assertThat(StringUtils.countMatches(messages.get(0), "Item has no dc.title metadata"), is(2)); |
| 486 | + // check if duplicate value error is present exactly 2 times |
| 487 | + assertThat(StringUtils.countMatches(messages.get(0), "value [dc.type] is present multiple times"), is(2)); |
| 488 | + |
| 489 | + // check if all dc.relation errors are present |
| 490 | + assertThat(StringUtils.countMatches( |
| 491 | + messages.get(0), "does not refer back via dc.relation.replaces"), is(1)); |
| 492 | + assertThat(StringUtils.countMatches( |
| 493 | + messages.get(0), "does not refer back via dc.relation.isreplacedby"), is(1)); |
| 494 | + assertThat(messages.get(0), containsString("and more...")); |
| 495 | + } finally { |
| 496 | + configurationService.setProperty("healthcheck.metadata.max-errors-to-show", null); |
| 497 | + configurationService.setProperty("healthcheck.metadata.error-dispersion-quota", null); |
| 498 | + } |
496 | 499 | } |
497 | 500 |
|
498 | 501 | private String findItemUri(Item item) { |
499 | | - return item.getMetadata().stream() |
500 | | - .filter(metadataValue -> "dc_identifier_uri".equals(metadataValue.getMetadataField().toString())) |
501 | | - .findFirst() |
502 | | - .map(MetadataValue::getValue) |
503 | | - .orElse(null); |
| 502 | + return ContentServiceFactory.getInstance().getItemService() |
| 503 | + .getMetadataFirstValue(item, "dc", "identifier", "uri", Item.ANY); |
504 | 504 | } |
505 | 505 |
|
506 | 506 | ReportResult findLastReportResult(List<ReportResult> reportResults) { |
|
0 commit comments