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());
}
Aggregations