Added strict compare mode for Json

Issue: SPR-13607
This commit is contained in:
Hronom
2015-10-23 16:45:02 +03:00
committed by Sebastien Deleuze
parent 9334fabe26
commit 1d60a6a6af
3 changed files with 92 additions and 14 deletions

View File

@@ -79,17 +79,28 @@ public class ContentResultMatchersTests {
}
@Test
public void json() throws Exception {
new ContentResultMatchers().json("{\n \"foo\" : \"bar\" \n}").match(getStubMvcResult());
public void jsonLenientMatch() throws Exception {
new ContentResultMatchers().json("{\n \"foo\" : \"bar\" \n}").match(getStubMvcResult());
new ContentResultMatchers().json("{\n \"foo\" : \"bar\" \n}", false).match(getStubMvcResult());
}
@Test
public void jsonStrictMatch() throws Exception {
new ContentResultMatchers().json("{\n \"foo\":\"bar\", \"foo array\":[\"foo\",\"bar\"] \n}", true).match(getStubMvcResult());
new ContentResultMatchers().json("{\n \"foo array\":[\"foo\",\"bar\"], \"foo\":\"bar\" \n}", true).match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void jsonNoMatch() throws Exception {
public void jsonLenientNoMatch() throws Exception {
new ContentResultMatchers().json("{\n\"fooo\":\"bar\"\n}").match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void jsonStrictNoMatch() throws Exception {
new ContentResultMatchers().json("{\"foo\":\"bar\", \"foo array\":[\"bar\",\"foo\"]}", true).match(getStubMvcResult());
}
private static final String CONTENT = "{\"foo\":\"bar\"}";
private static final String CONTENT = "{\"foo\":\"bar\",\"foo array\":[\"foo\",\"bar\"]}";
private StubMvcResult getStubMvcResult() throws Exception {
MockHttpServletResponse response = new MockHttpServletResponse();