Relax XML content type expectations in tests

Requests in XmlContentAssertionTests and XpathAssertionTests now accept
"application/xml;charset=UTF-8" in addition to "application/xml".
This commit is contained in:
Sam Brannen 2014-08-15 20:56:38 +02:00
parent 85e52e59e3
commit e1d7f08d7b
2 changed files with 8 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@ -44,7 +44,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
* Examples of defining expectations on XML response content with XMLUnit.
*
* @author Rossen Stoyanchev
*
* @author Sam Brannen
* @see ContentAssertionTests
* @see XpathAssertionTests
*/
@ -65,9 +65,9 @@ public class XmlContentAssertionTests {
@Before
public void setup() {
this.mockMvc = standaloneSetup(new MusicController())
.defaultRequest(get("/").accept(MediaType.APPLICATION_XML))
.defaultRequest(get("/").accept(MediaType.APPLICATION_XML, MediaType.parseMediaType("application/xml;charset=UTF-8")))
.alwaysExpect(status().isOk())
.alwaysExpect(content().contentType(MediaType.APPLICATION_XML))
.alwaysExpect(content().contentType(MediaType.parseMediaType("application/xml;charset=UTF-8")))
.build();
}
@ -78,7 +78,6 @@ public class XmlContentAssertionTests {
@Test
public void testNodeHamcrestMatcher() throws Exception {
this.mockMvc.perform(get("/music/people"))
.andExpect(content().node(hasXPath("/people/composers/composer[1]")));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@ -46,7 +46,7 @@ import static org.springframework.web.bind.annotation.RequestMethod.*;
* Examples of expectations on XML response content with XPath expressions.
*
* @author Rossen Stoyanchev
*
* @author Sam Brannen
* @see ContentAssertionTests
* @see XmlContentAssertionTests
*/
@ -60,9 +60,9 @@ public class XpathAssertionTests {
@Before
public void setup() throws Exception {
this.mockMvc = standaloneSetup(new MusicController())
.defaultRequest(get("/").accept(MediaType.APPLICATION_XML))
.defaultRequest(get("/").accept(MediaType.APPLICATION_XML, MediaType.parseMediaType("application/xml;charset=UTF-8")))
.alwaysExpect(status().isOk())
.alwaysExpect(content().contentType(MediaType.APPLICATION_XML))
.alwaysExpect(content().contentType(MediaType.parseMediaType("application/xml;charset=UTF-8")))
.build();
}