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());
}
}
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());
}
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());
}
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);
}
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());
}
Aggregations