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:
Rossen Stoyanchev
2017-03-21 09:39:16 -04:00
parent 0aaa6528dc
commit 1329ccf1bc
9 changed files with 30 additions and 83 deletions

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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));
}

View File

@@ -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\"); }");
}

View File

@@ -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

View File

@@ -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