Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
JastAdd
RagConnect
Commits
70ccb958
Commit
70ccb958
authored
Jan 22, 2021
by
René Schöne
Browse files
Harmonize test structure.
parent
8d587b45
Pipeline
#8682
passed with stages
in 7 minutes and 11 seconds
Changes
9
Pipelines
1
Show whitespace changes
Inline
Side-by-side
ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/DefaultOnlyReadTest.java
View file @
70ccb958
...
...
@@ -43,13 +43,16 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
private
MqttHandler
sender
;
@Override
public
void
closeConnections
()
{
if
(
sender
!=
null
)
{
sender
.
close
();
}
if
(
model
!=
null
)
{
model
.
ragconnectCloseConnections
();
}
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
);
}
@Override
...
...
@@ -74,6 +77,11 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
assertTrue
(
sender
.
waitUntilReady
(
2
,
TimeUnit
.
SECONDS
));
}
@Override
protected
void
communicateSendInitialValue
()
{
// empty
}
@Override
protected
void
communicateOnlyUpdatedValue
()
throws
InterruptedException
{
final
int
expectedIntValue
=
1
;
...
...
@@ -118,21 +126,13 @@ public class DefaultOnlyReadTest extends AbstractMqttTest {
}
@Override
protected
void
communicateSendInitialValue
()
{
// empty
public
void
closeConnections
()
{
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
);
}
}
ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/DefaultOnlyWriteTest.java
View file @
70ccb958
...
...
@@ -43,61 +43,6 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
private
MqttHandler
receiver
;
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
protected
void
createModel
()
{
model
=
new
A
();
...
...
@@ -211,6 +156,58 @@ public class DefaultOnlyWriteTest extends AbstractMqttTest {
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
)
{
nativeIntegers
.
setDriverSyn
(
integerDriver
);
nativeFloats
.
setDriverSyn
(
floatDriver
);
...
...
ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/Errors.java
View file @
70ccb958
...
...
@@ -19,7 +19,7 @@ import static org.jastadd.ragconnect.tests.TestUtils.exec;
import
static
org
.
jastadd
.
ragconnect
.
tests
.
TestUtils
.
readFile
;
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
String
FILENAME_PATTERN
=
"$FILENAME"
;
...
...
ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/ExampleTest.java
View file @
70ccb958
...
...
@@ -37,16 +37,70 @@ public class ExampleTest extends AbstractMqttTest {
}
@Override
public
void
closeConnections
()
{
if
(
handler
!=
null
)
{
handler
.
close
();
}
if
(
model
!=
null
)
{
model
.
ragconnectCloseConnections
();
}
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
);
}
@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
communicateSendInitialValue
()
throws
InterruptedException
{
...
...
@@ -182,6 +236,16 @@ public class ExampleTest extends AbstractMqttTest {
assertFalse
(
data
.
failedLastConversion
);
}
@Override
public
void
closeConnections
()
{
if
(
handler
!=
null
)
{
handler
.
close
();
}
if
(
model
!=
null
)
{
model
.
ragconnectCloseConnections
();
}
}
@Test
public
void
testFailedConversion
()
throws
IOException
{
createModel
();
...
...
@@ -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
)
{
return
IntPosition
.
of
(
x
,
y
,
z
);
}
...
...
ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/Read1Write2Test.java
View file @
70ccb958
...
...
@@ -37,78 +37,6 @@ public class Read1Write2Test extends AbstractMqttTest {
private
ReceiverData
dataOther1
;
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
protected
void
createModel
()
{
// Setting value for Input without dependencies does not trigger any updates
...
...
@@ -183,6 +111,68 @@ public class Read1Write2Test extends AbstractMqttTest {
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
)
{
handler
.
publish
(
TOPIC_SAME_READ
,
inputSame
.
getBytes
());
handler
.
publish
(
TOPIC_DIFFERENT_READ
,
inputDifferent
.
getBytes
());
...
...
@@ -194,32 +184,13 @@ public class Read1Write2Test extends AbstractMqttTest {
private
void
checkData
(
int
numberOfSameValues
,
Integer
lastSameIntValue
,
String
lastSameStringValue
,
int
numberOfDifferentValues
,
Integer
lastDifferentIntValue
,
String
lastDifferentStringValue
)
{
/* the value "-2" is never used in the test, so a test will always fail comparing to this value
especially, it is not the initial value */
ReceiverData
expectedDataSame
=
ReceiverData
.
of
(
numberOfSameValues
,
lastSameIntValue
!=
null
?
lastSameIntValue
:
-
2
,
lastSameStringValue
);
compareData
(
expectedDataSame
,
dataSame
);
ReceiverData
expectedDataDifferent
=
ReceiverData
.
of
(
numberOfDifferentValues
,
lastDifferentIntValue
!=
null
?
lastDifferentIntValue
:
-
2
,
lastDifferentStringValue
);
compareData
(
expectedDataDifferent
,
dataOther1
);
compareData
(
expectedDataDifferent
,
dataOther2
);
}
private
void
compareData
(
ReceiverData
expectedData
,
ReceiverData
actual
)
{
assertEquals
(
expectedData
.
numberOfIntValues
,
actual
.
numberOfIntValues
);
assertEquals
(
expectedData
.
numberOfStringValues
,
actual
.
numberOfStringValues
);
if
(
expectedData
.
numberOfIntValues
>
0
)
{
assertEquals
(
expectedData
.
lastIntValue
,
actual
.
lastIntValue
);
}
if
(
expectedData
.
numberOfStringValues
>
0
)
{
assertEquals
(
expectedData
.
lastStringValue
,
actual
.
lastStringValue
);
}
String
lastDifferentStringValue
)
throws
InterruptedException
{
TestUtils
.
waitForMqtt
();
dataSame
.
assertEqualData
(
numberOfSameValues
,
lastSameIntValue
,
lastSameStringValue
);
dataOther1
.
assertEqualData
(
numberOfDifferentValues
,
lastDifferentIntValue
,
lastDifferentStringValue
);
dataOther2
.
assertEqualData
(
numberOfDifferentValues
,
lastDifferentIntValue
,
lastDifferentStringValue
);
}
private
static
class
ReceiverData
{
...
...
@@ -228,14 +199,19 @@ public class Read1Write2Test extends AbstractMqttTest {
String
lastStringValue
;
int
numberOfStringValues
=
0
;
static
ReceiverData
of
(
int
numberOfValues
,
int
lastIntValue
,
String
lastStringValue
)
{
ReceiverData
result
=
new
ReceiverData
();
result
.
lastIntValue
=
lastIntValue
;
result
.
lastStringValue
=
lastStringValue
;
result
.
numberOfIntValues
=
numberOfValues
;
result
.
numberOfStringValues
=
numberOfValues
;
return
result
;
void
assertEqualData
(
int
expectedNumberOfValues
,
Integer
expectedLastIntValue
,
String
expectedLastStringValue
)
{
/* the value "-2" is never used in the test, so a test will always fail comparing to this value
especially, it is not the initial value */
assertEquals
(
expectedNumberOfValues
,
this
.
numberOfIntValues
);
assertEquals
(
expectedNumberOfValues
,
this
.
numberOfStringValues
);
if
(
expectedNumberOfValues
>
0
)
{
assertEquals
(
expectedLastIntValue
!=
null
?
expectedLastIntValue
:
-
2
,
this
.
lastIntValue
);
}
if
(
expectedNumberOfValues
>
0
)
{
assertEquals
(
expectedLastStringValue
,
this
.
lastStringValue
);
}
}