private RegistrationChildForm getExpectedForm(String caseId) { ChildCase expectedChildCase = new ChildCase(); expectedChildCase.setCaseId(caseId); Flw expectedFlw = new Flw(); expectedFlw.setFlwId("89fda0284e008d2e0c980fb13fa0e5bb"); RegistrationChildForm expectedChildForm = new RegistrationChildForm(); expectedChildForm.setChildCase(expectedChildCase); expectedChildForm.setFlw(expectedFlw); expectedChildForm.setDateModified( new DateTime(2013, 3, 3, 10, 38, 52, 804, DateTimeZone.forOffsetHoursMinutes(5, 30)) .toDate()); expectedChildForm.setChildName("suraj"); expectedChildForm.setBirthStatus("healthy"); expectedChildForm.setInstanceId("ff2eb090-03a9-4f23-afed-cf6012784c55"); expectedChildForm.setTimeStart( new DateTime(2013, 3, 3, 10, 31, 51, 45, DateTimeZone.forOffsetHoursMinutes(5, 30)) .toDate()); expectedChildForm.setTimeEnd( new DateTime(2013, 3, 3, 10, 38, 52, 804, DateTimeZone.forOffsetHoursMinutes(5, 30)) .toDate()); return expectedChildForm; }
private Flw processProvider(Map<String, FlwGroup> flwGroups, Provider provider) { logger.info(String.format("Creating/Updating provider with id: %s", provider.getId())); Map<String, Object> parsedProvider = providerParser.parse(provider); Flw flw = genericMapper.map(Flw.class, parsedProvider); flw.setFlwGroups(new HashSet<>(getAssociatedFlwGroups(provider.getGroups(), flwGroups))); flw.setLocationDimension(getLocationDimension(parsedProvider)); return flw; }
@Test public void shouldSearchExistingFlwsAndUpdateFlw() { Flw toBeUpdatedFlw = flw( "5ba9a0928dde95d187544babf6c0ad24", "FirstName1", flwGroupWithNameAndId("64a9a0928dde95d187544babf6c0ad38", "oldGroupName")); Flw notToBeUpdateFlw = flw("5ba9a0928dde95d187544babf6c0ad25", "FirstName2", new FlwGroup()); template.saveOrUpdateAll(Arrays.asList(toBeUpdatedFlw, notToBeUpdateFlw)); Flw newFlw = flw( "5ba9a0928dde95d187544babf6c0ad24", "FirstName3", flwGroupWithNameAndId("38a9a0928dde95d187544babf6c0ad64", "newGroupName")); ArrayList<Flw> flwsToUpdate = new ArrayList<>(); flwsToUpdate.add(newFlw); careService.saveOrUpdateAllByExternalPrimaryKey(Flw.class, flwsToUpdate); Flw updatedFlw = template.load(Flw.class, toBeUpdatedFlw.getId()); assertReflectionEqualsWithIgnore( newFlw, updatedFlw, new String[] {"id", "creationTime", "lastModifiedTime"}); assertDateIgnoringSeconds(new Date(), updatedFlw.getCreationTime()); assertDateIgnoringSeconds(new Date(), updatedFlw.getLastModifiedTime()); Flw unchangedFlw = template.load(Flw.class, notToBeUpdateFlw.getId()); assertEquals("FirstName2", unchangedFlw.getFirstName()); }
@Test public void shouldSaveMotherFormForExistingCase() { MotherCase motherCase = new MotherCase(); motherCase.setCaseId("94d5374f-290e-409f-bc57-86c2e4bcc43f"); template.save(motherCase); Flw flw = new Flw(); flw.setFlwId("89fda0284e008d2e0c980fb13fa0e5bb"); template.save(flw); Map<String, String> motherForm = motherFormValues(motherCase.getCaseId(), flw.getFlwId()); careService.processAndSaveForms(motherForm, new ArrayList<Map<String, String>>()); List<MotherCase> persistedMotherCases = template.loadAll(MotherCase.class); assertEquals(1, persistedMotherCases.size()); List<NewForm> newForms = template.loadAll(NewForm.class); assertEquals(1, newForms.size()); NewForm expectedForm = expectedForm(motherCase, flw); assertReflectionEqualsWithIgnore( expectedForm, newForms.get(0), new String[] {"id", "creationTime", "lastModifiedTime"}); }