Search in sources :

Example 96 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class SourceInActivitiesTest method sourceDoesntChange_Funding_Test.

@Test
@Transactional
public void sourceDoesntChange_Funding_Test() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Funding funding1 = getFunding(userOrcid);
    assertNotNull(funding1);
    assertNotNull(funding1.getTitle());
    assertNotNull(funding1.getTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(funding1.getTitle().getTitle().getContent()));
    assertEquals(userOrcid, funding1.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Funding funding2 = getFunding(userOrcid);
    assertNotNull(funding2.getTitle());
    assertNotNull(funding2.getTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(funding2.getTitle().getTitle().getContent()));
    assertEquals(CLIENT_1_ID, funding2.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
    Funding funding3 = getFunding(userOrcid);
    assertNotNull(funding3.getTitle());
    assertNotNull(funding3.getTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(funding3.getTitle().getTitle().getContent()));
    assertEquals(CLIENT_2_ID, funding3.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Funding funding4 = getFunding(userOrcid);
    assertNotNull(funding4.getTitle());
    assertNotNull(funding4.getTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(funding4.getTitle().getTitle().getContent()));
    assertEquals(userOrcid, funding4.getSource().retrieveSourcePath());
    Funding fromDb1 = profileFundingManager.getFunding(userOrcid, funding1.getPutCode());
    assertNotNull(fromDb1);
    assertEquals(userOrcid, fromDb1.getSource().retrieveSourcePath());
    Funding fromDb2 = profileFundingManager.getFunding(userOrcid, funding2.getPutCode());
    assertNotNull(fromDb2);
    assertEquals(CLIENT_1_ID, fromDb2.getSource().retrieveSourcePath());
    Funding fromDb3 = profileFundingManager.getFunding(userOrcid, funding3.getPutCode());
    assertNotNull(fromDb3);
    assertEquals(CLIENT_2_ID, fromDb3.getSource().retrieveSourcePath());
    Funding fromDb4 = profileFundingManager.getFunding(userOrcid, funding4.getPutCode());
    assertNotNull(fromDb4);
    assertEquals(userOrcid, fromDb4.getSource().retrieveSourcePath());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 97 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method deriveEmailFriendlyNameTest.

@Test
public void deriveEmailFriendlyNameTest() {
    ProfileEntity testProfile = new ProfileEntity("0000-0000-0000-0003");
    assertEquals("ORCID Registry User", notificationManager.deriveEmailFriendlyName(testProfile));
    testProfile.setRecordNameEntity(new RecordNameEntity());
    assertEquals("ORCID Registry User", notificationManager.deriveEmailFriendlyName(testProfile));
    testProfile.getRecordNameEntity().setGivenNames("Given Name");
    assertEquals("Given Name", notificationManager.deriveEmailFriendlyName(testProfile));
    testProfile.getRecordNameEntity().setFamilyName("Family Name");
    assertEquals("Given Name Family Name", notificationManager.deriveEmailFriendlyName(testProfile));
    testProfile.getRecordNameEntity().setCreditName("Credit Name");
    assertEquals("Credit Name", notificationManager.deriveEmailFriendlyName(testProfile));
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 98 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method testSendDeactivateEmail.

@Test
public void testSendDeactivateEmail() throws JAXBException, IOException, URISyntaxException {
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
    final String orcid = "0000-0000-0000-0003";
    ProfileEntity profile = new ProfileEntity(orcid);
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setCreditName("My credit name");
    recordName.setVisibility(Visibility.PUBLIC);
    profile.setRecordNameEntity(recordName);
    Email email = new Email();
    email.setEmail("test@email.com");
    when(mockProfileEntityCacheManager.retrieve(orcid)).thenReturn(profile);
    when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
    for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
        profile.setLocale(locale);
        notificationManager.sendOrcidDeactivateEmail(orcid);
    }
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 99 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class NotificationManagerTest method testChangeEmailAddress.

@Test
public void testChangeEmailAddress() throws Exception {
    TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
    final String orcid = "0000-0000-0000-0003";
    ProfileEntity profile = new ProfileEntity(orcid);
    RecordNameEntity recordName = new RecordNameEntity();
    recordName.setCreditName("My credit name");
    recordName.setVisibility(Visibility.PUBLIC);
    profile.setRecordNameEntity(recordName);
    Email email = new Email();
    email.setEmail("test@email.com");
    when(mockProfileEntityCacheManager.retrieve(orcid)).thenReturn(profile);
    when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
    for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
        profile.setLocale(locale);
        notificationManager.sendEmailAddressChangedNotification(orcid, "new@email.com", "original@email.com");
    }
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 100 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class OrcidClientCredentialEndPointDelegatorTest method createAuthorizationCode.

private OrcidOauth2AuthoriziationCodeDetail createAuthorizationCode(String value, String clientId, String redirectUri, boolean persistent, String... scopes) {
    OrcidOauth2AuthoriziationCodeDetail authorizationCode = new OrcidOauth2AuthoriziationCodeDetail();
    authorizationCode.setId(value);
    authorizationCode.setApproved(true);
    authorizationCode.setScopes(new HashSet<String>(Arrays.asList(scopes)));
    authorizationCode.setClientDetailsEntity(new ClientDetailsEntity(clientId));
    authorizationCode.setPersistent(persistent);
    authorizationCode.setProfileEntity(new ProfileEntity(USER_ORCID));
    authorizationCode.setRedirectUri(redirectUri);
    authorizationCode.setResourceIds(new HashSet<String>(Arrays.asList("orcid")));
    authorizationCode.setAuthenticated(true);
    orcidOauth2AuthoriziationCodeDetailDao.persist(authorizationCode);
    return authorizationCode;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidOauth2AuthoriziationCodeDetail(org.orcid.persistence.jpa.entities.OrcidOauth2AuthoriziationCodeDetail) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Aggregations

ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)231 Test (org.junit.Test)65 Date (java.util.Date)64 Transactional (org.springframework.transaction.annotation.Transactional)58 DBUnitTest (org.orcid.test.DBUnitTest)44 HashMap (java.util.HashMap)41 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)37 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)36 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)33 HashSet (java.util.HashSet)30 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)28 Rollback (org.springframework.test.annotation.Rollback)25 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)20 Set (java.util.Set)16 ArrayList (java.util.ArrayList)15 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)14 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)14 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)13 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)13 Authentication (org.springframework.security.core.Authentication)12