ContentNegotiatingViewResolver properly handles invalid accept headers (SPR-7712)

This commit is contained in:
Juergen Hoeller
2011-08-02 19:13:56 +00:00
parent 3fb753bc0c
commit 0a48936f4f
2 changed files with 93 additions and 91 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -16,15 +16,6 @@
package org.springframework.web.servlet.view;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -37,6 +28,7 @@ import java.util.Set;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -48,6 +40,9 @@ import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
*/
@@ -191,6 +186,14 @@ public class ContentNegotiatingViewResolverTests {
verify(viewResolverMock, viewMock);
}
@Test
public void resolveViewNameWithInvalidAcceptHeader() throws Exception {
request.addHeader("Accept", "application");
View result = viewResolver.resolveViewName("test", Locale.ENGLISH);
assertNull(result);
}
@Test
public void resolveViewNameWithRequestParameter() throws Exception {
request.addParameter("format", "xls");