|
1 | 1 | package de.symeda.sormas.backend.dashboard;
|
2 | 2 |
|
| 3 | +import java.text.SimpleDateFormat; |
3 | 4 | import java.util.Date;
|
4 | 5 | import java.util.List;
|
5 | 6 | import java.util.Map;
|
|
34 | 35 | import de.symeda.sormas.backend.TestDataCreator.RDCF;
|
35 | 36 | import org.testcontainers.shaded.org.apache.commons.lang3.time.DateUtils;
|
36 | 37 |
|
| 38 | +import static de.symeda.sormas.api.event.eventimport.EventImportEntities.createEvent; |
37 | 39 | import static org.junit.jupiter.api.Assertions.*;
|
38 | 40 |
|
39 | 41 | public class DashboardFacadeEjbTest extends AbstractBeanTest {
|
@@ -473,9 +475,6 @@ public void testGetEpiCurveSeriesElementsPerPresentCondition() {
|
473 | 475 | assertTrue(currentDateFound, "CurrentDate not found in the result map");
|
474 | 476 | }
|
475 | 477 |
|
476 |
| - |
477 |
| - |
478 |
| - |
479 | 478 | @Test
|
480 | 479 | public void testGetCaseMeasurePerDistrict() {
|
481 | 480 | // Create necessary data for testing
|
@@ -520,6 +519,202 @@ public void testCountCasesConvertedFromContacts() {
|
520 | 519 | assertEquals(0, result); // Assuming no cases converted from contacts
|
521 | 520 | }
|
522 | 521 |
|
| 522 | + @Test |
| 523 | + public void testGetEpiCurveSeriesElementsPerContactClassification() { |
| 524 | + // Create necessary data for testing |
| 525 | + RDCF rdcf = creator.createRDCF(); |
| 526 | + UserDto user = creator.createSurveillanceSupervisor(rdcf); |
| 527 | + Date currentDate = new Date(); |
| 528 | + |
| 529 | + // Create cases |
| 530 | + CaseDataDto case1 = creator.createCase( |
| 531 | + user.toReference(), |
| 532 | + creator.createPerson("Case", "Person1").toReference(), |
| 533 | + Disease.EVD, |
| 534 | + CaseClassification.CONFIRMED, |
| 535 | + InvestigationStatus.PENDING, |
| 536 | + currentDate, |
| 537 | + rdcf); |
| 538 | + |
| 539 | + CaseDataDto case2 = creator.createCase( |
| 540 | + user.toReference(), |
| 541 | + creator.createPerson("Case", "Person2").toReference(), |
| 542 | + Disease.EVD, |
| 543 | + CaseClassification.PROBABLE, |
| 544 | + InvestigationStatus.PENDING, |
| 545 | + currentDate, |
| 546 | + rdcf); |
| 547 | + |
| 548 | + // Create contacts with classifications |
| 549 | + creator.createContact( |
| 550 | + user.toReference(), |
| 551 | + creator.createPerson("Contact", "Person1").toReference(), |
| 552 | + case1, |
| 553 | + rdcf, |
| 554 | + ContactClassification.CONFIRMED,new Date()); |
| 555 | + |
| 556 | + creator.createContact( |
| 557 | + user.toReference(), |
| 558 | + creator.createPerson("Contact", "Person2").toReference(), |
| 559 | + case2, |
| 560 | + rdcf, |
| 561 | + ContactClassification.UNCONFIRMED,new Date()); |
| 562 | + |
| 563 | + // Define dashboard criteria |
| 564 | + DashboardCriteria dashboardCriteria = new DashboardCriteria() |
| 565 | + .region(rdcf.region) |
| 566 | + .district(rdcf.district) |
| 567 | + .disease(Disease.EVD) |
| 568 | + .newCaseDateType(NewCaseDateType.MOST_RELEVANT) |
| 569 | + .setEpiCurveGrouping(EpiCurveGrouping.DAY) |
| 570 | + .dateBetween(DateHelper.subtractDays(currentDate, 1), DateHelper.addDays(currentDate, 1)); |
| 571 | + |
| 572 | + // Call the method under test |
| 573 | + Map<Date, Map<ContactClassification, Long>> result = getDashboardFacade().getEpiCurveSeriesElementsPerContactClassification(dashboardCriteria); |
| 574 | + |
| 575 | + // Assertions |
| 576 | + assertEquals(3, result.size()); // Ensure only one date entry for current date |
| 577 | + assertTrue(result.containsKey(DateHelper.resetTime(currentDate))); // Ensure currentDate is in the map |
| 578 | + |
| 579 | + // Get the map for currentDate |
| 580 | + Map<ContactClassification, Long> classificationMap = result.get(DateHelper.resetTime(currentDate)); |
| 581 | + assertNotNull(classificationMap); // Ensure the classificationMap for currentDate is not null |
| 582 | + |
| 583 | + // Perform assertions on ContactClassification.HIGH_RISK |
| 584 | + Long confirmedContactCount = classificationMap.get(ContactClassification.CONFIRMED); |
| 585 | + assertNotNull(confirmedContactCount); // Ensure the count for HIGH_RISK is not null |
| 586 | + assertEquals(1L, confirmedContactCount.longValue()); // Check the count for HIGH_RISK |
| 587 | + |
| 588 | + // Perform assertions on ContactClassification.LOW_RISK |
| 589 | + Long unconfirmedCount = classificationMap.get(ContactClassification.UNCONFIRMED); |
| 590 | + assertNotNull(unconfirmedCount); // Ensure the count for LOW_RISK is not null |
| 591 | + assertEquals(1L, unconfirmedCount.longValue()); // Check the count for LOW_RISK |
| 592 | + } |
| 593 | + |
| 594 | + @Test |
| 595 | + public void testGetEpiCurveSeriesElementsPerContactFollowUpUntil() { |
| 596 | + // Create necessary data for testing |
| 597 | + RDCF rdcf = creator.createRDCF(); |
| 598 | + UserDto user = creator.createSurveillanceSupervisor(rdcf); |
| 599 | + Date currentDate = new Date(); |
| 600 | + |
| 601 | + // Create cases |
| 602 | + CaseDataDto case1 = creator.createCase( |
| 603 | + user.toReference(), |
| 604 | + creator.createPerson("Case", "Person1").toReference(), |
| 605 | + Disease.EVD, |
| 606 | + CaseClassification.CONFIRMED, |
| 607 | + InvestigationStatus.DONE, |
| 608 | + currentDate, |
| 609 | + rdcf); |
| 610 | + |
| 611 | + // Create contacts with follow-up dates |
| 612 | + creator.createContact( |
| 613 | + user.toReference(), |
| 614 | + creator.createPerson("Contact", "Person1").toReference(), |
| 615 | + case1, |
| 616 | + rdcf, |
| 617 | + ContactClassification.CONFIRMED, |
| 618 | + DateHelper.subtractDays(currentDate, 5)); // Example follow-up date 5 days before currentDate |
| 619 | + |
| 620 | + // Define dashboard criteria |
| 621 | + DashboardCriteria dashboardCriteria = new DashboardCriteria() |
| 622 | + .region(rdcf.region) |
| 623 | + .district(rdcf.district) |
| 624 | + .disease(Disease.EVD) |
| 625 | + .newCaseDateType(NewCaseDateType.MOST_RELEVANT) |
| 626 | + .setEpiCurveGrouping(EpiCurveGrouping.DAY) |
| 627 | + .dateBetween(DateHelper.subtractDays(currentDate, 1), DateHelper.addDays(currentDate, 1)); |
| 628 | + |
| 629 | + // Call the method under test |
| 630 | + Map<Date, Integer> result = getDashboardFacade().getEpiCurveSeriesElementsPerContactFollowUpUntil(dashboardCriteria); |
| 631 | + |
| 632 | + // Assertions |
| 633 | + assertEquals(3, result.size()); // Ensure only one date entry for current date |
| 634 | + assertTrue(result.containsKey(DateHelper.resetTime(currentDate))); // Ensure currentDate is in the map |
| 635 | + } |
| 636 | + |
523 | 637 |
|
| 638 | + @Test |
| 639 | + public void testGetEventCountByStatus() { |
| 640 | + // Create necessary data for testing |
| 641 | + RDCF rdcf = creator.createRDCF(); |
| 642 | + UserDto user = creator.createSurveillanceSupervisor(rdcf); |
| 643 | + Date currentDate = new Date(); |
| 644 | + |
| 645 | + // Create mock events with different statuses |
| 646 | + creator.createEvent(user.toReference(), Disease.EVD, rdcf); |
| 647 | + creator.createEvent(user.toReference(), Disease.MALARIA, rdcf); |
| 648 | + creator.createEvent(user.toReference(), Disease.NEW_INFLUENZA, rdcf); |
| 649 | + |
| 650 | + // Define dashboard criteria |
| 651 | + DashboardCriteria dashboardCriteria = new DashboardCriteria() |
| 652 | + .region(rdcf.region) |
| 653 | + .district(rdcf.district) |
| 654 | + .disease(Disease.EVD) // Adjust disease as needed for your test case |
| 655 | + .newCaseDateType(NewCaseDateType.MOST_RELEVANT) |
| 656 | + .dateBetween(DateHelper.subtractDays(currentDate, 1), DateHelper.addDays(currentDate, 1)); |
| 657 | + |
| 658 | + // Call the method under test |
| 659 | + Map<EventStatus, Long> result = getDashboardFacade().getEventCountByStatus(dashboardCriteria); |
| 660 | + |
| 661 | + // Assertions |
| 662 | + assertNotNull(result); // Ensure result is not null |
| 663 | + |
| 664 | + // Verify specific status counts (adjust these based on your mock events and expected logic) |
| 665 | + assertTrue(result.containsKey(EventStatus.SIGNAL)); |
| 666 | + assertEquals(1L, result.getOrDefault(EventStatus.SIGNAL, 0L).longValue()); // Example assertion |
| 667 | + } |
| 668 | + |
| 669 | + @Test |
| 670 | + public void testGetIntervalEndDate() { |
| 671 | + DashboardFacadeEjb dashboardFacadeEjb = new DashboardFacadeEjb(); |
| 672 | + |
| 673 | + // Test case 1: DAY grouping |
| 674 | + Date startDate1 = new Date(); // Replace with actual date values |
| 675 | + Date expectedEndDate1 = DateHelper.getEndOfDay(startDate1); |
| 676 | + assertEquals(expectedEndDate1, dashboardFacadeEjb.getIntervalEndDate(startDate1, EpiCurveGrouping.DAY)); |
| 677 | + |
| 678 | + // Test case 2: WEEK grouping |
| 679 | + Date startDate2 = new Date(); // Replace with actual date values |
| 680 | + Date expectedEndDate2 = DateHelper.getEndOfWeek(startDate2); |
| 681 | + assertEquals(expectedEndDate2, dashboardFacadeEjb.getIntervalEndDate(startDate2, EpiCurveGrouping.WEEK)); |
| 682 | + |
| 683 | + // Test case 3: MONTH grouping |
| 684 | + Date startDate3 = new Date(); // Replace with actual date values |
| 685 | + Date expectedEndDate3 = DateHelper.getEndOfMonth(startDate3); |
| 686 | + assertEquals(expectedEndDate3, dashboardFacadeEjb.getIntervalEndDate(startDate3, EpiCurveGrouping.MONTH)); |
| 687 | + } |
| 688 | + |
| 689 | + // Method to test |
| 690 | + |
| 691 | + @Test |
| 692 | + public void testSetNewCaseDatesInCaseCriteria() { |
| 693 | + DashboardFacadeEjb dashboardFacadeEjb = new DashboardFacadeEjb(); |
| 694 | + |
| 695 | + // Test case 1: DAY grouping |
| 696 | + Date date1 = new Date(); // Replace with actual date values |
| 697 | + DashboardCriteria dashboardCriteria1 = new DashboardCriteria() |
| 698 | + .setEpiCurveGrouping(EpiCurveGrouping.DAY); |
| 699 | + DashboardCriteria result1 = dashboardFacadeEjb.setNewCaseDatesInCaseCriteria(date1, dashboardCriteria1); |
| 700 | + assertEquals(DateHelper.getStartOfDay(date1), result1.getDateFrom()); |
| 701 | + assertEquals(DateHelper.getEndOfDay(date1), result1.getDateTo()); |
| 702 | + |
| 703 | + // Test case 2: WEEK grouping |
| 704 | + Date date2 = new Date(); // Replace with actual date values |
| 705 | + DashboardCriteria dashboardCriteria2 = new DashboardCriteria() |
| 706 | + .setEpiCurveGrouping(EpiCurveGrouping.WEEK); |
| 707 | + DashboardCriteria result2 = dashboardFacadeEjb.setNewCaseDatesInCaseCriteria(date2, dashboardCriteria2); |
| 708 | + assertEquals(DateHelper.getStartOfWeek(date2), result2.getDateFrom()); |
| 709 | + assertEquals(DateHelper.getEndOfWeek(date2), result2.getDateTo()); |
| 710 | + |
| 711 | + // Test case 3: MONTH grouping |
| 712 | + Date date3 = new Date(); // Replace with actual date values |
| 713 | + DashboardCriteria dashboardCriteria3 = new DashboardCriteria() |
| 714 | + .setEpiCurveGrouping(EpiCurveGrouping.MONTH); |
| 715 | + DashboardCriteria result3 = dashboardFacadeEjb.setNewCaseDatesInCaseCriteria(date3, dashboardCriteria3); |
| 716 | + assertEquals(DateHelper.getStartOfMonth(date3), result3.getDateFrom()); |
| 717 | + assertEquals(DateHelper.getEndOfMonth(date3), result3.getDateTo()); |
| 718 | + } |
524 | 719 |
|
525 | 720 | }
|
0 commit comments