Search in sources :

Example 76 with Rollback

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

the class OrcidProfileManagerImplTest method testOrcidWorksHashCodeAndEquals.

@Test
@Transactional
@Rollback(true)
public void testOrcidWorksHashCodeAndEquals() {
    OrcidWork workA = createWork1();
    OrcidWork workB = createWork1();
    assertEquals(workA, workB);
    assertEquals(workA.hashCode(), workB.hashCode());
}
Also used : OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 77 with Rollback

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

the class OrcidProfileManagerImplTest method testDuplicatedExternalIdentifiersThrowsException.

@Test
@Transactional
@Rollback(true)
public void testDuplicatedExternalIdentifiersThrowsException() {
    OrcidWork work2 = createWork2();
    OrcidWork work3 = createWork3();
    WorkExternalIdentifier sharedExternalIdentifier1 = new WorkExternalIdentifier();
    sharedExternalIdentifier1.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
    sharedExternalIdentifier1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("shared-doi1"));
    work2.getWorkExternalIdentifiers().getWorkExternalIdentifier().add(sharedExternalIdentifier1);
    work3.getWorkExternalIdentifiers().getWorkExternalIdentifier().add(sharedExternalIdentifier1);
    OrcidProfile profile = createBasicProfile();
    profile = orcidProfileManager.createOrcidProfile(profile, false, false);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(1, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
    try {
        orcidProfileManager.addOrcidWorks(profile);
        fail("This should not pass since we add works with duplicated external identifiers");
    } catch (IllegalArgumentException iae) {
        assertEquals("Works \"Test Title # 2\" and \"Test Title # 3\" have the same external id \"shared-doi1\"", iae.getMessage());
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) WorkExternalIdentifierId(org.orcid.jaxb.model.message.WorkExternalIdentifierId) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 78 with Rollback

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

the class OrcidProfileManagerImplTest method testUpdateProfileButRemoveWorkExternalIdentifier.

@Test
@Transactional
@Rollback(true)
public void testUpdateProfileButRemoveWorkExternalIdentifier() {
    OrcidProfile profile1 = createBasicProfile();
    profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
    List<WorkExternalIdentifier> workExternalIdentifiers = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getWorkExternalIdentifiers().getWorkExternalIdentifier();
    assertEquals(3, workExternalIdentifiers.size());
    Iterator<WorkExternalIdentifier> workExternalIdentifiersIterator = workExternalIdentifiers.iterator();
    while (workExternalIdentifiersIterator.hasNext()) {
        if (WorkExternalIdentifierType.PMID.equals(workExternalIdentifiersIterator.next().getWorkExternalIdentifierType())) {
            workExternalIdentifiersIterator.remove();
        }
    }
    profile1 = orcidProfileManager.updateOrcidProfile(profile1);
    OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNotNull(resultProfile);
    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());
    assertEquals(2, resultProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getWorkExternalIdentifiers().getWorkExternalIdentifier().size());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 79 with Rollback

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

the class OrcidProfileManagerImplTest method testRetrieveProfileWhenNonExistant.

@Test
@Transactional
@Rollback(true)
public void testRetrieveProfileWhenNonExistant() {
    OrcidProfile orcidProfile = orcidProfileManager.retrievePublicOrcidProfile("1234-5678-8765-4321");
    assertNull(orcidProfile);
}
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 80 with Rollback

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

the class OrcidProfileManagerImplTest method testUpdatePersonalInformationRemovesOrcidIndexFields.

@Test
@Transactional
@Rollback(true)
public void testUpdatePersonalInformationRemovesOrcidIndexFields() throws Exception {
    // re-use the createFull method but add some extra criteria so we can
    // use our specific orcidAllSolrFieldsPopulatedForSave matcher
    OrcidProfile profile = createFullOrcidProfile();
    OtherNames otherNames = new OtherNames();
    otherNames.getOtherName().add(new OtherName("Stan", null));
    otherNames.getOtherName().add(new OtherName("Willis", null));
    profile.getOrcidBio().getPersonalDetails().setOtherNames(otherNames);
    OrcidWorks orcidWorks = new OrcidWorks();
    profile.setOrcidWorks(orcidWorks);
    WorkTitle singleWorkTitle = new WorkTitle();
    singleWorkTitle.setTitle(new Title("Single works"));
    singleWorkTitle.setSubtitle(new Subtitle("Single works"));
    OrcidWork orcidWork = createWork1(singleWorkTitle);
    // TODO JB some doi testing here?
    // orcidWork.getElectronicResourceNum().add(new
    // ElectronicResourceNum("10.1016/S0021-8502(00)90373-2",
    // ElectronicResourceNumType.DOI));
    orcidWorks.getOrcidWork().add(orcidWork);
    orcidProfileManager.createOrcidProfile(profile, false, false);
    // now negate all fields that form part of a solr query, leaving only
    // the orcid itself
    // we do this by passing through an orcid missing the fields from an
    // OrcidSolrDocument
    OrcidProfile negatedProfile = createBasicProfile();
    negatedProfile.getOrcidBio().getPersonalDetails().setFamilyName(null);
    negatedProfile.getOrcidBio().getPersonalDetails().setGivenNames(null);
    negatedProfile.getOrcidBio().getPersonalDetails().setCreditName(null);
    negatedProfile.getOrcidBio().getPersonalDetails().setOtherNames(null);
    negatedProfile.getOrcidActivities().setAffiliations(null);
    orcidProfileManager.updateOrcidBio(negatedProfile);
    assertEquals(IndexingStatus.PENDING, profileDao.find(TEST_ORCID).getIndexingStatus());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Subtitle(org.orcid.jaxb.model.message.Subtitle) OtherNames(org.orcid.jaxb.model.message.OtherNames) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) OtherName(org.orcid.jaxb.model.message.OtherName) 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) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Rollback (org.springframework.test.annotation.Rollback)108 Test (org.junit.Test)104 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