Fix failing test

Issue: SPR-7905
This commit is contained in:
Rossen Stoyanchev
2012-10-22 20:09:38 -04:00
parent c7e7e80a3a
commit 8270d82bda
7 changed files with 23 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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