Search in sources :

Example 1 with ApprovalStatus

use of org.cloudfoundry.identity.uaa.approval.Approval.ApprovalStatus in project uaa by cloudfoundry.

the class JdbcApprovalStoreTests method addAndGetApproval.

@Test
void addAndGetApproval() {
    String userId = "user";
    String clientId = "client";
    String scope = "uaa.user";
    long expiresIn = 1000L;
    Date lastUpdatedAt = new Date();
    ApprovalStatus status = APPROVED;
    testAccounts.addUser(jdbcTemplate, userId, IdentityZoneHolder.get().getId());
    Date expiresAt = new Timestamp(new Date().getTime() + expiresIn);
    Approval newApproval = new Approval().setUserId(userId).setClientId(clientId).setScope(scope).setExpiresAt(expiresAt).setStatus(status).setLastUpdatedAt(lastUpdatedAt);
    jdbcApprovalStore.addApproval(newApproval, defaultZoneId);
    List<Approval> approvals = jdbcApprovalStore.getApprovals(userId, clientId, defaultZoneId);
    assertEquals(clientId, approvals.get(0).getClientId());
    assertEquals(userId, approvals.get(0).getUserId());
    // time comparison - we're satisfied if it is within 2 seconds
    assertThat((int) Math.abs(expiresAt.getTime() / 1000d - approvals.get(0).getExpiresAt().getTime() / 1000d), lessThan(2));
    assertThat((int) Math.abs(lastUpdatedAt.getTime() / 1000d - approvals.get(0).getLastUpdatedAt().getTime() / 1000d), lessThan(2));
    assertEquals(scope, approvals.get(0).getScope());
    assertEquals(status, approvals.get(0).getStatus());
}
Also used : Approval(org.cloudfoundry.identity.uaa.approval.Approval) Timestamp(java.sql.Timestamp) Date(java.util.Date) ApprovalStatus(org.cloudfoundry.identity.uaa.approval.Approval.ApprovalStatus) Test(org.junit.jupiter.api.Test)

Aggregations

Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 Approval (org.cloudfoundry.identity.uaa.approval.Approval)1 ApprovalStatus (org.cloudfoundry.identity.uaa.approval.Approval.ApprovalStatus)1 Test (org.junit.jupiter.api.Test)1