use of org.broadinstitute.consent.http.enumeration.UserFields in project consent by DataBiosphere.
the class ResearcherServiceTest method testUpdatePropertiesWithValidation.
@Test
public void testUpdatePropertiesWithValidation() {
List<UserProperty> props = new ArrayList<>();
Map<String, String> propMap = new HashMap<>();
for (UserFields researcherField : UserFields.values()) {
if (researcherField.getRequired()) {
String val = RandomStringUtils.random(10, true, false);
props.add(new UserProperty(user.getDacUserId(), researcherField.getValue(), val));
propMap.put(researcherField.getValue(), val);
}
}
when(userDAO.findUserByEmail(any())).thenReturn(user);
when(userDAO.findUserById(any())).thenReturn(user);
when(userPropertyDAO.findResearcherPropertiesByUser(any())).thenReturn(props);
initService();
List<UserProperty> foundProps = service.updateProperties(propMap, authUser, true);
Assert.assertFalse(foundProps.isEmpty());
Assert.assertEquals(props.size(), foundProps.size());
}
use of org.broadinstitute.consent.http.enumeration.UserFields in project consent by DataBiosphere.
the class ResearcherServiceTest method testUpdatePropertiesIncompleteProfile.
@Test
public void testUpdatePropertiesIncompleteProfile() throws Exception {
List<UserProperty> props = new ArrayList<>();
Map<String, String> propMap = new HashMap<>();
for (UserFields researcherField : UserFields.values()) {
if (researcherField.getRequired()) {
String val1 = RandomStringUtils.random(10, true, false);
String val2 = RandomStringUtils.random(10, true, false);
props.add(new UserProperty(user.getDacUserId(), researcherField.getValue(), val1));
propMap.put(researcherField.getValue(), val2);
}
}
props.add(new UserProperty(user.getDacUserId(), UserFields.COMPLETED.getValue(), Boolean.FALSE.toString()));
propMap.put(UserFields.COMPLETED.getValue(), Boolean.FALSE.toString());
when(userDAO.findUserByEmail(any())).thenReturn(user);
when(userDAO.findUserById(any())).thenReturn(user);
when(userPropertyDAO.findResearcherPropertiesByUser(any())).thenReturn(props);
when(userPropertyDAO.isProfileCompleted(any())).thenReturn(Boolean.FALSE.toString());
doNothing().when(userPropertyDAO).deletePropertiesByUserAndKey(any());
doNothing().when(userPropertyDAO).insertAll(any());
doNothing().when(userPropertyDAO).deleteAllPropertiesByUser(any());
doNothing().when(emailNotifierService).sendNewResearcherCreatedMessage(any(), any());
initService();
List<UserProperty> foundProps = service.updateProperties(propMap, authUser, true);
Assert.assertFalse(foundProps.isEmpty());
Assert.assertEquals(props.size(), foundProps.size());
verify(emailNotifierService, times(0)).sendNewResearcherCreatedMessage(any(), any());
}
use of org.broadinstitute.consent.http.enumeration.UserFields in project consent by DataBiosphere.
the class ResearcherServiceTest method testUpdatePropertiesCompleteProfile.
@Test
public void testUpdatePropertiesCompleteProfile() throws Exception {
List<UserProperty> props = new ArrayList<>();
Map<String, String> propMap = new HashMap<>();
for (UserFields researcherField : UserFields.values()) {
String val1 = RandomStringUtils.random(10, true, false);
String val2 = RandomStringUtils.random(10, true, false);
props.add(new UserProperty(user.getDacUserId(), researcherField.getValue(), val1));
propMap.put(researcherField.getValue(), val2);
}
props.add(new UserProperty(user.getDacUserId(), UserFields.COMPLETED.getValue(), Boolean.TRUE.toString()));
propMap.put(UserFields.COMPLETED.getValue(), Boolean.TRUE.toString());
when(userDAO.findUserByEmail(any())).thenReturn(user);
when(userDAO.findUserById(any())).thenReturn(user);
when(userPropertyDAO.findResearcherPropertiesByUser(any())).thenReturn(props);
when(userPropertyDAO.isProfileCompleted(any())).thenReturn(Boolean.TRUE.toString());
doNothing().when(userPropertyDAO).deletePropertiesByUserAndKey(any());
doNothing().when(userPropertyDAO).insertAll(any());
doNothing().when(userPropertyDAO).deleteAllPropertiesByUser(any());
doNothing().when(emailNotifierService).sendNewResearcherCreatedMessage(any(), any());
initService();
List<UserProperty> foundProps = service.updateProperties(propMap, authUser, true);
Assert.assertFalse(foundProps.isEmpty());
Assert.assertEquals(props.size(), foundProps.size());
verify(emailNotifierService, never()).sendNewResearcherCreatedMessage(any(), any());
}
Aggregations