Search in sources :

Example 6 with ApplicationSummary

use of org.orcid.pojo.ApplicationSummary in project ORCID-Source by ORCID.

the class ProfileEntityManagerImplTest method testDontGetDuplicatedApplications.

@SuppressWarnings("unused")
@Test
public void testDontGetDuplicatedApplications() {
    Long seed = System.currentTimeMillis();
    Date expiration = new Date(System.currentTimeMillis() + 10000);
    // Displayed
    OrcidOauth2TokenDetail token1 = createToken(CLIENT_ID_1, "token-1-" + seed, USER_ORCID, expiration, "/read-limited", false);
    // Displayed
    OrcidOauth2TokenDetail token2 = createToken(CLIENT_ID_1, "token-2-" + seed, USER_ORCID, expiration, "/orcid-profile/read-limited", false);
    // Displayed
    OrcidOauth2TokenDetail token3 = createToken(CLIENT_ID_1, "token-3-" + seed, USER_ORCID, expiration, "/activities/update", false);
    OrcidOauth2TokenDetail token4 = createToken(CLIENT_ID_1, "token-4-" + seed, USER_ORCID, expiration, "/read-limited", false);
    OrcidOauth2TokenDetail token5 = createToken(CLIENT_ID_1, "token-5-" + seed, USER_ORCID, expiration, "/orcid-profile/read-limited", false);
    OrcidOauth2TokenDetail token6 = createToken(CLIENT_ID_1, "token-6-" + seed, USER_ORCID, expiration, "/activities/update", false);
    OrcidOauth2TokenDetail token7 = createToken(CLIENT_ID_1, "token-7-" + seed, USER_ORCID, expiration, "/read-limited", false);
    OrcidOauth2TokenDetail token8 = createToken(CLIENT_ID_1, "token-8-" + seed, USER_ORCID, expiration, "/orcid-profile/read-limited", false);
    OrcidOauth2TokenDetail token9 = createToken(CLIENT_ID_1, "token-9-" + seed, USER_ORCID, expiration, "/activities/update", false);
    // Displayed
    OrcidOauth2TokenDetail token10 = createToken(CLIENT_ID_1, "token-10-" + seed, USER_ORCID, expiration, "/person/read-limited", false);
    OrcidOauth2TokenDetail token11 = createToken(CLIENT_ID_1, "token-11-" + seed, USER_ORCID, expiration, "/person/read-limited", false);
    List<ApplicationSummary> applications = profileEntityManager.getApplications(USER_ORCID);
    assertNotNull(applications);
    assertEquals(4, applications.size());
    boolean found1 = false, found2 = false, found3 = false, found10 = false;
    for (ApplicationSummary summary : applications) {
        assertNotNull(summary.getTokenId());
        if (summary.getTokenId().equals(String.valueOf(token1.getId()))) {
            found1 = true;
        } else if (summary.getTokenId().equals(String.valueOf(token2.getId()))) {
            found2 = true;
        } else if (summary.getTokenId().equals(String.valueOf(token3.getId()))) {
            found3 = true;
        } else if (summary.getTokenId().equals(String.valueOf(token10.getId()))) {
            found10 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found10);
    // Revoke them to check revoking one revokes all the ones with the same scopes
    profileEntityManager.disableApplication(token1.getId(), USER_ORCID);
    profileEntityManager.disableApplication(token2.getId(), USER_ORCID);
    applications = profileEntityManager.getApplications(USER_ORCID);
    assertNotNull(applications);
    assertEquals(2, applications.size());
    found1 = found2 = found3 = found10 = false;
    for (ApplicationSummary summary : applications) {
        assertNotNull(summary.getTokenId());
        if (summary.getTokenId().equals(String.valueOf(token1.getId()))) {
            found1 = true;
        } else if (summary.getTokenId().equals(String.valueOf(token2.getId()))) {
            found2 = true;
        } else if (summary.getTokenId().equals(String.valueOf(token3.getId()))) {
            found3 = true;
        } else if (summary.getTokenId().equals(String.valueOf(token10.getId()))) {
            found10 = true;
        }
    }
    assertFalse(found1);
    assertFalse(found2);
    assertTrue(found3);
    assertTrue(found10);
    // Revoke them all
    profileEntityManager.disableApplication(token3.getId(), USER_ORCID);
    profileEntityManager.disableApplication(token10.getId(), USER_ORCID);
    applications = profileEntityManager.getApplications(USER_ORCID);
    assertNotNull(applications);
    assertTrue(applications.isEmpty());
}
Also used : ApplicationSummary(org.orcid.pojo.ApplicationSummary) Date(java.util.Date) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

OrcidOauth2TokenDetail (org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)6 ApplicationSummary (org.orcid.pojo.ApplicationSummary)6 Date (java.util.Date)4 Test (org.junit.Test)4 DBUnitTest (org.orcid.test.DBUnitTest)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 Pair (org.apache.commons.lang3.tuple.Pair)2 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 NoSuchMessageException (org.springframework.context.NoSuchMessageException)2