Fix failing HeaderAssertionTests

Since SPR-11792, Last-Modified and ETag headers are also written in
`HTTP 304 Not Modified` responses. This is expected as per
https://tools.ietf.org/html/rfc7232#section-4.1 .

Those tests expected "Last-Modified" to be missing in case of HTTP 304
responses, which is not the case anymore since 953608ec .

Issue: SPR-11792
master
Brian Clozel 10 years ago
parent 90ed0cf04c
commit 7f845f7b5e
  1. 10
      spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HeaderAssertionTests.java

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -84,14 +84,14 @@ public class HeaderAssertionTests {
public void stringWithMissingResponseHeader() throws Exception {
this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, currentTime))//
.andExpect(status().isNotModified())//
.andExpect(header().string(LAST_MODIFIED, (String) null));
.andExpect(header().string("X-Custom-Header", (String) null));
}
@Test
public void stringWithMatcherAndMissingResponseHeader() throws Exception {
this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, currentTime))//
.andExpect(status().isNotModified())//
.andExpect(header().string(LAST_MODIFIED, nullValue()));
.andExpect(header().string("X-Custom-Header", nullValue()));
}
@Test
@ -99,7 +99,7 @@ public class HeaderAssertionTests {
try {
this.mockMvc.perform(get("/persons/1").header(IF_MODIFIED_SINCE, currentTime))//
.andExpect(status().isNotModified())//
.andExpect(header().longValue(LAST_MODIFIED, 99L));
.andExpect(header().longValue("X-Custom-Header", 99L));
fail(EXPECTED_ASSERTION_ERROR_MSG);
}
@ -107,7 +107,7 @@ public class HeaderAssertionTests {
if (EXPECTED_ASSERTION_ERROR_MSG.equals(e.getMessage())) {
throw e;
}
assertEquals("Response does not contain header " + LAST_MODIFIED, e.getMessage());
assertEquals("Response does not contain header " + "X-Custom-Header", e.getMessage());
}
}

Loading…
Cancel
Save