|
| 1 | +package com.github.nhojpatrick.cucumber.http.response.steps; |
| 2 | + |
| 3 | +import com.github.nhojpatrick.cucumber.core.exceptions.IllegalKeyException; |
| 4 | +import com.github.nhojpatrick.cucumber.core.exceptions.IllegalTypeClassException; |
| 5 | +import com.github.nhojpatrick.cucumber.core.exceptions.TypeMismatchException; |
| 6 | +import com.github.nhojpatrick.cucumber.http.core.model.HttpResponse; |
| 7 | +import com.github.nhojpatrick.cucumber.state.RunState; |
| 8 | +import com.github.nhojpatrick.cucumber.state.exceptions.NullRunStateException; |
| 9 | +import com.github.nhojpatrick.cucumber.state.validation.RunStateValidatorFactory; |
| 10 | +import com.google.inject.Inject; |
| 11 | +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 12 | +import io.cucumber.java.en.Given; |
| 13 | + |
| 14 | +import static com.github.nhojpatrick.cucumber.http.constants.HttpConstants.HTTP_RESPONSE_BODY; |
| 15 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 16 | +import static org.hamcrest.core.Is.is; |
| 17 | +import static org.hamcrest.core.IsEqual.equalTo; |
| 18 | + |
| 19 | +public class HttpResponseSteps { |
| 20 | + |
| 21 | + @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Accepted will look at changing") |
| 22 | + private final RunState runState; |
| 23 | + |
| 24 | + @Inject |
| 25 | + public HttpResponseSteps(final RunState runState) { |
| 26 | + this.runState = runState; |
| 27 | + } |
| 28 | + |
| 29 | + @Given("http response status code of {int}") |
| 30 | + public void httpResponseStatusCode(final int expectedStatusCode) |
| 31 | + throws IllegalKeyException, |
| 32 | + IllegalTypeClassException, |
| 33 | + NullRunStateException, |
| 34 | + TypeMismatchException { |
| 35 | + |
| 36 | + RunStateValidatorFactory.getInstance() |
| 37 | + .withValue(HTTP_RESPONSE_BODY) |
| 38 | + .verify(this.runState); |
| 39 | + |
| 40 | + final HttpResponse httpResponse = this.runState.get(HTTP_RESPONSE_BODY, HttpResponse.class); |
| 41 | + final int actualStatusCode = httpResponse.getStatusCode(); |
| 42 | + |
| 43 | + assertThat("Unexpected http status code", actualStatusCode, is(equalTo(expectedStatusCode))); |
| 44 | + } |
| 45 | + |
| 46 | +} |
0 commit comments