use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.
the class FundingsControllerTest method testEditOrgOnExistingFunding.
@Test
@Rollback(true)
public void testEditOrgOnExistingFunding() throws Exception {
HttpSession session = mock(HttpSession.class);
when(servletRequest.getSession()).thenReturn(session);
when(localeManager.getLocale()).thenReturn(new Locale("us", "EN"));
FundingForm funding = fundingController.getFundingJson(Long.valueOf("1"));
// Check old org
assertEquals("London", funding.getCity().getValue());
assertEquals("GB", funding.getCountry().getValue());
// Update org
funding.getCity().setValue("San Jose");
funding.getCountry().setValue("CR");
fundingController.postFunding(funding);
// Fetch the funding again
FundingForm updated = fundingController.getFundingJson(Long.valueOf("1"));
assertNotNull(updated);
// Check new org
assertEquals("San Jose", funding.getCity().getValue());
assertEquals("CR", funding.getCountry().getValue());
}
use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method before.
@Before
@Transactional
@Rollback
public void before() throws Exception {
OrcidProfileManagerImpl orcidProfileManagerImpl = getTargetObject(orcidProfileManager, OrcidProfileManagerImpl.class);
orcidProfileManagerImpl.setNotificationManager(notificationManager);
if (profileDao.find(TEST_ORCID) != null) {
profileDao.remove(TEST_ORCID);
}
subjectDao.merge(new SubjectEntity("Computer Science"));
subjectDao.merge(new SubjectEntity("Dance"));
OrcidProfile delegateProfile = new OrcidProfile();
delegateProfile.setOrcidIdentifier(DELEGATE_ORCID);
OrcidBio delegateBio = new OrcidBio();
delegateProfile.setOrcidBio(delegateBio);
PersonalDetails delegatePersonalDetails = new PersonalDetails();
delegateBio.setPersonalDetails(delegatePersonalDetails);
CreditName delegateCreditName = new CreditName("H. Shearer");
delegateCreditName.setVisibility(Visibility.PUBLIC);
delegatePersonalDetails.setCreditName(delegateCreditName);
orcidProfileManager.createOrcidProfile(delegateProfile, false, false);
OrcidProfile applicationProfile = new OrcidProfile();
applicationProfile.setOrcidIdentifier(APPLICATION_ORCID);
OrcidBio applicationBio = new OrcidBio();
applicationProfile.setOrcidBio(applicationBio);
PersonalDetails applicationPersonalDetails = new PersonalDetails();
applicationBio.setPersonalDetails(applicationPersonalDetails);
applicationPersonalDetails.setCreditName(new CreditName("Brown University"));
orcidProfileManager.createOrcidProfile(applicationProfile, false, false);
ClientDetailsEntity clientDetails = new ClientDetailsEntity();
clientDetails.setId(applicationProfile.getOrcidIdentifier().getPath());
ProfileEntity applicationProfileEntity = profileDao.find(applicationProfile.getOrcidIdentifier().getPath());
profileDao.refresh(applicationProfileEntity);
clientDetails.setGroupProfileId(applicationProfileEntity.getId());
clientDetailsManager.merge(clientDetails);
OrcidOauth2TokenDetail token = new OrcidOauth2TokenDetail();
token.setTokenValue("1234");
token.setClientDetailsId(clientDetails.getId());
token.setProfile(profileDao.find(delegateProfile.getOrcidIdentifier().getPath()));
token.setScope(StringUtils.join(new String[] { ScopePathType.ORCID_BIO_READ_LIMITED.value(), ScopePathType.ORCID_BIO_UPDATE.value() }, " "));
SortedSet<OrcidOauth2TokenDetail> tokens = new TreeSet<>();
tokens.add(token);
ProfileEntity delegateProfileEntity = profileDao.find(delegateProfile.getOrcidIdentifier().getPath());
delegateProfileEntity.setTokenDetails(tokens);
profileDao.merge(delegateProfileEntity);
SecurityQuestionEntity existingSecurityQuestionEntity = securityQuestionDao.find(3);
if (existingSecurityQuestionEntity == null) {
SecurityQuestionEntity securityQuestionEntity = new SecurityQuestionEntity();
securityQuestionEntity.setId(3);
securityQuestionEntity.setQuestion("What?");
securityQuestionDao.persist(securityQuestionEntity);
}
orcidProfileManager.setCompareWorksUsingScopusWay(true);
}
use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testAddOrcidWorksWhenDefaultVisibilityIsPublic.
@Test
@Transactional
@Rollback(true)
public void testAddOrcidWorksWhenDefaultVisibilityIsPublic() {
OrcidProfile profile1 = createBasicProfile();
OrcidHistory history = new OrcidHistory();
history.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
profile1.setOrcidHistory(history);
history.setClaimed(new Claimed(true));
profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.PUBLIC));
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);
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 ("Test Title".equals(work.getWorkTitle().getTitle().getContent()))
assertEquals(Visibility.PRIVATE, work.getVisibility());
else
assertEquals(Visibility.PUBLIC, work.getVisibility());
}
}
use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testDeactivateProfile.
@Test
@Transactional
@Rollback(true)
public void testDeactivateProfile() {
OrcidProfile profile1 = createBasicProfile();
profile1.getOrcidBio().getPersonalDetails().setCreditName(new CreditName("My Credit Name"));
ExternalIdentifiers extIds = new ExternalIdentifiers();
ExternalIdentifier extId = new ExternalIdentifier();
extId.setExternalIdCommonName(new ExternalIdCommonName("External body"));
extId.setExternalIdReference(new ExternalIdReference("abc123"));
extIds.getExternalIdentifier().add(extId);
profile1.getOrcidBio().setExternalIdentifiers(extIds);
OtherNames otherNames = new OtherNames();
otherNames.addOtherName("OtherName 1", null);
otherNames.addOtherName("OtherName 2", null);
profile1.getOrcidBio().getPersonalDetails().setOtherNames(otherNames);
profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
assertEquals(1, profile1.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
assertEquals(2, profile1.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().size());
assertEquals("My Credit Name", profile1.getOrcidBio().getPersonalDetails().getCreditName().getContent());
assertEquals(Visibility.PRIVATE, profile1.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().iterator().next().getVisibility());
orcidProfileManager.deactivateOrcidProfile(profile1);
OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile(profile1.getOrcidIdentifier().getPath());
assertTrue(retrievedProfile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().isEmpty());
assertNull(retrievedProfile.getOrcidBio().getPersonalDetails().getCreditName());
assertEquals(0, retrievedProfile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().size());
assertEquals("Given Names Deactivated", retrievedProfile.getOrcidBio().getPersonalDetails().getGivenNames().getContent());
assertEquals("Family Name Deactivated", retrievedProfile.getOrcidBio().getPersonalDetails().getFamilyName().getContent());
assertNull(retrievedProfile.getOrcidBio().getBiography().getContent());
}
use of org.springframework.test.annotation.Rollback in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testUpdatePasswordResultsInEncypytedProfile.
@Test
@Transactional
@Rollback(true)
public void testUpdatePasswordResultsInEncypytedProfile() {
OrcidProfile basicProfile = createBasicProfile();
OrcidProfile derivedProfile = orcidProfileManager.createOrcidProfile(basicProfile, false, false);
assertTrue(encryptionManager.hashMatches("password", derivedProfile.getPassword()));
assertEquals("random answer", encryptionManager.decryptForInternalUse(derivedProfile.getSecurityQuestionAnswer()));
assertEquals("1234", encryptionManager.decryptForInternalUse(derivedProfile.getVerificationCode()));
OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile(derivedProfile.getOrcidIdentifier().getPath());
assertTrue(encryptionManager.hashMatches("password", derivedProfile.getPassword()));
assertEquals("random answer", retrievedProfile.getSecurityQuestionAnswer());
assertEquals("1234", retrievedProfile.getVerificationCode());
}
Aggregations