CONNECTTimestamp extends Timestamp { public boolean verifyCreated(int timeToLive, int futureTimeToLive, Date invocationDate) { Date currentInvocationDate = invocationDate == null ? new Date() : invocationDate; long invocationTime = currentInvocationDate.getTime(); if (futureTimeToLive > 0) { currentInvocationDate.setTime(invocationTime + futureTimeToLive * 1000); } if (!verifyCreatedAfter(currentInvocationDate)) { return false; } invocationTime -= timeToLive * 1000; currentInvocationDate.setTime(invocationTime); if (!verifyCreatedBefore(currentInvocationDate)) { return false; } LOG.info("Validation of Timestamp: Everything is ok"); return true; } CONNECTTimestamp(Element timestampElement);  CONNECTTimestamp(Timestamp timestamp); boolean isExpired(Date invocationDate); boolean verifyCreated(int timeToLive, int futureTimeToLive, Date invocationDate);  }
@Test public void testVerifyCreated_Pass() throws ParseException, WSSecurityException { Date invocationDate = dateFormat.parse(INVOCATION_HAPPY_PATH); CONNECTTimestamp connectTimestamp = new CONNECTTimestamp(TIMESTAMP_ELEMENT); assertTrue(connectTimestamp.verifyCreated(2, 2, invocationDate)); }
@Test public void testVerifyCreated_Fail_CreatedTimeInFuture() throws ParseException, WSSecurityException { Date invocationDate = dateFormat.parse(INVOCATION_FUTURE_ERROR_TIME); CONNECTTimestamp connectTimestamp = new CONNECTTimestamp(TIMESTAMP_ELEMENT); assertFalse(connectTimestamp.verifyCreated(2, 2, invocationDate)); }
@Test public void testVerifyCreated_Fail_CreatedTimeInPast() throws ParseException, WSSecurityException { Date invocationDate = dateFormat.parse(INVOCATION_OLD_ERROR_TIME); CONNECTTimestamp connectTimestamp = new CONNECTTimestamp(TIMESTAMP_ELEMENT); assertFalse(connectTimestamp.verifyCreated(0, 2, invocationDate)); }