Skip to content
Snippets Groups Projects
Commit e8fec8cc authored by René Schöne's avatar René Schöne
Browse files

Extend testcase of "tree allowed tokens" with mapping nonterminal <-> primitive data type.

- also merged shared functionality of splitted test (manual/incremental)
parent e4029cd2
No related branches found
No related tags found
1 merge request!4Resolve "Subtree update"
Pipeline #9121 passed
Showing
with 365 additions and 355 deletions
......@@ -62,7 +62,6 @@ aspect AttributesForMustache {
syn String MEndpointDefinition.lastDefinitionToType() = lastDefinition().toType();
syn String MEndpointDefinition.lastResult() = lastDefinition().outputVarName();
syn String MEndpointDefinition.condition() {
// TODO check which case is valid for type endpoints
if (lastDefinition().mappingDef().getToType().isArray()) {
return "java.util.Arrays.equals(" + preemptiveExpectedValue() + ", " + lastResult() + ")";
}
......@@ -130,7 +129,6 @@ aspect AttributesForMustache {
syn String MTypeSendDefinition.sender() = "_sender_" + typeName();
syn String MTypeSendDefinition.lastValue() = "_lastValue" + typeName();
// TODO check if this is correct (type does not have token)
syn String MTypeSendDefinition.tokenResetMethod() = "get" + typeName() + "_reset";
syn boolean MTypeSendDefinition.shouldSendValue() = endpointDef().asTypeEndpointDefinition().shouldSendValue();
......
......@@ -65,6 +65,14 @@ aspect Computation {
eq Nameable.isNameable() = true;
}
aspect Testing {
class ReceiverRoot implements org.jastadd.ragconnect.tests.AbstractTreeTest.TestWrapperReceiverRoot {}
class Alfa implements org.jastadd.ragconnect.tests.AbstractTreeTest.TestWrapperAlfa {}
class Bravo implements org.jastadd.ragconnect.tests.AbstractTreeTest.TestWrapperBravo {}
class Charlie implements org.jastadd.ragconnect.tests.AbstractTreeTest.TestWrapperCharlie {}
class Delta implements org.jastadd.ragconnect.tests.AbstractTreeTest.TestWrapperDelta {}
}
aspect NameResolution {
@Override
protected String Nameable.customID() {
......
......@@ -5,3 +5,22 @@ receive SenderRoot.Input1WhenFlagIsTrue ;
receive SenderRoot.Input1WhenFlagIsFalse ;
receive SenderRoot.Input2 ;
receive SenderRoot.Input3 ;
send tree SenderRoot.AlfaPrimitive using Alfa2String ;
receive tree ReceiverRoot.AlfaPrimitive using String2Alfa ;
Alfa2String maps Alfa alfa to String {:
StringBuilder sb = new StringBuilder();
sb.append(alfa.getID()).append(":").append(alfa.getStringValue()).append(";");
return sb.toString();
:}
String2Alfa maps String s to Alfa {:
int colonIndex = s.indexOf(":");
int id = Integer.parseInt(s.substring(0, colonIndex));
String value = s.substring(colonIndex + 1, s.length() - 1);
Alfa result = new Alfa();
result.setID(id);
result.setStringValue(value);
return result;
:}
......@@ -21,6 +21,12 @@ aspect Computation {
return result;
}
syn Alfa SenderRoot.getAlfaPrimitive() {
Alfa result = new Alfa();
result.setStringValue(getInput2());
return result;
}
syn boolean ASTNode.isNameable() = false;
eq Nameable.isNameable() = true;
}
......@@ -28,6 +34,10 @@ aspect Computation {
aspect Enum {
public enum MyEnum { FALSE, TRUE; }
}
aspect Testing {
class ReceiverRoot implements org.jastadd.ragconnect.tests.AbstractTreeAllowedTokensTest.TestWrapperReceiverRoot {}
class Alfa implements org.jastadd.ragconnect.tests.AbstractTreeAllowedTokensTest.TestWrapperAlfa {}
}
aspect NameResolution {
// this should most likely be generated
......
Root ::= SenderRoot* ReceiverRoot* ;
Nameable ::= <ID:int> ;
SenderRoot : Nameable ::= <Flag:boolean> <Input1WhenFlagIsTrue:int> <Input1WhenFlagIsFalse:int> <Input2:String> <Input3:double> /Alfa/ ;
SenderRoot : Nameable ::= <Flag:boolean> <Input1WhenFlagIsTrue:int> <Input1WhenFlagIsFalse:int> <Input2:String> <Input3:double> /Alfa/ /AlfaPrimitive:Alfa/ ;
ReceiverRoot : Nameable ::= Alfa ;
ReceiverRoot : Nameable ::= Alfa AlfaPrimitive:Alfa ;
Alfa : Nameable ::= <BooleanValue:boolean> <IntValue:int> <ShortValue:short> <LongValue:long> <FloatValue:float> <DoubleValue:double> <CharValue:char> <StringValue:String> <InstantValue:java.time.Instant> <PeriodValue:java.time.Period> <EnumValue:MyEnum> ;
......@@ -3,3 +3,5 @@ SenderRoot.Alfa canDependOn SenderRoot.Input1WhenFlagIsTrue as Input1WhenFlagIsT
SenderRoot.Alfa canDependOn SenderRoot.Input1WhenFlagIsFalse as Input1WhenFlagIsFalseDependency ;
SenderRoot.Alfa canDependOn SenderRoot.Input2 as Input2Dependency ;
SenderRoot.Alfa canDependOn SenderRoot.Input3 as Input3Dependency ;
SenderRoot.AlfaPrimitive canDependOn SenderRoot.Input2 as PrimitiveInput2Dependency ;
package org.jastadd.ragconnect.tests;
import java.io.IOException;
import java.time.Instant;
import java.time.Period;
import static org.junit.jupiter.api.Assertions.*;
/**
* Base class for test cases "tree allowed tokens manual" and "tree allowed tokens incremental".
*
......@@ -12,92 +18,133 @@ public abstract class AbstractTreeAllowedTokensTest extends AbstractMqttTest {
protected static final String TOPIC_INPUT2 = "input2";
protected static final String TOPIC_INPUT3 = "input3";
protected static final String TOPIC_ALFA = "alfa";
protected static final String TOPIC_ALFA_PRIMITIVE = "primitive";
protected static final String INSTANT_A = "1999-12-03T10:15:30Z";
protected static final String INSTANT_B = "2011-12-03T10:15:30Z";
protected static final String INSTANT_C = "2012-12-03T10:15:30Z";
protected TestWrapperReceiverRoot receiverRoot;
public interface TestWrapperReceiverRoot {
TestWrapperAlfa getAlfa();
TestWrapperAlfa getAlfaPrimitive();
boolean connectAlfa(String mqttUri) throws IOException;
boolean connectAlfaPrimitive(String mqttUri) throws IOException;
}
public interface TestWrapperAlfa {
boolean getBooleanValue();
int getIntValue();
short getShortValue();
long getLongValue();
float getFloatValue();
double getDoubleValue();
String getStringValue();
char getCharValue();
Instant getInstantValue();
Period getPeriodValue();
}
@Override
protected void communicateSendInitialValue() throws InterruptedException {
checkTree(1, false, 0, INSTANT_A, 0);
checkPrimitiveTree(1, INSTANT_A);
// flag: false. sendInput1WhenFalse(2)
sendInput1WhenFalse(2);
checkTree(2, false, 2, INSTANT_A, 0);
checkPrimitiveTree(1, INSTANT_A);
// flag: false. setFlag(false) -> no change
setFlag(false);
checkTree(2, false, 2, INSTANT_A, 0);
checkPrimitiveTree(1, INSTANT_A);
// flag: false. setFlag(true)
setFlag(true);
checkTree(3, true, 0, INSTANT_A, 0);
checkPrimitiveTree(1, INSTANT_A);
// flag: true. sendInput1WhenFalse(3) -> no change
sendInput1WhenFalse(3);
checkTree(3, true, 0, INSTANT_A, 0);
checkPrimitiveTree(1, INSTANT_A);
// flag: true. sendInput1WhenTrue(4)
sendInput1WhenTrue(4);
checkTree(4, true, 4, INSTANT_A, 0);
checkPrimitiveTree(1, INSTANT_A);
// sendInput2(INSTANT_B)
sendInput2(INSTANT_B);
checkTree(5, true, 4, INSTANT_B, 0);
checkPrimitiveTree(2, INSTANT_B);
// sendInput2(INSTANT_B) -> no change
sendInput2(INSTANT_B);
checkTree(5, true, 4, INSTANT_B, 0);
checkPrimitiveTree(2, INSTANT_B);
// sendInput3(5.1)
sendInput3(5.1);
checkTree(6, true, 4, INSTANT_B, 5.1);
checkPrimitiveTree(2, INSTANT_B);
// sendInput3(5.1) -> no change
sendInput3(5.1);
checkTree(6, true, 4, INSTANT_B, 5.1);
checkPrimitiveTree(2, INSTANT_B);
}
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
checkTree(0, false, null, null, 0);
checkPrimitiveTree(0, null);
// flag: false. sendInput1WhenFalse(12)
sendInput1WhenFalse(12);
checkTree(1, false, 12, INSTANT_A, 0);
checkPrimitiveTree(0, null);
// flag: false. setFlag(false) -> no change
setFlag(false);
checkTree(1, false, 12, INSTANT_A, 0);
checkPrimitiveTree(0, null);
// flag: false. setFlag(true)
setFlag(true);
checkTree(2, true, 0, INSTANT_A, 0);
checkPrimitiveTree(0, null);
// flag: true. sendInput1WhenFalse(13) -> no change
sendInput1WhenFalse(13);
checkTree(2, true, 0, INSTANT_A, 0);
checkPrimitiveTree(0, null);
// flag: true. sendInput1WhenTrue(14)
sendInput1WhenTrue(14);
checkTree(3, true, 14, INSTANT_A, 0);
checkPrimitiveTree(0, null);
// sendInput2(INSTANT_C)
sendInput2(INSTANT_C);
checkTree(4, true, 14, INSTANT_C, 0);
checkPrimitiveTree(1, INSTANT_C);
// sendInput2(INSTANT_C) -> no change
sendInput2(INSTANT_C);
checkTree(4, true, 14, INSTANT_C, 0);
checkPrimitiveTree(1, INSTANT_C);
// sendInput3(15.1)
sendInput3(15.1);
checkTree(5, true, 14, INSTANT_C, 15.1);
checkPrimitiveTree(1, INSTANT_C);
// sendInput3(15.1) -> no change
sendInput3(15.1);
checkTree(5, true, 14, INSTANT_C, 15.1);
checkPrimitiveTree(1, INSTANT_C);
}
protected void sendInput1WhenFalse(int value) {
......@@ -118,12 +165,52 @@ public abstract class AbstractTreeAllowedTokensTest extends AbstractMqttTest {
protected abstract void setFlag(boolean value);
protected abstract void checkTree(int expectedCount, boolean expectedBooleanValue, Integer expectedIntValue, String expectedStringValue, double expectedDoubleValue) throws InterruptedException;
protected void checkTree(int expectedCount, boolean expectedBooleanValue, Integer expectedIntValue, String expectedStringValue, double expectedDoubleValue) throws InterruptedException {
TestUtils.waitForMqtt();
assertEquals(expectedCount, data.numberOfTrees);
if (expectedStringValue == null) {
assertNull(receiverRoot.getAlfa());
} else {
assertNotNull(receiverRoot.getAlfa());
TestWrapperAlfa alfa = receiverRoot.getAlfa();
assertEquals(expectedBooleanValue, alfa.getBooleanValue());
assertEquals(expectedIntValue, alfa.getIntValue());
assertEquals(expectedIntValue.shortValue(), alfa.getShortValue());
assertEquals(expectedIntValue.longValue(), alfa.getLongValue());
assertEquals(expectedDoubleValue, alfa.getFloatValue(), TestUtils.DELTA);
assertEquals(expectedDoubleValue, alfa.getDoubleValue(), TestUtils.DELTA);
assertEquals(expectedStringValue, alfa.getStringValue());
assertEquals(expectedStringValue.charAt(0), alfa.getCharValue());
assertEquals(Instant.parse(expectedStringValue), alfa.getInstantValue());
assertEquals(Period.of(0, 0, expectedIntValue), alfa.getPeriodValue());
checkMyEnum(alfa, expectedBooleanValue);
}
}
protected void checkPrimitiveTree(int expectedCount, String expectedStringValue) {
assertEquals(expectedCount, data.numberOfPrimitiveTrees);
if (expectedStringValue == null) {
assertNull(receiverRoot.getAlfaPrimitive());
} else {
assertNotNull(receiverRoot.getAlfaPrimitive());
TestWrapperAlfa alfaPrimitive = receiverRoot.getAlfaPrimitive();
assertEquals(expectedStringValue, alfaPrimitive.getStringValue());
}
}
protected abstract void checkMyEnum(TestWrapperAlfa alfa, boolean expectedBooleanValue);
protected ReceiverData data;
protected static class ReceiverData {
int numberOfTrees = 0;
int numberOfPrimitiveTrees = 0;
}
}
package org.jastadd.ragconnect.tests;
import java.io.IOException;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
/**
* Base class for test cases "tree manual" and "tree incremental".
*
* @author rschoene - Initial contribution
*/
public abstract class AbstractTreeTest extends AbstractMqttTest {
protected static final String TOPIC_ALFA = "alfa";
protected ReceiverData data;
protected TestWrapperReceiverRoot receiverRoot;
public interface TestWrapperReceiverRoot {
TestWrapperAlfa getAlfa();
boolean connectAlfa(String mqttUri) throws IOException;
}
public interface TestWrapperAlfa {
TestWrapperBravo getBravo(int i);
int getNumBravo();
int getNumCharlie();
int getNumDelta();
TestWrapperAlfa getMyself();
TestWrapperBravo getMyBravo();
boolean hasOptionalBravo();
TestWrapperBravo getOptionalBravo();
TestWrapperCharlie getCharlie(int i);
TestWrapperDelta getDelta(int i);
<T extends TestWrapperBravo> List<T> getMultiBravoList();
}
public interface TestWrapperBravo {
TestWrapperCharlie getMyCharlie();
boolean hasOptionalCharlie();
TestWrapperCharlie getOptionalCharlie();
<T extends TestWrapperCharlie> List<T> getMultiCharlieList();
boolean hasSingleBi1Delta();
TestWrapperDelta getSingleBi1Delta();
<T extends TestWrapperDelta> List<T> getMultiBi2DeltaList();
<T extends TestWrapperDelta> List<T> getMultiBi3DeltaList();
}
public interface TestWrapperCharlie {
boolean hasMyAlfa();
TestWrapperAlfa getMyAlfa();
}
public interface TestWrapperDelta {
boolean hasSingleBack1Alfa();
TestWrapperAlfa getSingleBack1Alfa();
boolean hasSingleBack2Alfa();
TestWrapperAlfa getSingleBack2Alfa();
<T extends TestWrapperAlfa> List<T> getMultiBack3AlfaList();
boolean hasSingleBack1Bravo();
TestWrapperBravo getSingleBack1Bravo();
TestWrapperBravo getSingleBack2Bravo();
boolean hasSingleBack2Bravo();
<T extends TestWrapperBravo> List<T> getMultiBack3BravoList();
}
@Override
protected void communicateSendInitialValue() throws InterruptedException {
checkTree(1, 0);
setInput(1);
checkTree(2, 1);
setInput(1);
checkTree(2, 1);
setInput(2);
checkTree(3, 2);
}
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
checkTree(0, null);
setInput(1);
checkTree(1, 1);
setInput(1);
checkTree(1, 1);
setInput(2);
checkTree(2, 2);
}
protected abstract void setInput(int input);
protected void checkTree(int expectedCount, Integer expectedInput) throws InterruptedException {
TestUtils.waitForMqtt();
assertEquals(expectedCount, data.numberOfTrees);
if (expectedInput == null) {
assertNull(receiverRoot.getAlfa());
} else {
assertNotNull(receiverRoot.getAlfa());
TestWrapperAlfa alfa = receiverRoot.getAlfa();
assertEquals(4, alfa.getNumBravo());
assertEquals(4, alfa.getNumCharlie());
assertEquals(4, alfa.getNumDelta());
TestWrapperBravo inputBravo = alfa.getBravo(expectedInput);
TestWrapperCharlie inputCharlie = alfa.getCharlie(expectedInput);
TestWrapperDelta inputDelta = alfa.getDelta(expectedInput);
// Alfa -> Alfa
assertEquals(alfa, alfa.getMyself());
// Alfa -> Bravo
assertEquals(inputBravo, alfa.getMyBravo());
assertTrue(alfa.hasOptionalBravo());
assertEquals(inputBravo, alfa.getOptionalBravo());
assertThat(alfa.getMultiBravoList()).containsExactly(
inputBravo, alfa.getBravo(expectedInput + 1));
// Charlie -> Alfa
for (int i = 0; i < 4; i++) {
TestWrapperCharlie Charlie = alfa.getCharlie(i);
if (i == expectedInput) {
assertTrue(Charlie.hasMyAlfa());
assertEquals(alfa, Charlie.getMyAlfa());
} else {
assertFalse(Charlie.hasMyAlfa());
}
}
// Alfa <-> Delta
for (int i = 0; i < 4; i++) {
TestWrapperDelta Delta = alfa.getDelta(i);
if (i == expectedInput) {
assertTrue(Delta.hasSingleBack1Alfa());
assertEquals(alfa, Delta.getSingleBack1Alfa());
} else {
assertFalse(Delta.hasSingleBack1Alfa());
}
if (i == expectedInput || i == expectedInput + 1) {
assertTrue(Delta.hasSingleBack2Alfa());
assertEquals(alfa, Delta.getSingleBack2Alfa());
assertThat(Delta.getMultiBack3AlfaList()).containsExactly(alfa);
} else {
assertFalse(Delta.hasSingleBack2Alfa());
assertThat(Delta.getMultiBack3AlfaList()).isEmpty();
}
}
// Bravo -> Charlie
for (int i = 0; i < 4; i++) {
TestWrapperBravo Bravo = alfa.getBravo(i);
if (i == expectedInput) {
assertEquals(inputCharlie, Bravo.getMyCharlie());
assertTrue(Bravo.hasOptionalCharlie());
assertEquals(inputCharlie, Bravo.getOptionalCharlie());
assertThat(Bravo.getMultiCharlieList()).containsExactly(
inputCharlie, alfa.getCharlie(expectedInput + 1));
} else {
assertEquals(alfa.getCharlie(0), Bravo.getMyCharlie());
assertFalse(Bravo.hasOptionalCharlie());
assertThat(Bravo.getMultiCharlieList()).isEmpty();
}
}
// Bravo <-> Delta
for (int i = 0; i < 4; i++) {
TestWrapperBravo Bravo = alfa.getBravo(i);
TestWrapperDelta Delta = alfa.getDelta(i);
if (i == expectedInput) {
assertTrue(Bravo.hasSingleBi1Delta());
assertTrue(Delta.hasSingleBack1Bravo());
assertEquals(inputDelta, Bravo.getSingleBi1Delta());
assertEquals(inputBravo, Delta.getSingleBack1Bravo());
assertThat(Bravo.getMultiBi2DeltaList()).containsExactly(
inputDelta, alfa.getDelta(expectedInput + 1));
} else {
assertFalse(Bravo.hasSingleBi1Delta());
assertFalse(Delta.hasSingleBack1Bravo());
assertThat(Bravo.getMultiBi2DeltaList()).isEmpty();
}
if (i == expectedInput || i == expectedInput + 1) {
assertThat(Bravo.getMultiBi3DeltaList()).containsExactly(
inputDelta, alfa.getDelta(expectedInput + 1));
assertTrue(Delta.hasSingleBack2Bravo());
assertEquals(inputBravo, Delta.getSingleBack2Bravo());
assertThat(Delta.getMultiBack3BravoList()).containsExactly(
inputBravo, alfa.getBravo(expectedInput + 1));
} else {
assertThat(Bravo.getMultiBi3DeltaList()).isEmpty();
assertFalse(Delta.hasSingleBack2Bravo());
assertThat(Delta.getMultiBack3BravoList()).isEmpty();
}
}
}
}
protected static class ReceiverData {
int numberOfTrees = 0;
}
}
package org.jastadd.ragconnect.tests;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import treeAllowedTokensInc.ast.*;
import java.io.IOException;
import java.nio.file.Paths;
import java.time.Instant;
import java.time.Period;
import java.util.concurrent.TimeUnit;
import static org.jastadd.ragconnect.tests.TestUtils.mqttUri;
import static org.jastadd.ragconnect.tests.TestUtils.testJaddContainReferenceToJackson;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test case "tree allowed tokens incremental"
*
* @author rschoene - Initial contribution
*/
@Tag("SpecificTest")
public class TreeAllowedTokensIncrementalTest extends AbstractTreeAllowedTokensTest {
private Root model;
private SenderRoot senderRoot;
private ReceiverRoot receiverRoot;
private MqttHandler handler;
@Test
......@@ -41,7 +41,7 @@ public class TreeAllowedTokensIncrementalTest extends AbstractTreeAllowedTokensT
model.addSenderRoot(senderRoot);
receiverRoot = new ReceiverRoot();
model.addReceiverRoot(receiverRoot);
model.addReceiverRoot((ReceiverRoot) receiverRoot);
}
@Override
......@@ -55,6 +55,7 @@ public class TreeAllowedTokensIncrementalTest extends AbstractTreeAllowedTokensT
data = new ReceiverData();
handler.newConnection(TOPIC_ALFA, bytes -> data.numberOfTrees += 1);
handler.newConnection(TOPIC_ALFA_PRIMITIVE, bytes -> data.numberOfPrimitiveTrees += 1);
// connect. important: first receiver, then sender. to not miss initial value.
senderRoot.connectInput1WhenFlagIsFalse(mqttUri(TOPIC_INPUT1FALSE));
......@@ -62,7 +63,9 @@ public class TreeAllowedTokensIncrementalTest extends AbstractTreeAllowedTokensT
senderRoot.connectInput2(mqttUri(TOPIC_INPUT2));
senderRoot.connectInput3(mqttUri(TOPIC_INPUT3));
receiverRoot.connectAlfa(mqttUri(TOPIC_ALFA));
receiverRoot.connectAlfaPrimitive(mqttUri(TOPIC_ALFA_PRIMITIVE));
senderRoot.connectAlfa(mqttUri(TOPIC_ALFA), writeCurrentValue);
senderRoot.connectAlfaPrimitive(mqttUri(TOPIC_ALFA_PRIMITIVE), writeCurrentValue);
}
@Override
......@@ -79,30 +82,8 @@ public class TreeAllowedTokensIncrementalTest extends AbstractTreeAllowedTokensT
senderRoot.setFlag(value);
}
protected void checkTree(int expectedCount, boolean expectedBooleanValue, Integer expectedIntValue, String expectedStringValue, double expectedDoubleValue) throws InterruptedException {
TestUtils.waitForMqtt();
assertEquals(expectedCount, data.numberOfTrees);
if (expectedIntValue == null) {
assertNull(receiverRoot.getAlfa());
} else {
assertNotNull(receiverRoot.getAlfa());
Alfa alfa = receiverRoot.getAlfa();
assertEquals(expectedBooleanValue, alfa.getBooleanValue());
assertEquals(expectedIntValue, alfa.getIntValue());
assertEquals(expectedIntValue.shortValue(), alfa.getShortValue());
assertEquals(expectedIntValue.longValue(), alfa.getLongValue());
assertEquals(expectedDoubleValue, alfa.getFloatValue(), TestUtils.DELTA);
assertEquals(expectedDoubleValue, alfa.getDoubleValue(), TestUtils.DELTA);
assertEquals(expectedStringValue, alfa.getStringValue());
assertEquals(expectedStringValue.charAt(0), alfa.getCharValue());
assertEquals(Instant.parse(expectedStringValue), alfa.getInstantValue());
assertEquals(Period.of(0, 0, expectedIntValue), alfa.getPeriodValue());
assertEquals(expectedBooleanValue ? MyEnum.TRUE : MyEnum.FALSE, alfa.getEnumValue());
}
@Override
protected void checkMyEnum(TestWrapperAlfa alfa, boolean expectedBooleanValue) {
assertEquals(expectedBooleanValue ? MyEnum.TRUE : MyEnum.FALSE, ((Alfa) alfa).getEnumValue());
}
}
......@@ -22,7 +22,6 @@ public class TreeAllowedTokensManualTest extends AbstractTreeAllowedTokensTest {
private Root model;
private SenderRoot senderRoot;
private ReceiverRoot receiverRoot;
private MqttHandler handler;
@Test
......@@ -41,7 +40,7 @@ public class TreeAllowedTokensManualTest extends AbstractTreeAllowedTokensTest {
model.addSenderRoot(senderRoot);
receiverRoot = new ReceiverRoot();
model.addReceiverRoot(receiverRoot);
model.addReceiverRoot((ReceiverRoot) receiverRoot);
}
@Override
......@@ -57,9 +56,11 @@ public class TreeAllowedTokensManualTest extends AbstractTreeAllowedTokensTest {
senderRoot.addInput1WhenFlagIsTrueDependency(senderRoot);
senderRoot.addInput2Dependency(senderRoot);
senderRoot.addInput3Dependency(senderRoot);
senderRoot.addPrimitiveInput2Dependency(senderRoot);
data = new ReceiverData();
handler.newConnection(TOPIC_ALFA, bytes -> data.numberOfTrees += 1);
handler.newConnection(TOPIC_ALFA_PRIMITIVE, bytes -> data.numberOfPrimitiveTrees += 1);
// connect. important: first receiver, then sender. to not miss initial value.
senderRoot.connectInput1WhenFlagIsFalse(mqttUri(TOPIC_INPUT1FALSE));
......@@ -67,7 +68,9 @@ public class TreeAllowedTokensManualTest extends AbstractTreeAllowedTokensTest {
senderRoot.connectInput2(mqttUri(TOPIC_INPUT2));
senderRoot.connectInput3(mqttUri(TOPIC_INPUT3));
receiverRoot.connectAlfa(mqttUri(TOPIC_ALFA));
receiverRoot.connectAlfaPrimitive(mqttUri(TOPIC_ALFA_PRIMITIVE));
senderRoot.connectAlfa(mqttUri(TOPIC_ALFA), writeCurrentValue);
senderRoot.connectAlfaPrimitive(mqttUri(TOPIC_ALFA_PRIMITIVE), writeCurrentValue);
}
@Override
......@@ -84,30 +87,8 @@ public class TreeAllowedTokensManualTest extends AbstractTreeAllowedTokensTest {
senderRoot.setFlag(value);
}
protected void checkTree(int expectedCount, boolean expectedBooleanValue, Integer expectedIntValue, String expectedStringValue, double expectedDoubleValue) throws InterruptedException {
TestUtils.waitForMqtt();
assertEquals(expectedCount, data.numberOfTrees);
if (expectedIntValue == null) {
assertNull(receiverRoot.getAlfa());
} else {
assertNotNull(receiverRoot.getAlfa());
Alfa alfa = receiverRoot.getAlfa();
assertEquals(expectedBooleanValue, alfa.getBooleanValue());
assertEquals(expectedIntValue, alfa.getIntValue());
assertEquals(expectedIntValue.shortValue(), alfa.getShortValue());
assertEquals(expectedIntValue.longValue(), alfa.getLongValue());
assertEquals(expectedDoubleValue, alfa.getFloatValue(), TestUtils.DELTA);
assertEquals(expectedDoubleValue, alfa.getDoubleValue(), TestUtils.DELTA);
assertEquals(expectedStringValue, alfa.getStringValue());
assertEquals(expectedStringValue.charAt(0), alfa.getCharValue());
assertEquals(Instant.parse(expectedStringValue), alfa.getInstantValue());
assertEquals(Period.of(0, 0, expectedIntValue), alfa.getPeriodValue());
assertEquals(expectedBooleanValue ? MyEnum.TRUE : MyEnum.FALSE, alfa.getEnumValue());
}
@Override
protected void checkMyEnum(TestWrapperAlfa alfa, boolean expectedBooleanValue) {
assertEquals(expectedBooleanValue ? MyEnum.TRUE : MyEnum.FALSE, ((Alfa) alfa).getEnumValue());
}
}
......@@ -17,14 +17,11 @@ import static org.junit.jupiter.api.Assertions.*;
*
* @author rschoene - Initial contribution
*/
public class TreeIncrementalTest extends AbstractMqttTest {
public class TreeIncrementalTest extends AbstractTreeTest {
private static final String TOPIC_ALFA = "alfa";
private Root model;
private SenderRoot senderRoot;
private ReceiverRoot receiverRoot;
private MqttHandler handler;
private ReceiverData data;
@Test
public void checkJacksonReference() {
......@@ -40,7 +37,7 @@ public class TreeIncrementalTest extends AbstractMqttTest {
model.addSenderRoot(senderRoot);
receiverRoot = new ReceiverRoot();
model.addReceiverRoot(receiverRoot);
model.addReceiverRoot((ReceiverRoot) receiverRoot);
}
@Override
......@@ -60,34 +57,6 @@ public class TreeIncrementalTest extends AbstractMqttTest {
senderRoot.connectAlfa(mqttUri(TOPIC_ALFA), writeCurrentValue);
}
@Override
protected void communicateSendInitialValue() throws InterruptedException {
checkTree(1, 0);
setInput(1);
checkTree(2, 1);
setInput(1);
checkTree(2, 1);
setInput(2);
checkTree(3, 2);
}
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
checkTree(0, null);
setInput(1);
checkTree(1, 1);
setInput(1);
checkTree(1, 1);
setInput(2);
checkTree(2, 2);
}
@Override
protected void closeConnections() {
if (handler != null) {
......@@ -98,118 +67,7 @@ public class TreeIncrementalTest extends AbstractMqttTest {
}
}
private void setInput(int input) {
protected void setInput(int input) {
senderRoot.setInput(input);
}
private void checkTree(int expectedCount, Integer expectedInput) throws InterruptedException {
TestUtils.waitForMqtt();
assertEquals(expectedCount, data.numberOfTrees);
if (expectedInput == null) {
assertNull(receiverRoot.getAlfa());
} else {
assertNotNull(receiverRoot.getAlfa());
Alfa alfa = receiverRoot.getAlfa();
assertEquals(4, alfa.getNumBravo());
assertEquals(4, alfa.getNumCharlie());
assertEquals(4, alfa.getNumDelta());
Bravo inputBravo = alfa.getBravo(expectedInput);
Charlie inputCharlie = alfa.getCharlie(expectedInput);
Delta inputDelta = alfa.getDelta(expectedInput);
// Alfa -> Alfa
assertEquals(alfa, alfa.getMyself());
// Alfa -> Bravo
assertEquals(inputBravo, alfa.getMyBravo());
assertTrue(alfa.hasOptionalBravo());
assertEquals(inputBravo, alfa.getOptionalBravo());
assertThat(alfa.getMultiBravoList()).containsExactly(
inputBravo, alfa.getBravo(expectedInput + 1));
// Charlie -> Alfa
for (int i = 0; i < 4; i++) {
Charlie Charlie = alfa.getCharlie(i);
if (i == expectedInput) {
assertTrue(Charlie.hasMyAlfa());
assertEquals(alfa, Charlie.getMyAlfa());
} else {
assertFalse(Charlie.hasMyAlfa());
}
}
// Alfa <-> Delta
for (int i = 0; i < 4; i++) {
Delta Delta = alfa.getDelta(i);
if (i == expectedInput) {
assertTrue(Delta.hasSingleBack1Alfa());
assertEquals(alfa, Delta.getSingleBack1Alfa());
} else {
assertFalse(Delta.hasSingleBack1Alfa());
}
if (i == expectedInput || i == expectedInput + 1) {
assertTrue(Delta.hasSingleBack2Alfa());
assertEquals(alfa, Delta.getSingleBack2Alfa());
assertThat(Delta.getMultiBack3AlfaList()).containsExactly(alfa);
} else {
assertFalse(Delta.hasSingleBack2Alfa());
assertThat(Delta.getMultiBack3AlfaList()).isEmpty();
}
}
// Bravo -> Charlie
for (int i = 0; i < 4; i++) {
Bravo Bravo = alfa.getBravo(i);
if (i == expectedInput) {
assertEquals(inputCharlie, Bravo.getMyCharlie());
assertTrue(Bravo.hasOptionalCharlie());
assertEquals(inputCharlie, Bravo.getOptionalCharlie());
assertThat(Bravo.getMultiCharlieList()).containsExactly(
inputCharlie, alfa.getCharlie(expectedInput + 1));
} else {
assertEquals(alfa.getCharlie(0), Bravo.getMyCharlie());
assertFalse(Bravo.hasOptionalCharlie());
assertThat(Bravo.getMultiCharlieList()).isEmpty();
}
}
// Bravo <-> Delta
for (int i = 0; i < 4; i++) {
Bravo Bravo = alfa.getBravo(i);
Delta Delta = alfa.getDelta(i);
if (i == expectedInput) {
assertTrue(Bravo.hasSingleBi1Delta());
assertTrue(Delta.hasSingleBack1Bravo());
assertEquals(inputDelta, Bravo.getSingleBi1Delta());
assertEquals(inputBravo, Delta.getSingleBack1Bravo());
assertThat(Bravo.getMultiBi2DeltaList()).containsExactly(
inputDelta, alfa.getDelta(expectedInput + 1));
} else {
assertFalse(Bravo.hasSingleBi1Delta());
assertFalse(Delta.hasSingleBack1Bravo());
assertThat(Bravo.getMultiBi2DeltaList()).isEmpty();
}
if (i == expectedInput || i == expectedInput + 1) {
assertThat(Bravo.getMultiBi3DeltaList()).containsExactly(
inputDelta, alfa.getDelta(expectedInput + 1));
assertTrue(Delta.hasSingleBack2Bravo());
assertEquals(inputBravo, Delta.getSingleBack2Bravo());
assertThat(Delta.getMultiBack3BravoList()).containsExactly(
inputBravo, alfa.getBravo(expectedInput + 1));
} else {
assertThat(Bravo.getMultiBi3DeltaList()).isEmpty();
assertFalse(Delta.hasSingleBack2Bravo());
assertThat(Delta.getMultiBack3BravoList()).isEmpty();
}
}
}
}
private static class ReceiverData {
int numberOfTrees = 0;
}
}
package org.jastadd.ragconnect.tests;
import org.junit.jupiter.api.Test;
import tree.ast.*;
import tree.ast.MqttHandler;
import tree.ast.ReceiverRoot;
import tree.ast.Root;
import tree.ast.SenderRoot;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.jastadd.ragconnect.tests.TestUtils.mqttUri;
import static org.jastadd.ragconnect.tests.TestUtils.testJaddContainReferenceToJackson;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Test case "tree manual"
*
* @author rschoene - Initial contribution
*/
public class TreeManualTest extends AbstractMqttTest {
public class TreeManualTest extends AbstractTreeTest {
private static final String TOPIC_ALFA = "alfa";
private Root model;
private SenderRoot senderRoot;
private ReceiverRoot receiverRoot;
private MqttHandler handler;
private ReceiverData data;
@Test
public void checkJacksonReference() {
......@@ -40,7 +39,7 @@ public class TreeManualTest extends AbstractMqttTest {
model.addSenderRoot(senderRoot);
receiverRoot = new ReceiverRoot();
model.addReceiverRoot(receiverRoot);
model.addReceiverRoot((ReceiverRoot) receiverRoot);
}
@Override
......@@ -61,34 +60,6 @@ public class TreeManualTest extends AbstractMqttTest {
senderRoot.connectAlfa(mqttUri(TOPIC_ALFA), writeCurrentValue);
}
@Override
protected void communicateSendInitialValue() throws InterruptedException {
checkTree(1, 0);
setInput(1);
checkTree(2, 1);
setInput(1);
checkTree(2, 1);
setInput(2);
checkTree(3, 2);
}
@Override
protected void communicateOnlyUpdatedValue() throws InterruptedException {
checkTree(0, null);
setInput(1);
checkTree(1, 1);
setInput(1);
checkTree(1, 1);
setInput(2);
checkTree(2, 2);
}
@Override
protected void closeConnections() {
if (handler != null) {
......@@ -99,118 +70,7 @@ public class TreeManualTest extends AbstractMqttTest {
}
}
private void setInput(int input) {
protected void setInput(int input) {
senderRoot.setInput(input);
}
private void checkTree(int expectedCount, Integer expectedInput) throws InterruptedException {
TestUtils.waitForMqtt();
assertEquals(expectedCount, data.numberOfTrees);
if (expectedInput == null) {
assertNull(receiverRoot.getAlfa());
} else {
assertNotNull(receiverRoot.getAlfa());
Alfa alfa = receiverRoot.getAlfa();
assertEquals(4, alfa.getNumBravo());
assertEquals(4, alfa.getNumCharlie());
assertEquals(4, alfa.getNumDelta());
Bravo inputBravo = alfa.getBravo(expectedInput);
Charlie inputCharlie = alfa.getCharlie(expectedInput);
Delta inputDelta = alfa.getDelta(expectedInput);
// Alfa -> Alfa
assertEquals(alfa, alfa.getMyself());
// Alfa -> Bravo
assertEquals(inputBravo, alfa.getMyBravo());
assertTrue(alfa.hasOptionalBravo());
assertEquals(inputBravo, alfa.getOptionalBravo());
assertThat(alfa.getMultiBravoList()).containsExactly(
inputBravo, alfa.getBravo(expectedInput + 1));
// Charlie -> Alfa
for (int i = 0; i < 4; i++) {
Charlie Charlie = alfa.getCharlie(i);
if (i == expectedInput) {
assertTrue(Charlie.hasMyAlfa());
assertEquals(alfa, Charlie.getMyAlfa());
} else {
assertFalse(Charlie.hasMyAlfa());
}
}
// Alfa <-> Delta
for (int i = 0; i < 4; i++) {
Delta Delta = alfa.getDelta(i);
if (i == expectedInput) {
assertTrue(Delta.hasSingleBack1Alfa());
assertEquals(alfa, Delta.getSingleBack1Alfa());
} else {
assertFalse(Delta.hasSingleBack1Alfa());
}
if (i == expectedInput || i == expectedInput + 1) {
assertTrue(Delta.hasSingleBack2Alfa());
assertEquals(alfa, Delta.getSingleBack2Alfa());
assertThat(Delta.getMultiBack3AlfaList()).containsExactly(alfa);
} else {
assertFalse(Delta.hasSingleBack2Alfa());
assertThat(Delta.getMultiBack3AlfaList()).isEmpty();
}
}
// Bravo -> Charlie
for (int i = 0; i < 4; i++) {
Bravo Bravo = alfa.getBravo(i);
if (i == expectedInput) {
assertEquals(inputCharlie, Bravo.getMyCharlie());
assertTrue(Bravo.hasOptionalCharlie());
assertEquals(inputCharlie, Bravo.getOptionalCharlie());
assertThat(Bravo.getMultiCharlieList()).containsExactly(
inputCharlie, alfa.getCharlie(expectedInput + 1));
} else {
assertEquals(alfa.getCharlie(0), Bravo.getMyCharlie());
assertFalse(Bravo.hasOptionalCharlie());
assertThat(Bravo.getMultiCharlieList()).isEmpty();
}
}
// Bravo <-> Delta
for (int i = 0; i < 4; i++) {
Bravo Bravo = alfa.getBravo(i);
Delta Delta = alfa.getDelta(i);
if (i == expectedInput) {
assertTrue(Bravo.hasSingleBi1Delta());
assertTrue(Delta.hasSingleBack1Bravo());
assertEquals(inputDelta, Bravo.getSingleBi1Delta());
assertEquals(inputBravo, Delta.getSingleBack1Bravo());
assertThat(Bravo.getMultiBi2DeltaList()).containsExactly(
inputDelta, alfa.getDelta(expectedInput + 1));
} else {
assertFalse(Bravo.hasSingleBi1Delta());
assertFalse(Delta.hasSingleBack1Bravo());
assertThat(Bravo.getMultiBi2DeltaList()).isEmpty();
}
if (i == expectedInput || i == expectedInput + 1) {
assertThat(Bravo.getMultiBi3DeltaList()).containsExactly(
inputDelta, alfa.getDelta(expectedInput + 1));
assertTrue(Delta.hasSingleBack2Bravo());
assertEquals(inputBravo, Delta.getSingleBack2Bravo());
assertThat(Delta.getMultiBack3BravoList()).containsExactly(
inputBravo, alfa.getBravo(expectedInput + 1));
} else {
assertThat(Bravo.getMultiBi3DeltaList()).isEmpty();
assertFalse(Delta.hasSingleBack2Bravo());
assertThat(Delta.getMultiBack3BravoList()).isEmpty();
}
}
}
}
private static class ReceiverData {
int numberOfTrees = 0;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment