Search in sources :

Example 26 with Rollback

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

the class OrcidProfileManagerImplTest method testAddOrcidWorkToUnclaimedProfile.

@Test
@Transactional
@Rollback(true)
public void testAddOrcidWorkToUnclaimedProfile() {
    OrcidProfile profile1 = createBasicProfile();
    orcidProfileManager.createOrcidProfile(profile1, false, false);
    OrcidProfile profile2 = new OrcidProfile();
    profile2.setOrcidIdentifier(TEST_ORCID);
    OrcidWorks orcidWorks = new OrcidWorks();
    profile2.setOrcidWorks(orcidWorks);
    WorkTitle workTitle1 = new WorkTitle();
    workTitle1.setTitle(new Title("Another Title"));
    workTitle1.setSubtitle(new Subtitle("Journal of Cloud Spotting"));
    OrcidWork work1 = createWork1(workTitle1);
    Source source = new Source(TEST_ORCID);
    work1.setSource(source);
    orcidWorks.getOrcidWork().add(work1);
    WorkTitle workTitle2 = new WorkTitle();
    workTitle2.setTitle(new Title("New Title"));
    workTitle2.setSubtitle(new Subtitle("Another New subtitle"));
    OrcidWork work2 = createWork2(workTitle2);
    work2.setVisibility(Visibility.PUBLIC);
    orcidWorks.getOrcidWork().add(work2);
    // Try to add a duplicate
    WorkTitle workTitle3 = new WorkTitle();
    workTitle3.setTitle(new Title("Further Title"));
    workTitle3.setSubtitle(new Subtitle("Further subtitle"));
    OrcidWork work3 = createWork3(workTitle3);
    work3.setVisibility(Visibility.LIMITED);
    orcidWorks.getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile2);
    OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals("Will", resultProfile.getOrcidBio().getPersonalDetails().getGivenNames().getContent());
    List<OrcidWork> works = resultProfile.retrieveOrcidWorks().getOrcidWork();
    assertEquals(4, works.size());
    assertEquals("Another Title", works.get(0).getWorkTitle().getTitle().getContent());
    assertEquals("Journal of Cloud Spotting", works.get(0).getWorkTitle().getSubtitle().getContent());
    for (OrcidWork work : works) {
        if ("Further Title".equals(work.getWorkTitle().getTitle().getContent()))
            assertEquals(Visibility.LIMITED, work.getVisibility());
        else if ("New Title".equals(work.getWorkTitle().getTitle().getContent()))
            assertEquals(Visibility.PUBLIC, work.getVisibility());
        else
            assertEquals(Visibility.PRIVATE, work.getVisibility());
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Subtitle(org.orcid.jaxb.model.message.Subtitle) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Title(org.orcid.jaxb.model.message.Title) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) Source(org.orcid.jaxb.model.message.Source) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with Rollback

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

the class OrcidProfileManagerImplTest method testRevokeDelegate.

@Test
@Transactional
@Rollback(true)
public void testRevokeDelegate() {
    OrcidProfile profile1 = createBasicProfile();
    Delegation delegation = new Delegation();
    profile1.getOrcidBio().setDelegation(delegation);
    GivenPermissionTo givenPermissionTo = new GivenPermissionTo();
    delegation.setGivenPermissionTo(givenPermissionTo);
    DelegationDetails delegationDetails = new DelegationDetails();
    delegationDetails.setApprovalDate(new ApprovalDate(DateUtils.convertToXMLGregorianCalendar("2011-03-14T02:34:16")));
    DelegateSummary profileSummary = new DelegateSummary(new OrcidIdentifier(DELEGATE_ORCID));
    delegationDetails.setDelegateSummary(profileSummary);
    givenPermissionTo.getDelegationDetails().add(delegationDetails);
    orcidProfileManager.createOrcidProfile(profile1, false, false);
    orcidProfileManager.revokeDelegate(TEST_ORCID, DELEGATE_ORCID);
    OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNull(retrievedProfile.getOrcidBio().getDelegation());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) GivenPermissionTo(org.orcid.jaxb.model.message.GivenPermissionTo) DelegateSummary(org.orcid.jaxb.model.message.DelegateSummary) OrcidIdentifier(org.orcid.jaxb.model.message.OrcidIdentifier) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) Delegation(org.orcid.jaxb.model.message.Delegation) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with Rollback

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

the class OrcidProfileManagerImplTest method testUpdatePasswordInformationLeavesSecurityQuestionsUnchanged.

@Test
@Transactional
@Rollback(true)
public void testUpdatePasswordInformationLeavesSecurityQuestionsUnchanged() {
    OrcidProfile profile1 = createBasicProfile();
    assertEquals("password", profile1.getPassword());
    assertEquals("random answer", profile1.getSecurityQuestionAnswer());
    orcidProfileManager.createOrcidProfile(profile1, false, false);
    OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile(profile1.getOrcidIdentifier().getPath());
    String hashedPasswordValue = retrievedProfile.getPassword();
    assertTrue("Should have hashed password", 108 == hashedPasswordValue.length() && !"password".equals(hashedPasswordValue));
    assertEquals("Should have security question", 3, retrievedProfile.getOrcidInternal().getSecurityDetails().getSecurityQuestionId().getValue());
    assertEquals("Should have decrypted security answer", "random answer", retrievedProfile.getSecurityQuestionAnswer());
    retrievedProfile.setPassword("A new password");
    orcidProfileManager.updatePasswordInformation(retrievedProfile);
    OrcidProfile updatedProfile = orcidProfileManager.retrieveOrcidProfile(profile1.getOrcidIdentifier().getPath());
    String updatedPassword = updatedProfile.getPassword();
    assertEquals("Password should be hashed", 108, updatedPassword.length());
    assertFalse("Password should have changed but was still: " + updatedPassword, hashedPasswordValue.equals(updatedPassword));
    assertEquals("Should have security question", 3, updatedProfile.getOrcidInternal().getSecurityDetails().getSecurityQuestionId().getValue());
    assertEquals("Should have decrypted security answer", "random answer", updatedProfile.getSecurityQuestionAnswer());
}
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)

Example 29 with Rollback

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

the class OrcidProfileManagerImplTest method addNewFundingModifyExistingWorksDisplayIndex.

@Test
@Transactional
@Rollback(true)
public void addNewFundingModifyExistingWorksDisplayIndex() {
    OrcidProfile profile1 = createBasicProfile();
    String orcidIdentifier = null;
    profile1.setOrcidIdentifier(orcidIdentifier);
    setBio(profile1, Visibility.PUBLIC);
    profile1 = orcidProfileManager.createOrcidProfile(profile1, true, false);
    assertNotNull(profile1);
    assertNotNull(profile1.getOrcidIdentifier());
    String orcidId = profile1.getOrcidIdentifier().getPath();
    OrcidProfile profile = getFundingInsideOrcidProfile("f1", orcidId);
    orcidProfileManager.addFundings(profile);
    profile = getFundingInsideOrcidProfile("f2", orcidId);
    orcidProfileManager.addFundings(profile);
    profile = getFundingInsideOrcidProfile("f3", orcidId);
    orcidProfileManager.addFundings(profile);
    profile = getFundingInsideOrcidProfile("f4", orcidId);
    orcidProfileManager.addFundings(profile);
    List<ProfileFundingEntity> all = profileFundingDao.getByUser(orcidId);
    assertNotNull(all);
    Long displayIndex1 = null;
    Long displayIndex2 = null;
    Long displayIndex3 = null;
    for (ProfileFundingEntity entity : all) {
        Long displayIndex = entity.getDisplayIndex();
        if ("f1".equals(entity.getTitle())) {
            displayIndex1 = displayIndex;
        } else if ("f2".equals(entity.getTitle())) {
            displayIndex2 = displayIndex;
        } else if ("f3".equals(entity.getTitle())) {
            displayIndex3 = displayIndex;
        }
    }
    assertNotNull(displayIndex1);
    assertNotNull(displayIndex2);
    assertNotNull(displayIndex3);
    assertEquals(Long.valueOf(0L), displayIndex3);
//TODO: Might need to be readed in a later release
//assertTrue(displayIndex3 < displayIndex2);
//assertTrue(displayIndex2 < displayIndex1);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with Rollback

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

the class OrcidProfileManagerImplTest method testUpdateLastModifiedDate.

@Test
@Transactional
@Rollback(true)
public void testUpdateLastModifiedDate() throws InterruptedException {
    Date start = new Date();
    OrcidProfile profile1 = createBasicProfile();
    profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
    Date profile1LastModified = profile1.getOrcidHistory().getLastModifiedDate().getValue().toGregorianCalendar().getTime();
    assertNotNull(profile1LastModified);
    assertFalse(start.after(profile1LastModified));
    Thread.sleep(100);
    orcidProfileManager.updateLastModifiedDate(TEST_ORCID);
    OrcidProfile profile2 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    Date profile2LastModified = profile2.getOrcidHistory().getLastModifiedDate().getValue().toGregorianCalendar().getTime();
    assertTrue(profile2LastModified.getTime() > profile1LastModified.getTime());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) 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