Search in sources :

Example 1 with UserFields

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());
}
Also used : UserProperty(org.broadinstitute.consent.http.models.UserProperty) UserFields(org.broadinstitute.consent.http.enumeration.UserFields) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with UserFields

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());
}
Also used : UserProperty(org.broadinstitute.consent.http.models.UserProperty) UserFields(org.broadinstitute.consent.http.enumeration.UserFields) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with UserFields

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());
}
Also used : UserProperty(org.broadinstitute.consent.http.models.UserProperty) UserFields(org.broadinstitute.consent.http.enumeration.UserFields) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 UserFields (org.broadinstitute.consent.http.enumeration.UserFields)3 UserProperty (org.broadinstitute.consent.http.models.UserProperty)3 Test (org.junit.Test)3