Search in sources :

Example 1 with FacadeProvider

use of de.symeda.sormas.api.FacadeProvider in project SORMAS-Project by hzi-braunschweig.

the class LabMessageMapperTest method testMigrateDiseaseVariant.

@Test
public void testMigrateDiseaseVariant() throws CustomEnumNotFoundException {
    CustomizableEnumFacadeEjb customizableEnumFacade = mock(CustomizableEnumFacadeEjb.class);
    LabMessageDto labMessage = LabMessageDto.build();
    labMessage.setTestedDisease(Disease.CORONAVIRUS);
    TestReportDto testReport = TestReportDto.build();
    LabMessageMapper mapper = LabMessageMapper.forLabMessage(labMessage);
    DiseaseVariant diseaseVariant = new DiseaseVariant();
    when(customizableEnumFacade.getEnumValue(CustomizableEnumType.DISEASE_VARIANT, "P.2", Disease.CORONAVIRUS)).thenReturn(diseaseVariant);
    when(customizableEnumFacade.getEnumValue(CustomizableEnumType.DISEASE_VARIANT, "NON-EXISTENT", Disease.CORONAVIRUS)).thenThrow(new CustomEnumNotFoundException("not found"));
    when(customizableEnumFacade.getEnumValue(CustomizableEnumType.DISEASE_VARIANT, null, Disease.CORONAVIRUS)).thenThrow(new CustomEnumNotFoundException("not found"));
    try (MockedStatic<FacadeProvider> facadeProvider = Mockito.mockStatic(FacadeProvider.class)) {
        facadeProvider.when(FacadeProvider::getCustomizableEnumFacade).thenReturn(customizableEnumFacade);
        // No disease variant set
        ImmutableTriple<String, DiseaseVariant, String> result = mapper.migrateDiseaseVariant(testReport);
        assertNull(result.getLeft());
        assertNull(result.getMiddle());
        assertNull(result.getRight());
        // Unknown disease variant set
        testReport.setTestedDiseaseVariant("NON-EXISTENT");
        result = mapper.migrateDiseaseVariant(testReport);
        assertEquals(I18nProperties.getPrefixCaption(PathogenTestDto.I18N_PREFIX, PathogenTestDto.TESTED_DISEASE_VARIANT) + ": NON-EXISTENT\n", result.getLeft());
        assertNull(result.getMiddle());
        assertNull(result.getRight());
        // Unknown disease variant and disease variant details set
        testReport.setTestedDiseaseVariantDetails("SOME-DETAILS");
        result = mapper.migrateDiseaseVariant(testReport);
        assertEquals(I18nProperties.getPrefixCaption(PathogenTestDto.I18N_PREFIX, PathogenTestDto.TESTED_DISEASE_VARIANT) + ": NON-EXISTENT\n" + I18nProperties.getPrefixCaption(PathogenTestDto.I18N_PREFIX, PathogenTestDto.TESTED_DISEASE_VARIANT_DETAILS) + ": SOME-DETAILS\n", result.getLeft());
        assertNull(result.getMiddle());
        assertNull(result.getRight());
        // Only disease variant details set
        testReport.setTestedDiseaseVariant(null);
        result = mapper.migrateDiseaseVariant(testReport);
        assertEquals(I18nProperties.getPrefixCaption(PathogenTestDto.I18N_PREFIX, PathogenTestDto.TESTED_DISEASE_VARIANT_DETAILS) + ": SOME-DETAILS\n", result.getLeft());
        assertNull(result.getMiddle());
        assertNull(result.getRight());
        // Known disease variant and disease variant details set
        testReport.setTestedDiseaseVariant("P.2");
        result = mapper.migrateDiseaseVariant(testReport);
        assertNull(result.getLeft());
        assertEquals(diseaseVariant, result.getMiddle());
        assertEquals("SOME-DETAILS", result.getRight());
        // Known disease variant set
        testReport.setTestedDiseaseVariantDetails(null);
        result = mapper.migrateDiseaseVariant(testReport);
        assertNull(result.getLeft());
        assertEquals(diseaseVariant, result.getMiddle());
        assertNull(result.getRight());
    }
}
Also used : TestReportDto(de.symeda.sormas.api.labmessage.TestReportDto) CustomEnumNotFoundException(de.symeda.sormas.api.customizableenum.CustomEnumNotFoundException) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) LabMessageDto(de.symeda.sormas.api.labmessage.LabMessageDto) FacadeProvider(de.symeda.sormas.api.FacadeProvider) CustomizableEnumFacadeEjb(de.symeda.sormas.backend.customizableenum.CustomizableEnumFacadeEjb) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Aggregations

FacadeProvider (de.symeda.sormas.api.FacadeProvider)1 CustomEnumNotFoundException (de.symeda.sormas.api.customizableenum.CustomEnumNotFoundException)1 DiseaseVariant (de.symeda.sormas.api.disease.DiseaseVariant)1 LabMessageDto (de.symeda.sormas.api.labmessage.LabMessageDto)1 TestReportDto (de.symeda.sormas.api.labmessage.TestReportDto)1 CustomizableEnumFacadeEjb (de.symeda.sormas.backend.customizableenum.CustomizableEnumFacadeEjb)1 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)1 Test (org.junit.Test)1