Update tests to new mime types
This commit updates the test code base to conform to changes in media types returned by the MediaTypeFactory. Issue: SPR-14908
This commit is contained in:
parent
0aaa6528dc
commit
1329ccf1bc
|
|
@ -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={};")));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.<MediaType>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);
|
||||
|
|
|
|||
|
|
@ -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<MediaType> mediaTypes = strategy.resolveMediaTypes(this.webRequest);
|
||||
|
||||
assertEquals(Collections.<MediaType>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<MediaType> 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);
|
||||
|
|
|
|||
|
|
@ -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.<MediaType>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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||
|
||||
assertEquals(Collections.<MediaType>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<MediaType> 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);
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public class WebFluxConfigurationSupportTests {
|
|||
List<MediaType> 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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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\"); }");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue