Search in sources :

Example 81 with Rollback

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

the class OrcidProfileManagerImplTest method testAddOrcidWorksWhenDefaultVisibilityIsLimited.

@Test
@Transactional
@Rollback(true)
public void testAddOrcidWorksWhenDefaultVisibilityIsLimited() {
    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.LIMITED));
    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.LIMITED, work.getVisibility());
    }
}
Also used : 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) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) Claimed(org.orcid.jaxb.model.message.Claimed) Source(org.orcid.jaxb.model.message.Source) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Subtitle(org.orcid.jaxb.model.message.Subtitle) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) ActivitiesVisibilityDefault(org.orcid.jaxb.model.message.ActivitiesVisibilityDefault) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 82 with Rollback

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

the class OrcidProfileManagerImplTest method testUpdateProfileWithEmailVerified.

@Test
@Transactional
@Rollback(true)
public void testUpdateProfileWithEmailVerified() {
    OrcidProfile profile = createBasicProfile();
    profile = orcidProfileManager.createOrcidProfile(profile, false, false);
    assertNotNull(profile.getOrcidBio().getContactDetails().retrievePrimaryEmail());
    assertFalse(profile.getOrcidBio().getContactDetails().retrievePrimaryEmail().isVerified());
    profile.getOrcidBio().getContactDetails().retrievePrimaryEmail().setVerified(true);
    orcidProfileManager.updateOrcidProfile(profile);
    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());
    assertTrue(profile.getOrcidBio().getContactDetails().retrievePrimaryEmail().isVerified());
}
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 83 with Rollback

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

the class WebhookDaoTest method testMergeFindAndRemove.

@Test
@Rollback(true)
public void testMergeFindAndRemove() {
    ProfileEntity profile = new ProfileEntity("1234-1234-1234-1234");
    profileDao.merge(profile);
    ProfileEntity clientProfile = new ProfileEntity("4444-4444-4444-4449");
    profileDao.merge(clientProfile);
    ClientDetailsEntity clientDetails = new ClientDetailsEntity();
    clientDetails.setGroupProfileId(clientProfile.getId());
    clientDetails.setId(clientProfile.getId());
    clientDetailsDao.merge(clientDetails);
    WebhookEntity webhook = new WebhookEntity();
    webhook.setProfile(profile);
    webhook.setUri("http://semantico.com/orcid/1234");
    webhook.setClientDetails(clientDetails);
    webhookDao.merge(webhook);
    WebhookEntityPk pk = new WebhookEntityPk();
    pk.setProfile(profile);
    pk.setUri("http://semantico.com/orcid/1234");
    WebhookEntity retrieved = webhookDao.find(pk);
    assertNotNull(retrieved);
    assertEquals("1234-1234-1234-1234", retrieved.getProfile().getId());
    assertEquals("http://semantico.com/orcid/1234", retrieved.getUri());
    assertEquals("4444-4444-4444-4449", retrieved.getClientDetails().getClientId());
    assertTrue(retrieved.isEnabled());
    assertEquals(0, retrieved.getFailedAttemptCount());
    assertNull(retrieved.getLastFailed());
    webhookDao.remove(pk);
    retrieved = webhookDao.find(pk);
    assertNull(retrieved);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) WebhookEntityPk(org.orcid.persistence.jpa.entities.keys.WebhookEntityPk) WebhookEntity(org.orcid.persistence.jpa.entities.WebhookEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback)

Example 84 with Rollback

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

the class WebhookDaoTest method testFindWebhooksReadyToProcess.

@Test
@Rollback(true)
public void testFindWebhooksReadyToProcess() {
    Date now = new Date();
    List<WebhookEntity> results = webhookDao.findWebhooksReadyToProcess(now, 5, 10);
    assertNotNull(results);
    assertEquals(1, results.size());
    Set<String> orcids = new HashSet<>();
    for (WebhookEntity result : results) {
        orcids.add(result.getProfile().getId());
    }
    assertTrue(orcids.contains("4444-4444-4444-4443"));
}
Also used : WebhookEntity(org.orcid.persistence.jpa.entities.WebhookEntity) Date(java.util.Date) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback)

Example 85 with Rollback

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

the class WebhookDaoTest method testCountWebhooksReadyToProcess.

@Test
@Rollback(true)
public void testCountWebhooksReadyToProcess() {
    Date now = new Date();
    long count = webhookDao.countWebhooksReadyToProcess(now, 5);
    assertNotNull(count);
    assertEquals(1, count);
}
Also used : Date(java.util.Date) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback)

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