Skip to content
Snippets Groups Projects
Commit abbdf239 authored by Sören Henning's avatar Sören Henning
Browse files

Add test for URI with path

parent 90dac8ca
No related branches found
No related tags found
No related merge requests found
......@@ -11,24 +11,15 @@ 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 java.net.URI;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import rocks.theodolite.benchmarks.commons.model.records.ActivePowerRecord;
public class HttpRecordSenderTest {
private HttpRecordSender<ActivePowerRecord> httpRecordSender;
@Rule
public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
@Before
public void setup() {
this.httpRecordSender =
new HttpRecordSender<>(URI.create("http://localhost:" + this.wireMockRule.port()));
}
@Test
public void testValidUri() {
this.wireMockRule.stubFor(
......@@ -38,14 +29,36 @@ public class HttpRecordSenderTest {
.withStatus(200)
.withBody("received")));
final HttpRecordSender<ActivePowerRecord> httpRecordSender =
new HttpRecordSender<>(URI.create("http://localhost:" + this.wireMockRule.port()));
final ActivePowerRecord record = new ActivePowerRecord("my-id", 12345L, 12.34);
this.httpRecordSender.send(record);
httpRecordSender.send(record);
final String expectedJson = "{\"identifier\":\"my-id\",\"timestamp\":12345,\"valueInW\":12.34}";
verify(exactly(1), postRequestedFor(urlEqualTo("/"))
.withRequestBody(equalTo(expectedJson))); // toJson
}
@Test
public void testValidUriWithPath() {
this.wireMockRule.stubFor(
post(urlPathEqualTo("/post"))
.willReturn(
aResponse()
.withStatus(200)
.withBody("received")));
final HttpRecordSender<ActivePowerRecord> httpRecordSender =
new HttpRecordSender<>(
URI.create("http://localhost:" + this.wireMockRule.port() + "/post"));
final ActivePowerRecord record = new ActivePowerRecord("my-id", 12345L, 12.34);
httpRecordSender.send(record);
final String expectedJson = "{\"identifier\":\"my-id\",\"timestamp\":12345,\"valueInW\":12.34}";
verify(exactly(1), postRequestedFor(urlEqualTo("/post"))
.withRequestBody(equalTo(expectedJson))); // toJson
}
@Test
public void testTimeout() {
this.wireMockRule.stubFor(
......@@ -56,8 +69,10 @@ public class HttpRecordSenderTest {
.withStatus(200)
.withBody("received")));
final HttpRecordSender<ActivePowerRecord> httpRecordSender =
new HttpRecordSender<>(URI.create("http://localhost:" + this.wireMockRule.port()));
final ActivePowerRecord record = new ActivePowerRecord("my-id", 12345L, 12.34);
this.httpRecordSender.send(record);
httpRecordSender.send(record);
final String expectedJson = "{\"identifier\":\"my-id\",\"timestamp\":12345,\"valueInW\":12.34}";
verify(exactly(1), postRequestedFor(urlEqualTo("/"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment