diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/WebAppResourceTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/WebAppResourceTests.java index 86728218b1..3c3e13bec4 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/WebAppResourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/context/WebAppResourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 the original author or authors. + * Copyright 2002-2017 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. @@ -30,9 +30,12 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler; -import static org.hamcrest.Matchers.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.handler; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /** * Tests dependent on access to resources under the web application root directory. @@ -70,7 +73,7 @@ public class WebAppResourceTests { @Test public void resourceRequest() throws Exception { this.mockMvc.perform(get("/resources/Spring.js")) - .andExpect(content().contentType("text/javascript")) + .andExpect(content().contentType("application/javascript")) .andExpect(content().string(containsString("Spring={};"))); } diff --git a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java index 33b9dca29f..5041ed05cb 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.ServletWebRequest; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Test fixture for {@link ContentNegotiationManagerFactoryBean} tests. @@ -70,7 +70,7 @@ public class ContentNegotiationManagerFactoryBeanTests { assertEquals("Should be able to resolve file extensions by default", Collections.singletonList(MediaType.IMAGE_GIF), manager.resolveMediaTypes(this.webRequest)); - this.servletRequest.setRequestURI("/flower.xyz"); + this.servletRequest.setRequestURI("/flower.foobarbaz"); assertEquals("Should ignore unknown extensions by default", Collections.emptyList(), manager.resolveMediaTypes(this.webRequest)); @@ -107,20 +107,6 @@ public class ContentNegotiationManagerFactoryBeanTests { assertEquals(Collections.singletonList(MediaType.IMAGE_GIF), manager.resolveMediaTypes(this.webRequest)); } - @Test - public void favorPathWithJafTurnedOff() throws Exception { - this.factoryBean.setFavorPathExtension(true); - this.factoryBean.setUseJaf(false); - this.factoryBean.afterPropertiesSet(); - ContentNegotiationManager manager = this.factoryBean.getObject(); - - this.servletRequest.setRequestURI("/flower.foo"); - assertEquals(Collections.emptyList(), manager.resolveMediaTypes(this.webRequest)); - - this.servletRequest.setRequestURI("/flower.gif"); - assertEquals(Collections.emptyList(), manager.resolveMediaTypes(this.webRequest)); - } - @Test(expected = HttpMediaTypeNotAcceptableException.class) // SPR-10170 public void favorPathWithIgnoreUnknownPathExtensionTurnedOff() throws Exception { this.factoryBean.setFavorPathExtension(true); @@ -128,7 +114,7 @@ public class ContentNegotiationManagerFactoryBeanTests { this.factoryBean.afterPropertiesSet(); ContentNegotiationManager manager = this.factoryBean.getObject(); - this.servletRequest.setRequestURI("/flower.xyz"); + this.servletRequest.setRequestURI("/flower.foobarbaz"); this.servletRequest.addParameter("format", "json"); manager.resolveMediaTypes(this.webRequest); diff --git a/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java b/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java index bc1e9858f7..401aad90e9 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/PathExtensionContentNegotiationStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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. @@ -19,7 +19,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -import javax.servlet.ServletContext; import org.junit.Before; import org.junit.Test; @@ -30,7 +29,8 @@ import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.ServletWebRequest; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * A test fixture for PathExtensionContentNegotiationStrategy. @@ -70,7 +70,7 @@ public class PathExtensionContentNegotiationStrategyTests { } @Test - public void resolveMediaTypesFromJaf() throws Exception { + public void resolveMediaTypesFromMediaTypeFactory() throws Exception { this.servletRequest.setRequestURI("test.xls"); @@ -80,21 +80,6 @@ public class PathExtensionContentNegotiationStrategyTests { assertEquals(Arrays.asList(new MediaType("application", "vnd.ms-excel")), mediaTypes); } - // SPR-10334 - - @Test - public void getMediaTypeFromFilenameNoJaf() throws Exception { - - this.servletRequest.setRequestURI("test.json"); - - ServletContext servletCxt = this.servletRequest.getServletContext(); - PathExtensionContentNegotiationStrategy strategy = new ServletPathExtensionContentNegotiationStrategy(servletCxt); - strategy.setUseJaf(false); - List mediaTypes = strategy.resolveMediaTypes(this.webRequest); - - assertEquals(Collections.emptyList(), mediaTypes); - } - // SPR-8678 @Test @@ -128,7 +113,7 @@ public class PathExtensionContentNegotiationStrategyTests { @Test public void resolveMediaTypesIgnoreUnknownExtension() throws Exception { - this.servletRequest.setRequestURI("test.xyz"); + this.servletRequest.setRequestURI("test.foobar"); PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(); List mediaTypes = strategy.resolveMediaTypes(this.webRequest); @@ -139,7 +124,7 @@ public class PathExtensionContentNegotiationStrategyTests { @Test(expected = HttpMediaTypeNotAcceptableException.class) public void resolveMediaTypesDoNotIgnoreUnknownExtension() throws Exception { - this.servletRequest.setRequestURI("test.xyz"); + this.servletRequest.setRequestURI("test.foobar"); PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(); strategy.setIgnoreUnknownExtensions(false); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/accept/CompositeContentTypeResolverBuilderTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/accept/CompositeContentTypeResolverBuilderTests.java index c6ba6b2a5e..4441c1b43f 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/accept/CompositeContentTypeResolverBuilderTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/accept/CompositeContentTypeResolverBuilderTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ public class CompositeContentTypeResolverBuilderTests { assertEquals("Should be able to resolve file extensions by default", Collections.singletonList(MediaType.IMAGE_GIF), resolver.resolveMediaTypes(exchange)); - exchange = MockServerHttpRequest.get("/flower.xyz").toExchange(); + exchange = MockServerHttpRequest.get("/flower.foobar").toExchange(); assertEquals("Should ignore unknown extensions by default", Collections.emptyList(), resolver.resolveMediaTypes(exchange)); @@ -80,20 +80,6 @@ public class CompositeContentTypeResolverBuilderTests { assertEquals(Collections.singletonList(MediaType.IMAGE_GIF), resolver.resolveMediaTypes(exchange)); } - @Test - public void favorPathWithJafTurnedOff() throws Exception { - RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder() - .favorPathExtension(true) - .useJaf(false) - .build(); - - ServerWebExchange exchange = MockServerHttpRequest.get("/flower.foo").toExchange(); - assertEquals(Collections.emptyList(), resolver.resolveMediaTypes(exchange)); - - exchange = MockServerHttpRequest.get("/flower.gif").toExchange(); - assertEquals(Collections.emptyList(), resolver.resolveMediaTypes(exchange)); - } - @Test(expected = NotAcceptableStatusException.class) // SPR-10170 public void favorPathWithIgnoreUnknownPathExtensionTurnedOff() throws Exception { RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder() @@ -101,7 +87,7 @@ public class CompositeContentTypeResolverBuilderTests { .ignoreUnknownPathExtensions(false) .build(); - ServerWebExchange exchange = MockServerHttpRequest.get("/flower.xyz?format=json").toExchange(); + ServerWebExchange exchange = MockServerHttpRequest.get("/flower.foobar?format=json").toExchange(); resolver.resolveMediaTypes(exchange); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolverTests.java index 480b281edb..0148839354 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolverTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -59,18 +59,6 @@ public class PathExtensionContentTypeResolverTests { assertEquals(Collections.singletonList(new MediaType("application", "vnd.ms-excel")), mediaTypes); } - // SPR-10334 - - @Test - public void getMediaTypeFromFilenameNoJaf() throws Exception { - ServerWebExchange exchange = MockServerHttpRequest.get("test.json").toExchange(); - PathExtensionContentTypeResolver resolver = new PathExtensionContentTypeResolver(); - resolver.setUseJaf(false); - List mediaTypes = resolver.resolveMediaTypes(exchange); - - assertEquals(Collections.emptyList(), mediaTypes); - } - // SPR-9390 @Test @@ -86,7 +74,7 @@ public class PathExtensionContentTypeResolverTests { @Test public void resolveMediaTypesIgnoreUnknownExtension() throws Exception { - ServerWebExchange exchange = MockServerHttpRequest.get("test.xyz").toExchange(); + ServerWebExchange exchange = MockServerHttpRequest.get("test.foobar").toExchange(); PathExtensionContentTypeResolver resolver = new PathExtensionContentTypeResolver(); List mediaTypes = resolver.resolveMediaTypes(exchange); @@ -95,7 +83,7 @@ public class PathExtensionContentTypeResolverTests { @Test(expected = NotAcceptableStatusException.class) public void resolveMediaTypesDoNotIgnoreUnknownExtension() throws Exception { - ServerWebExchange exchange = MockServerHttpRequest.get("test.xyz").toExchange(); + ServerWebExchange exchange = MockServerHttpRequest.get("test.foobar").toExchange(); PathExtensionContentTypeResolver resolver = new PathExtensionContentTypeResolver(); resolver.setIgnoreUnknownExtensions(false); resolver.resolveMediaTypes(exchange); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java index d03d8a4b28..004f66b072 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java @@ -103,7 +103,7 @@ public class WebFluxConfigurationSupportTests { List list = Collections.singletonList(MediaType.APPLICATION_JSON); assertEquals(list, resolver.resolveMediaTypes(exchange)); - exchange = MockServerHttpRequest.get("/path.xml").toExchange(); + exchange = MockServerHttpRequest.get("/path.foobar").toExchange(); assertEquals(Collections.emptyList(), resolver.resolveMediaTypes(exchange)); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java index 5edfb4118f..0bee1cf939 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java @@ -52,7 +52,6 @@ import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.accept.CompositeContentTypeResolver; import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder; import org.springframework.web.server.MethodNotAllowedException; -import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ServerWebExchange; import static org.junit.Assert.assertEquals; @@ -209,7 +208,7 @@ public class ResourceWebHandlerTests { setPathWithinHandlerMapping(exchange, "js/foo.js"); this.handler.handle(exchange).block(TIMEOUT); - assertEquals(MediaType.parseMediaType("text/javascript"), exchange.getResponse().getHeaders().getContentType()); + assertEquals(MediaType.parseMediaType("application/javascript"), exchange.getResponse().getHeaders().getContentType()); assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }"); } @@ -219,7 +218,7 @@ public class ResourceWebHandlerTests { setPathWithinHandlerMapping(exchange, "js/baz.js"); this.handler.handle(exchange).block(TIMEOUT); - assertEquals(MediaType.parseMediaType("text/javascript"), exchange.getResponse().getHeaders().getContentType()); + assertEquals(MediaType.parseMediaType("application/javascript"), exchange.getResponse().getHeaders().getContentType()); assertResponseBody(exchange, "function foo() { console.log(\"hello world\"); }"); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java index 25d226b4d3..039aba439f 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageWriterResultHandlerTests.java @@ -95,7 +95,7 @@ public class MessageWriterResultHandlerTests { MethodParameter type = on(TestController.class).resolveReturnType(Resource.class); this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5)); - assertEquals("image/x-png", this.exchange.getResponse().getHeaders().getFirst("Content-Type")); + assertEquals("image/png", this.exchange.getResponse().getHeaders().getFirst("Content-Type")); } @Test // SPR-13631 diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java index f2c643cc9d..5aeb7b0766 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -181,7 +181,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq assertTrue(response.hasBody()); assertEquals(951, response.getHeaders().getContentLength()); assertEquals(951, response.getBody().length); - assertEquals(new MediaType("image", "x-png"), response.getHeaders().getContentType()); + assertEquals(new MediaType("image", "png"), response.getHeaders().getContentType()); } @Test