Search in sources :

Example 41 with Rollback

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

the class ProfileDaoTest method testRemove.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testRemove() {
    ProfileEntity profile = profileDao.find("4444-4444-4444-4442");
    profileDao.remove(profile);
    profileDao.flush();
    profile = profileDao.find("4444-4444-4444-4442");
    assertNull(profile);
    profile = profileDao.find("4444-4444-4444-4443");
    assertNotNull(profile);
    profileDao.remove(profile.getId());
    profileDao.flush();
    profile = profileDao.find("4444-4444-4444-4443");
    assertNull(profile);
    List<ProfileEntity> all = profileDao.getAll();
    assertEquals(18, all.size());
}
Also used : 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)

Example 42 with Rollback

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

the class ProfileDaoTest method testFindUnclaimedNeedingReminder.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testFindUnclaimedNeedingReminder() {
    List<String> results = profileDao.findUnclaimedNeedingReminder(1, 10, Collections.<String>emptyList());
    assertNotNull(results);
    assertEquals(3, results.size());
    assertTrue(results.contains("4444-4444-4444-4447"));
    // Now insert claimed reminder event, result should be excluded
    // thereafter.
    ProfileEventEntity eventEntity = new ProfileEventEntity();
    eventEntity.setOrcid("4444-4444-4444-4447");
    eventEntity.setType(ProfileEventType.CLAIM_REMINDER_SENT);
    profileEventDao.persist(eventEntity);
    results = profileDao.findUnclaimedNeedingReminder(1, 10, Collections.<String>emptyList());
    assertEquals(2, results.size());
}
Also used : ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with Rollback

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

the class ResearcherUrlDaoTest method testCannotAddDuplicatedResearcherUrl.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testCannotAddDuplicatedResearcherUrl() {
    try {
        ResearcherUrlEntity newRUrl = new ResearcherUrlEntity();
        newRUrl.setDateCreated(new Date());
        newRUrl.setLastModified(new Date());
        newRUrl.setClientSourceId("4444-4444-4444-4443");
        newRUrl.setUrl("http://www.researcherurl2.com?id=1");
        newRUrl.setUrlName("test");
        newRUrl.setUser(new ProfileEntity("4444-4444-4444-4443"));
        newRUrl.setVisibility(Visibility.PUBLIC);
        newRUrl = researcherUrlDao.merge(newRUrl);
        assertNotNull(newRUrl);
        fail();
    } catch (PersistenceException e) {
    }
}
Also used : ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) PersistenceException(javax.persistence.PersistenceException) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with Rollback

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

the class OrcidOauth2AuthorizationDetailsDaoTest method testFindByTokenValue.

@Test
@Transactional
@Rollback
public void testFindByTokenValue() throws Exception {
    List<OrcidOauth2TokenDetail> all = orcidOauth2TokenDetailDao.getAll();
    assertEquals(5, all.size());
    for (OrcidOauth2TokenDetail detail : all) {
        List<OrcidOauth2TokenDetail> another = orcidOauth2TokenDetailDao.findByAuthenticationKey(detail.getAuthenticationKey());
        assertNotNull(another);
        assertFalse(another.isEmpty());
        for (OrcidOauth2TokenDetail token : another) {
            assertEquals(detail.getId(), token.getId());
            assertTrue(detail.getTokenExpiration().after(new Date()));
            assertTrue(detail.getRefreshTokenExpiration().after(new Date()));
        }
    }
}
Also used : OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Date(java.util.Date) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 45 with Rollback

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

the class OrcidOauth2AuthorizationDetailsDaoTest method testFindByUsername.

@Test
@Transactional
@Rollback
public void testFindByUsername() throws Exception {
    List<OrcidOauth2TokenDetail> all = orcidOauth2TokenDetailDao.getAll();
    assertEquals(5, all.size());
    for (OrcidOauth2TokenDetail detail : all) {
        List<OrcidOauth2TokenDetail> allForClient = orcidOauth2TokenDetailDao.findByUserName(detail.getProfile().getId());
        assertEquals(1, allForClient.size());
    }
}
Also used : OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest) 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