diff --git a/theodolite-benchmarks/load-generator-commons/build.gradle b/theodolite-benchmarks/load-generator-commons/build.gradle index f2aa10b079f4be80d19d9ac5d822b7bdab0b6d78..2d8f77b5154b5b788e0729da69122b443740ce75 100644 --- a/theodolite-benchmarks/load-generator-commons/build.gradle +++ b/theodolite-benchmarks/load-generator-commons/build.gradle @@ -13,14 +13,16 @@ repositories { } dependencies { - implementation 'com.google.guava:guava:30.1-jre' implementation 'com.hazelcast:hazelcast:4.1.1' implementation 'com.hazelcast:hazelcast-kubernetes:2.2.1' implementation 'org.slf4j:slf4j-simple:1.7.25' + implementation 'com.google.guava:guava:30.1-jre' + implementation 'com.google.code.gson:gson:2.8.2' implementation('org.industrial-devops:titan-ccp-common:0.1.0-SNAPSHOT') { changing = true } implementation('org.industrial-devops:titan-ccp-common-kafka:0.1.0-SNAPSHOT') { changing = true } implementation 'org.apache.kafka:kafka-streams:2.6.0' // TODO required? // Use JUnit test framework testImplementation 'junit:junit:4.12' + testImplementation 'com.github.tomakehurst:wiremock-jre8:2.32.0' } diff --git a/theodolite-benchmarks/load-generator-commons/src/test/java/theodolite/commons/workloadgeneration/HttpRecordSenderTest.java b/theodolite-benchmarks/load-generator-commons/src/test/java/theodolite/commons/workloadgeneration/HttpRecordSenderTest.java new file mode 100644 index 0000000000000000000000000000000000000000..002a97d1badfca560410b76d7d2ad260b90afbfd --- /dev/null +++ b/theodolite-benchmarks/load-generator-commons/src/test/java/theodolite/commons/workloadgeneration/HttpRecordSenderTest.java @@ -0,0 +1,52 @@ +package theodolite.commons.workloadgeneration; + +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.exactly; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.verify; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.google.gson.Gson; +import java.net.URI; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import titan.ccp.model.records.ActivePowerRecord; + +public class HttpRecordSenderTest { + + private HttpRecordSender<ActivePowerRecord> httpRecordSender; + + private Gson gson; + + @Rule + public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort()); + + @Before + public void setup() { + this.httpRecordSender = + new HttpRecordSender<>(URI.create("http://localhost:" + this.wireMockRule.port())); + this.gson = new Gson(); + } + + @Test + public void testValidUri() { + this.wireMockRule.stubFor( + post(urlPathEqualTo("/")) + .willReturn( + aResponse() + .withStatus(200) + .withBody("received"))); + + final ActivePowerRecord record = new ActivePowerRecord("my-id", 12345L, 12.34); + this.httpRecordSender.send(record); + + verify(exactly(1), postRequestedFor(urlEqualTo("/")) + .withRequestBody(equalTo(this.gson.toJson(record)))); // toJson + } + +}