Search in sources :

Example 6 with Rollback

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

the class SecurityQuestionDaoTest method testMergeFindAndRemove.

@Test
@Rollback(true)
public void testMergeFindAndRemove() {
    SecurityQuestionEntity question = new SecurityQuestionEntity();
    question.setQuestion("What is your pet's name?");
    securityQuestionDao.merge(question);
    assertNotNull(question.getId());
    SecurityQuestionEntity retrieved = securityQuestionDao.find(question.getId());
    assertNotNull(retrieved);
    assertEquals("What is your pet's name?", retrieved.getQuestion());
    securityQuestionDao.remove(question.getId());
    retrieved = securityQuestionDao.find(question.getId());
    assertNull(retrieved);
}
Also used : SecurityQuestionEntity(org.orcid.persistence.jpa.entities.SecurityQuestionEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest) Rollback(org.springframework.test.annotation.Rollback)

Example 7 with Rollback

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

the class OrcidProfileManagerImplTest method testUpdatePreferences.

@Test
@Transactional
@Rollback(true)
public void testUpdatePreferences() {
    OrcidProfile profile1 = createBasicProfile();
    profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
    assertEquals(Visibility.PRIVATE, profile1.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue());
    OrcidProfile profile2 = new OrcidProfile();
    profile2.setOrcidIdentifier(TEST_ORCID);
    OrcidInternal internal = new OrcidInternal();
    profile2.setOrcidInternal(internal);
    Preferences preferences = new Preferences();
    internal.setPreferences(preferences);
    preferences.setSendChangeNotifications(new SendChangeNotifications(false));
    preferences.setSendOrcidNews(new SendOrcidNews(true));
    preferences.setDeveloperToolsEnabled(new DeveloperToolsEnabled(true));
    preferences.setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.PUBLIC));
    orcidProfileManager.updatePreferences(profile2.getOrcidIdentifier().getPath(), profile2.getOrcidInternal().getPreferences());
    OrcidProfile retrievedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals(false, retrievedProfile.getOrcidInternal().getPreferences().getSendChangeNotifications().isValue());
    assertEquals(true, retrievedProfile.getOrcidInternal().getPreferences().getSendOrcidNews().isValue());
    assertEquals(true, retrievedProfile.getOrcidInternal().getPreferences().getDeveloperToolsEnabled().isValue());
    assertEquals(Visibility.PUBLIC, retrievedProfile.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) SendOrcidNews(org.orcid.jaxb.model.message.SendOrcidNews) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) ActivitiesVisibilityDefault(org.orcid.jaxb.model.message.ActivitiesVisibilityDefault) Preferences(org.orcid.jaxb.model.message.Preferences) DefaultPreferences(org.orcid.core.constants.DefaultPreferences) SendChangeNotifications(org.orcid.jaxb.model.message.SendChangeNotifications) DeveloperToolsEnabled(org.orcid.jaxb.model.message.DeveloperToolsEnabled) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Rollback

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

the class OrcidProfileManagerImplTest method addNewWorksModifyExistingWorksDisplayIndex.

@Test
@Transactional
@Rollback(true)
public void addNewWorksModifyExistingWorksDisplayIndex() {
    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 = getWorkInsideOrcidProfile("w1", orcidId);
    orcidProfileManager.addOrcidWorks(profile);
    profile = getWorkInsideOrcidProfile("w2", orcidId);
    orcidProfileManager.addOrcidWorks(profile);
    profile = getWorkInsideOrcidProfile("w3", orcidId);
    orcidProfileManager.addOrcidWorks(profile);
    List<MinimizedWorkEntity> all = workDao.findWorks(orcidId, System.currentTimeMillis());
    assertNotNull(all);
    Long displayIndex1 = null;
    Long displayIndex2 = null;
    Long displayIndex3 = null;
    for (MinimizedWorkEntity entity : all) {
        Long displayIndex = entity.getDisplayIndex();
        if ("w1".equals(entity.getTitle())) {
            displayIndex1 = displayIndex;
        } else if ("w2".equals(entity.getTitle())) {
            displayIndex2 = displayIndex;
        } else if ("w3".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);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Rollback

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

the class OrcidProfileManagerImplTest method testAddOrcidWorks.

@Test
@Transactional
@Rollback(true)
public void testAddOrcidWorks() {
    OrcidProfile profile1 = createBasicProfile();
    OrcidHistory history = new OrcidHistory();
    history.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    profile1.setOrcidHistory(history);
    history.setClaimed(new Claimed(true));
    profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
    String originalPutCode = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getPutCode();
    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("New Title"));
    workTitle3.setSubtitle(new Subtitle("Another New subtitle"));
    OrcidWork work3 = createWork2(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(3, 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) {
        assertEquals(Visibility.PRIVATE, work.getVisibility());
    }
    assertEquals("Put code of original work should not have changed", originalPutCode, works.get(2).getPutCode());
}
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) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with Rollback

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

the class OrcidIndexManagerImplTest method visibilityConstraintsAppliedToSolr.

@Test
@Rollback
@Ignore
public void visibilityConstraintsAppliedToSolr() throws Exception {
    OrcidProfile hiddenNamesOrcid = orcidProfileLimitedVisiblityCreditNameAndOtherNames();
    orcidIndexManager.persistProfileInformationForIndexing(hiddenNamesOrcid);
    // check that limited fields are hidden from solr indexing
    OrcidSolrDocument namesHiddenSolrDoc = solrDocFilteredByNameVisibility();
    verify(solrDao).persist(eq(namesHiddenSolrDoc));
    // reset orcid test data and check affilations
    OrcidProfile limitedOrcid = orcidProfileLimitedVisiblityAffiliations();
    orcidIndexManager.persistProfileInformationForIndexing(limitedOrcid);
    OrcidSolrDocument hiddenPastAffiliations = solrDocFilteredByAffilliationVisibility();
    verify(solrDao).persist(eq(hiddenPastAffiliations));
    OrcidProfile orcidAllWorksPrivate = orcidProfileAllLimitedVisibilityWorks();
    orcidIndexManager.persistProfileInformationForIndexing(orcidAllWorksPrivate);
    OrcidSolrDocument hiddenWorks = solrDocFilteredByAffilliationVisibility();
    verify(solrDao).persist(eq(hiddenWorks));
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) 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