|
|
|
@ -16,6 +16,9 @@ |
|
|
|
|
|
|
|
|
|
package org.springframework.web.reactive.result.method.annotation; |
|
|
|
|
|
|
|
|
|
import java.net.URI; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
@ -23,7 +26,10 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext |
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
import org.springframework.context.annotation.ComponentScan; |
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
import org.springframework.http.RequestEntity; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
|
import org.springframework.ui.Model; |
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
@ -31,8 +37,11 @@ import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
import org.springframework.web.reactive.config.ViewResolverRegistry; |
|
|
|
|
import org.springframework.web.reactive.config.WebReactiveConfiguration; |
|
|
|
|
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer; |
|
|
|
|
import org.springframework.web.server.ServerWebExchange; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
import static org.junit.Assert.assertNull; |
|
|
|
|
import static org.springframework.http.RequestEntity.get; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -58,6 +67,16 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques |
|
|
|
|
assertEquals(expected, performGet("/html?name=Jason", MediaType.TEXT_HTML, String.class).getBody()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void etagCheckWithNotModifiedResponse() throws Exception { |
|
|
|
|
URI uri = new URI("http://localhost:" + this.port + "/html"); |
|
|
|
|
RequestEntity<Void> request = get(uri).ifNoneMatch("\"deadb33f8badf00d\"").build(); |
|
|
|
|
ResponseEntity<String> response = getRestTemplate().exchange(request, String.class); |
|
|
|
|
|
|
|
|
|
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode()); |
|
|
|
|
assertNull(response.getBody()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
@ComponentScan(resourcePattern = "**/RequestMappingViewResolutionIntegrationTests$*.class") |
|
|
|
@ -84,10 +103,16 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques |
|
|
|
|
private static class TestController { |
|
|
|
|
|
|
|
|
|
@GetMapping("/html") |
|
|
|
|
public String getHtmlPage(@RequestParam String name, Model model) { |
|
|
|
|
model.addAttribute("hello", "Hello: " + name + "!"); |
|
|
|
|
public String getHtmlPage(@RequestParam Optional<String> name, Model model, |
|
|
|
|
ServerWebExchange exchange) { |
|
|
|
|
|
|
|
|
|
if (exchange.checkNotModified("deadb33f8badf00d")) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
model.addAttribute("hello", "Hello: " + name.orElse("<no name>") + "!"); |
|
|
|
|
return "test"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|