@Test public void RecordLastModifiedTest() { Date now = new Date(); Calendar c = Calendar.getInstance(); c.setTime(now); c.add(Calendar.MINUTE, -5); Date _5MinutesAgo = c.getTime(); c.setTime(now); c.add(Calendar.MINUTE, 15); Date _15MinutesAhead = c.getTime(); String token = "Token_" + System.currentTimeMillis(); // Create token internalSSODao.insert(ORCID, token); assertNotNull(internalSSODao.getRecordLastModified(ORCID, token, _5MinutesAgo)); assertNull(internalSSODao.getRecordLastModified(ORCID, token, _15MinutesAhead)); }
@Test public void internalSSODaoTest() { String token = "Token_" + System.currentTimeMillis(); Date now = new Date(); Calendar c = Calendar.getInstance(); c.setTime(now); c.add(Calendar.MINUTE, -5); Date _5MinutesAgo = c.getTime(); c.setTime(now); c.add(Calendar.MINUTE, 15); Date _15MinutesAhead = c.getTime(); // Create token InternalSSOEntity entity = internalSSODao.insert(ORCID, token); assertNotNull(entity); // Check the token is not expired yet assertTrue(internalSSODao.verify(ORCID, token, _5MinutesAgo)); // Update it assertTrue(internalSSODao.update(ORCID, token)); // Assert that it is expired assertFalse(internalSSODao.verify(ORCID, token, _15MinutesAhead)); // Create an invalid token String updatedToken = token + "!"; // Cannot update invalid token assertFalse(internalSSODao.update(ORCID, updatedToken)); // Cannot verify invalid token assertFalse(internalSSODao.verify(ORCID, updatedToken, _5MinutesAgo)); }
@Before public void before() { internalSSODao.delete(ORCID); }