Skip to content

Commit e1d7f08

Browse files
committed
Relax XML content type expectations in tests
Requests in XmlContentAssertionTests and XpathAssertionTests now accept "application/xml;charset=UTF-8" in addition to "application/xml".
1 parent 85e52e5 commit e1d7f08

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XmlContentAssertionTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@
4444
* Examples of defining expectations on XML response content with XMLUnit.
4545
*
4646
* @author Rossen Stoyanchev
47-
*
47+
* @author Sam Brannen
4848
* @see ContentAssertionTests
4949
* @see XpathAssertionTests
5050
*/
@@ -65,9 +65,9 @@ public class XmlContentAssertionTests {
6565
@Before
6666
public void setup() {
6767
this.mockMvc = standaloneSetup(new MusicController())
68-
.defaultRequest(get("/").accept(MediaType.APPLICATION_XML))
68+
.defaultRequest(get("/").accept(MediaType.APPLICATION_XML, MediaType.parseMediaType("application/xml;charset=UTF-8")))
6969
.alwaysExpect(status().isOk())
70-
.alwaysExpect(content().contentType(MediaType.APPLICATION_XML))
70+
.alwaysExpect(content().contentType(MediaType.parseMediaType("application/xml;charset=UTF-8")))
7171
.build();
7272
}
7373

@@ -78,7 +78,6 @@ public void testXmlEqualTo() throws Exception {
7878

7979
@Test
8080
public void testNodeHamcrestMatcher() throws Exception {
81-
8281
this.mockMvc.perform(get("/music/people"))
8382
.andExpect(content().node(hasXPath("/people/composers/composer[1]")));
8483
}

spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XpathAssertionTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@
4646
* Examples of expectations on XML response content with XPath expressions.
4747
*
4848
* @author Rossen Stoyanchev
49-
*
49+
* @author Sam Brannen
5050
* @see ContentAssertionTests
5151
* @see XmlContentAssertionTests
5252
*/
@@ -60,9 +60,9 @@ public class XpathAssertionTests {
6060
@Before
6161
public void setup() throws Exception {
6262
this.mockMvc = standaloneSetup(new MusicController())
63-
.defaultRequest(get("/").accept(MediaType.APPLICATION_XML))
63+
.defaultRequest(get("/").accept(MediaType.APPLICATION_XML, MediaType.parseMediaType("application/xml;charset=UTF-8")))
6464
.alwaysExpect(status().isOk())
65-
.alwaysExpect(content().contentType(MediaType.APPLICATION_XML))
65+
.alwaysExpect(content().contentType(MediaType.parseMediaType("application/xml;charset=UTF-8")))
6666
.build();
6767
}
6868

0 commit comments

Comments
 (0)