Search in sources :

Example 36 with Rollback

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

the class ProfileDaoTest method testGetConfirmedProfileCount.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testGetConfirmedProfileCount() {
    String orcid = "4444-4444-4444-4446";
    Long confirmedProfileCount = profileDao.getConfirmedProfileCount();
    assertEquals(Long.valueOf(20), confirmedProfileCount);
    ProfileEntity profileEntity = profileDao.find(orcid);
    profileEntity.setCompletedDate(null);
    profileDao.persist(profileEntity);
    confirmedProfileCount = profileDao.getConfirmedProfileCount();
    assertEquals(Long.valueOf(19), confirmedProfileCount);
}
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 37 with Rollback

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

the class ProfileDaoTest method testInsert.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsert() throws DataSetException {
    String newOrcid = "4444-1111-6666-4441";
    ProfileEntity profile = new ProfileEntity();
    profile.setId(newOrcid);
    profileDao.persist(profile);
    Date dateCreated = new Date();
    profile.setDateCreated(dateCreated);
    profileDao.merge(profile);
    profileDao.flush();
    profile = profileDao.find(profile.getId());
    assertEquals(dateCreated.getTime(), profile.getDateCreated().getTime());
    Long count = profileDao.countAll();
    assertEquals(Long.valueOf(21), count);
    profile = profileDao.find(newOrcid);
    assertNotNull(profile);
    assertEquals(newOrcid, profile.getId());
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with Rollback

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

the class ProfileDaoTest method testInsertWithPrimaryInstitutions.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsertWithPrimaryInstitutions() throws DataSetException {
    String newOrcid = "4444-1111-6666-4442";
    ProfileEntity profile = new ProfileEntity();
    profile.setId(newOrcid);
    profileDao.persist(profile);
    Date dateCreated = new Date();
    profile.setDateCreated(dateCreated);
    profileDao.merge(profile);
    profileDao.flush();
    profile = profileDao.find(profile.getId());
    assertEquals(dateCreated.getTime(), profile.getDateCreated().getTime());
    Long count = profileDao.countAll();
    assertEquals(Long.valueOf(21), count);
    profile = profileDao.find(newOrcid);
    assertNotNull(profile);
    assertEquals(newOrcid, profile.getId());
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with Rollback

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

the class ProfileDaoTest method testInsertGroupWithClients.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsertGroupWithClients() {
    String groupOrcid = "4444-1111-6666-4444";
    ProfileEntity groupProfile = new ProfileEntity();
    groupProfile.setId(groupOrcid);
    groupProfile.setOrcidType(OrcidType.GROUP);
    groupProfile.setGroupType(MemberType.BASIC);
    SortedSet<ClientDetailsEntity> clients = new TreeSet<>(new OrcidEntityIdComparator<String>());
    String clientOrcid1 = "4444-4444-4444-4442";
    ClientDetailsEntity clientProfile1 = new ClientDetailsEntity();
    clientProfile1.setId(clientOrcid1);
    clients.add(clientProfile1);
    String clientOrcid2 = "4444-4444-4444-4443";
    ClientDetailsEntity clientProfile2 = new ClientDetailsEntity();
    clientProfile2.setId(clientOrcid2);
    clients.add(clientProfile2);
    groupProfile.setClients(clients);
    profileDao.persist(groupProfile);
    profileDao.flush();
    groupProfile = profileDao.find(groupOrcid);
    assertNotNull(groupProfile);
    assertEquals(groupOrcid, groupProfile.getId());
    assertEquals(MemberType.BASIC, groupProfile.getGroupType());
    assertNotNull(groupProfile.getClients());
    assertEquals(2, groupProfile.getClients().size());
    Map<String, ClientDetailsEntity> map = ProfileEntity.mapById(groupProfile.getClients());
    assertTrue(map.containsKey(clientOrcid1));
    assertTrue(map.containsKey(clientOrcid2));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) TreeSet(java.util.TreeSet) 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 40 with Rollback

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

the class ProfileDaoTest method testUpdateNotificationsPreferences.

@Test
@Rollback(true)
public void testUpdateNotificationsPreferences() {
    ProfileEntity entity1 = profileDao.find("1000-0000-0000-0001");
    ProfileEntity entity6 = profileDao.find("0000-0000-0000-0006");
    assertFalse(entity1.getSendChangeNotifications());
    assertFalse(entity1.getSendAdministrativeChangeNotifications());
    assertFalse(entity1.getSendOrcidNews());
    assertFalse(entity1.getSendMemberUpdateRequests());
    assertFalse(entity6.getSendChangeNotifications());
    assertFalse(entity6.getSendAdministrativeChangeNotifications());
    assertFalse(entity6.getSendOrcidNews());
    assertFalse(entity6.getSendMemberUpdateRequests());
    // Enable some preferences
    assertTrue(profileDao.updateNotificationsPreferences("0000-0000-0000-0006", true, false, true, false));
    entity1 = profileDao.find("1000-0000-0000-0001");
    entity6 = profileDao.find("0000-0000-0000-0006");
    // Nothing changed on entity1
    assertFalse(entity1.getSendChangeNotifications());
    assertFalse(entity1.getSendAdministrativeChangeNotifications());
    assertFalse(entity1.getSendOrcidNews());
    assertFalse(entity1.getSendMemberUpdateRequests());
    // Updates on entity6
    assertTrue(entity6.getSendChangeNotifications());
    assertFalse(entity6.getSendAdministrativeChangeNotifications());
    assertTrue(entity6.getSendOrcidNews());
    assertFalse(entity6.getSendMemberUpdateRequests());
    // Enable all preferences
    assertTrue(profileDao.updateNotificationsPreferences("0000-0000-0000-0006", true, true, true, true));
    entity1 = profileDao.find("1000-0000-0000-0001");
    entity6 = profileDao.find("0000-0000-0000-0006");
    // Nothing changed on entity1
    assertFalse(entity1.getSendChangeNotifications());
    assertFalse(entity1.getSendAdministrativeChangeNotifications());
    assertFalse(entity1.getSendOrcidNews());
    assertFalse(entity1.getSendMemberUpdateRequests());
    // Updates on entity6
    assertTrue(entity6.getSendChangeNotifications());
    assertTrue(entity6.getSendAdministrativeChangeNotifications());
    assertTrue(entity6.getSendOrcidNews());
    assertTrue(entity6.getSendMemberUpdateRequests());
    // Disable all preferences
    assertTrue(profileDao.updateNotificationsPreferences("0000-0000-0000-0006", false, false, false, false));
    entity1 = profileDao.find("1000-0000-0000-0001");
    entity6 = profileDao.find("0000-0000-0000-0006");
    // Nothing changed on entity1
    assertFalse(entity1.getSendChangeNotifications());
    assertFalse(entity1.getSendAdministrativeChangeNotifications());
    assertFalse(entity1.getSendOrcidNews());
    assertFalse(entity1.getSendMemberUpdateRequests());
    // Updates on entity6
    assertFalse(entity6.getSendChangeNotifications());
    assertFalse(entity6.getSendAdministrativeChangeNotifications());
    assertFalse(entity6.getSendOrcidNews());
    assertFalse(entity6.getSendMemberUpdateRequests());
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) 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