Search in sources :

Example 6 with RoboSystem

use of com.robo4j.core.RoboSystem in project robo4j by Robo4J.

the class RoboHttpDynamicTests method getClientRoboSystem.

private RoboSystem getClientRoboSystem() throws Exception {
    /* system which is testing main system */
    Configuration config = ConfigurationFactory.createEmptyConfiguration();
    RoboSystem result = new RoboSystem();
    HttpClientUnit httpClient = new HttpClientUnit(result, CLIENT_UNIT_ID);
    config.setString("address", HOST_SYSTEM);
    config.setInteger("port", PORT);
    /* specific configuration */
    Configuration configuration = config.createChildConfiguration(RoboHttpUtils.HTTP_TARGET_UNITS);
    configuration.setString("controller", "POST");
    httpClient.initialize(config);
    result.addUnits(httpClient);
    System.out.println("Client State after start:");
    System.out.println(SystemUtil.printStateReport(result));
    result.start();
    return result;
}
Also used : RoboSystem(com.robo4j.core.RoboSystem) Configuration(com.robo4j.core.configuration.Configuration)

Example 7 with RoboSystem

use of com.robo4j.core.RoboSystem in project robo4j by Robo4J.

the class RoboHttpDynamicTests method getServerRoboSystem.

// Private Methods
private RoboSystem getServerRoboSystem() throws Exception {
    /* tested system configuration */
    RoboSystem result = new RoboSystem();
    Configuration config = ConfigurationFactory.createEmptyConfiguration();
    HttpServerUnit httpServer = new HttpServerUnit(result, "http");
    config.setString("target", TARGET_UNIT);
    config.setInteger("port", PORT);
    config.setString("packages", "com.robo4j.core.httpunit.test.codec");
    Configuration targetUnits = config.createChildConfiguration(RoboHttpUtils.HTTP_TARGET_UNITS);
    targetUnits.setString(TARGET_UNIT, "POST");
    httpServer.initialize(config);
    HttpCommandTestController ctrl = new HttpCommandTestController(result, TARGET_UNIT);
    config = ConfigurationFactory.createEmptyConfiguration();
    config.setString("target", "request_consumer");
    ctrl.initialize(config);
    StringConsumer consumer = new StringConsumer(result, "request_consumer");
    Assert.assertNotNull(result.getUnits());
    Assert.assertEquals(result.getUnits().size(), 0);
    Assert.assertEquals(httpServer.getState(), LifecycleState.INITIALIZED);
    Assert.assertEquals(result.getState(), LifecycleState.UNINITIALIZED);
    result.addUnits(httpServer, ctrl, consumer);
    System.out.println(SystemUtil.printSocketEndPoint(httpServer, ctrl));
    result.start();
    return result;
}
Also used : RoboSystem(com.robo4j.core.RoboSystem) Configuration(com.robo4j.core.configuration.Configuration) HttpCommandTestController(com.robo4j.core.httpunit.test.HttpCommandTestController) StringConsumer(com.robo4j.core.StringConsumer)

Example 8 with RoboSystem

use of com.robo4j.core.RoboSystem in project robo4j by Robo4J.

the class RoboHttpPingPongTest method configurePongSystem.

// Private Methods
private RoboSystem configurePongSystem() throws Exception {
    final RoboSystem result = new RoboSystem();
    Configuration config = ConfigurationFactory.createEmptyConfiguration();
    HttpServerUnit httpServer = new HttpServerUnit(result, "http_server");
    config.setString("target", CONTROLLER_PING_PONG);
    config.setInteger("port", PORT);
    config.setString("packages", "com.robo4j.core.httpunit.test.codec");
    /* specific configuration */
    Configuration targetUnits = config.createChildConfiguration(RoboHttpUtils.HTTP_TARGET_UNITS);
    targetUnits.setString(CONTROLLER_PING_PONG, "POST");
    httpServer.initialize(config);
    StringConsumer consumer = new StringConsumer(result, "request_consumer");
    config = ConfigurationFactory.createEmptyConfiguration();
    consumer.initialize(config);
    HttpCommandTestController ctrl = new HttpCommandTestController(result, CONTROLLER_PING_PONG);
    config = ConfigurationFactory.createEmptyConfiguration();
    config.setString("target", "request_consumer");
    ctrl.initialize(config);
    result.addUnits(httpServer, consumer, ctrl);
    return result;
}
Also used : RoboSystem(com.robo4j.core.RoboSystem) Configuration(com.robo4j.core.configuration.Configuration) HttpCommandTestController(com.robo4j.core.httpunit.test.HttpCommandTestController) StringConsumer(com.robo4j.core.StringConsumer)

Example 9 with RoboSystem

use of com.robo4j.core.RoboSystem in project robo4j by Robo4J.

the class RoboHttpPingPongTest method pingPongTest.

@Test
public void pingPongTest() throws Exception {
    RoboSystem systemPong = configurePongSystem();
    RoboSystem systemPing = configurePingSystem();
    System.out.println("systemPong: State before start:");
    System.out.println(SystemUtil.printStateReport(systemPong));
    systemPong.start();
    System.out.println("systemPong: State after start:");
    System.out.println(SystemUtil.printStateReport(systemPong));
    System.out.println("systemPing: State before start:");
    System.out.println(SystemUtil.printStateReport(systemPing));
    systemPing.start();
    System.out.println("systemPing: State after start:");
    System.out.println(SystemUtil.printStateReport(systemPing));
    System.out.println("systemPing: send messages");
    RoboReference<Object> systemPingProducer = systemPing.getReference("http_producer");
    for (int i = 0; i < MESSAGES; i++) {
        systemPingProducer.sendMessage("sendPostMessage::".concat(RoboHttpDynamicTests.JSON_STRING));
    }
    RoboReference<Object> pongConsumer = systemPong.getReference("request_consumer");
    System.out.println("systemPing : Going Down!");
    systemPing.stop();
    systemPing.shutdown();
    System.out.println("systemPong : Going Down!");
    systemPong.stop();
    final DefaultAttributeDescriptor<Integer> messagesNumberDescriptor = DefaultAttributeDescriptor.create(Integer.class, "getNumberOfSentMessages");
    final int number = pongConsumer.getAttribute(messagesNumberDescriptor).get();
    // NOTE: Not working
    Assert.assertEquals(number, MESSAGES);
    System.out.println("PingPong is down!");
    systemPong.shutdown();
}
Also used : RoboSystem(com.robo4j.core.RoboSystem) Test(org.junit.Test)

Example 10 with RoboSystem

use of com.robo4j.core.RoboSystem in project robo4j by Robo4J.

the class RoboHttpPingPongTest method configurePingSystem.

private RoboSystem configurePingSystem() throws Exception {
    final RoboSystem result = new RoboSystem();
    Configuration config = ConfigurationFactory.createEmptyConfiguration();
    HttpClientUnit httpClient = new HttpClientUnit(result, "http_client");
    config.setString("address", HOST_SYSTEM);
    config.setInteger("port", PORT);
    /* specific configuration */
    Configuration targetUnits = config.createChildConfiguration(RoboHttpUtils.HTTP_TARGET_UNITS);
    targetUnits.setString(CONTROLLER_PING_PONG, "POST");
    httpClient.initialize(config);
    StringProducer producer = new StringProducer(result, "http_producer");
    config = ConfigurationFactory.createEmptyConfiguration();
    config.setString("target", "http_client");
    config.setString("method", "POST");
    config.setString("uri", "/controller");
    config.setString("targetAddress", HOST_SYSTEM);
    producer.initialize(config);
    result.addUnits(producer, httpClient);
    return result;
}
Also used : RoboSystem(com.robo4j.core.RoboSystem) Configuration(com.robo4j.core.configuration.Configuration) StringProducer(com.robo4j.core.StringProducer)

Aggregations

RoboSystem (com.robo4j.core.RoboSystem)12 Configuration (com.robo4j.core.configuration.Configuration)9 Test (org.junit.Test)8 HttpCommandTestController (com.robo4j.core.httpunit.test.HttpCommandTestController)3 StringConsumer (com.robo4j.core.StringConsumer)2 Robo4JSystem (com.robo4j.db.sql.model.Robo4JSystem)2 RoboEntity (com.robo4j.db.sql.model.RoboEntity)2 List (java.util.List)2 StringProducer (com.robo4j.core.StringProducer)1 HttpServerUnit (com.robo4j.core.httpunit.HttpServerUnit)1 Robo4JUnit (com.robo4j.db.sql.model.Robo4JUnit)1 LcdTestUnit (com.robo4j.units.lego.LcdTestUnit)1 SimpleTankTestUnit (com.robo4j.units.lego.SimpleTankTestUnit)1 LegoPlatformMessage (com.robo4j.units.lego.platform.LegoPlatformMessage)1