From 8270d82bda85f227780f03e6cdcac9ae721118ad Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 22 Oct 2012 20:09:38 -0400 Subject: [PATCH] Fix failing test Issue: SPR-7905 --- .../web/client/match/ContentRequestMatchers.java | 6 +++--- .../client/match/ContentRequestMatchersTests.java | 8 ++++---- .../samples/matchers/ContentRequestMatcherTests.java | 4 ++-- .../samples/matchers/HeaderRequestMatcherTests.java | 2 +- .../matchers/JsonPathRequestMatcherTests.java | 10 +++++----- .../matchers/XmlContentRequestMatcherTests.java | 4 ++-- .../samples/matchers/XpathRequestMatcherTests.java | 12 ++++++------ 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java b/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java index b8e5134c1d5..220b006cef0 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java @@ -56,14 +56,14 @@ public class ContentRequestMatchers { /** * Assert the request content type as a String. */ - public RequestMatcher mimeType(String expectedContentType) { - return mimeType(MediaType.parseMediaType(expectedContentType)); + public RequestMatcher contentType(String expectedContentType) { + return contentType(MediaType.parseMediaType(expectedContentType)); } /** * Assert the request content type as a {@link MediaType}. */ - public RequestMatcher mimeType(final MediaType expectedContentType) { + public RequestMatcher contentType(final MediaType expectedContentType) { return new RequestMatcher() { public void match(ClientHttpRequest request) throws IOException, AssertionError { MediaType actualContentType = request.getHeaders().getContentType(); diff --git a/spring-test-mvc/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java b/spring-test-mvc/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java index 6e0e708a40d..a1631510762 100644 --- a/spring-test-mvc/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java +++ b/spring-test-mvc/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java @@ -42,22 +42,22 @@ public class ContentRequestMatchersTests { public void testContentType() throws Exception { this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON); - MockRestRequestMatchers.content().mimeType("application/json").match(this.request); - MockRestRequestMatchers.content().mimeType(MediaType.APPLICATION_JSON).match(this.request); + MockRestRequestMatchers.content().contentType("application/json").match(this.request); + MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_JSON).match(this.request); } @Test(expected=AssertionError.class) public void testContentTypeNoMatch1() throws Exception { this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON); - MockRestRequestMatchers.content().mimeType("application/xml").match(this.request); + MockRestRequestMatchers.content().contentType("application/xml").match(this.request); } @Test(expected=AssertionError.class) public void testContentTypeNoMatch2() throws Exception { this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON); - MockRestRequestMatchers.content().mimeType(MediaType.APPLICATION_ATOM_XML).match(this.request); + MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_ATOM_XML).match(this.request); } @Test diff --git a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatcherTests.java b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatcherTests.java index 4e2a8e861cb..7155be9b0cf 100644 --- a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatcherTests.java +++ b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatcherTests.java @@ -62,14 +62,14 @@ public class ContentRequestMatcherTests { @Test public void contentType() throws Exception { - this.mockServer.expect(content().mimeType("application/json;charset=UTF-8")).andRespond(withSuccess()); + this.mockServer.expect(content().contentType("application/json;charset=UTF-8")).andRespond(withSuccess()); this.restTemplate.put(new URI("/foo"), new Person()); this.mockServer.verify(); } @Test public void contentTypeNoMatch() throws Exception { - this.mockServer.expect(content().mimeType("application/json;charset=UTF-8")).andRespond(withSuccess()); + this.mockServer.expect(content().contentType("application/json;charset=UTF-8")).andRespond(withSuccess()); try { this.restTemplate.put(new URI("/foo"), "foo"); } diff --git a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatcherTests.java b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatcherTests.java index bf8d9a06ef6..339d59918bf 100644 --- a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatcherTests.java +++ b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatcherTests.java @@ -63,7 +63,7 @@ public class HeaderRequestMatcherTests { public void testString() throws Exception { this.mockServer.expect(requestTo("/person/1")) - .andExpect(header("Accept", "application/json")) + .andExpect(header("Accept", "application/json, application/*+json")) .andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON)); this.restTemplate.getForObject(new URI("/person/1"), Person.class); diff --git a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatcherTests.java b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatcherTests.java index 0c97ca2ca46..1b4a7b9da97 100644 --- a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatcherTests.java +++ b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatcherTests.java @@ -77,7 +77,7 @@ public class JsonPathRequestMatcherTests { @Test public void testExists() throws Exception { this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/json;charset=UTF-8")) + .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0]").exists()) .andExpect(jsonPath("$.composers[1]").exists()) .andExpect(jsonPath("$.composers[2]").exists()) @@ -91,7 +91,7 @@ public class JsonPathRequestMatcherTests { @Test public void testDoesNotExist() throws Exception { this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/json;charset=UTF-8")) + .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[?(@.name = 'Edvard Grieeeeeeg')]").doesNotExist()) .andExpect(jsonPath("$.composers[?(@.name = 'Robert Schuuuuuuman')]").doesNotExist()) .andExpect(jsonPath("$.composers[-1]").doesNotExist()) @@ -105,7 +105,7 @@ public class JsonPathRequestMatcherTests { @Test public void testEqualTo() throws Exception { this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/json;charset=UTF-8")) + .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].name").value("Johann Sebastian Bach")) .andExpect(jsonPath("$.performers[1].name").value("Yehudi Menuhin")) .andExpect(jsonPath("$.composers[0].name").value(equalTo("Johann Sebastian Bach"))) // Hamcrest @@ -119,7 +119,7 @@ public class JsonPathRequestMatcherTests { @Test public void testHamcrestMatcher() throws Exception { this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/json;charset=UTF-8")) + .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].name", startsWith("Johann"))) .andExpect(jsonPath("$.performers[0].name", endsWith("Ashkenazy"))) .andExpect(jsonPath("$.performers[1].name", containsString("di Me"))) @@ -136,7 +136,7 @@ public class JsonPathRequestMatcherTests { String performerName = "$.performers[%s].name"; this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/json;charset=UTF-8")) + .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath(composerName, 0).value(startsWith("Johann"))) .andExpect(jsonPath(performerName, 0).value(endsWith("Ashkenazy"))) .andExpect(jsonPath(performerName, 1).value(containsString("di Me"))) diff --git a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatcherTests.java b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatcherTests.java index 059e3be3108..948310f750c 100644 --- a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatcherTests.java +++ b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatcherTests.java @@ -89,7 +89,7 @@ public class XmlContentRequestMatcherTests { @Test public void testXmlEqualTo() throws Exception { this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/xml")) + .andExpect(content().contentType("application/xml")) .andExpect(content().xml(PEOPLE_XML)) .andRespond(withSuccess()); @@ -101,7 +101,7 @@ public class XmlContentRequestMatcherTests { public void testHamcrestNodeMatcher() throws Exception { this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/xml")) + .andExpect(content().contentType("application/xml")) .andExpect(content().node(hasXPath("/people/composers/composer[1]"))) .andRespond(withSuccess()); diff --git a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatcherTests.java b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatcherTests.java index 3e9243114f6..b26f3cd29d9 100644 --- a/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatcherTests.java +++ b/spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatcherTests.java @@ -97,7 +97,7 @@ public class XpathRequestMatcherTests { String performer = "/ns:people/performers/performer[%s]"; this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/xml")) + .andExpect(content().contentType("application/xml")) .andExpect(xpath(composer, NS, 1).exists()) .andExpect(xpath(composer, NS, 2).exists()) .andExpect(xpath(composer, NS, 3).exists()) @@ -117,7 +117,7 @@ public class XpathRequestMatcherTests { String performer = "/ns:people/performers/performer[%s]"; this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/xml")) + .andExpect(content().contentType("application/xml")) .andExpect(xpath(composer, NS, 0).doesNotExist()) .andExpect(xpath(composer, NS, 5).doesNotExist()) .andExpect(xpath(performer, NS, 0).doesNotExist()) @@ -135,7 +135,7 @@ public class XpathRequestMatcherTests { String performerName = "/ns:people/performers/performer[%s]/name"; this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/xml")) + .andExpect(content().contentType("application/xml")) .andExpect(xpath(composerName, NS, 1).string("Johann Sebastian Bach")) .andExpect(xpath(composerName, NS, 2).string("Johannes Brahms")) .andExpect(xpath(composerName, NS, 3).string("Edvard Grieg")) @@ -157,7 +157,7 @@ public class XpathRequestMatcherTests { String composerDouble = "/ns:people/composers/composer[%s]/someDouble"; this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/xml")) + .andExpect(content().contentType("application/xml")) .andExpect(xpath(composerDouble, NS, 1).number(21d)) .andExpect(xpath(composerDouble, NS, 2).number(.0025)) .andExpect(xpath(composerDouble, NS, 3).number(1.6035)) @@ -176,7 +176,7 @@ public class XpathRequestMatcherTests { String performerBooleanValue = "/ns:people/performers/performer[%s]/someBoolean"; this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/xml")) + .andExpect(content().contentType("application/xml")) .andExpect(xpath(performerBooleanValue, NS, 1).booleanValue(false)) .andExpect(xpath(performerBooleanValue, NS, 2).booleanValue(true)) .andRespond(withSuccess()); @@ -189,7 +189,7 @@ public class XpathRequestMatcherTests { public void testNodeCount() throws Exception { this.mockServer.expect(requestTo("/composers")) - .andExpect(content().mimeType("application/xml")) + .andExpect(content().contentType("application/xml")) .andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(4)) .andExpect(xpath("/ns:people/performers/performer", NS).nodeCount(2)) .andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(lessThan(5))) // Hamcrest..