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