DtoHelper { public static void fillDto(EntityDto dto, AbstractDomainObject entity) { dto.setCreationDate(entity.getCreationDate()); dto.setChangeDate(entity.getChangeDate()); dto.setUuid(entity.getUuid()); } private  DtoHelper(); static void validateDto(EntityDto dto, AbstractDomainObject entity); static void fillDto(EntityDto dto, AbstractDomainObject entity); @SuppressWarnings({ "unchecked", "rawtypes" }) static void fillDto(T target, T source, boolean overrideValues); static final int CHANGE_DATE_TOLERANCE_MS; }
@Test public void testFillDto() { RDCFEntities rdcf = creator.createRDCFEntities(); RDCFEntities rdcf2 = creator.createRDCFEntities(); rdcf2.facility.setType(FacilityType.LABORATORY); UserDto user = creator.createUser(rdcf, UserRole.ADMIN); { HealthConditionsDto targetDto = new HealthConditionsDto(); HealthConditionsDto sourceDto = new HealthConditionsDto(); targetDto.setTuberculosis(YesNoUnknown.YES); sourceDto.setTuberculosis(YesNoUnknown.NO); targetDto.setAsplenia(YesNoUnknown.YES); sourceDto.setDiabetes(YesNoUnknown.YES); DtoHelper.fillDto(targetDto, sourceDto, false); assertNull(targetDto.getHiv()); assertNotEquals(sourceDto.getTuberculosis(), targetDto.getTuberculosis()); assertEquals(YesNoUnknown.YES, targetDto.getAsplenia()); assertNull(sourceDto.getAsplenia()); assertEquals(sourceDto.getDiabetes(), targetDto.getDiabetes()); } { PersonDto person = creator.createPerson("First", "Last"); CaseDataDto targetDto = creator.createCase(user.toReference(), person.toReference(), rdcf); CaseDataDto sourceDto = creator.createCase(user.toReference(), person.toReference(), rdcf); SymptomsDto targetSymptomsDto = targetDto.getSymptoms(); SymptomsDto sourceSymptomsDto = sourceDto.getSymptoms(); SymptomState abdominalPain = SymptomState.NO; targetSymptomsDto.setAbdominalPain(abdominalPain); sourceSymptomsDto.setAbdominalPain(SymptomState.UNKNOWN); SymptomState alteredConsciousness = SymptomState.YES; targetSymptomsDto.setAlteredConsciousness(alteredConsciousness); SymptomState anorexiaAppetiteLoss = SymptomState.UNKNOWN; sourceSymptomsDto.setAnorexiaAppetiteLoss(anorexiaAppetiteLoss); targetDto.setSymptoms(targetSymptomsDto); sourceDto.setSymptoms(sourceSymptomsDto); DtoHelper.fillDto(targetDto, sourceDto, false); assertNull(targetDto.getSymptoms().getBackache()); assertEquals(abdominalPain, targetDto.getSymptoms().getAbdominalPain()); assertEquals(alteredConsciousness, targetDto.getSymptoms().getAlteredConsciousness()); assertEquals(anorexiaAppetiteLoss, targetDto.getSymptoms().getAnorexiaAppetiteLoss()); } { PersonDto person = creator.createPerson("First", "Last"); CaseDataDto targetDto = creator.createCase(user.toReference(), person.toReference(), rdcf); CaseDataDto sourceDto = creator.createCase(user.toReference(), person.toReference(), rdcf); EpiDataBurialDto subDto1 = EpiDataBurialDto.build(); EpiDataBurialDto subDto2 = EpiDataBurialDto.build(); ArrayList<EpiDataBurialDto> targetList1 = new ArrayList<EpiDataBurialDto>(); targetList1.add(subDto1); ArrayList<EpiDataBurialDto> sourceList1 = new ArrayList<EpiDataBurialDto>(); sourceList1.add(subDto2); ArrayList<EpiDataBurialDto> targetList2 = new ArrayList<EpiDataBurialDto>(); targetList2.add(subDto1); targetList2.add(subDto2); ArrayList<EpiDataBurialDto> sourceList2 = new ArrayList<EpiDataBurialDto>(); sourceList2.add(subDto1); sourceList2.add(subDto2); DtoHelper.fillDto(targetDto, sourceDto, false); assertTrue(targetDto.getEpiData().getBurials().isEmpty()); targetDto.getEpiData().setBurials(targetList1); sourceDto.getEpiData().setBurials(sourceList1); String existingUuid = targetList1.get(0).getUuid(); DtoHelper.fillDto(targetDto, sourceDto, false); assertEquals(targetList1.size(), targetDto.getEpiData().getBurials().size()); assertNotNull(targetDto.getEpiData().getBurials().get(0).getUuid()); assertEquals(existingUuid, targetDto.getEpiData().getBurials().get(0).getUuid()); assertNotEquals(existingUuid, sourceDto.getEpiData().getBurials().get(0).getUuid()); targetDto.getEpiData().setBurials(targetList2); sourceDto.getEpiData().setBurials(null); DtoHelper.fillDto(targetDto, sourceDto, false); assertNotNull(targetDto.getEpiData().getBurials().get(0).getUuid()); assertEquals(targetList2.size(), targetDto.getEpiData().getBurials().size()); assertEquals(targetList2.get(0).getUuid(), targetDto.getEpiData().getBurials().get(0).getUuid()); assertEquals(targetList2.get(1).getUuid(), targetDto.getEpiData().getBurials().get(1).getUuid()); targetDto.getEpiData().setBurials(null); sourceDto.getEpiData().setBurials(sourceList2); DtoHelper.fillDto(targetDto, sourceDto, false); assertNotNull(targetDto.getEpiData().getBurials().get(0).getUuid()); assertEquals(sourceList2.size(), targetDto.getEpiData().getBurials().size()); assertNotEquals(sourceList2.get(0).getUuid(), targetDto.getEpiData().getBurials().get(0).getUuid()); assertNotEquals(sourceList2.get(1).getUuid(), targetDto.getEpiData().getBurials().get(1).getUuid()); } { PersonDto person = creator.createPerson("First", "Last"); CaseDataDto targetCaseDto = creator.createCase(user.toReference(), person.toReference(), rdcf); CaseDataDto sourceCaseDto = creator.createCase(user.toReference(), person.toReference(), rdcf); SampleDto sourceDto = creator.createSample(sourceCaseDto.toReference(), user.toReference(), rdcf2.facility); sourceDto.setPathogenTestingRequested(true); sourceDto.getRequestedPathogenTests().add(PathogenTestType.ANTIGEN_DETECTION); sourceDto.getRequestedPathogenTests().add(PathogenTestType.NEUTRALIZING_ANTIBODIES); SampleDto targetDto = SampleDto.build(user.toReference(), targetCaseDto.toReference()); DtoHelper.fillDto(targetDto, sourceDto, false); assertEquals(2, targetDto.getRequestedPathogenTests().size()); } }