@Test(expected = AssertionError.class) public void testBytesNoMatch() throws Exception { this.request.getBody().write("test".getBytes()); MockRestRequestMatchers.content().bytes("Test".getBytes()).match(this.request); }
@Test(expected = AssertionError.class) public void testStringNoMatch() throws Exception { this.request.getBody().write("test".getBytes()); MockRestRequestMatchers.content().string("Test").match(this.request); }
@Test public void testString() throws Exception { this.request.getBody().write("test".getBytes()); MockRestRequestMatchers.content().string("test").match(this.request); }
@Test public void testJsonStrictMatch() throws Exception { String content = "{\n \"foo\": \"bar\", \"foo array\":[\"first\",\"second\"] \n}"; this.request.getBody().write(content.getBytes()); MockRestRequestMatchers .content() .json("{\n \"foo array\":[\"first\",\"second\"] , \"foo\": \"bar\" \n}", true) .match(this.request); }
@Test(expected = AssertionError.class) public void testXmlNoMatch() throws Exception { this.request.getBody().write("<foo>11</foo>".getBytes()); MockRestRequestMatchers.content().xml("<foo>22</foo>").match(this.request); }
@Test(expected = AssertionError.class) public void testJsonStrictNoMatch() throws Exception { String content = "{\n \"foo array\":[\"first\",\"second\"] , \"someExtraProperty\": \"which is NOT allowed\" \n}"; this.request.getBody().write(content.getBytes()); MockRestRequestMatchers .content() .json("{\n \"foo array\":[\"second\",\"first\"] \n}", true) .match(this.request); }
@Test public void testContentType() throws Exception { this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON); MockRestRequestMatchers.content().contentType("application/json").match(this.request); MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_JSON).match(this.request); }
@Test(expected = AssertionError.class) public void testContentTypeNoMatch2() throws Exception { this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON); MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_ATOM_XML).match(this.request); }
@Test(expected = AssertionError.class) public void testContentTypeNoMatch1() throws Exception { this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON); MockRestRequestMatchers.content().contentType("application/xml").match(this.request); }
@Test public void testNodeMatcher() throws Exception { String content = "<foo><bar>baz</bar></foo>"; this.request.getBody().write(content.getBytes()); MockRestRequestMatchers.content().node(hasXPath("/foo/bar")).match(this.request); }
@Test public void contentAsBytes() throws Exception { this.mockServer.expect(content().bytes("foo".getBytes())).andRespond(withSuccess()); executeAndVerify("foo"); }
@Test public void contentAsString() throws Exception { this.mockServer.expect(content().string("foo")).andRespond(withSuccess()); executeAndVerify("foo"); }
@Test public void contentType() throws Exception { this.mockServer.expect(content().contentType("application/json;charset=UTF-8")).andRespond(withSuccess()); executeAndVerify(new Person()); }
@Test public void contentStringStartsWith() throws Exception { this.mockServer.expect(content().string(startsWith("foo"))).andRespond(withSuccess()); executeAndVerify("foo123"); }
@Test public void isNumber() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].someDouble").isNumber()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void isString() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].name").isString()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void isBoolean() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0].someBoolean").isBoolean()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void value() throws Exception { this.mockServer.expect(requestTo("/composers")) .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")) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void doesNotExist() throws Exception { this.mockServer.expect(requestTo("/composers")) .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[4]").doesNotExist()) .andRespond(withSuccess()); executeAndVerify(); }
@Test public void exists() throws Exception { this.mockServer.expect(requestTo("/composers")) .andExpect(content().contentType("application/json;charset=UTF-8")) .andExpect(jsonPath("$.composers[0]").exists()) .andExpect(jsonPath("$.composers[1]").exists()) .andExpect(jsonPath("$.composers[2]").exists()) .andExpect(jsonPath("$.composers[3]").exists()) .andRespond(withSuccess()); executeAndVerify(); }