Search in sources :

Example 51 with Rollback

use of org.springframework.test.annotation.Rollback in project cas by apereo.

the class SessionHealthIndicatorJpaTests method verifyObserveOkJpaTicketRegistry.

@Test
@Rollback(false)
public void verifyObserveOkJpaTicketRegistry() {
    addTicketsToRegistry(jpaRegistry, 5, 5);
    assertEquals(10, jpaRegistry.getTickets().size());
    final SessionMonitor monitor = new SessionMonitor(jpaRegistry, -1, -1);
    final Health status = monitor.health();
    assertEquals(Status.UP, status.getStatus());
}
Also used : Health(org.springframework.boot.actuate.health.Health) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback)

Example 52 with Rollback

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

the class IdentifierTypeManagerTest method test2CreateAndUpdateIdentifier.

@Test
@Transactional
@Rollback
public void test2CreateAndUpdateIdentifier() {
    IdentifierType id = idTypeMan.createIdentifierType(createIdentifierType(1));
    assertNotNull(id);
    assertNotNull(id.getPutCode());
    assertTrue(new Date().after(id.getDateCreated()));
    id = idTypeMan.fetchIdentifierTypeByDatabaseName("TEST1", null);
    assertNotNull(id);
    id = idTypeMan.fetchIdentifierTypeByDatabaseName("TEST1", null);
    Date last = id.getLastModified();
    id.setValidationRegex("test");
    id = idTypeMan.updateIdentifierType(id);
    assertTrue(last.before(id.getLastModified()));
    id = idTypeMan.fetchIdentifierTypeByDatabaseName("TEST1", null);
    assertEquals("test1", id.getName());
    assertEquals("test", id.getValidationRegex());
    assertTrue(last.getTime() < id.getLastModified().getTime());
}
Also used : IdentifierType(org.orcid.pojo.IdentifierType) Date(java.util.Date) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with Rollback

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

the class OrcidIndexManagerImplTest method checkGrantsPersisted.

@Test
@Rollback
public void checkGrantsPersisted() throws Exception {
    OrcidProfile grantsProfileListing = getOrcidWithGrants();
    OrcidSolrDocument grantsListing = solrDocWithFundingTitles();
    orcidIndexManager.persistProfileInformationForIndexing(grantsProfileListing);
    verify(solrDao).persist(eq(grantsListing));
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 54 with Rollback

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

the class OrcidOauth2TokenDetailServiceTest method removeAllTokensWithSameScopesTest.

@Test
@Transactional
@Rollback
public void removeAllTokensWithSameScopesTest() {
    //We will test deleting this token
    //Delete
    Long token1Id = createToken(CLIENT_ID_1, "token-1", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/activities/update /read-limited", false).getId();
    //Should not delete this        
    Long token2Id = createToken(CLIENT_ID_1, "token-2", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/activities/update", false).getId();
    //Should not delete this
    Long token3Id = createToken(CLIENT_ID_1, "token-3", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/read-limited", false).getId();
    //Should delete this one since it have the same scopes but in different order
    //Delete
    Long token4Id = createToken(CLIENT_ID_1, "token-4", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/read-limited /activities/update", false).getId();
    //Should not delete this since it have one scope more /orcid-profile/read-limited
    Long token5Id = createToken(CLIENT_ID_1, "token-5", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/orcid-profile/read-limited /activities/update /read-limited", false).getId();
    //Should not delete this since it have one scope more /activities/read-limited
    Long token6Id = createToken(CLIENT_ID_1, "token-6", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/read-limited /activities/update /activities/read-limited", false).getId();
    //Should not delete this
    Long token7Id = createToken(CLIENT_ID_1, "token-7", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/person/read-limited", false).getId();
    //Should not delete this since it have several more scopes
    Long token8Id = createToken(CLIENT_ID_1, "token-8", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/funding/read-limited /read-limited /activities/read-limited /orcid-works/create /affiliations/update /activities/update", false).getId();
    //Should remove this since it contains the same scopes
    //Delete
    Long token9Id = createToken(CLIENT_ID_1, "token-9", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/activities/update /read-limited", false).getId();
    List<OrcidOauth2TokenDetail> activeTokens = orcidOauth2TokenDetailService.findByUserName(USER_ORCID);
    assertNotNull(activeTokens);
    assertEquals(9, activeTokens.size());
    orcidOauth2TokenDetailService.disableAccessToken(token1Id, USER_ORCID);
    activeTokens = orcidOauth2TokenDetailService.findByUserName(USER_ORCID);
    assertEquals(6, activeTokens.size());
    for (OrcidOauth2TokenDetail token : activeTokens) {
        assertThat(token.getId(), allOf(not(token1Id), not(token4Id), not(token9Id)));
        assertThat(token.getId(), anyOf(is(token2Id), is(token3Id), is(token5Id), is(token6Id), is(token7Id), is(token8Id)));
    }
}
Also used : Date(java.util.Date) 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)

Example 55 with Rollback

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

the class OrcidOauth2TokenDetailServiceTest method dontGetExpiredTokensTest.

@Test
@Transactional
@Rollback
public void dontGetExpiredTokensTest() {
    //Token # 1: expired
    createToken(CLIENT_ID_1, "expired-1", USER_ORCID, new Date(System.currentTimeMillis() - 1000), "/read-limited", false);
    //Token # 2: /activities/update
    createToken(CLIENT_ID_1, "active-1", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/activities/update", false);
    //Token # 3: disabled
    createToken(CLIENT_ID_1, "disabled-1", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/activities/update", true);
    //Token # 4: /read-limited
    createToken(CLIENT_ID_1, "active-2", USER_ORCID, new Date(System.currentTimeMillis() + 100000), "/read-limited", false);
    //Fetch all active tokens
    List<OrcidOauth2TokenDetail> activeTokens = orcidOauth2TokenDetailService.findByUserName(USER_ORCID);
    assertNotNull(activeTokens);
    assertEquals(2, activeTokens.size());
    assertThat(activeTokens.get(0).getScope(), anyOf(is("/activities/update"), is("/read-limited")));
    assertThat(activeTokens.get(1).getScope(), anyOf(is("/activities/update"), is("/read-limited")));
    //Find the id of the token with scope '/activities/update' and disable that token
    Long tokenToDisableId = null;
    for (OrcidOauth2TokenDetail token : activeTokens) {
        if ("/activities/update".equals(token.getScope())) {
            tokenToDisableId = token.getId();
            break;
        }
    }
    assertNotNull(tokenToDisableId);
    //Disable that access token
    orcidOauth2TokenDetailService.disableAccessToken(tokenToDisableId, USER_ORCID);
    //Fetch the active tokens again, it should contain just one
    activeTokens = orcidOauth2TokenDetailService.findByUserName(USER_ORCID);
    assertNotNull(activeTokens);
    assertEquals(1, activeTokens.size());
    assertEquals("/read-limited", activeTokens.get(0).getScope());
    assertEquals("active-2", activeTokens.get(0).getTokenValue());
}
Also used : Date(java.util.Date) 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