|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -16,8 +16,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.web.context.request; |
|
|
|
package org.springframework.web.context.request; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
@ -34,6 +32,8 @@ import org.junit.runners.Parameterized.Parameters; |
|
|
|
import org.springframework.mock.web.test.MockHttpServletRequest; |
|
|
|
import org.springframework.mock.web.test.MockHttpServletRequest; |
|
|
|
import org.springframework.mock.web.test.MockHttpServletResponse; |
|
|
|
import org.springframework.mock.web.test.MockHttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Parameterized tests for ServletWebRequest |
|
|
|
* Parameterized tests for ServletWebRequest |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
@ -66,8 +66,9 @@ public class ServletWebRequestHttpMethodsTests { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
public void setUp() { |
|
|
|
public void setup() { |
|
|
|
currentDate = new Date(); |
|
|
|
currentDate = new Date(); |
|
|
|
dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); |
|
|
|
dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); |
|
|
|
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); |
|
|
|
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); |
|
|
|
@ -76,6 +77,7 @@ public class ServletWebRequestHttpMethodsTests { |
|
|
|
request = new ServletWebRequest(servletRequest, servletResponse); |
|
|
|
request = new ServletWebRequest(servletRequest, servletResponse); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkNotModifiedNon2xxStatus() { |
|
|
|
public void checkNotModifiedNon2xxStatus() { |
|
|
|
long epochTime = currentDate.getTime(); |
|
|
|
long epochTime = currentDate.getTime(); |
|
|
|
@ -87,8 +89,7 @@ public class ServletWebRequestHttpMethodsTests { |
|
|
|
assertNull(servletResponse.getHeader("Last-Modified")); |
|
|
|
assertNull(servletResponse.getHeader("Last-Modified")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SPR-13516
|
|
|
|
@Test // SPR-13516
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void checkNotModifiedInvalidStatus() { |
|
|
|
public void checkNotModifiedInvalidStatus() { |
|
|
|
long epochTime = currentDate.getTime(); |
|
|
|
long epochTime = currentDate.getTime(); |
|
|
|
servletRequest.addHeader("If-Modified-Since", epochTime); |
|
|
|
servletRequest.addHeader("If-Modified-Since", epochTime); |
|
|
|
@ -97,7 +98,7 @@ public class ServletWebRequestHttpMethodsTests { |
|
|
|
assertFalse(request.checkNotModified(epochTime)); |
|
|
|
assertFalse(request.checkNotModified(epochTime)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-14559
|
|
|
|
@Test // SPR-14559
|
|
|
|
public void checkNotModifiedInvalidIfNoneMatchHeader() { |
|
|
|
public void checkNotModifiedInvalidIfNoneMatchHeader() { |
|
|
|
String eTag = "\"etagvalue\""; |
|
|
|
String eTag = "\"etagvalue\""; |
|
|
|
servletRequest.addHeader("If-None-Match", "missingquotes"); |
|
|
|
servletRequest.addHeader("If-None-Match", "missingquotes"); |
|
|
|
@ -223,8 +224,7 @@ public class ServletWebRequestHttpMethodsTests { |
|
|
|
assertEquals(dateFormat.format(currentDate.getTime()), servletResponse.getHeader("Last-Modified")); |
|
|
|
assertEquals(dateFormat.format(currentDate.getTime()), servletResponse.getHeader("Last-Modified")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// SPR-14224
|
|
|
|
@Test // SPR-14224
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void checkNotModifiedETagAndModifiedTimestamp() { |
|
|
|
public void checkNotModifiedETagAndModifiedTimestamp() { |
|
|
|
String eTag = "\"Foo\""; |
|
|
|
String eTag = "\"Foo\""; |
|
|
|
servletRequest.addHeader("If-None-Match", eTag); |
|
|
|
servletRequest.addHeader("If-None-Match", eTag); |
|
|
|
|