Commit 44d8fa86 authored by René Schöne's avatar René Schöne
Browse files

Extend ViaTest for both2both case

parent cc712218
Pipeline #7549 failed with stages
in 1 minute and 44 seconds
......@@ -31,11 +31,16 @@ public class ViaTest extends AbstractMqttTest {
private static final String PATH_REST_2_REST_RECEIVE = "rest2rest/receive";
private static final String TOPIC_MQTT_2_REST_RECEIVE = "mqtt2rest/receive";
private static final String PATH_REST_2_MQTT_RECEIVE = "rest2mqtt/receive";
private static final String TOPIC_BOTH_MQTT_RECEIVE = "both/send";
private static final String PATH_BOTH_REST_RECEIVE = "both/send";
private static final String TOPIC_MQTT_2_MQTT_SEND = "mqtt2mqtt/send";
private static final String PATH_REST_2_REST_SEND = "rest2rest/send";
private static final String PATH_MQTT_2_REST_SEND = "mqtt2rest/send";
private static final String TOPIC_REST_2_MQTT_SEND = "rest2mqtt/send";
private static final String TOPIC_BOTH_2_MQTT_SEND = "both2mqtt/send";
private static final String PATH_BOTH_2_REST_SEND = "both2rest/send";
private static final String REST_SERVER_BASE_URL = "http://localhost:" + REST_PORT + "/";
private MqttHandler handler;
......@@ -44,8 +49,12 @@ public class ViaTest extends AbstractMqttTest {
private ReceiverData dataRest2Mqtt;
private WebTarget dataRest2Rest;
private WebTarget dataMqtt2Rest;
private ReceiverData dataBoth2Mqtt;
private WebTarget dataBoth2Rest;
private WebTarget senderRest2Rest;
private WebTarget senderRest2Mqtt;
private WebTarget senderBoth2Rest;
@AfterEach
public void closeConnections() {
......@@ -70,13 +79,72 @@ public class ViaTest extends AbstractMqttTest {
// check initial value
TestUtils.waitForMqtt();
checkData(1, "100-M2M-ToMqtt", "200-R2R-ToRest", "300-M2R-ToRest", 1, "400-R2M-ToMqtt");
checkData(1, "100-M2M-ToMqtt",
"200-R2R-ToRest",
"300-M2R-ToRest",
1, "400-R2M-ToMqtt",
1, "500-B2M-ToMqtt",
"500-B2R-ToRest");
sendData("101", "201", "301", "401");
sendDataForBoth("501", true);
// check new value
TestUtils.waitForMqtt();
checkData(2, "FromMqtt-101-M2M-ToMqtt", "FromRest-201-R2R-ToRest", "FromMqtt-301-M2R-ToRest", 2, "FromRest-401-R2M-ToMqtt");
checkData(2, "FromMqtt-101-M2M-ToMqtt",
"FromRest-201-R2R-ToRest",
"FromMqtt-301-M2R-ToRest",
2, "FromRest-401-R2M-ToMqtt",
2, "FromMqtt-501-B2M-ToMqtt",
"FromMqtt-501-B2R-ToRest");
// send value only for bothInput via REST
sendDataForBoth("502", false);
// check this value
TestUtils.waitForMqtt();
checkData(2, "FromMqtt-101-M2M-ToMqtt",
"FromRest-201-R2R-ToRest",
"FromMqtt-301-M2R-ToRest",
2, "FromRest-401-R2M-ToMqtt",
3, "FromRest-502-B2M-ToMqtt",
"FromRest-502-B2R-ToRest");
// send same value only for bothInput via MQTT
sendDataForBoth("502", true);
// check this value
TestUtils.waitForMqtt();
checkData(2, "FromMqtt-101-M2M-ToMqtt",
"FromRest-201-R2R-ToRest",
"FromMqtt-301-M2R-ToRest",
2, "FromRest-401-R2M-ToMqtt",
4, "FromMqtt-502-B2M-ToMqtt",
"FromMqtt-502-B2R-ToRest");
// send values for other things
sendData("102", "202", "302", "402");
// check this value
TestUtils.waitForMqtt();
checkData(3, "FromMqtt-102-M2M-ToMqtt",
"FromRest-202-R2R-ToRest",
"FromMqtt-302-M2R-ToRest",
3, "FromRest-402-R2M-ToMqtt",
4, "FromMqtt-502-B2M-ToMqtt",
"FromMqtt-502-B2R-ToRest");
// send same values again for other things
sendData("102", "202", "302", "402");
// check this value
TestUtils.waitForMqtt();
checkData(3, "FromMqtt-102-M2M-ToMqtt",
"FromRest-202-R2R-ToRest",
"FromMqtt-302-M2R-ToRest",
3, "FromRest-402-R2M-ToMqtt",
4, "FromMqtt-502-B2M-ToMqtt",
"FromMqtt-502-B2R-ToRest");
}
@Test
......@@ -86,13 +154,72 @@ public class ViaTest extends AbstractMqttTest {
// check initial value
TestUtils.waitForMqtt();
checkData(0, null, "200-R2R-ToRest", "300-M2R-ToRest", 0, null);
checkData(0, null,
"200-R2R-ToRest",
"300-M2R-ToRest",
0, null,
0, null,
"500-B2R-ToRest");
sendData("111", "211", "311", "411");
sendDataForBoth("511", true);
// check new value
TestUtils.waitForMqtt();
checkData(1, "FromMqtt-111-M2M-ToMqtt", "FromRest-211-R2R-ToRest", "FromMqtt-311-M2R-ToRest", 1, "FromRest-411-R2M-ToMqtt");
checkData(1, "FromMqtt-111-M2M-ToMqtt",
"FromRest-211-R2R-ToRest",
"FromMqtt-311-M2R-ToRest",
1, "FromRest-411-R2M-ToMqtt",
1, "FromMqtt-511-B2M-ToMqtt",
"FromMqtt-511-B2R-ToRest");
// send value only for bothInput via REST
sendDataForBoth("512", false);
// check this value
TestUtils.waitForMqtt();
checkData(1, "FromMqtt-111-M2M-ToMqtt",
"FromRest-211-R2R-ToRest",
"FromMqtt-311-M2R-ToRest",
1, "FromRest-411-R2M-ToMqtt",
2, "FromRest-512-B2M-ToMqtt",
"FromRest-512-B2R-ToRest");
// send same value only for bothInput via MQTT
sendDataForBoth("512", true);
// check this value
TestUtils.waitForMqtt();
checkData(1, "FromMqtt-111-M2M-ToMqtt",
"FromRest-211-R2R-ToRest",
"FromMqtt-311-M2R-ToRest",
1, "FromRest-411-R2M-ToMqtt",
3, "FromMqtt-512-B2M-ToMqtt",
"FromMqtt-512-B2R-ToRest");
// send values for other things
sendData("112", "212", "312", "412");
// check this value
TestUtils.waitForMqtt();
checkData(2, "FromMqtt-112-M2M-ToMqtt",
"FromRest-212-R2R-ToRest",
"FromMqtt-312-M2R-ToRest",
2, "FromRest-412-R2M-ToMqtt",
3, "FromMqtt-512-B2M-ToMqtt",
"FromMqtt-512-B2R-ToRest");
// send same values again for other things
sendData("112", "212", "312", "412");
// check this value
TestUtils.waitForMqtt();
checkData(2, "FromMqtt-112-M2M-ToMqtt",
"FromRest-212-R2R-ToRest",
"FromMqtt-312-M2R-ToRest",
2, "FromRest-412-R2M-ToMqtt",
3, "FromMqtt-512-B2M-ToMqtt",
"FromMqtt-512-B2R-ToRest");
}
private void sendData(String inputMqtt2Mqtt, String inputRest2Rest, String inputMqtt2Rest, String inputRest2Mqtt) {
......@@ -102,11 +229,21 @@ public class ViaTest extends AbstractMqttTest {
senderRest2Mqtt.request().put(Entity.entity(inputRest2Mqtt, MediaType.TEXT_PLAIN_TYPE));
}
private void checkData(int numberOfMqtt2MqttValues, String mqtt2MqttValue, String rest2RestValue, String mqtt2RestValue, int numberOfRest2MqttValues, String rest2MqttValue) {
private void sendDataForBoth(String input, boolean useMqtt) {
if (useMqtt) {
handler.publish(TOPIC_BOTH_MQTT_RECEIVE, input.getBytes());
} else {
senderBoth2Rest.request().put(Entity.entity(input, MediaType.TEXT_PLAIN_TYPE));
}
}
private void checkData(int numberOfMqtt2MqttValues, String mqtt2MqttValue, String rest2RestValue, String mqtt2RestValue, int numberOfRest2MqttValues, String rest2MqttValue, int numberOfBoth2MqttValues, String both2MqttValue, String both2RestValue) {
dataMqtt2Mqtt.assertEqualData(numberOfMqtt2MqttValues, mqtt2MqttValue);
dataRest2Mqtt.assertEqualData(numberOfRest2MqttValues, rest2MqttValue);
dataBoth2Mqtt.assertEqualData(numberOfBoth2MqttValues, both2MqttValue);
assertEquals(rest2RestValue, readRest2Rest());
assertEquals(mqtt2RestValue, readMqtt2Rest());
assertEquals(both2RestValue, readBoth2Rest());
}
private String readRest2Rest() {
......@@ -117,6 +254,10 @@ public class ViaTest extends AbstractMqttTest {
return dataMqtt2Rest.request().get().readEntity(String.class);
}
private String readBoth2Rest() {
return dataBoth2Rest.request().get().readEntity(String.class);
}
private void createModel() {
// Setting value for Input without dependencies does not trigger any updates
model = new A();
......@@ -124,6 +265,7 @@ public class ViaTest extends AbstractMqttTest {
model.setRest2RestInput("200");
model.setMqtt2RestInput("300");
model.setRest2MqttInput("400");
model.setBoth2BothInput("500");
}
private void setupReceiverAndConnect(boolean writeCurrentValue) throws IOException {
......@@ -138,9 +280,12 @@ public class ViaTest extends AbstractMqttTest {
model.addDependencyRest2Rest(model);
model.addDependencyMqtt2Rest(model);
model.addDependencyRest2Mqtt(model);
model.addDependencyBoth2Mqtt(model);
model.addDependencyBoth2Rest(model);
dataMqtt2Mqtt = new ReceiverData();
dataRest2Mqtt = new ReceiverData();
dataBoth2Mqtt = new ReceiverData();
handler.newConnection(TOPIC_MQTT_2_MQTT_SEND, bytes -> {
dataMqtt2Mqtt.numberOfStringValues += 1;
......@@ -150,12 +295,18 @@ public class ViaTest extends AbstractMqttTest {
dataRest2Mqtt.numberOfStringValues += 1;
dataRest2Mqtt.lastStringValue = new String(bytes);
});
handler.newConnection(TOPIC_BOTH_2_MQTT_SEND, bytes -> {
dataBoth2Mqtt.numberOfStringValues += 1;
dataBoth2Mqtt.lastStringValue = new String(bytes);
});
Client client = ClientBuilder.newClient();
dataRest2Rest = client.target(REST_SERVER_BASE_URL + PATH_REST_2_REST_SEND);
dataMqtt2Rest = client.target(REST_SERVER_BASE_URL + PATH_MQTT_2_REST_SEND);
dataBoth2Rest = client.target(REST_SERVER_BASE_URL + PATH_BOTH_2_REST_SEND);
senderRest2Rest = client.target(REST_SERVER_BASE_URL + PATH_REST_2_REST_RECEIVE);
senderRest2Mqtt = client.target(REST_SERVER_BASE_URL + PATH_REST_2_MQTT_RECEIVE);
senderBoth2Rest = client.target(REST_SERVER_BASE_URL + PATH_BOTH_REST_RECEIVE);
model.connectMqtt2MqttInput(TOPIC_MQTT_2_MQTT_RECEIVE);
model.connectMqtt2MqttOutput(TOPIC_MQTT_2_MQTT_SEND, writeCurrentValue);
......@@ -165,6 +316,10 @@ public class ViaTest extends AbstractMqttTest {
model.connectRest2MqttOutput(TOPIC_REST_2_MQTT_SEND, writeCurrentValue);
model.connectRest2RestInput(PATH_REST_2_REST_RECEIVE);
model.connectRest2RestOutput(PATH_REST_2_REST_SEND, writeCurrentValue);
model.connectBoth2BothInputViaMqtt(TOPIC_BOTH_MQTT_RECEIVE);
model.connectBoth2BothInputViaRest(PATH_BOTH_REST_RECEIVE);
model.connectBoth2MqttOutput(TOPIC_BOTH_2_MQTT_SEND, writeCurrentValue);
model.connectBoth2RestOutput(PATH_BOTH_2_REST_SEND, writeCurrentValue);
}
private static class ReceiverData {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment