Commit 70ccb958 authored by René Schöne's avatar René Schöne
Browse files

Harmonize test structure.

parent 8d587b45
Pipeline #8682 passed with stages
in 7 minutes and 11 seconds
...@@ -43,13 +43,16 @@ public class DefaultOnlyReadTest extends AbstractMqttTest { ...@@ -43,13 +43,16 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
private MqttHandler sender; private MqttHandler sender;
@Override @Override
public void closeConnections() { protected void createModel() {
if (sender != null) { model = new A();
sender.close(); integers = new NativeTypes();
} model.addNativeTypes(integers);
if (model != null) { floats = new NativeTypes();
model.ragconnectCloseConnections(); model.addNativeTypes(floats);
} chars = new NativeTypes();
model.addNativeTypes(chars);
allBoxed = new BoxedTypes();
model.addBoxedTypes(allBoxed);
} }
@Override @Override
...@@ -74,6 +77,11 @@ public class DefaultOnlyReadTest extends AbstractMqttTest { ...@@ -74,6 +77,11 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
assertTrue(sender.waitUntilReady(2, TimeUnit.SECONDS)); assertTrue(sender.waitUntilReady(2, TimeUnit.SECONDS));
} }
@Override
protected void communicateSendInitialValue() {
// empty
}
@Override @Override
protected void communicateOnlyUpdatedValue() throws InterruptedException { protected void communicateOnlyUpdatedValue() throws InterruptedException {
final int expectedIntValue = 1; final int expectedIntValue = 1;
...@@ -118,21 +126,13 @@ public class DefaultOnlyReadTest extends AbstractMqttTest { ...@@ -118,21 +126,13 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
} }
@Override @Override
protected void communicateSendInitialValue() { public void closeConnections() {
// empty if (sender != null) {
sender.close();
}
if (model != null) {
model.ragconnectCloseConnections();
} }
@Override
protected void createModel() {
model = new A();
integers = new NativeTypes();
model.addNativeTypes(integers);
floats = new NativeTypes();
model.addNativeTypes(floats);
chars = new NativeTypes();
model.addNativeTypes(chars);
allBoxed = new BoxedTypes();
model.addBoxedTypes(allBoxed);
} }
} }
...@@ -43,61 +43,6 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest { ...@@ -43,61 +43,6 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
private MqttHandler receiver; private MqttHandler receiver;
private ReceiverData data; private ReceiverData data;
@Override
public void closeConnections() {
if (receiver != null) {
receiver.close();
}
if (model != null) {
model.ragconnectCloseConnections();
}
}
@Override
protected void communicateSendInitialValue() throws InterruptedException {
// check initial value
TestUtils.waitForMqtt();
checkData(1, 1, 1.1, 'a', "ab");
// set new value
setData("2", "2.2", "cd");
// check new value
TestUtils.waitForMqtt();
checkData(2, 2, 2.2, 'c', "cd");
// set new value
setData("3", "3.2", "ee");
// check new value
TestUtils.waitForMqtt();
checkData(3, 3, 3.2, 'e', "ee");
}
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
// check initial value (will be default values)
TestUtils.waitForMqtt();
checkData(0, null, null, null, null);
// set new value
setData("2", "2.2", "cd");
// check new value
TestUtils.waitForMqtt();
checkData(1, 2, 2.2, 'c', "cd");
// set new value
setData("3", "3.2", "ee");
// check new value
TestUtils.waitForMqtt();
checkData(2, 3, 3.2, 'e', "ee");
}
@Override @Override
protected void createModel() { protected void createModel() {
model = new A(); model = new A();
...@@ -211,6 +156,58 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest { ...@@ -211,6 +156,58 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
boxedChars.connectCharValue(mqttUri(TOPIC_BOXED_CHARACTER), writeCurrentValue); boxedChars.connectCharValue(mqttUri(TOPIC_BOXED_CHARACTER), writeCurrentValue);
} }
@Override
protected void communicateSendInitialValue() throws InterruptedException {
// check initial value
TestUtils.waitForMqtt();
checkData(1, 1, 1.1, 'a', "ab");
// set new value
setData("2", "2.2", "cd");
// check new value
TestUtils.waitForMqtt();
checkData(2, 2, 2.2, 'c', "cd");
// set new value
setData("3", "3.2", "ee");
// check new value
TestUtils.waitForMqtt();
checkData(3, 3, 3.2, 'e', "ee");
}
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
// check initial value (will be default values)
TestUtils.waitForMqtt();
checkData(0, null, null, null, null);
// set new value
setData("2", "2.2", "cd");
// check new value
TestUtils.waitForMqtt();
checkData(1, 2, 2.2, 'c', "cd");
// set new value
setData("3", "3.2", "ee");
// check new value
TestUtils.waitForMqtt();
checkData(2, 3, 3.2, 'e', "ee");
}
@Override
public void closeConnections() {
if (receiver != null) {
receiver.close();
}
if (model != null) {
model.ragconnectCloseConnections();
}
}
private void setData(String integerDriver, String floatDriver, String stringDriver) { private void setData(String integerDriver, String floatDriver, String stringDriver) {
nativeIntegers.setDriverSyn(integerDriver); nativeIntegers.setDriverSyn(integerDriver);
nativeFloats.setDriverSyn(floatDriver); nativeFloats.setDriverSyn(floatDriver);
......
...@@ -19,7 +19,7 @@ import static org.jastadd.ragconnect.tests.TestUtils.exec; ...@@ -19,7 +19,7 @@ import static org.jastadd.ragconnect.tests.TestUtils.exec;
import static org.jastadd.ragconnect.tests.TestUtils.readFile; import static org.jastadd.ragconnect.tests.TestUtils.readFile;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
class Errors { public class Errors {
private static final Logger logger = LogManager.getLogger(Errors.class); private static final Logger logger = LogManager.getLogger(Errors.class);
private static final String FILENAME_PATTERN = "$FILENAME"; private static final String FILENAME_PATTERN = "$FILENAME";
......
...@@ -37,16 +37,70 @@ public class ExampleTest extends AbstractMqttTest { ...@@ -37,16 +37,70 @@ public class ExampleTest extends AbstractMqttTest {
} }
@Override @Override
public void closeConnections() { protected void createModel() {
if (handler != null) { model = new Model();
handler.close();
} ZoneModel zoneModel = new ZoneModel();
if (model != null) {
model.ragconnectCloseConnections(); IntPosition firstPosition = makePosition(0, 0, 0);
} IntPosition secondPosition = makePosition(-1, 0, 0);
IntPosition thirdPosition = makePosition(1, 0, 0);
Zone safetyZone = new Zone();
safetyZone.addCoordinate(new Coordinate(firstPosition));
safetyZone.addCoordinate(new Coordinate(secondPosition));
safetyZone.addCoordinate(new Coordinate(thirdPosition));
zoneModel.addSafetyZone(safetyZone);
model.setZoneModel(zoneModel);
robotArm = new RobotArm();
link1 = new Link();
link1.setName("joint1");
link1.setCurrentPosition(firstPosition);
link2 = new Link();
link2.setName("joint2");
link2.setCurrentPosition(secondPosition);
EndEffector endEffector = new EndEffector();
endEffector.setName("gripper");
endEffector.setCurrentPosition(makePosition(2, 2, 3));
robotArm.addLink(link1);
robotArm.addLink(link2);
robotArm.setEndEffector(endEffector);
model.setRobotArm(robotArm);
} }
@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));
// add dependencies
robotArm.addDependency1(link1);
robotArm.addDependency1(link2);
robotArm.addDependency1(robotArm.getEndEffector());
data = new ReceiverData();
handler.newConnection(TOPIC_CONFIG, bytes -> {
data.numberOfConfigs += 1;
try {
data.lastConfig = RobotConfig.parseFrom(bytes);
data.failedLastConversion = false;
} catch (InvalidProtocolBufferException e) {
data.failedLastConversion = true;
}
});
robotArm.connectAppropriateSpeed(mqttUri(TOPIC_CONFIG), writeCurrentValue);
link1.connectCurrentPosition(mqttUri(TOPIC_JOINT1));
link2.connectCurrentPosition(mqttUri(TOPIC_JOINT2));
}
@Override @Override
protected void communicateSendInitialValue() throws InterruptedException { protected void communicateSendInitialValue() throws InterruptedException {
...@@ -182,6 +236,16 @@ public class ExampleTest extends AbstractMqttTest { ...@@ -182,6 +236,16 @@ public class ExampleTest extends AbstractMqttTest {
assertFalse(data.failedLastConversion); assertFalse(data.failedLastConversion);
} }
@Override
public void closeConnections() {
if (handler != null) {
handler.close();
}
if (model != null) {
model.ragconnectCloseConnections();
}
}
@Test @Test
public void testFailedConversion() throws IOException { public void testFailedConversion() throws IOException {
createModel(); createModel();
...@@ -200,72 +264,6 @@ public class ExampleTest extends AbstractMqttTest { ...@@ -200,72 +264,6 @@ public class ExampleTest extends AbstractMqttTest {
); );
} }
@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));
// add dependencies
robotArm.addDependency1(link1);
robotArm.addDependency1(link2);
robotArm.addDependency1(robotArm.getEndEffector());
data = new ReceiverData();
handler.newConnection(TOPIC_CONFIG, bytes -> {
data.numberOfConfigs += 1;
try {
data.lastConfig = RobotConfig.parseFrom(bytes);
data.failedLastConversion = false;
} catch (InvalidProtocolBufferException e) {
data.failedLastConversion = true;
}
});
robotArm.connectAppropriateSpeed(mqttUri(TOPIC_CONFIG), writeCurrentValue);
link1.connectCurrentPosition(mqttUri(TOPIC_JOINT1));
link2.connectCurrentPosition(mqttUri(TOPIC_JOINT2));
}
@Override
protected void createModel() {
model = new Model();
ZoneModel zoneModel = new ZoneModel();
IntPosition firstPosition = makePosition(0, 0, 0);
IntPosition secondPosition = makePosition(-1, 0, 0);
IntPosition thirdPosition = makePosition(1, 0, 0);
Zone safetyZone = new Zone();
safetyZone.addCoordinate(new Coordinate(firstPosition));
safetyZone.addCoordinate(new Coordinate(secondPosition));
safetyZone.addCoordinate(new Coordinate(thirdPosition));
zoneModel.addSafetyZone(safetyZone);
model.setZoneModel(zoneModel);
robotArm = new RobotArm();
link1 = new Link();
link1.setName("joint1");
link1.setCurrentPosition(firstPosition);
link2 = new Link();
link2.setName("joint2");
link2.setCurrentPosition(secondPosition);
EndEffector endEffector = new EndEffector();
endEffector.setName("gripper");
endEffector.setCurrentPosition(makePosition(2, 2, 3));
robotArm.addLink(link1);
robotArm.addLink(link2);
robotArm.setEndEffector(endEffector);
model.setRobotArm(robotArm);
}
private static IntPosition makePosition(int x, int y, int z) { private static IntPosition makePosition(int x, int y, int z) {
return IntPosition.of(x, y, z); return IntPosition.of(x, y, z);
} }
......
...@@ -37,78 +37,6 @@ public class Read1Write2Test extends AbstractMqttTest { ...@@ -37,78 +37,6 @@ public class Read1Write2Test extends AbstractMqttTest {
private ReceiverData dataOther1; private ReceiverData dataOther1;
private ReceiverData dataOther2; private ReceiverData dataOther2;
@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, Integer.parseInt(INITIAL_VALUE), prefixed(INITIAL_VALUE), 1, Integer.parseInt(INITIAL_VALUE), prefixed(INITIAL_VALUE));
// set new value
sendData("2", "3");
// check new value
TestUtils.waitForMqtt();
checkData(2, 2, prefixed("2"), 2, 3, prefixed("3"));
// set new value
sendData("4", "4");
// check new value
TestUtils.waitForMqtt();
checkData(3, 4, prefixed("4"), 3, 4, prefixed("4"));
// set new value only for same
setDataOnlySame("77");
// check new value
TestUtils.waitForMqtt();
checkData(4, 77, prefixed("77"), 3, 4, prefixed("4"));
}
private String prefixed(String s) {
return "prefix" + s;
}
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
// check initial value
TestUtils.waitForMqtt();
checkData(0, null, null, 0, null, null);
// set new value
sendData("2", "3");
// check new value
TestUtils.waitForMqtt();
checkData(1, 2, prefixed("2"), 1, 3, prefixed("3"));
// set new value
sendData("4", "4");
// check new value
TestUtils.waitForMqtt();
checkData(2, 4, prefixed("4"), 2, 4, prefixed("4"));
// set new value only for same
setDataOnlySame("77");
// check new value
TestUtils.waitForMqtt();
checkData(3, 77, prefixed("77"), 2, 4, prefixed("4"));
}
@Override @Override
protected void createModel() { protected void createModel() {
// Setting value for Input without dependencies does not trigger any updates // Setting value for Input without dependencies does not trigger any updates
...@@ -183,6 +111,68 @@ public class Read1Write2Test extends AbstractMqttTest { ...@@ -183,6 +111,68 @@ public class Read1Write2Test extends AbstractMqttTest {
other2.connectOutString(mqttUri(TOPIC_DIFFERENT_WRITE2_STRING), writeCurrentValue); other2.connectOutString(mqttUri(TOPIC_DIFFERENT_WRITE2_STRING), writeCurrentValue);
} }
@Override
protected void communicateSendInitialValue() throws InterruptedException {
// check initial value
checkData(1, Integer.parseInt(INITIAL_VALUE), prefixed(INITIAL_VALUE), 1, Integer.parseInt(INITIAL_VALUE), prefixed(INITIAL_VALUE));
// set new value
sendData("2", "3");
// check new value
checkData(2, 2, prefixed("2"), 2, 3, prefixed("3"));
// set new value
sendData("4", "4");
// check new value
checkData(3, 4, prefixed("4"), 3, 4, prefixed("4"));
// set new value only for same
setDataOnlySame("77");
// check new value
checkData(4, 77, prefixed("77"), 3, 4, prefixed("4"));
}
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
// check initial value
checkData(0, null, null, 0, null, null);
// set new value
sendData("2", "3");
// check new value
checkData(1, 2, prefixed("2"), 1, 3, prefixed("3"));
// set new value
sendData("4", "4");
// check new value
checkData(2, 4, prefixed("4"), 2, 4, prefixed("4"));
// set new value only for same
setDataOnlySame("78");
// check new value
checkData(3, 78, prefixed("78"), 2, 4, prefixed("4"));
}
@Override
public void closeConnections() {
if (handler != null) {
handler.close();
}
if (model != null) {
model.ragconnectCloseConnections();
}
}
private String prefixed(String s) {
return "prefix" + s;
}
private void sendData(String inputSame, String inputDifferent) { private void sendData(String inputSame, String inputDifferent) {
handler.publish(TOPIC_SAME_READ, inputSame.getBytes()); handler.publish(TOPIC_SAME_READ, inputSame.getBytes());
handler.publish(TOPIC_DIFFERENT_READ, inputDifferent.getBytes()); handler.publish(TOPIC_DIFFERENT_READ, inputDifferent.getBytes());
...@@ -194,32 +184,13 @@ public class Read1Write2Test extends AbstractMqttTest { ...@@ -194,32 +184,13 @@ public class Read1Write2Test extends AbstractMqttTest {
private void checkData(int numberOfSameValues, Integer lastSameIntValue, String lastSameStringValue, private void checkData(int numberOfSameValues, Integer lastSameIntValue, String lastSameStringValue,
int numberOfDifferentValues, Integer lastDifferentIntValue, int numberOfDifferentValues, Integer lastDifferentIntValue,
String lastDifferentStringValue) { String lastDifferentStringValue) throws InterruptedException {
/* the value "-2" is never used in the test, so a test will always fail comparing to this value TestUtils.waitForMqtt();
especially, it is not the initial value */ dataSame.assertEqualData(numberOfSameValues, lastSameIntValue, lastSameStringValue);
ReceiverData expectedDataSame = ReceiverData.of( dataOther1.assertEqualData(numberOfDifferentValues,
numberOfSameValues,