Search in sources :

Example 21 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationManagerImplTest method testCreateMinimalRegistrationMultipleEmails.

@Test
public void testCreateMinimalRegistrationMultipleEmails() {
    String email = "new_user_" + System.currentTimeMillis() + "@test.orcid.org";
    String additionalEmail = "new_user_addl_" + System.currentTimeMillis() + "@test.orcid.org";
    List<Text> emailsAdditionalList = new ArrayList<Text>();
    Text emailAdditional = new Text();
    emailAdditional.setValue(additionalEmail);
    emailsAdditionalList.add(emailAdditional);
    Registration form = createRegistrationFormMultipleEmails(email, emailsAdditionalList, true);
    String userOrcid = registrationManager.createMinimalRegistration(form, true, java.util.Locale.ENGLISH, "0.0.0.0");
    assertNotNull(userOrcid);
    assertTrue(OrcidStringUtils.isValidOrcid(userOrcid));
    Map<String, String> map = emailManager.findOricdIdsByCommaSeparatedEmails(email + "," + additionalEmail);
    assertNotNull(map);
    assertEquals(userOrcid, map.get(email));
    assertEquals(userOrcid, map.get(additionalEmail));
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration) ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 22 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationManagerImplTest method testCreateMinimalRegistrationWithExistingEmailThatCanBeAutoDeprecated.

@Test
public void testCreateMinimalRegistrationWithExistingEmailThatCanBeAutoDeprecated() {
    // Create the user, but set it as unclaimed
    String email = "new_user_" + System.currentTimeMillis() + "@test.orcid.org";
    // Create a record by a member
    OrcidProfile orcidProfile = createBasicProfile(email, false, CLIENT_ID_AUTODEPRECATE_ENABLED);
    orcidProfile = orcidProfileManager.createOrcidProfile(orcidProfile, true, true);
    assertNotNull(orcidProfile);
    assertNotNull(orcidProfile.getOrcidIdentifier());
    assertNotNull(orcidProfile.getOrcidIdentifier().getPath());
    String orcidBefore = orcidProfile.getOrcidIdentifier().getPath();
    Map<String, String> map1 = emailManager.findOricdIdsByCommaSeparatedEmails(email);
    assertNotNull(map1);
    assertEquals(orcidBefore, map1.get(email));
    // Then try to create it again, this time claimed and without source
    Registration form = createRegistrationForm(email, true);
    String orcidAfter = registrationManager.createMinimalRegistration(form, true, java.util.Locale.ENGLISH, "0.0.0.0");
    assertTrue(OrcidStringUtils.isValidOrcid(orcidAfter));
    assertThat(orcidAfter, is(not(equalTo(orcidBefore))));
    Map<String, String> map2 = emailManager.findOricdIdsByCommaSeparatedEmails(email);
    assertNotNull(map2);
    assertEquals(orcidAfter, map2.get(email));
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Registration(org.orcid.pojo.ajaxForm.Registration) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 23 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationManagerImplTest method testCreateMinimalRegistrationWithExistingClaimedEmailAdditional.

@Test
public void testCreateMinimalRegistrationWithExistingClaimedEmailAdditional() {
    // Create the user
    String email = "new_user_" + System.currentTimeMillis() + "@test.orcid.org";
    Registration form = createRegistrationForm(email, true);
    String userOrcid = registrationManager.createMinimalRegistration(form, true, java.util.Locale.ENGLISH, "0.0.0.0");
    assertNotNull(userOrcid);
    assertTrue(OrcidStringUtils.isValidOrcid(userOrcid));
    // Then try to create it again, with additional email set to primary email of existing user
    String email2 = "new_user2_" + System.currentTimeMillis() + "@test.orcid.org";
    List<Text> emailsAdditionalList = new ArrayList<Text>();
    Text emailAdditional = new Text();
    emailAdditional.setValue(email);
    emailsAdditionalList.add(emailAdditional);
    form = createRegistrationFormMultipleEmails(email2, emailsAdditionalList, true);
    try {
        registrationManager.createMinimalRegistration(form, true, java.util.Locale.ENGLISH, "0.0.0.0");
        fail();
    } catch (InvalidRequestException e) {
        assertEquals("Unable to register user due: Email " + email + " already exists and is claimed, so, it can't be used again", e.getMessage());
    } catch (Exception e) {
        fail();
    }
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration) ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text) InvalidRequestException(org.springframework.security.oauth2.common.exceptions.InvalidRequestException) InvalidRequestException(org.springframework.security.oauth2.common.exceptions.InvalidRequestException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 24 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationManagerImplTest method createRegistrationFormMultipleEmails.

private Registration createRegistrationFormMultipleEmails(String email, List<Text> emailsAdditionalList, boolean claimed) {
    Registration registration = new Registration();
    registration.setPassword(Text.valueOf("password"));
    registration.setEmail(Text.valueOf(email));
    registration.setEmailsAdditional(emailsAdditionalList);
    registration.setFamilyNames(Text.valueOf("User"));
    registration.setGivenNames(Text.valueOf("New"));
    registration.setCreationType(Text.valueOf(CreationMethod.DIRECT.value()));
    return registration;
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration)

Example 25 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationManagerImplTest method testCreateMinimalRegistrationWithExistingUnclaimedEmailNotAutoDeprecatable.

@Test
public void testCreateMinimalRegistrationWithExistingUnclaimedEmailNotAutoDeprecatable() {
    // Create the user, but set it as unclaimed
    String email = "new_user_" + System.currentTimeMillis() + "@test.orcid.org";
    // Create a record by a member
    OrcidProfile orcidProfile = createBasicProfile(email, false, CLIENT_ID_AUTODEPRECATE_DISABLED);
    orcidProfile = orcidProfileManager.createOrcidProfile(orcidProfile, true, true);
    assertNotNull(orcidProfile);
    assertNotNull(orcidProfile.getOrcidIdentifier());
    assertNotNull(orcidProfile.getOrcidIdentifier().getPath());
    try {
        Registration form = createRegistrationForm(email, true);
        registrationManager.createMinimalRegistration(form, true, java.util.Locale.ENGLISH, "0.0.0.0");
        fail();
    } catch (InvalidRequestException e) {
        assertEquals("Unable to register user due: Autodeprecate is not enabled for " + email, e.getMessage());
    } catch (Exception e) {
        fail();
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Registration(org.orcid.pojo.ajaxForm.Registration) InvalidRequestException(org.springframework.security.oauth2.common.exceptions.InvalidRequestException) InvalidRequestException(org.springframework.security.oauth2.common.exceptions.InvalidRequestException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Registration (org.orcid.pojo.ajaxForm.Registration)26 Test (org.junit.Test)23 DBUnitTest (org.orcid.test.DBUnitTest)23 Text (org.orcid.pojo.ajaxForm.Text)13 ArrayList (java.util.ArrayList)11 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)5 InvalidRequestException (org.springframework.security.oauth2.common.exceptions.InvalidRequestException)5 Locale (java.util.Locale)2 HttpSession (javax.servlet.http.HttpSession)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Checkbox (org.orcid.pojo.ajaxForm.Checkbox)2 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)2 Principal (java.security.Principal)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)1 Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)1 OauthRegistrationForm (org.orcid.pojo.ajaxForm.OauthRegistrationForm)1 Authentication (org.springframework.security.core.Authentication)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1