Search in sources :

Example 21 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class CustomEmailManagerTest method testUpdateCustomEmail.

@Rollback
public void testUpdateCustomEmail() {
    // Check old values
    List<CustomEmailEntity> customEmails = customEmailManager.getCustomEmails("4444-4444-4444-4441");
    assertNotNull(customEmails);
    assertEquals(1, customEmails.size());
    CustomEmailEntity customEmail = customEmails.get(0);
    assertNotNull(customEmail);
    assertEquals("This is the content", customEmail.getContent());
    assertEquals(EmailType.CLAIM, customEmail.getEmailType());
    assertEquals("angel.montenegro.jimenez@gmail.com", customEmail.getSender());
    assertEquals("This is the subject", customEmail.getSubject());
    assertTrue(customEmail.isHtml());
    // Update
    customEmailManager.updateCustomEmail("4444-4444-4444-4441", EmailType.CLAIM, "updated@sender.com", "updated subject", "updated content", false);
    // Check new values
    customEmails = customEmailManager.getCustomEmails("4444-4444-4444-4441");
    assertNotNull(customEmails);
    assertEquals(1, customEmails.size());
    customEmail = customEmails.get(0);
    assertNotNull(customEmail);
    assertEquals("updated content", customEmail.getContent());
    assertEquals(EmailType.CLAIM, customEmail.getEmailType());
    assertEquals("updated@sender.com", customEmail.getSender());
    assertEquals("updated subject", customEmail.getSubject());
    assertFalse(customEmail.isHtml());
}
Also used : CustomEmailEntity(org.orcid.persistence.jpa.entities.CustomEmailEntity) Rollback(org.springframework.test.annotation.Rollback)

Example 22 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class CustomEmailManagerTest method testAddAmendCustomEmail.

@Test
@Transactional
@Rollback
public void testAddAmendCustomEmail() {
    assertTrue(customEmailManager.createCustomEmail("4444-4444-4444-4441", EmailType.AMEND, "angel.montenegro.jimenez@gmail.com", "Amend subject", "Amend content", false));
    List<CustomEmailEntity> customEmails = customEmailManager.getCustomEmails("4444-4444-4444-4441");
    assertNotNull(customEmails);
    assertEquals(2, customEmails.size());
    boolean amend = false, claim = false;
    for (CustomEmailEntity customEmail : customEmails) {
        if (EmailType.AMEND.equals(customEmail.getEmailType())) {
            assertEquals("Amend subject", customEmail.getSubject());
            assertEquals("angel.montenegro.jimenez@gmail.com", customEmail.getSender());
            assertEquals("Amend content", customEmail.getContent());
            assertFalse(customEmail.isHtml());
            amend = true;
        } else {
            assertEquals("This is the content", customEmail.getContent());
            assertEquals(EmailType.CLAIM, customEmail.getEmailType());
            assertEquals("angel.montenegro.jimenez@gmail.com", customEmail.getSender());
            assertEquals("This is the subject", customEmail.getSubject());
            claim = true;
        }
    }
    assertTrue(amend);
    assertTrue(claim);
}
Also used : CustomEmailEntity(org.orcid.persistence.jpa.entities.CustomEmailEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method testDefaultVisibilityForItemsAppliedOnUpdate.

@Test
@Transactional
@Rollback(true)
public void testDefaultVisibilityForItemsAppliedOnUpdate() {
    OrcidProfile profile = createBasicProfile();
    OrcidHistory orcidHistory = new OrcidHistory();
    orcidHistory.setClaimed(new Claimed(true));
    orcidHistory.setCreationMethod(CreationMethod.DIRECT);
    orcidHistory.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    profile.setOrcidHistory(orcidHistory);
    Keyword k = new Keyword("word", null);
    Keywords kk = new Keywords();
    kk.getKeyword().add(k);
    kk.setVisibility(Visibility.LIMITED);
    ResearcherUrl r = new ResearcherUrl(new Url("http://whatever.com"), null);
    ResearcherUrls rr = new ResearcherUrls();
    rr.getResearcherUrl().add(r);
    rr.setVisibility(Visibility.LIMITED);
    ExternalIdentifier i = new ExternalIdentifier(null);
    i.setExternalIdReference(new ExternalIdReference("ref"));
    i.setExternalIdCommonName(new ExternalIdCommonName("cn"));
    ExternalIdentifiers ii = new ExternalIdentifiers();
    ii.getExternalIdentifier().add(i);
    ii.setVisibility(Visibility.LIMITED);
    OtherNames oo = new OtherNames();
    oo.addOtherName("other", null);
    oo.setVisibility(Visibility.LIMITED);
    profile.getOrcidBio().setKeywords(kk);
    profile.getOrcidBio().setResearcherUrls(rr);
    profile.getOrcidBio().setExternalIdentifiers(ii);
    profile.getOrcidBio().getPersonalDetails().setOtherNames(oo);
    //Create the profile
    profile = orcidProfileManager.createOrcidProfile(profile, true, false);
    Preferences preferences = new Preferences();
    preferences.setSendChangeNotifications(new SendChangeNotifications(true));
    preferences.setSendOrcidNews(new SendOrcidNews(true));
    //Default visibility for user will be LIMITED
    preferences.setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
    preferences.setNotificationsEnabled(DefaultPreferences.NOTIFICATIONS_ENABLED);
    preferences.setSendEmailFrequencyDays(DefaultPreferences.SEND_EMAIL_FREQUENCY_DAYS);
    preferences.setSendMemberUpdateRequests(DefaultPreferences.SEND_MEMBER_UPDATE_REQUESTS);
    OrcidInternal internal = new OrcidInternal();
    internal.setPreferences(preferences);
    profile.setOrcidInternal(internal);
    profile.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
    //Claim the profile
    profile = orcidProfileManager.updateOrcidProfile(profile);
    //now attempt to alter privacy.  It should fail as record has been claimed.
    profile.getOrcidBio().getKeywords().setVisibility(Visibility.PUBLIC);
    profile.getOrcidBio().getResearcherUrls().setVisibility(Visibility.PUBLIC);
    profile.getOrcidBio().getExternalIdentifiers().setVisibility(Visibility.PUBLIC);
    profile.getOrcidBio().getPersonalDetails().getOtherNames().setVisibility(Visibility.PUBLIC);
    profile = orcidProfileManager.updateOrcidProfile(profile);
    assertEquals("word", profile.getOrcidBio().getKeywords().getKeyword().iterator().next().getContent());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getKeywords().getKeyword().iterator().next().getVisibility());
    assertEquals(new Url("http://whatever.com"), profile.getOrcidBio().getResearcherUrls().getResearcherUrl().iterator().next().getUrl());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getResearcherUrls().getResearcherUrl().iterator().next().getVisibility());
    assertEquals("cn", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().iterator().next().getExternalIdCommonName().getContent());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().iterator().next().getVisibility());
    assertEquals("other", profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().iterator().next().getContent());
    assertEquals(Visibility.LIMITED, profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().iterator().next().getVisibility());
}
Also used : SendOrcidNews(org.orcid.jaxb.model.message.SendOrcidNews) Keywords(org.orcid.jaxb.model.message.Keywords) Keyword(org.orcid.jaxb.model.message.Keyword) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.message.FundingExternalIdentifier) OtherNames(org.orcid.jaxb.model.message.OtherNames) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Claimed(org.orcid.jaxb.model.message.Claimed) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) Url(org.orcid.jaxb.model.message.Url) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ActivitiesVisibilityDefault(org.orcid.jaxb.model.message.ActivitiesVisibilityDefault) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) FundingExternalIdentifiers(org.orcid.jaxb.model.message.FundingExternalIdentifiers) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) Preferences(org.orcid.jaxb.model.message.Preferences) DefaultPreferences(org.orcid.core.constants.DefaultPreferences) SendChangeNotifications(org.orcid.jaxb.model.message.SendChangeNotifications) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method testDedupeWorks.

@Test
@Transactional
@Rollback(true)
public void testDedupeWorks() {
    OrcidWorks orcidWorks = new OrcidWorks();
    orcidWorks.getOrcidWork().add(createWork1());
    orcidWorks.getOrcidWork().add(createWork1());
    assertEquals(2, orcidWorks.getOrcidWork().size());
    OrcidWorks dedupedOrcidWorks = orcidProfileManager.dedupeWorks(orcidWorks);
    assertEquals(1, dedupedOrcidWorks.getOrcidWork().size());
}
Also used : OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with Rollback

use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method testUpdateProfileWhenTokenPresent.

@Test
@Transactional
@Rollback(true)
public void testUpdateProfileWhenTokenPresent() {
    OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(DELEGATE_ORCID);
    assertNotNull(profile1);
    //		Applications are not linked with OrcidProfile object anymore.
    //        assertNotNull(profile1.getOrcidBio().getApplications());
    //        assertEquals(1, profile1.getOrcidBio().getApplications().getApplicationSummary().size());
    OrcidProfile profile2 = createBasicProfile();
    profile2.setOrcidIdentifier(DELEGATE_ORCID);
    orcidProfileManager.updateOrcidProfile(profile2);
    OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(DELEGATE_ORCID);
    assertNotNull(resultProfile);
    //Applications are not linked with OrcidProfile object anymore.
    //assertNotNull(resultProfile.getOrcidBio().getApplications());
    //assertEquals(1, resultProfile.getOrcidBio().getApplications().getApplicationSummary().size());
    assertEquals("Will", resultProfile.getOrcidBio().getPersonalDetails().getGivenNames().getContent());
    assertEquals(1, resultProfile.retrieveOrcidWorks().getOrcidWork().size());
    assertEquals(1, resultProfile.getOrcidBio().getResearcherUrls().getResearcherUrl().size());
    assertEquals("http://www.wjrs.co.uk", resultProfile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Rollback (org.springframework.test.annotation.Rollback)107 Test (org.junit.Test)103 Transactional (org.springframework.transaction.annotation.Transactional)81 DBUnitTest (org.orcid.test.DBUnitTest)46 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)37 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)25 Date (java.util.Date)24 BaseTest (org.orcid.core.BaseTest)13 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)12 OrcidOauth2TokenDetail (org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)12 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)11 HashSet (java.util.HashSet)10 ApprovalDate (org.orcid.jaxb.model.message.ApprovalDate)8 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)8 BaseControllerTest (org.orcid.frontend.web.util.BaseControllerTest)7 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)7 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)7 Claimed (org.orcid.jaxb.model.message.Claimed)6 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)6 ArrayList (java.util.ArrayList)5