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
Branches
Tags
No related merge requests found
...@@ -11,24 +11,15 @@ import static com.github.tomakehurst.wiremock.client.WireMock.verify; ...@@ -11,24 +11,15 @@ import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.net.URI; import java.net.URI;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import rocks.theodolite.benchmarks.commons.model.records.ActivePowerRecord; import rocks.theodolite.benchmarks.commons.model.records.ActivePowerRecord;
public class HttpRecordSenderTest { public class HttpRecordSenderTest {
private HttpRecordSender<ActivePowerRecord> httpRecordSender;
@Rule @Rule
public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort()); public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort());
@Before
public void setup() {
this.httpRecordSender =
new HttpRecordSender<>(URI.create("http://localhost:" + this.wireMockRule.port()));
}
@Test @Test
public void testValidUri() { public void testValidUri() {
this.wireMockRule.stubFor( this.wireMockRule.stubFor(
...@@ -38,14 +29,36 @@ public class HttpRecordSenderTest { ...@@ -38,14 +29,36 @@ public class HttpRecordSenderTest {
.withStatus(200) .withStatus(200)
.withBody("received"))); .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); 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}"; final String expectedJson = "{\"identifier\":\"my-id\",\"timestamp\":12345,\"valueInW\":12.34}";
verify(exactly(1), postRequestedFor(urlEqualTo("/")) verify(exactly(1), postRequestedFor(urlEqualTo("/"))
.withRequestBody(equalTo(expectedJson))); // toJson .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 @Test
public void testTimeout() { public void testTimeout() {
this.wireMockRule.stubFor( this.wireMockRule.stubFor(
...@@ -56,8 +69,10 @@ public class HttpRecordSenderTest { ...@@ -56,8 +69,10 @@ public class HttpRecordSenderTest {
.withStatus(200) .withStatus(200)
.withBody("received"))); .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); 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}"; final String expectedJson = "{\"identifier\":\"my-id\",\"timestamp\":12345,\"valueInW\":12.34}";
verify(exactly(1), postRequestedFor(urlEqualTo("/")) verify(exactly(1), postRequestedFor(urlEqualTo("/"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment