use of de.symeda.sormas.api.customizableenum.CustomEnumNotFoundException 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());
}
}
use of de.symeda.sormas.api.customizableenum.CustomEnumNotFoundException in project SORMAS-Project by hzi-braunschweig.
the class LabMessageMapper method migrateDiseaseVariant.
/**
* The migration depends on whether the disease variant can be found as a customizable enum value or not.
* If yes, the enum is set as disease variant. If not, the disease variant is added to the test result text,
* along with the disease variant details.
*/
protected ImmutableTriple<String, DiseaseVariant, String> migrateDiseaseVariant(TestReportDto sourceTestReport) {
if (sourceTestReport.getTestedDiseaseVariant() == null && sourceTestReport.getTestedDiseaseVariantDetails() == null) {
return new ImmutableTriple<>(null, null, null);
}
String testResultText = null;
DiseaseVariant testedDiseaseVariant = null;
String testedDiseaseVariantDetails = null;
try {
testedDiseaseVariant = FacadeProvider.getCustomizableEnumFacade().getEnumValue(CustomizableEnumType.DISEASE_VARIANT, sourceTestReport.getTestedDiseaseVariant(), labMessage.getTestedDisease());
testedDiseaseVariantDetails = sourceTestReport.getTestedDiseaseVariantDetails();
} catch (CustomEnumNotFoundException e) {
String diseaseVariantString = sourceTestReport.getTestedDiseaseVariant();
testResultText = StringUtils.isEmpty(diseaseVariantString) ? null : I18nProperties.getPrefixCaption(PathogenTestDto.I18N_PREFIX, PathogenTestDto.TESTED_DISEASE_VARIANT) + ": " + diseaseVariantString + "\n";
String diseaseVariantDetailsString = sourceTestReport.getTestedDiseaseVariantDetails();
if (!StringUtils.isEmpty(diseaseVariantDetailsString)) {
diseaseVariantDetailsString = I18nProperties.getPrefixCaption(PathogenTestDto.I18N_PREFIX, PathogenTestDto.TESTED_DISEASE_VARIANT_DETAILS) + ": " + diseaseVariantDetailsString + "\n";
testResultText = StringUtils.isEmpty(testResultText) ? diseaseVariantDetailsString : testResultText + diseaseVariantDetailsString;
}
}
return new ImmutableTriple<>(testResultText, testedDiseaseVariant, testedDiseaseVariantDetails);
}
Aggregations