diff --git a/edgegrid-signer-apache-http-client/src/test/java/com/akamai/edgegrid/signer/apachehttpclient/ApacheHttpClientEdgeGridInterceptorIntegrationTest.java b/edgegrid-signer-apache-http-client/src/test/java/com/akamai/edgegrid/signer/apachehttpclient/ApacheHttpClientEdgeGridInterceptorIntegrationTest.java index e031db0..77b6de1 100644 --- a/edgegrid-signer-apache-http-client/src/test/java/com/akamai/edgegrid/signer/apachehttpclient/ApacheHttpClientEdgeGridInterceptorIntegrationTest.java +++ b/edgegrid-signer-apache-http-client/src/test/java/com/akamai/edgegrid/signer/apachehttpclient/ApacheHttpClientEdgeGridInterceptorIntegrationTest.java @@ -17,12 +17,21 @@ package com.akamai.edgegrid.signer.apachehttpclient; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.matching; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; + import com.akamai.edgegrid.signer.ClientCredential; import com.akamai.edgegrid.signer.exceptions.RequestSigningException; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.matching.RequestPattern; import com.github.tomakehurst.wiremock.verification.LoggedRequest; - +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.List; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.hamcrest.CoreMatchers; @@ -33,17 +42,6 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.List; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.matching; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; - /** * Integration tests for {@link com.akamai.edgegrid.signer.apachehttpclient.ApacheHttpClientEdgeGridInterceptor}. @@ -54,21 +52,24 @@ public class ApacheHttpClientEdgeGridInterceptorIntegrationTest { static final String SERVICE_MOCK_HOST = "localhost"; - static final int SERVICE_MOCK_PORT = 9089; - static final String SERVICE_MOCK = SERVICE_MOCK_HOST + ":" + SERVICE_MOCK_PORT; - ClientCredential credential = ClientCredential.builder() - .accessToken("akaa-dm5g2bfwoodqnc6k-ju7vlao2wz6oz2rp") - .clientToken("akaa-k7glklzuxkkh2ycw-oadjphopvpn6yjoj") - .clientSecret("SOMESECRET") - .host(SERVICE_MOCK) - .build(); + WireMockServer wireMockServer = new WireMockServer(wireMockConfig().dynamicHttpsPort()); - WireMockServer wireMockServer = new WireMockServer(wireMockConfig().httpsPort(SERVICE_MOCK_PORT)); + ClientCredential credential; + + private String getHost() { + return SERVICE_MOCK_HOST + ":" + wireMockServer.httpsPort(); + } @BeforeClass public void setUp() { wireMockServer.start(); + credential = ClientCredential.builder() + .accessToken("akaa-dm5g2bfwoodqnc6k-ju7vlao2wz6oz2rp") + .clientToken("akaa-k7glklzuxkkh2ycw-oadjphopvpn6yjoj") + .clientSecret("SOMESECRET") + .host(getHost()) + .build(); } @BeforeMethod @@ -77,25 +78,28 @@ public void reset() { wireMockServer.resetRequests(); } + @AfterClass + public void tearDownAll() { + wireMockServer.stop(); + } + @Test public void testInterceptor() throws URISyntaxException, IOException, RequestSigningException { - wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources")) .withHeader("Authorization", matching(".*")) - .withHeader("Host", equalTo(SERVICE_MOCK)) + .withHeader("Host", equalTo(getHost())) .willReturn(aResponse() .withStatus(302) .withHeader("Location", "/billing-usage/v1/reportSources/alternative"))); wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources/alternative")) .withHeader("Authorization", matching(".*")) - .withHeader("Host", equalTo(SERVICE_MOCK)) + .withHeader("Host", equalTo(getHost())) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "text/xml") .withBody("Some content"))); - HttpGet request = new HttpGet("http://endpoint.net/billing-usage/v1/reportSources"); HttpClient client = HttpClientSetup.getHttpClientWithRelaxedSsl() @@ -112,10 +116,4 @@ public void testInterceptor() throws URISyntaxException, IOException, RequestSig Matchers.not(CoreMatchers.equalTo(loggedRequests.get(1).getHeader("Authorization")))); } - @AfterClass - public void tearDownAll() { - wireMockServer.stop(); - } - - }