Skip to content

Commit

Permalink
tests(api-serenity-tests): Fix Serenity REST Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hypery2k committed Jun 4, 2017
1 parent 9987806 commit 3dde596
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
package ngSpring.demo.integration.steps;

import com.google.inject.Inject;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification;
import net.thucydides.core.annotations.Step;
import net.thucydides.core.annotations.StepGroup;
import net.thucydides.core.configuration.SystemPropertiesConfiguration;
import org.apache.commons.httpclient.HttpStatus;

import static net.serenitybdd.rest.SerenityRest.given;
import org.junit.Before;

/**
* @author mreinhardt
*/
// tag::serenity-rest-test[]
public class EventSteps {

@Step
public RequestSpecification login(String username, String password) {
return given()
.authentication().basic(username, password);
}
// end::serenity-rest-test[]
@Inject
public SystemPropertiesConfiguration systemPropertiesConfiguration;
// tag::serenity-rest-test[]


@StepGroup
public Response getEvent(String username, String password, String eventId) {
return login(username, password)
return RestAssured.given()
.with().baseUri(getBaseUrl()).basePath("")
.auth().basic(username, password)
.expect()
.statusCode(HttpStatus.SC_OK)
.when()
Expand All @@ -32,12 +34,26 @@ public Response getEvent(String username, String password, String eventId) {

@Step
public Response getEvents(String username, String password) {
return login(username, password)
return RestAssured.given()
.with().baseUri(getBaseUrl()).basePath("")
.auth().basic(username, password)
.expect()
.statusCode(HttpStatus.SC_OK)
.when()
.get("/api/events/");
}
}

// end::serenity-rest-test[]
// end::serenity-rest-test[]

@Before
public String getBaseUrl() {
String baseurl = "http://localhost:9080";
if (this.systemPropertiesConfiguration != null && this.systemPropertiesConfiguration.getBaseUrl() != null) {
baseurl = this.systemPropertiesConfiguration.getBaseUrl();
}
return baseurl;
}

// tag::serenity-rest-test[]
// end::serenity-rest-test[]
}

0 comments on commit 3dde596

Please sign in to comment.