diff --git a/ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/TestUtils.java b/ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/TestUtils.java index 185bd0fa29f298f6f2624d7c399db9705742aec2..655d61e1710014d37c7aeaa3fdcc140995568f9d 100644 --- a/ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/TestUtils.java +++ b/ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/TestUtils.java @@ -211,14 +211,13 @@ public class TestUtils { // if there is at least one call to this, we do not need to manually wait in the next check() needManualWait = false; Integer currentExpected = intValues.computeIfAbsent(NUMBER_OF_VALUES, ActualAndExpected::new).expected; - if (currentExpected == null) { - currentExpected = 0; - } return put(NUMBER_OF_VALUES, currentExpected + increment); } public TestChecker setActualNumberOfValues(Callable<Integer> actual) { - return setActualInteger(NUMBER_OF_VALUES, actual); + setActualInteger(NUMBER_OF_VALUES, actual); + intValues.get(NUMBER_OF_VALUES).expected = 0; + return this; } public TestChecker setActualString(String name, Callable<String> actual) { diff --git a/ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/relation/RelationTest.java b/ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/relation/RelationTest.java index 5e953f5a412bc1b8838945eb097ef98d0bf64ab0..a88f97fefabd47159f91d268a96ffe67a3dcee7e 100644 --- a/ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/relation/RelationTest.java +++ b/ragconnect.tests/src/test/java/org/jastadd/ragconnect/tests/relation/RelationTest.java @@ -7,13 +7,12 @@ import relationInc.ast.*; import java.io.IOException; import java.util.List; -import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; -import static java.util.function.Predicate.isEqual; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.groups.Tuple.tuple; -import static org.jastadd.ragconnect.tests.TestUtils.*; +import static org.jastadd.ragconnect.tests.TestUtils.TestChecker; +import static org.jastadd.ragconnect.tests.TestUtils.mqttUri; import static org.junit.jupiter.api.Assertions.*; /** @@ -39,9 +38,6 @@ public class RelationTest extends AbstractMqttTest { private static final String TOPIC_BI_OPTIONAL_B = "rel/bi_optional_b"; private static final String TOPIC_BI_MANY_B = "rel/bi_many_b"; - // FIXME: remove when finished with test -// private final boolean testing_shortcut = true; - private MqttHandler handler; private ReceiverData data; private TestChecker checker; @@ -182,28 +178,10 @@ public class RelationTest extends AbstractMqttTest { assertTrue(senderBi.connectBiMyB(mqttUri(TOPIC_BI_MY_B), isWriteCurrentValue())); assertTrue(senderBi.connectBiOptionalB(mqttUri(TOPIC_BI_OPTIONAL_B), isWriteCurrentValue())); assertTrue(senderBi.connectBiManyB(mqttUri(TOPIC_BI_MANY_B), isWriteCurrentValue())); - -// waitForNonNull(receiverRoot::getFromMyA); -// waitForNonNull(receiverRoot::getFromBiMyA); -// waitForNonNull(receiverRoot::getFromMyB); -// waitForNonNull(receiverRoot::getFromBiMyB); } -// private <T> void waitForValue(T expectedValue, Callable<T> callable) { -// if (isWriteCurrentValue()) { -// awaitMqtt().until(callable, isEqual(expectedValue)); -// } -// } -// -// private <T> void waitForNonNull(Callable<T> callable) { -// if (isWriteCurrentValue()) { -// awaitMqtt().until(callable, Predicate.not(isEqual(null))); -// } -// } - @Override - protected void communicateSendInitialValue() throws IOException, InterruptedException { - // myA -> uni-a1, myB -> uni-b1 + protected void communicateSendInitialValue() throws IOException { checker.addToNumberOfValues(8) .put(TOPIC_MY_A, "uni-a1") .put(TOPIC_OPTIONAL_A, (String) null) @@ -218,8 +196,31 @@ public class RelationTest extends AbstractMqttTest { .put(TOPIC_BI_OPTIONAL_B, (String) null) .put(TOPIC_BI_MANY_B, tuple()); + communicateBoth(); + } + + @Override + protected void communicateOnlyUpdatedValue() throws IOException, InterruptedException { + checker.put(TOPIC_MY_A, (String) null) + .put(TOPIC_OPTIONAL_A, (String) null) + .put(TOPIC_MANY_A, tuple()) + .put(TOPIC_BI_MY_A, (String) null) + .put(TOPIC_BI_OPTIONAL_A, (String) null) + .put(TOPIC_BI_MANY_A, tuple()) + .put(TOPIC_MY_B, (String) null) + .put(TOPIC_OPTIONAL_B, (String) null) + .put(TOPIC_MANY_B, tuple()) + .put(TOPIC_BI_MY_B, (String) null) + .put(TOPIC_BI_OPTIONAL_B, (String) null) + .put(TOPIC_BI_MANY_B, tuple()); + + communicateBoth(); + } + + protected void communicateBoth() throws IOException { checker.check(); + // myA -> uni-a1, myB -> uni-b1 // --- testing unmapped unidirectional normal role --- // uniA(1).setValue("test-1"); @@ -618,17 +619,6 @@ public class RelationTest extends AbstractMqttTest { } - @Override - protected void communicateOnlyUpdatedValue() throws IOException, InterruptedException { - waitForMqtt(); - // TODO implement test - // TODO also check disconnect - } - - private <T> void awaitEquals(T expected, Callable<T> actual, String alias) { - awaitMqtt().alias(alias).until(actual, isEqual(expected)); - } - private void assertNullOrA(String expectedValue, A actual, String alias) { if (expectedValue == null) { assertNull(actual, alias);