REPO-4705: Allow to reconfigure server URI in RestWrapper

This commit is contained in:
Alex Mukha
2019-10-17 18:03:20 +01:00
parent 3d6c34c8d6
commit 2bd64e48b5

View File

@@ -96,6 +96,23 @@ public class RestWrapper extends DSLWrapper<RestWrapper>
private RequestSpecBuilder requestSpecBuilder = new RequestSpecBuilder(); private RequestSpecBuilder requestSpecBuilder = new RequestSpecBuilder();
private Headers responseHeaders; private Headers responseHeaders;
private RestResponse response; private RestResponse response;
private String serverURI;
private int serverPort;
/**
* After configuring {@link #setServerURI(String)} and {@link #setServerPort(int)} call {@link #configureServerEndpoint()}
*
* @param serverURI in format of "http://localhost", without port. Set port via {@link #setServerPort(int)}
*/
public void setServerURI(String serverURI)
{
this.serverURI = serverURI;
}
public void setServerPort(int serverPort)
{
this.serverPort = serverPort;
}
@Autowired @Autowired
private RestAisAuthentication aisAuthentication; private RestAisAuthentication aisAuthentication;
@@ -131,11 +148,9 @@ public class RestWrapper extends DSLWrapper<RestWrapper>
@PostConstruct @PostConstruct
public void initializeRequestSpecBuilder() public void initializeRequestSpecBuilder()
{ {
requestSpecBuilder = new RequestSpecBuilder(); this.serverURI = restProperties.envProperty().getTestServerUrl();
RestAssured.baseURI = restProperties.envProperty().getTestServerUrl(); this.serverPort = restProperties.envProperty().getPort();
RestAssured.port = restProperties.envProperty().getPort(); configureServerEndpoint();
configureRequestSpec().setBaseUri(restProperties.envProperty().getTestServerUrl());
configureRequestSpec().setPort(restProperties.envProperty().getPort());
} }
/** /**
@@ -617,7 +632,7 @@ public class RestWrapper extends DSLWrapper<RestWrapper>
logResponseInformation(restRequest, returnedResponse); logResponseInformation(restRequest, returnedResponse);
initializeRequestSpecBuilder(); configureServerEndpoint();
response = new RestResponse(returnedResponse); response = new RestResponse(returnedResponse);
return returnedResponse; return returnedResponse;
} }
@@ -1092,17 +1107,31 @@ public class RestWrapper extends DSLWrapper<RestWrapper>
public void configureSyncServiceEndPoint() public void configureSyncServiceEndPoint()
{ {
RestAssured.baseURI = restProperties.envProperty().getSyncServerUrl(); this.serverURI = restProperties.envProperty().getSyncServerUrl();
RestAssured.port = restProperties.envProperty().getSyncPort(); this.serverPort = restProperties.envProperty().getSyncPort();
configureRequestSpec().setBaseUri(restProperties.envProperty().getSyncServerUrl()); configureServerEndpoint();
configureRequestSpec().setPort(restProperties.envProperty().getSyncPort());
} }
public void configureSolrEndPoint() public void configureSolrEndPoint()
{ {
RestAssured.baseURI = restProperties.envProperty().getSolrServerUrl(); this.serverURI = restProperties.envProperty().getSolrServerUrl();
RestAssured.port = restProperties.envProperty().getSolrPort(); this.serverPort = restProperties.envProperty().getSolrPort();
configureRequestSpec().setBaseUri(restProperties.envProperty().getSolrServerUrl()); configureServerEndpoint();
configureRequestSpec().setPort(restProperties.envProperty().getSolrPort()); }
/**
* Use {@link #setServerURI(String)} and {@link #setServerPort(int)}
*/
public void configureServerEndpoint()
{
requestSpecBuilder = new RequestSpecBuilder();
// use static variables for logs, etc
// the request spec is built from data set via setters, see RestWrapper#onRequest
RestAssured.baseURI = this.serverURI;
RestAssured.port = this.serverPort;
configureRequestSpec().setBaseUri(this.serverURI);
configureRequestSpec().setPort(this.serverPort);
} }
} }