Search in sources :

Example 31 with Rollback

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

the class OrcidProfileManagerImplTest method testPreventDuplicatedWorks.

@Test
@Transactional
@Rollback(true)
public void testPreventDuplicatedWorks() {
    OrcidWork work1 = createWork1();
    OrcidWork work2 = createWork2();
    OrcidWork work3 = createWork3();
    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());
    assertEquals(work1.getWorkTitle().getTitle().getContent(), profile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getWorkTitle().getTitle().getContent());
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    boolean found1 = false;
    boolean found2 = false;
    boolean found3 = false;
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(2, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    for (OrcidWork work : profile.getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        String workTitle = work.getWorkTitle().getTitle().getContent();
        if (workTitle.equals(work1.getWorkTitle().getTitle().getContent())) {
            found1 = true;
        } else if (workTitle.equals(work2.getWorkTitle().getTitle().getContent())) {
            found2 = true;
        } else if (workTitle.equals(work3.getWorkTitle().getTitle().getContent())) {
            found3 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertFalse(found3);
    // Add work # 3 and duplicate other works
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    // Work 3 was added and work 1 and 2 where not added twice
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(3, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    found1 = false;
    found2 = false;
    found3 = false;
    for (OrcidWork work : profile.getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        String workTitle = work.getWorkTitle().getTitle().getContent();
        if (workTitle.equals(work1.getWorkTitle().getTitle().getContent())) {
            found1 = true;
        } else if (workTitle.equals(work2.getWorkTitle().getTitle().getContent())) {
            found2 = true;
        } else if (workTitle.equals(work3.getWorkTitle().getTitle().getContent())) {
            found3 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    // Duplicate all works
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    // No new works are added and no duplicated was allowed
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(3, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    found1 = false;
    found2 = false;
    found3 = false;
    for (OrcidWork work : profile.getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        String workTitle = work.getWorkTitle().getTitle().getContent();
        if (workTitle.equals(work1.getWorkTitle().getTitle().getContent())) {
            found1 = true;
        } else if (workTitle.equals(work2.getWorkTitle().getTitle().getContent())) {
            found2 = true;
        } else if (workTitle.equals(work3.getWorkTitle().getTitle().getContent())) {
            found3 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    //Test using work source
    Source source = new Source();
    source.setSourceOrcid(new SourceOrcid(APPLICATION_ORCID));
    work1.setSource(source);
    // Add work1 again, since it have a different source, it should be added
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(4, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    //Add work1 again, and it should not be added, since is duplicated
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(4, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with Rollback

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

the class OrcidProfileManagerImplTest method testUpdateProfile.

@Test
@Transactional
@Rollback(true)
public void testUpdateProfile() {
    OrcidProfile profile1 = createBasicProfile();
    profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
    String originalPutCode = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getPutCode();
    OrcidProfile profile2 = createBasicProfile();
    profile2.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).setPutCode(originalPutCode);
    profile2 = orcidProfileManager.updateOrcidProfile(profile2);
    OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    String resultPutCode = resultProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getPutCode();
    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("Put code should not change", originalPutCode, resultPutCode);
}
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 33 with Rollback

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

the class OrcidSearchManagerImplTest method orcidRetrievalMandatoryFieldsOnly.

@Test
@Rollback
public void orcidRetrievalMandatoryFieldsOnly() {
    when(solrDao.findByOrcid("1434")).thenReturn(getSolrRes5678());
    when(orcidProfileCacheManager.retrievePublicBio("5678")).thenReturn(getOrcidProfile5678MandatoryOnly());
    OrcidMessage retrievedOrcidMessage = orcidSearchManager.findOrcidSearchResultsById("1434");
    assertNotNull(retrievedOrcidMessage);
    assertTrue(retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().size() == 1);
    OrcidSearchResult result = retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().get(0);
    OrcidProfile retrievedProfile = result.getOrcidProfile();
    assertEquals("5678", retrievedProfile.getOrcidIdentifier().getPath());
    OrcidBio orcidBio = retrievedProfile.getOrcidBio();
    assertEquals("Logan", orcidBio.getPersonalDetails().getFamilyName().getContent());
    assertEquals("Donald Edward", orcidBio.getPersonalDetails().getGivenNames().getContent());
}
Also used : OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 34 with Rollback

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

the class OrcidSearchManagerImplTest method orcidInIndexButNotinDb.

@Test
@Rollback
public void orcidInIndexButNotinDb() {
    when(solrDao.findByOrcid("1434")).thenReturn(getSolrRes5678());
    when(orcidProfileCacheManager.retrievePublicBio("5678")).thenReturn(null);
    OrcidMessage retrievedOrcidMessage = orcidSearchManager.findOrcidSearchResultsById("1434");
    assertNotNull(retrievedOrcidMessage);
    assertNotNull(retrievedOrcidMessage.getOrcidSearchResults());
    assertTrue(retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().isEmpty());
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 35 with Rollback

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

the class ProfileDaoTest method testInsertClient.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsertClient() {
    String clientOrcid = "4444-1111-6666-4444";
    ClientDetailsEntity client = new ClientDetailsEntity();
    client.setId(clientOrcid);
    String groupOrcid = "4444-4444-4444-4441";
    client.setGroupProfileId(groupOrcid);
    clientDetailsDao.persist(client);
    clientDetailsDao.flush();
    client = clientDetailsDao.find(clientOrcid);
    assertNotNull(client);
    assertEquals(clientOrcid, client.getId());
    ProfileEntity groupProfile = profileDao.find(groupOrcid);
    assertNotNull(groupProfile);
    assertNotNull(groupProfile.getClients());
    assertEquals(1, groupProfile.getClients().size());
    assertEquals(clientOrcid, groupProfile.getClients().iterator().next().getId());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) 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