@Test public void shouldSendGetRequestToUrl() throws Exception { testServer.expect().get(by(uri(uri))).response(representation); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(GET, uri); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); }
@Test public void shouldSendDeleteRequestToUrl() throws Exception { testServer.expect().delete(by(uri(uri))).response(status(OK)); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(DELETE, uri); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); }
@Test public void shouldSendOptionsRequestToUrl() throws Exception { testServer.expect().request(and(by(method("OPTIONS")), by(uri(uri)))).response(status(200)); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(OPTIONS, uri); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); }
@Test public void shouldSendGetRequestWithHeaderToUrl() throws Exception { testServer.expect().get(and(by(uri(uri)), eq(header(header), value))).response(representation); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(GET, uri); testee.theRequestHasAHeaderWithValue(header, value); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); }
@Test public void shouldPassWhenContentFromFileMatches() throws Exception { testServer.expect().get(by(uri(uri))).response(representation); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(GET, uri); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); testee.theResponseContentWillMatchTheFile(filename); }
@Test public void shouldPassWhenResponseDoesNotHaveBannedHeader() throws Exception { testServer.expect().get(by(uri(uri))).response(representation); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(GET, uri); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); testee.theResponseWillNotHaveAHeaderWithValue(header, value); }
@Test public void shouldSendPatchRequestToUrl() throws Exception { testServer.expect().request(and(by(method("PATCH")), by(uri(uri)))).response(status(OK)); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(PATCH, uri); testee.theRequestHasContent(representation); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); }
@Test public void shouldSendPostRequestWithContentFromFileToUrl() throws Exception { testServer.expect().post(and(by(uri(uri)), by(representation))).response(status(OK)); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(POST, uri); testee.theRequestHasContentFromFile(filename); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); }
@Test public void shouldFailWhenResponseHasIncorrectStatusCode() throws Exception { testServer.expect().get(by(uri(uri))).response(status(418)); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(GET, uri); testee.theResponseIsReceived(); catchThrowable(testee).theResponseWillHaveTheStatusCode(OK); assertThat(caughtThrowable(), instanceOf(AssertionError.class)); assertThat(caughtThrowable(), hasMessage("Expected status code " + OK + " but was 418")); }
@Test public void shouldFailWhenContentFromFileDoesNotMatch() throws Exception { testServer.expect().get(by(uri(uri))).response("wrongRepresentation"); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(GET, uri); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); catchThrowable(testee).theResponseContentWillMatch(representation); assertThat(caughtThrowable(), instanceOf(AssertionError.class)); assertThat(caughtThrowable(), hasMessage("Actual content does not match expected content")); }
@Test public void shouldFailWhenResponseMissingExpectedHeader() throws Exception { testServer.expect().get(by(uri(uri))).response(representation); testee.aServiceRunningOn(testServer.baseUri()); testee.aRequestToTheResource(GET, uri); testee.theResponseIsReceived(); testee.theResponseWillHaveTheStatusCode(OK); catchThrowable(testee).theResponseWillHaveAHeaderWithValue(header, value); assertThat(caughtThrowable(), instanceOf(AssertionError.class)); assertThat( caughtThrowable(), hasMessage("No header '" + header + "' with value '" + value + "' found")); }