From 24cb345b6c838f7571d084eb7a051781776fa912 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Jul 2011 23:02:08 +0000 Subject: [PATCH] backported HttpHeadersTests update --- .../http/HttpHeadersTests.java | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/org.springframework.web/src/test/java/org/springframework/http/HttpHeadersTests.java b/org.springframework.web/src/test/java/org/springframework/http/HttpHeadersTests.java index 6fe9ed0d9dc..1b82eeb8d6a 100644 --- a/org.springframework.web/src/test/java/org/springframework/http/HttpHeadersTests.java +++ b/org.springframework.web/src/test/java/org/springframework/http/HttpHeadersTests.java @@ -1,11 +1,11 @@ /* - * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.EnumSet; import java.util.GregorianCalendar; @@ -27,10 +28,11 @@ import java.util.List; import java.util.Locale; import java.util.TimeZone; -import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.*; + /** @author Arjen Poutsma */ public class HttpHeadersTests { @@ -65,6 +67,13 @@ public class HttpHeadersTests { assertEquals("Invalid Accept header", "utf-8, iso-8859-1", headers.getFirst("Accept-Charset")); } + @Test + public void acceptCharsetWildcard() { + headers.set("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); + assertEquals("Invalid Accept header", Arrays.asList(Charset.forName("ISO-8859-1"), Charset.forName("UTF-8")), + headers.getAcceptCharset()); + } + @Test public void allow() { EnumSet methods = EnumSet.of(HttpMethod.GET, HttpMethod.POST); @@ -99,6 +108,14 @@ public class HttpHeadersTests { @Test public void eTag() { + String eTag = "\"v2.6\""; + headers.setETag(eTag); + assertEquals("Invalid ETag header", eTag, headers.getETag()); + assertEquals("Invalid ETag header", "\"v2.6\"", headers.getFirst("ETag")); + } + + @Test(expected = IllegalArgumentException.class) + public void illegalETag() { String eTag = "v2.6"; headers.setETag(eTag); assertEquals("Invalid ETag header", eTag, headers.getETag()); @@ -107,7 +124,7 @@ public class HttpHeadersTests { @Test public void ifNoneMatch() { - String ifNoneMatch = "v2.6"; + String ifNoneMatch = "\"v2.6\""; headers.setIfNoneMatch(ifNoneMatch); assertEquals("Invalid If-None-Match header", ifNoneMatch, headers.getIfNoneMatch().get(0)); assertEquals("Invalid If-None-Match header", "\"v2.6\"", headers.getFirst("If-None-Match")); @@ -115,8 +132,8 @@ public class HttpHeadersTests { @Test public void ifNoneMatchList() { - String ifNoneMatch1 = "v2.6"; - String ifNoneMatch2 = "v2.7"; + String ifNoneMatch1 = "\"v2.6\""; + String ifNoneMatch2 = "\"v2.7\""; List ifNoneMatchList = new ArrayList(2); ifNoneMatchList.add(ifNoneMatch1); ifNoneMatchList.add(ifNoneMatch2); @@ -213,11 +230,12 @@ public class HttpHeadersTests { @Test public void contentDisposition() { headers.setContentDispositionFormData("name", null); - assertEquals("Invalid Content-Disposition header", "form-data; name=\"name\"", headers.getFirst("Content-Disposition")); - + assertEquals("Invalid Content-Disposition header", "form-data; name=\"name\"", + headers.getFirst("Content-Disposition")); headers.setContentDispositionFormData("name", "filename"); - assertEquals("Invalid Content-Disposition header", "form-data; name=\"name\"; filename=\"filename\"", headers.getFirst("Content-Disposition")); + assertEquals("Invalid Content-Disposition header", "form-data; name=\"name\"; filename=\"filename\"", + headers.getFirst("Content-Disposition")); }