Skip to content

Commit 5c68a25

Browse files
committed
#32 Verify Gatling simulations whether edgegrid-signer-gatling really includes correct headers in HTTP request.
1 parent b948a7b commit 5c68a25

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

edgegrid-signer-gatling/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<groupId>org.scala-lang</groupId>
3333
<artifactId>scala-library</artifactId>
3434
</dependency>
35+
<dependency>
36+
<groupId>com.github.tomakehurst</groupId>
37+
<artifactId>wiremock</artifactId>
38+
</dependency>
3539
</dependencies>
3640

3741
<build>

edgegrid-signer-gatling/src/test/scala/com/akamai/edgegrid/signer/gatling/EdgeGridSignerSimulation1.scala

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,46 @@
1717
package com.akamai.edgegrid.signer.gatling
1818

1919
import com.akamai.edgegrid.signer.ahc.AsyncHttpClientEdgeGridSignatureCalculator
20+
import com.github.tomakehurst.wiremock.WireMockServer
21+
import com.github.tomakehurst.wiremock.client.WireMock._
22+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
2023
import io.gatling.core.Predef._
2124
import io.gatling.http.Predef._
2225

2326

2427
class EdgeGridSignerSimulation1 extends Simulation {
2528

2629
val httpConf = http
27-
.baseURL("http://localhost")
30+
.baseURL("http://" + testdata.SERVICE_MOCK_HOST)
31+
32+
val wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().port(testdata.SERVICE_MOCK_PORT))
2833

2934
val testScenario = scenario("Test scenario")
3035
.exec(
3136
http("fakeRequest")
3237
.get("/test")
3338
.signatureCalculator(new AsyncHttpClientEdgeGridSignatureCalculator(testdata.testCredential))
39+
.check(status.is(201))
40+
)
41+
42+
before {
43+
wireMockServer.start()
44+
wireMockServer.stubFor(get(urlPathEqualTo("/test"))
45+
.withHeader("Authorization", matching(".*"))
46+
.withHeader("Host", equalTo(testdata.SERVICE_MOCK))
47+
.willReturn(aResponse.withStatus(201)
48+
.withHeader("Content-Type", "text/xml")
49+
.withBody("<response>Some content</response>")))
50+
}
51+
52+
setUp(testScenario.inject(atOnceUsers(1)))
53+
.protocols(httpConf)
54+
.assertions(
55+
global.successfulRequests.percent.is(100)
3456
)
3557

36-
setUp(
37-
testScenario.inject(atOnceUsers(1))
38-
).protocols(httpConf)
58+
after {
59+
wireMockServer.stop()
60+
}
3961

4062
}

edgegrid-signer-gatling/src/test/scala/com/akamai/edgegrid/signer/gatling/EdgeGridSignerSimulation2.scala

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,44 @@
1717
package com.akamai.edgegrid.signer.gatling
1818

1919
import com.akamai.edgegrid.signer.ahc.AsyncHttpClientEdgeGridSignatureCalculator
20+
import com.github.tomakehurst.wiremock.WireMockServer
21+
import com.github.tomakehurst.wiremock.client.WireMock._
22+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
2023
import io.gatling.core.Predef._
2124
import io.gatling.http.Predef._
2225

23-
class EdgeGridSignerSimulation2 extends Simulation{
26+
class EdgeGridSignerSimulation2 extends Simulation {
2427

2528
val httpConf = http
2629

30+
val wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().port(testdata.SERVICE_MOCK_PORT))
31+
2732
val testScenario = scenario("Test scenario")
2833
.exec(
2934
http("fakeRequest")
30-
.get("https://" + testdata.testCredential.getHost + "/test")
35+
.get("http://" + testdata.testCredential.getHost + "/test")
3136
.signatureCalculator(new AsyncHttpClientEdgeGridSignatureCalculator(testdata.testCredential))
3237
)
3338

34-
setUp(
35-
testScenario.inject(atOnceUsers(1))
36-
).protocols(httpConf)
39+
before {
40+
wireMockServer.start()
41+
wireMockServer.stubFor(get(urlPathEqualTo("/test"))
42+
.withHeader("Authorization", matching(".*"))
43+
.withHeader("Host", equalTo(testdata.SERVICE_MOCK))
44+
.willReturn(aResponse.withStatus(201)
45+
.withHeader("Content-Type", "text/xml")
46+
.withBody("<response>Some content</response>")))
47+
}
48+
49+
setUp(testScenario.inject(atOnceUsers(1)))
50+
.protocols(httpConf)
51+
.assertions(
52+
global.successfulRequests.percent.is(100)
53+
)
54+
55+
after {
56+
wireMockServer.stop()
57+
}
58+
3759

3860
}

edgegrid-signer-gatling/src/test/scala/com/akamai/edgegrid/signer/gatling/TestData.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ package object testdata {
2626
.clientSecret("SOMESECRET")
2727
.host("localhost:9089").build
2828

29+
val SERVICE_MOCK_HOST = "localhost"
30+
val SERVICE_MOCK_PORT = 9089
31+
val SERVICE_MOCK = testdata.SERVICE_MOCK_HOST + ":" + testdata.SERVICE_MOCK_PORT
32+
33+
2934
}

0 commit comments

Comments
 (0)