Browse Source

Fix failing test

Issue: SPR-7905
pull/172/head
Rossen Stoyanchev 13 years ago
parent
commit
8270d82bda
  1. 6
      spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java
  2. 8
      spring-test-mvc/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java
  3. 4
      spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatcherTests.java
  4. 2
      spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatcherTests.java
  5. 10
      spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatcherTests.java
  6. 4
      spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatcherTests.java
  7. 12
      spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatcherTests.java

6
spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java

@ -56,14 +56,14 @@ public class ContentRequestMatchers { @@ -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();

8
spring-test-mvc/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java

@ -42,22 +42,22 @@ public class ContentRequestMatchersTests { @@ -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

4
spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatcherTests.java

@ -62,14 +62,14 @@ public class ContentRequestMatcherTests { @@ -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");
}

2
spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatcherTests.java

@ -63,7 +63,7 @@ public class HeaderRequestMatcherTests { @@ -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);

10
spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatcherTests.java

@ -77,7 +77,7 @@ public class JsonPathRequestMatcherTests { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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")))

4
spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatcherTests.java

@ -89,7 +89,7 @@ public class XmlContentRequestMatcherTests { @@ -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 { @@ -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());

12
spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatcherTests.java

@ -97,7 +97,7 @@ public class XpathRequestMatcherTests { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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..

Loading…
Cancel
Save