@Test public void queryParamContainsWithMissingValue() throws Exception { this.request.setURI(new URI("http://foo.com/a?foo=bar&foo=baz")); AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.queryParam("foo", containsString("bx")).match(this.request)); assertThat(error.getMessage(), containsString("was \"bar\"")); }
@Test public void queryParamMissingValue() throws Exception { this.request.setURI(new URI("http://foo.com/a?foo=bar&foo=baz")); AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.queryParam("foo", "bad").match(this.request)); assertThat(error.getMessage(), containsString("expected:<bad> but was:<bar>")); }
@Test public void queryParamMissing() throws Exception { this.request.setURI(new URI("http://foo.com/a")); AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.queryParam("foo", "bar").match(this.request)); assertThat(error.getMessage(), containsString("but was null")); }
@Test public void queryParamContains() throws Exception { this.request.setURI(new URI("http://foo.com/a?foo=bar&foo=baz")); MockRestRequestMatchers.queryParam("foo", containsString("ba")).match(this.request); }
@Test public void queryParam() throws Exception { this.request.setURI(new URI("http://foo.com/a?foo=bar&foo=baz")); MockRestRequestMatchers.queryParam("foo", "bar", "baz").match(this.request); }
@Test public void shouldExpectRequestWithAfterIdQueryAndResponseWithOneMessage() throws JsonProcessingException { server.expect(once(), requestTo(startsWith(GitterUriBuilder.from(properties.getApi()).build().toUriString()))) .andExpect(method(HttpMethod.GET)) .andExpect(queryParam("afterId", "qwerty")) .andRespond(withSuccess(objectMapper.writeValueAsBytes(ChatResponseFactory.messages(1)), MediaType.APPLICATION_JSON)); List<MessageResponse> messages = gitterClient.getMessages(WebUtils.parseMatrixVariables("afterId=qwerty")); server.verify(); Assert.assertEquals(1, messages.size()); Assertions.assertMessages(messages); } }