ExpiryCheckHandler { public static Integer getExpireAfter(MultiMap headers) { try { Integer ans = getExpireValue(headers.get(EXPIRE_AFTER_HEADER)); return (ans != null && ans == -1) ? null : ans; } catch (NumberFormatException e) { return null; } } private  ExpiryCheckHandler(); static void updateServerTimestampHeader(HttpRequest request); static void updateServerTimestampHeader(MultiMap headers); static Integer getExpireAfter(MultiMap headers); static Optional<Integer> getExpireAfterConcerningCaseOfCorruptHeaderAndInfinite(MultiMap headers); static Integer getQueueExpireAfter(MultiMap headers); static boolean isExpired(MultiMap headers, Long timestamp); static DateTime getExpirationTime(int expireAfter); static Optional<String> getExpirationTimeAsString(int expireAfter); static DateTime parseDateTime(String datetime); static String printDateTime(DateTime datetime); static void setExpireAfter(HttpServerRequest request, int expireAfter); static void setQueueExpireAfter(MultiMap headers, int queueExpireAfter); static final String SERVER_TIMESTAMP_HEADER; static final String EXPIRE_AFTER_HEADER; static final String QUEUE_EXPIRE_AFTER_HEADER; }
@Test public void getExpireAfter_returnsValueSpecifiedInHeader(TestContext testContext) { final String headerValue = "123456789"; final MultiMap headers = createHeaderReturningSimpleValue(HTTP_HEADER_X_EXPIRE_AFTER, headerValue); final Integer returnedExpireValue = ExpiryCheckHandler.getExpireAfter(headers); testContext.assertEquals(headerValue, "" + returnedExpireValue); }
@Test public void getExpireAfter_returnsZeroIfHeaderSpecifiesZero(TestContext testContext) { final String headerValue = "0"; final MultiMap headers = createHeaderReturningSimpleValue(HTTP_HEADER_X_EXPIRE_AFTER, headerValue); final Integer returnedExpireValue = ExpiryCheckHandler.getExpireAfter(headers); testContext.assertEquals(headerValue, "" + returnedExpireValue); }
@Test public void getExpireAfter_returnsNullIfHeaderNotPresent(TestContext testContext) { final String headerValue = null; final MultiMap headers = createHeaderReturningSimpleValue(HTTP_HEADER_X_EXPIRE_AFTER, headerValue); final Integer returnedExpireValue = ExpiryCheckHandler.getExpireAfter(headers); testContext.assertNull(returnedExpireValue); }
@Test public void getExpireAfter_returnsNullWhenHeaderIsMinusOne(TestContext testContext) { final String headerValue = "-1"; final MultiMap headers = createHeaderReturningSimpleValue(HTTP_HEADER_X_EXPIRE_AFTER, headerValue); final Integer returnedExpireValue = ExpiryCheckHandler.getExpireAfter(headers); testContext.assertNull(returnedExpireValue); }
@Test public void getExpireAfter_returnsNullIfHeaderValueBelowMinusOne(TestContext testContext) { final String headerValue = "-2147483640"; final MultiMap headers = createHeaderReturningSimpleValue(HTTP_HEADER_X_EXPIRE_AFTER, headerValue); final Integer returnedValue = ExpiryCheckHandler.getExpireAfter(headers); testContext.assertNull(returnedValue); }
@Test public void getExpireAfter_returnsNullIfHeaderValueIsNaN(TestContext testContext) { final String headerValue = "Definitively not a number :)"; final MultiMap headers = createHeaderReturningSimpleValue(HTTP_HEADER_X_EXPIRE_AFTER, headerValue); final Integer returnedValue = ExpiryCheckHandler.getExpireAfter(headers); testContext.assertNull(returnedValue); }