use of de.symeda.sormas.backend.customizableenum.CustomizableEnumFacadeEjb 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());
}
}
Aggregations