diff --git a/robo4j-hw-rpi/pom.xml b/robo4j-hw-rpi/pom.xml
index 68cc1fce..ba4be8c1 100644
--- a/robo4j-hw-rpi/pom.xml
+++ b/robo4j-hw-rpi/pom.xml
@@ -36,14 +36,6 @@
com.robo4j
robo4j-math
-
- org.slf4j
- slf4j-api
-
-
- org.slf4j
- slf4j-simple
-
com.pi4j
@@ -60,8 +52,17 @@
pi4j-plugin-linuxfs
${pi4j.version}
+
+ org.slf4j
+ slf4j-api
+
+
+ org.slf4j
+ slf4j-simple
+ test
+
org.junit.jupiter
junit-jupiter-engine
diff --git a/robo4j-socket-http/pom.xml b/robo4j-socket-http/pom.xml
index 0d11661d..3dfbf558 100644
--- a/robo4j-socket-http/pom.xml
+++ b/robo4j-socket-http/pom.xml
@@ -35,8 +35,16 @@
com.robo4j
robo4j-core
-
+
+ org.slf4j
+ slf4j-api
+
+
+ org.slf4j
+ slf4j-simple
+ test
+
org.junit.jupiter
junit-jupiter-engine
diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/json/JsonCodecsTests.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/json/JsonCodecsTests.java
index 15d791c1..b1c7475a 100644
--- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/json/JsonCodecsTests.java
+++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/json/JsonCodecsTests.java
@@ -170,40 +170,20 @@ void nestedObjectToJson() {
@Test
void nestedJsonToObject() {
- TestPerson testPerson2 = new TestPerson();
- testPerson2.setName("name2");
- testPerson2.setValue(5);
-
- TestPerson testPerson111 = new TestPerson();
- testPerson111.setName("name111");
- testPerson111.setValue(42);
-
- TestPerson testPerson11 = new TestPerson();
- testPerson11.setName("name11");
- testPerson11.setValue(0);
- testPerson11.setChild(testPerson111);
-
- TestPerson testPerson1 = new TestPerson();
- testPerson1.setName("name1");
- testPerson1.setValue(22);
- testPerson1.setChild(testPerson11);
-
- Map personMap = new LinkedHashMap<>();
- personMap.put("person1", testPerson1);
- personMap.put("person2", testPerson2);
+ Map personMap = getStringTestPersonMap();
long start = System.nanoTime();
NSBWithSimpleCollectionsTypesMessage obj1 = collectionsTypesMessageCodec.decode(testJson);
TimeUtils.printTimeDiffNano("decodeFromJson", start);
+ LOGGER.info("Obj: {}", obj1);
+
assertEquals(Integer.valueOf(42), obj1.getNumber());
assertEquals("no message", obj1.getMessage());
- assertTrue(!obj1.getActive());
+ assertFalse(obj1.getActive());
assertArrayEquals(new String[]{"one", "two"}, obj1.getArray());
assertTrue(obj1.getList().containsAll(Arrays.asList("text1", "text2")));
assertEquals(personMap, obj1.getPersonMap());
-
- System.out.println("Obj: " + obj1);
}
@Test
@@ -247,4 +227,29 @@ private static void printJson(String resultJson) {
LOGGER.debug("resultJson:{}", resultJson);
}
+ private static Map getStringTestPersonMap() {
+ TestPerson testPerson2 = new TestPerson();
+ testPerson2.setName("name2");
+ testPerson2.setValue(5);
+
+ TestPerson testPerson111 = new TestPerson();
+ testPerson111.setName("name111");
+ testPerson111.setValue(42);
+
+ TestPerson testPerson11 = new TestPerson();
+ testPerson11.setName("name11");
+ testPerson11.setValue(0);
+ testPerson11.setChild(testPerson111);
+
+ TestPerson testPerson1 = new TestPerson();
+ testPerson1.setName("name1");
+ testPerson1.setValue(22);
+ testPerson1.setChild(testPerson11);
+
+ Map personMap = new LinkedHashMap<>();
+ personMap.put("person1", testPerson1);
+ personMap.put("person2", testPerson2);
+ return personMap;
+ }
+
}
diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/HttpServerConfigTests.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/HttpServerConfigTests.java
index 545f8f44..c520c854 100644
--- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/HttpServerConfigTests.java
+++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/HttpServerConfigTests.java
@@ -22,17 +22,13 @@
import com.robo4j.socket.http.util.JsonUtil;
import com.robo4j.util.StringConstants;
import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.Collections;
-import java.util.List;
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
/**
* test for Http Server Unit configuration
@@ -41,100 +37,96 @@
* @author Miroslav Wengner (@miragemiko)
*/
class HttpServerConfigTests {
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpServerConfigTests.class);
- @Test
- void serverConfigurationNullTest() {
+ @Test
+ void serverConfigurationNullTest() {
+ Throwable exception = assertThrows(NullPointerException.class, () -> {
+ HttpPathMethodDTO serverUnitPathDTO = HttpPathUtils.readServerPathDTO(null);
+ assertNull(serverUnitPathDTO);
+ });
- Throwable exception = assertThrows(NullPointerException.class, () -> {
- HttpPathMethodDTO serverUnitPathDTO = HttpPathUtils.readServerPathDTO(null);
- assertNull(serverUnitPathDTO);
- });
+ assertNotNull(exception.getMessage());
+ }
- assertNotNull(exception.getMessage());
- }
+ @Test
+ void serverConfigurationEmptyTest() {
+ Throwable exception = assertThrows(ArrayIndexOutOfBoundsException.class, () -> {
+ HttpPathUtils.readServerPathDTO(StringConstants.EMPTY);
+ });
- @Test
- void serverConfigurationEmptyTest() {
- Throwable exception = assertThrows(ArrayIndexOutOfBoundsException.class, () -> {
- HttpPathUtils.readServerPathDTO(StringConstants.EMPTY);
- });
+ assertEquals("Index 0 out of bounds for length 0", exception.getMessage());
+ }
- assertEquals("Index 0 out of bounds for length 0", exception.getMessage());
- }
+ @Test
+ void serverConfigurationWithoutPropertiesDTOTest() {
+ var configurationJson = "{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\"}";
+ var serverUnitPathDTO = HttpPathUtils.readServerPathDTO(configurationJson);
- @Test
- void serverConfigurationWithoutPropertiesDTOTest() {
+ LOGGER.info("serverUnitPathDTO: {}", serverUnitPathDTO);
+ assertEquals("roboUnit1", serverUnitPathDTO.getRoboUnit());
+ assertEquals(HttpMethod.GET, serverUnitPathDTO.getMethod());
+ assertTrue(serverUnitPathDTO.getCallbacks().isEmpty());
- String configurationJson = "{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\"}";
- HttpPathMethodDTO serverUnitPathDTO = HttpPathUtils.readServerPathDTO(configurationJson);
+ }
- System.out.println("serverUnitPathDTO: " + serverUnitPathDTO);
- assertEquals("roboUnit1", serverUnitPathDTO.getRoboUnit());
- assertEquals(HttpMethod.GET, serverUnitPathDTO.getMethod());
- assertTrue(serverUnitPathDTO.getCallbacks().isEmpty());
+ @Test
+ void serverConfigurationWithPropertiesParsingDTOTest() {
+ var configurationJson = "{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\",\"callbacks\":[\"filter1\",\"filter2\"]}";
+ var serverUnitPathDTO = HttpPathUtils.readServerPathDTO(configurationJson);
- }
+ assertEquals("roboUnit1", serverUnitPathDTO.getRoboUnit());
+ assertEquals(HttpMethod.GET, serverUnitPathDTO.getMethod());
+ assertArrayEquals(Arrays.asList("filter1", "filter2").toArray(), serverUnitPathDTO.getCallbacks().toArray());
+ }
- @Test
- void serverConfigurationWithPropertiesParsingDTOTest() {
+ @Test
+ void serverConfigurationNullPathTest() {
+ var paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, null);
- String configurationJson = "{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\",\"callbacks\":[\"filter1\",\"filter2\"]}";
- HttpPathMethodDTO serverUnitPathDTO = HttpPathUtils.readServerPathDTO(configurationJson);
+ assertNotNull(paths);
+ assertTrue(paths.isEmpty());
- assertEquals("roboUnit1", serverUnitPathDTO.getRoboUnit());
- assertEquals(HttpMethod.GET, serverUnitPathDTO.getMethod());
- assertArrayEquals(Arrays.asList("filter1", "filter2").toArray(), serverUnitPathDTO.getCallbacks().toArray());
+ }
- System.out.println("serverUnitPathDTO: " + serverUnitPathDTO);
+ @Test
+ void serverConfigurationEmptyPathTest() {
+ var paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, StringConstants.EMPTY);
- }
+ assertNotNull(paths);
+ assertTrue(paths.isEmpty());
+ }
- @Test
- void serverConfigurationNullPathTest() {
- List paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, null);
- assertNotNull(paths);
- assertTrue(paths.isEmpty());
+ @Test
+ void serverConfigurationWithMultiplePathsWithoutPropertiesTest() {
+ var configurationJson = "[{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\"},"
+ + "{\"roboUnit\":\"roboUnit2\",\"method\":\"POST\"}]";
- }
+ var expectedPathList = Arrays.asList(new HttpPathMethodDTO("roboUnit1", HttpMethod.GET),
+ new HttpPathMethodDTO("roboUnit2", HttpMethod.POST));
- @Test
- void serverConfigurationEmptyPathTest() {
- List paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, StringConstants.EMPTY);
- assertNotNull(paths);
- assertTrue(paths.isEmpty());
+ var paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, configurationJson);
- }
+ assertEquals(expectedPathList.size(), paths.size());
+ assertArrayEquals(expectedPathList.toArray(), paths.toArray());
+ }
- @Test
- void serverConfigurationWithMultiplePathsWithoutPropertiesTest() {
- String configurationJson = "[{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\"},"
- + "{\"roboUnit\":\"roboUnit2\",\"method\":\"POST\"}]";
+ @Test
+ void serverConfigurationWithMultiplePathsWithPropertiesTest() {
+ var configurationJson = "[{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\" , \"callbacks\":[\"filter1\",\"filter2\"]},"
+ + "{\"roboUnit\":\"roboUnit2\",\"method\":\"POST\"}, {\"roboUnit\":\"roboUnit3\",\"method\":\"GET\",\"callbacks\":[]}]";
- List expectedPathList = Arrays.asList(new HttpPathMethodDTO("roboUnit1", HttpMethod.GET),
- new HttpPathMethodDTO("roboUnit2", HttpMethod.POST));
+ var expectedPathList = Arrays.asList(
+ new HttpPathMethodDTO("roboUnit1", HttpMethod.GET, Arrays.asList("filter1", "filter2")),
+ new HttpPathMethodDTO("roboUnit2", HttpMethod.POST),
+ new HttpPathMethodDTO("roboUnit3", HttpMethod.GET, Collections.emptyList()));
- List paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, configurationJson);
+ var paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, configurationJson);
- assertEquals(expectedPathList.size(), paths.size());
- assertArrayEquals(expectedPathList.toArray(), paths.toArray());
- }
-
- @Test
- void serverConfigurationWithMultiplePathsWithPropertiesTest() {
- String configurationJson = "[{\"roboUnit\":\"roboUnit1\",\"method\":\"GET\" , \"callbacks\":[\"filter1\",\"filter2\"]},"
- + "{\"roboUnit\":\"roboUnit2\",\"method\":\"POST\"}, {\"roboUnit\":\"roboUnit3\",\"method\":\"GET\",\"callbacks\":[]}]";
-
- List expectedPathList = Arrays.asList(
- new HttpPathMethodDTO("roboUnit1", HttpMethod.GET, Arrays.asList("filter1", "filter2")),
- new HttpPathMethodDTO("roboUnit2", HttpMethod.POST),
- new HttpPathMethodDTO("roboUnit3", HttpMethod.GET, Collections.emptyList()));
-
- List paths = JsonUtil.readPathConfig(HttpPathMethodDTO.class, configurationJson);
- System.out.println("paths: " + paths);
-
- assertNotNull(paths);
- assertEquals(expectedPathList.size(), paths.size());
- assertArrayEquals(expectedPathList.toArray(), paths.toArray());
- }
+ LOGGER.info("paths: {}", paths);
+ assertNotNull(paths);
+ assertEquals(expectedPathList.size(), paths.size());
+ assertArrayEquals(expectedPathList.toArray(), paths.toArray());
+ }
}
diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/HttpServerUnitTests.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/HttpServerUnitTests.java
index 7a82e34e..b668170e 100644
--- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/HttpServerUnitTests.java
+++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/HttpServerUnitTests.java
@@ -19,13 +19,13 @@
import com.robo4j.LifecycleState;
import com.robo4j.RoboBuilder;
import com.robo4j.RoboBuilderException;
-import com.robo4j.RoboContext;
import com.robo4j.RoboReference;
-import com.robo4j.configuration.Configuration;
import com.robo4j.configuration.ConfigurationBuilder;
import com.robo4j.socket.http.units.HttpServerUnit;
import com.robo4j.util.SystemUtil;
import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import static com.robo4j.socket.http.test.units.HttpUnitTests.CODECS_UNITS_TEST_PACKAGE;
import static com.robo4j.socket.http.util.RoboHttpUtils.PROPERTY_CODEC_PACKAGES;
@@ -38,50 +38,47 @@
* @author Miroslav Wengner (@miragemiko)
*/
class HttpServerUnitTests {
- private static final int PORT = 9000;
- private static final String ID_HTTP_SERVER = "empty_server";
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpServerUnitTests.class);
+ private static final int PORT = 9000;
+ private static final String ID_HTTP_SERVER = "empty_server";
- @Test
- void httpServerUnitNoCodecsPackageTest() throws Exception {
+ @Test
+ void httpServerUnitNoCodecsPackageTest() throws Exception {
- Throwable exception = assertThrows(RoboBuilderException.class, () -> {
- RoboBuilder builder = new RoboBuilder();
+ Throwable exception = assertThrows(RoboBuilderException.class, () -> {
+ var builder = new RoboBuilder();
+ var config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT).build();
+ builder.add(HttpServerUnit.class, config, ID_HTTP_SERVER);
+ var system = builder.build();
- Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT).build();
- builder.add(HttpServerUnit.class, config, ID_HTTP_SERVER);
- RoboContext system = builder.build();
+ system.start();
+ LOGGER.info(SystemUtil.printStateReport(system));
+ var systemReference = system.getReference(ID_HTTP_SERVER);
+ system.shutdown();
- system.start();
- System.out.println("system: State after start:");
- System.out.println(SystemUtil.printStateReport(system));
- RoboReference systemReference = system.getReference(ID_HTTP_SERVER);
- system.shutdown();
- System.out.println("system: State after shutdown:");
- System.out.println(SystemUtil.printStateReport(system));
- assertEquals(LifecycleState.SHUTDOWN, systemReference.getState());
- });
+ LOGGER.info(SystemUtil.printStateReport(system));
+ assertEquals(LifecycleState.SHUTDOWN, systemReference.getState());
+ });
- assertEquals("Error initializing RoboUnit", exception.getMessage());
+ assertEquals("Error initializing RoboUnit", exception.getMessage());
- }
+ }
- @Test
- void httpServerUnitNoPathTest() throws Exception {
- RoboBuilder builder = new RoboBuilder();
+ @Test
+ void httpServerUnitNoPathTest() throws Exception {
+ var builder = new RoboBuilder();
+ var config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT)
+ .addString(PROPERTY_CODEC_PACKAGES, CODECS_UNITS_TEST_PACKAGE).build();
+ builder.add(HttpServerUnit.class, config, ID_HTTP_SERVER);
+ var system = builder.build();
- Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT)
- .addString(PROPERTY_CODEC_PACKAGES, CODECS_UNITS_TEST_PACKAGE).build();
- builder.add(HttpServerUnit.class, config, ID_HTTP_SERVER);
- RoboContext system = builder.build();
+ system.start();
+ LOGGER.info(SystemUtil.printStateReport(system));
+ RoboReference systemReference = system.getReference(ID_HTTP_SERVER);
+ system.shutdown();
- system.start();
- System.out.println("system: State after start:");
- System.out.println(SystemUtil.printStateReport(system));
- RoboReference systemReference = system.getReference(ID_HTTP_SERVER);
- system.shutdown();
- System.out.println("system: State after shutdown:");
- System.out.println(SystemUtil.printStateReport(system));
- assertEquals(LifecycleState.SHUTDOWN, systemReference.getState());
- }
+ LOGGER.info(SystemUtil.printStateReport(system));
+ assertEquals(LifecycleState.SHUTDOWN, systemReference.getState());
+ }
}
diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboDatagramClientTest.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboDatagramClientTest.java
index fefbbe78..2d81c632 100644
--- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboDatagramClientTest.java
+++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboDatagramClientTest.java
@@ -22,6 +22,8 @@
import com.robo4j.util.SystemUtil;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -35,6 +37,7 @@
* @author Miroslav Wengner (@miragemiko)
*/
class RoboDatagramClientTest {
+ private static final Logger LOGGER = LoggerFactory.getLogger(RoboDatagramClientTest.class);
private static final int TIMEOUT = 10;
private static final TimeUnit TIME_UNIT = TimeUnit.HOURS;
private static final int MAX_NUMBER = 42;
@@ -44,17 +47,14 @@ class RoboDatagramClientTest {
@Test
void datagramClientServerTest() throws Exception {
- RoboContext producerSystem = RoboContextUtils.loadRoboContextByXml("robo_datagram_client_request_producer_text.xml");
- RoboContext consumerSystem = RoboContextUtils.loadRoboContextByXml("robo_datagram_client_request_consumer_text.xml");
+ var producerSystem = RoboContextUtils.loadRoboContextByXml("robo_datagram_client_request_producer_text.xml");
+ var consumerSystem = RoboContextUtils.loadRoboContextByXml("robo_datagram_client_request_consumer_text.xml");
consumerSystem.start();
producerSystem.start();
- System.out.println("consumer: State after start:");
- System.out.println(SystemUtil.printStateReport(consumerSystem));
-
- System.out.println("producer: State after start:");
- System.out.println(SystemUtil.printStateReport(producerSystem));
+ LOGGER.info(SystemUtil.printStateReport(consumerSystem));
+ LOGGER.info(SystemUtil.printStateReport(producerSystem));
RoboReference decoratedProducer = producerSystem.getReference("decoratedProducer");
decoratedProducer.sendMessage(MAX_NUMBER);
diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboDatagramPingPongTest.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboDatagramPingPongTest.java
index 41706041..6c6c5faa 100644
--- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboDatagramPingPongTest.java
+++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboDatagramPingPongTest.java
@@ -31,16 +31,13 @@
import com.robo4j.socket.http.util.RoboHttpUtils;
import com.robo4j.util.SystemUtil;
import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static com.robo4j.socket.http.test.units.HttpUnitTests.CODECS_UNITS_TEST_PACKAGE;
-import static com.robo4j.socket.http.util.RoboHttpUtils.PROPERTY_CODEC_PACKAGES;
-import static com.robo4j.socket.http.util.RoboHttpUtils.PROPERTY_HOST;
-import static com.robo4j.socket.http.util.RoboHttpUtils.PROPERTY_SOCKET_PORT;
-import static com.robo4j.socket.http.util.RoboHttpUtils.PROPERTY_UNIT_PATHS_CONFIG;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static com.robo4j.socket.http.util.RoboHttpUtils.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -49,84 +46,82 @@
* @author Miroslav Wengner (@miragemiko)
*/
class RoboDatagramPingPongTest {
-
- private static final int TIMEOUT = 20;
- private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS;
- private static final String UDP_CLIENT = "udp_client";
- private static final String UDP_SERVER = "udp_server";
-
- private static final int TOTAL_NUMBER = 122;
-
- @Test
- void datagramPingPongTest() throws Exception {
- RoboContext pongSystem = configurePongSystem(TOTAL_NUMBER);
- RoboContext pingSystem = configurePingSystem();
-
- pongSystem.start();
- pingSystem.start();
- System.out.println("UDP pongSystem: State after start:");
- System.out.println(SystemUtil.printStateReport(pongSystem));
- System.out.println("UDP pingSystem: State after start:");
- System.out.println(SystemUtil.printStateReport(pingSystem));
-
- RoboReference pongStringConsumerReference = pongSystem.getReference(StringConsumer.NAME);
- CountDownLatch totalMessageLatch = pongStringConsumerReference.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_LATCH).get();
-
- RoboReference udpClient = pingSystem.getReference(UDP_CLIENT);
- for (int i = 0; i < TOTAL_NUMBER; i++) {
- DatagramDenominator denominator = new DatagramDenominator(DatagramBodyType.JSON.getType(), "/units/stringConsumer");
- DatagramDecoratedRequest request = new DatagramDecoratedRequest(denominator);
- String message = "{\"message\": \"Hello i:" + i + "\"}";
- request.addMessage(message.getBytes());
- udpClient.sendMessage(request);
- }
-
- totalMessageLatch.await(TIMEOUT, TIME_UNIT);
- final int pongConsumerTotalNumber = pongStringConsumerReference.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_TOTAL).get();
-
-
- System.out.println("UDP pongSystem: State after shutdown:");
- System.out.println(SystemUtil.printStateReport(pongSystem));
- System.out.println("UDP pingSystem: State after shutdown:");
- System.out.println(SystemUtil.printStateReport(pingSystem));
- pingSystem.shutdown();
- pongSystem.shutdown();
-
- assertTrue(pongConsumerTotalNumber > 0 && pongConsumerTotalNumber <= TOTAL_NUMBER );
-
- }
-
- private RoboContext configurePingSystem() throws Exception {
- RoboBuilder builder = new RoboBuilder();
-
- Configuration config = new ConfigurationBuilder().addString(PROPERTY_CODEC_PACKAGES, CODECS_UNITS_TEST_PACKAGE)
- .addString(PROPERTY_HOST, "localhost").addInteger(PROPERTY_SOCKET_PORT, RoboHttpUtils.DEFAULT_UDP_PORT)
- .addString(PROPERTY_UNIT_PATHS_CONFIG, "[{\"roboUnit\":\"stringConsumer\",\"callbacks\": [\"stringConsumer\"]}]").build();
- builder.add(DatagramClientUnit.class, config, UDP_CLIENT);
-
- config = ConfigurationFactory.createEmptyConfiguration();
- builder.add(StringConsumer.class, config, StringConsumer.NAME);
-
- return builder.build();
- }
-
- /**
- * create simple UDP server with consumer unit
- *
- *
- * @return roboContext
- * @throws Exception
- * exception
- */
- private RoboContext configurePongSystem(int totalNumberOfMessage) throws Exception {
- RoboBuilder builder = new RoboBuilder();
- Configuration config = new ConfigurationBuilder().addString(PROPERTY_CODEC_PACKAGES, CODECS_UNITS_TEST_PACKAGE)
- .addString(PROPERTY_UNIT_PATHS_CONFIG, "[{\"roboUnit\":\"stringConsumer\",\"filters\":[]}]").build();
- builder.add(DatagramServerUnit.class, config, UDP_SERVER);
-
- config = new ConfigurationBuilder().addInteger(StringConsumer.PROP_TOTAL_NUMBER_MESSAGES, totalNumberOfMessage).build();
- builder.add(StringConsumer.class, config, StringConsumer.NAME);
-
- return builder.build();
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(RoboDatagramPingPongTest.class);
+ private static final int TIMEOUT = 20;
+ private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS;
+ private static final String UDP_CLIENT = "udp_client";
+ private static final String UDP_SERVER = "udp_server";
+
+ private static final int TOTAL_NUMBER = 122;
+
+ @Test
+ void datagramPingPongTest() throws Exception {
+ var pongSystem = configurePongSystem(TOTAL_NUMBER);
+ var pingSystem = configurePingSystem();
+
+ pongSystem.start();
+ pingSystem.start();
+ LOGGER.info("UDP pongSystem: State after start:");
+ LOGGER.info(SystemUtil.printStateReport(pongSystem));
+ LOGGER.info("UDP pingSystem: State after start:");
+ LOGGER.info(SystemUtil.printStateReport(pingSystem));
+
+ var pongStringConsumerReference = pongSystem.getReference(StringConsumer.NAME);
+ var totalMessageLatch = pongStringConsumerReference.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_LATCH).get();
+
+ RoboReference udpClient = pingSystem.getReference(UDP_CLIENT);
+ for (int i = 0; i < TOTAL_NUMBER; i++) {
+ DatagramDenominator denominator = new DatagramDenominator(DatagramBodyType.JSON.getType(), "/units/stringConsumer");
+ DatagramDecoratedRequest request = new DatagramDecoratedRequest(denominator);
+ String message = "{\"message\": \"Hello i:" + i + "\"}";
+ request.addMessage(message.getBytes());
+ udpClient.sendMessage(request);
+ }
+
+ totalMessageLatch.await(TIMEOUT, TIME_UNIT);
+ final int pongConsumerTotalNumber = pongStringConsumerReference.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_TOTAL).get();
+
+
+ LOGGER.debug("UDP pongSystem: State after shutdown:");
+ LOGGER.debug(SystemUtil.printStateReport(pongSystem));
+ LOGGER.debug("UDP pingSystem: State after shutdown:");
+ LOGGER.debug(SystemUtil.printStateReport(pingSystem));
+ pingSystem.shutdown();
+ pongSystem.shutdown();
+
+ assertTrue(pongConsumerTotalNumber > 0 && pongConsumerTotalNumber <= TOTAL_NUMBER);
+
+ }
+
+ private RoboContext configurePingSystem() throws Exception {
+ RoboBuilder builder = new RoboBuilder();
+
+ Configuration config = new ConfigurationBuilder().addString(PROPERTY_CODEC_PACKAGES, CODECS_UNITS_TEST_PACKAGE)
+ .addString(PROPERTY_HOST, "localhost").addInteger(PROPERTY_SOCKET_PORT, RoboHttpUtils.DEFAULT_UDP_PORT)
+ .addString(PROPERTY_UNIT_PATHS_CONFIG, "[{\"roboUnit\":\"stringConsumer\",\"callbacks\": [\"stringConsumer\"]}]").build();
+ builder.add(DatagramClientUnit.class, config, UDP_CLIENT);
+
+ config = ConfigurationFactory.createEmptyConfiguration();
+ builder.add(StringConsumer.class, config, StringConsumer.NAME);
+
+ return builder.build();
+ }
+
+ /**
+ * create simple UDP server with consumer unit
+ *
+ * @return roboContext
+ * @throws Exception exception
+ */
+ private RoboContext configurePongSystem(int totalNumberOfMessage) throws Exception {
+ RoboBuilder builder = new RoboBuilder();
+ Configuration config = new ConfigurationBuilder().addString(PROPERTY_CODEC_PACKAGES, CODECS_UNITS_TEST_PACKAGE)
+ .addString(PROPERTY_UNIT_PATHS_CONFIG, "[{\"roboUnit\":\"stringConsumer\",\"filters\":[]}]").build();
+ builder.add(DatagramServerUnit.class, config, UDP_SERVER);
+
+ config = new ConfigurationBuilder().addInteger(StringConsumer.PROP_TOTAL_NUMBER_MESSAGES, totalNumberOfMessage).build();
+ builder.add(StringConsumer.class, config, StringConsumer.NAME);
+
+ return builder.build();
+ }
}
diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpClientWithResponseTests.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpClientWithResponseTests.java
index 3f6738b3..fc113b21 100644
--- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpClientWithResponseTests.java
+++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpClientWithResponseTests.java
@@ -16,17 +16,17 @@
*/
package com.robo4j.socket.http.test.units;
-import com.robo4j.RoboContext;
-import com.robo4j.RoboReference;
import com.robo4j.socket.http.test.units.config.SocketMessageDecoratedProducerUnit;
import com.robo4j.socket.http.test.units.config.StringConsumer;
import com.robo4j.util.SystemUtil;
import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* testing http method GET with response
@@ -36,48 +36,52 @@
*/
class RoboHttpClientWithResponseTests {
- private static final int TIMEOUT = 20;
- private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS;
- private static final Integer MAX_NUMBER = 20;
- // private static final String ROBO_SYSTEM_DESC =
- // "[{\"id\":\"stringConsumer\",\"state\":\"STARTED\"},{\"id\":\"httpServer\",\"state\":\"STARTED\"}]";
+ private static final Logger LOGGER = LoggerFactory.getLogger(RoboHttpClientWithResponseTests.class);
+ private static final int TIMEOUT = 20;
+ private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS;
+ private static final Integer MAX_NUMBER = 20;
+ // private static final String ROBO_SYSTEM_DESC =
+ // "[{\"id\":\"stringConsumer\",\"state\":\"STARTED\"},{\"id\":\"httpServer\",\"state\":\"STARTED\"}]";
- @Test
- void simpleRoboSystemGetRequestTest() throws Exception {
+ @Test
+ void simpleRoboSystemGetRequestTest() throws Exception {
- RoboContext producerSystem = RoboContextUtils
- .loadRoboContextByXml("robo_http_client_request_producer_text.xml");
- RoboContext consumerSystem = RoboContextUtils
- .loadRoboContextByXml("robo_http_client_request_consumer_text.xml");
+ var producerSystem = RoboContextUtils
+ .loadRoboContextByXml("robo_http_client_request_producer_text.xml");
+ var consumerSystem = RoboContextUtils
+ .loadRoboContextByXml("robo_http_client_request_consumer_text.xml");
- consumerSystem.start();
- producerSystem.start();
+ consumerSystem.start();
+ producerSystem.start();
- System.out.println("consumer: State after start:");
- System.out.println(SystemUtil.printStateReport(consumerSystem));
+ LOGGER.info("consumer: State after start:");
+ LOGGER.info(SystemUtil.printStateReport(consumerSystem));
+ LOGGER.info("producer: State after start:");
+ LOGGER.info(SystemUtil.printStateReport(producerSystem));
- System.out.println("producer: State after start:");
- System.out.println(SystemUtil.printStateReport(producerSystem));
+ var decoratedProducer = producerSystem.getReference("decoratedProducer");
+ var producerSetupLatch = decoratedProducer
+ .getAttribute(SocketMessageDecoratedProducerUnit.DESCRIPTOR_SETUP_LATCH).get();
+ decoratedProducer.sendMessage(MAX_NUMBER);
+ var producerConfigured = producerSetupLatch.await(TIMEOUT, TIME_UNIT);
+ var producerLatch = decoratedProducer
+ .getAttribute(SocketMessageDecoratedProducerUnit.DESCRIPTOR_MESSAGES_LATCH).get();
+ var messagesSent = producerLatch.await(TIMEOUT, TIME_UNIT);
- RoboReference decoratedProducer = producerSystem.getReference("decoratedProducer");
- CountDownLatch producerSetupLatch = decoratedProducer
- .getAttribute(SocketMessageDecoratedProducerUnit.DESCRIPTOR_SETUP_LATCH).get();
- decoratedProducer.sendMessage(MAX_NUMBER);
- producerSetupLatch.await(TIMEOUT, TIME_UNIT);
- CountDownLatch producerLatch = decoratedProducer
- .getAttribute(SocketMessageDecoratedProducerUnit.DESCRIPTOR_MESSAGES_LATCH).get();
- producerLatch.await(TIMEOUT, TIME_UNIT);
+ var producerStringConsumer = producerSystem.getReference(StringConsumer.NAME);
+ var messagesLatchStringConsumer = producerStringConsumer
+ .getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_LATCH).get();
+ var messagesReceived = messagesLatchStringConsumer.await(TIMEOUT, TIME_UNIT);
- final RoboReference producerStringConsumer = producerSystem.getReference(StringConsumer.NAME);
- final CountDownLatch messagesLatchStringConsumer = producerStringConsumer
- .getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_LATCH).get();
- messagesLatchStringConsumer.await(TIMEOUT, TIME_UNIT);
+ var totalNumber = producerStringConsumer.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_TOTAL).get();
- final Integer totalNumber = producerStringConsumer.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_TOTAL).get();
- assertEquals(MAX_NUMBER, totalNumber);
+ assertTrue(producerConfigured);
+ assertTrue(messagesSent);
+ assertTrue(messagesReceived);
+ assertEquals(MAX_NUMBER, totalNumber);
- producerSystem.shutdown();
- consumerSystem.shutdown();
- }
+ producerSystem.shutdown();
+ consumerSystem.shutdown();
+ }
}
diff --git a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java
index e0c909be..b720401d 100644
--- a/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java
+++ b/robo4j-socket-http/src/test/java/com/robo4j/socket/http/test/units/RoboHttpDynamicTests.java
@@ -33,6 +33,8 @@
import com.robo4j.util.SystemUtil;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
@@ -49,7 +51,6 @@
* @author Miro Wengner (@miragemiko)
*/
class RoboHttpDynamicTests {
-
private static final int TIMEOUT = 20;
private static final TimeUnit TIME_UNIT = TimeUnit.HOURS;
private static final String ID_HTTP_SERVER = "http";
@@ -59,6 +60,7 @@ class RoboHttpDynamicTests {
private static final int MESSAGES_NUMBER = 42;
private static final String HOST_SYSTEM = "localhost";
static final String JSON_STRING = "{\"value\":\"stop\"}";
+ private static final Logger LOGGER = LoggerFactory.getLogger(RoboHttpDynamicTests.class);
private static final String DECORATED_PRODUCER = "decoratedProducer";
/**
@@ -73,34 +75,32 @@ class RoboHttpDynamicTests {
void simpleHttpNonUnitTest() throws Exception {
/* tested system configuration */
- RoboContext mainSystem = getServerRoboSystem(MESSAGES_NUMBER);
+ var mainSystem = getServerRoboSystem(MESSAGES_NUMBER);
/* system which is testing main system */
- RoboContext clientSystem = getClientRoboSystem();
-
- System.out.println("Client system state after start:");
- System.out.println(SystemUtil.printStateReport(clientSystem));
+ var clientSystem = getClientRoboSystem();
- System.out.println("Main system state after start:");
- System.out.println(SystemUtil.printStateReport(mainSystem));
+ LOGGER.info("Client system state after start:");
+ LOGGER.info(SystemUtil.printStateReport(clientSystem));
+ LOGGER.info("Main system state after start:");
+ LOGGER.info(SystemUtil.printStateReport(mainSystem));
/* client system sending a messages to the main system */
- RoboReference