Skip to content
Snippets Groups Projects
Commit 39f1effb authored by Sebastian Ebert's avatar Sebastian Ebert
Browse files

merged upstream master in fork-master

parents 38c4a6a2 24062cab
Branches
No related tags found
1 merge request!11Merge/dev to fork master merge
package org.jastadd.ragconnect.tests;
import org.junit.jupiter.api.Tag;
import via.ast.A;
import via.ast.MqttHandler;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static org.jastadd.ragconnect.tests.TestUtils.mqttUri;
import static org.jastadd.ragconnect.tests.TestUtils.restUri;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test case "via".
*
* @author rschoene - Initial contribution
*/
@Tag("rest")
public class ViaTest extends AbstractMqttTest {
private static final int REST_PORT = 9002;
private static final String TOPIC_MQTT_2_MQTT_RECEIVE = "mqtt2mqtt/receive";
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;
private A model;
private ReceiverData dataMqtt2Mqtt;
private ReceiverData dataRest2Mqtt;
private WebTarget dataRest2Rest;
private WebTarget dataMqtt2Rest;
private ReceiverData dataBoth2Mqtt;
private WebTarget dataBoth2Rest;
private WebTarget senderRest2Rest;
private WebTarget senderRest2Mqtt;
private WebTarget senderBoth2Rest;
@Override
public void closeConnections() {
if (handler != null) {
handler.close();
}
if (model != null) {
model.ragconnectCloseConnections();
}
}
@Override
protected void communicateSendInitialValue() throws InterruptedException {
// check initial value
TestUtils.waitForMqtt();
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",
2, "501-B2M-ToMqtt",
"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, "502-B2M-ToMqtt",
"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",
3, "502-B2M-ToMqtt",
"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",
3, "502-B2M-ToMqtt",
"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",
3, "502-B2M-ToMqtt",
"502-B2R-ToRest");
}
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
// check initial value
TestUtils.waitForMqtt();
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",
1, "511-B2M-ToMqtt",
"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, "512-B2M-ToMqtt",
"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",
2, "512-B2M-ToMqtt",
"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",
2, "512-B2M-ToMqtt",
"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",
2, "512-B2M-ToMqtt",
"512-B2R-ToRest");
}
private void sendData(String inputMqtt2Mqtt, String inputRest2Rest, String inputMqtt2Rest, String inputRest2Mqtt) {
handler.publish(TOPIC_MQTT_2_MQTT_RECEIVE, inputMqtt2Mqtt.getBytes());
senderRest2Rest.request().put(Entity.entity(inputRest2Rest, MediaType.TEXT_PLAIN_TYPE));
handler.publish(TOPIC_MQTT_2_REST_RECEIVE, inputMqtt2Rest.getBytes());
senderRest2Mqtt.request().put(Entity.entity(inputRest2Mqtt, MediaType.TEXT_PLAIN_TYPE));
}
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() {
return dataRest2Rest.request().get().readEntity(String.class);
}
private String readMqtt2Rest() {
return dataMqtt2Rest.request().get().readEntity(String.class);
}
private String readBoth2Rest() {
return dataBoth2Rest.request().get().readEntity(String.class);
}
@Override
protected void createModel() {
// Setting value for Input without dependencies does not trigger any updates
model = new A();
model.setMqtt2MqttInput("100");
model.setRest2RestInput("200");
model.setMqtt2RestInput("300");
model.setRest2MqttInput("400");
model.setBoth2BothInput("500");
}
@Override
protected void setupReceiverAndConnect(boolean writeCurrentValue) throws IOException {
model.ragconnectSetupMqttWaitUntilReady(2, TimeUnit.SECONDS);
handler = new MqttHandler().dontSendWelcomeMessage().setHost(TestUtils.getMqttHost());
assertTrue(handler.waitUntilReady(2, TimeUnit.SECONDS));
model.addDependencyMqtt2Mqtt(model);
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;
dataMqtt2Mqtt.lastStringValue = new String(bytes);
});
handler.newConnection(TOPIC_REST_2_MQTT_SEND, bytes -> {
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(mqttUri(TOPIC_MQTT_2_MQTT_RECEIVE));
model.connectMqtt2MqttOutput(mqttUri(TOPIC_MQTT_2_MQTT_SEND), writeCurrentValue);
model.connectMqtt2RestInput(mqttUri(TOPIC_MQTT_2_REST_RECEIVE));
model.connectMqtt2RestOutput(restUri(PATH_MQTT_2_REST_SEND, REST_PORT), writeCurrentValue);
model.connectRest2MqttInput(restUri(PATH_REST_2_MQTT_RECEIVE, REST_PORT));
model.connectRest2MqttOutput(mqttUri(TOPIC_REST_2_MQTT_SEND), writeCurrentValue);
model.connectRest2RestInput(restUri(PATH_REST_2_REST_RECEIVE, REST_PORT));
model.connectRest2RestOutput(restUri(PATH_REST_2_REST_SEND, REST_PORT), writeCurrentValue);
model.connectBoth2BothInput(mqttUri(TOPIC_BOTH_MQTT_RECEIVE));
model.connectBoth2BothInput(restUri(PATH_BOTH_REST_RECEIVE, REST_PORT));
model.connectBoth2MqttOutput(mqttUri(TOPIC_BOTH_2_MQTT_SEND), writeCurrentValue);
model.connectBoth2RestOutput(restUri(PATH_BOTH_2_REST_SEND, REST_PORT), writeCurrentValue);
}
private static class ReceiverData {
String lastStringValue;
int numberOfStringValues = 0;
public void assertEqualData(int expectedNumberOfValues, String expectedLastValue) {
assertEquals(expectedNumberOfValues, this.numberOfStringValues);
assertEquals(expectedLastValue, this.lastStringValue);
}
}
}
syntax = "proto3";
package config;
message RobotConfig {
double speed = 1;
}
\ No newline at end of file
syntax = "proto3";
package robot;
message RobotState {
message Position {
double x = 1;
double y = 2;
double z = 3;
}
message Orientation {
double x = 1;
double y = 2;
double z = 3;
double w = 4;
}
message LinearTwist {
double x = 1;
double y = 2;
double z = 3;
}
message AngularTwist {
double x = 1;
double y = 2;
double z = 3;
}
string name = 1;
Position position = 2;
Orientation orientation = 3;
LinearTwist linear_twist = 4;
AngularTwist angular_twist = 5;
}
\ No newline at end of file
syntax = "proto3";
package plan;
message Trajectory {
message Position {
double x = 1;
double y = 2;
double z = 3;
}
message Orientation {
double x = 1;
double y = 2;
double z = 3;
double w = 4;
}
enum PlanningMode {
FLUID = 0;
CARTESIAN = 1;
}
message Pose {
Position position = 1;
Orientation orientation = 2;
PlanningMode mode = 3;
}
repeated Pose pose = 1;
bool loop = 2;
}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
<Logger name="org.eclipse.jetty" level="info" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
</Configuration>
...@@ -2,3 +2,4 @@ rootProject.name = 'ragconnect' ...@@ -2,3 +2,4 @@ rootProject.name = 'ragconnect'
include 'relast-preprocessor' include 'relast-preprocessor'
include 'ragconnect.base' include 'ragconnect.base'
include 'ragconnect.tests'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment