Пример #1
0
  @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);
  }
Пример #2
0
  @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);
  }
Пример #3
0
  @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);
  }
Пример #4
0
  @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);
  }
Пример #5
0
  @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);
  }
Пример #6
0
  @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);
  }
Пример #7
0
  @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);
  }
Пример #8
0
  @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);
  }
Пример #9
0
  @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"));
  }
Пример #10
0
  @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"));
  }
Пример #11
0
  @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"));
  }
Пример #12
0
 @After
 public void tearDown() throws Exception {
   testServer.stop();
   testee.resetRestClient();
 }
Пример #13
0
 @Before
 public void setUp() throws Exception {
   testee = new RestSteps();
   testServer = new TestServerHelper();
   testServer.start();
 }