Search in sources :

Example 6 with Configuration

use of com.robo4j.core.configuration.Configuration in project robo4j by Robo4J.

the class SQLDataSourceUnitTests method testH2Database.

@SuppressWarnings("unchecked")
@Test
public void testH2Database() throws Exception {
    final RoboSystem system = new RoboSystem();
    Configuration config = ConfigurationFactory.createEmptyConfiguration();
    SQLDataSourceUnit sqlDataSourceUnit = new SQLDataSourceUnit(system, "dbSQLUnit");
    config.setString("sourceType", "h2");
    config.setString("packages", "com.robo4j.db.sql.model");
    config.setInteger("limit", 2);
    config.setString("sorted", "asc");
    sqlDataSourceUnit.initialize(config);
    system.addUnits(sqlDataSourceUnit);
    System.out.println("systemPong: State before start:");
    System.out.println(SystemUtil.printStateReport(system));
    system.start();
    System.out.println("systemPong: State after start:");
    System.out.println(SystemUtil.printStateReport(system));
    Robo4JUnit robo4JUnit1 = new Robo4JUnit();
    robo4JUnit1.setUid("system1");
    robo4JUnit1.setConfig("dbSQLUnit,httpClient");
    Robo4JUnit robo4JUnit2 = new Robo4JUnit();
    robo4JUnit2.setUid("system2");
    robo4JUnit2.setConfig("httpServer");
    Robo4JSystem robo4JSystem = new Robo4JSystem();
    robo4JSystem.setUid("mainSystem");
    sqlDataSourceUnit.onMessage(robo4JUnit1);
    sqlDataSourceUnit.onMessage(robo4JUnit2);
    sqlDataSourceUnit.onMessage(robo4JSystem);
    AttributeDescriptor<List> descriptor1 = DefaultAttributeDescriptor.create(List.class, "units");
    List<RoboEntity<Long>> list1 = (List<RoboEntity<Long>>) sqlDataSourceUnit.onGetAttribute(descriptor1);
    System.out.println("Stored entities = " + list1);
    AttributeDescriptor<List> descriptor2 = DefaultAttributeDescriptor.create(List.class, "system");
    List<RoboEntity<Long>> list2 = sqlDataSourceUnit.onGetAttribute(descriptor2);
    System.out.println("Stored system1 = " + list2);
    Assert.assertTrue(Arrays.asList(robo4JUnit1, robo4JUnit2, robo4JSystem).size() == list1.size());
    Assert.assertTrue(list1.contains(robo4JUnit1));
    Assert.assertTrue(list1.contains(robo4JUnit2));
    Assert.assertTrue(list1.contains(robo4JSystem));
    Assert.assertTrue(Arrays.asList(robo4JSystem).size() == list2.size());
    Assert.assertTrue(list2.contains(robo4JSystem));
    system.shutdown();
    System.out.println("systemPong: State after shutdown:");
    System.out.println(SystemUtil.printStateReport(system));
}
Also used : RoboEntity(com.robo4j.db.sql.model.RoboEntity) RoboSystem(com.robo4j.core.RoboSystem) Configuration(com.robo4j.core.configuration.Configuration) Robo4JUnit(com.robo4j.db.sql.model.Robo4JUnit) Robo4JSystem(com.robo4j.db.sql.model.Robo4JSystem) List(java.util.List) Test(org.junit.Test)

Example 7 with Configuration

use of com.robo4j.core.configuration.Configuration in project robo4j by Robo4J.

the class SQLDataSourceUnitTests method testEntityOrderWithLimit.

@SuppressWarnings("unchecked")
@Test
public void testEntityOrderWithLimit() throws Exception {
    final int max = 5;
    final int limit = 2;
    final RoboSystem system = new RoboSystem();
    Configuration config = ConfigurationFactory.createEmptyConfiguration();
    SQLDataSourceUnit sqlDataSourceUnit = new SQLDataSourceUnit(system, "dbSQLUnit");
    config.setString("sourceType", "h2");
    config.setString("packages", "com.robo4j.db.sql.model");
    config.setInteger("limit", limit);
    config.setString("sorted", "desc");
    sqlDataSourceUnit.initialize(config);
    system.addUnits(sqlDataSourceUnit);
    System.out.println("systemPong: State before start:");
    System.out.println(SystemUtil.printStateReport(system));
    system.start();
    System.out.println("systemPong: State after start:");
    System.out.println(SystemUtil.printStateReport(system));
    Robo4JSystem robo4JSystem = null;
    for (int i = 0; i < max; i++) {
        robo4JSystem = new Robo4JSystem();
        robo4JSystem.setUid("mainSystem");
        sqlDataSourceUnit.onMessage(robo4JSystem);
    }
    AttributeDescriptor<List> descriptor1 = DefaultAttributeDescriptor.create(List.class, "system");
    List<RoboEntity<Long>> list1 = sqlDataSourceUnit.onGetAttribute(descriptor1);
    System.out.println("Stored system1 = " + list1);
    Assert.assertNotNull(robo4JSystem);
    Assert.assertTrue(list1.size() == limit);
    Assert.assertTrue(list1.get(0).getId() == max);
    system.shutdown();
    System.out.println("systemPong: State after shutdown:");
    System.out.println(SystemUtil.printStateReport(system));
}
Also used : RoboEntity(com.robo4j.db.sql.model.RoboEntity) RoboSystem(com.robo4j.core.RoboSystem) Configuration(com.robo4j.core.configuration.Configuration) Robo4JSystem(com.robo4j.db.sql.model.Robo4JSystem) List(java.util.List) Test(org.junit.Test)

Example 8 with Configuration

use of com.robo4j.core.configuration.Configuration 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 9 with Configuration

use of com.robo4j.core.configuration.Configuration 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 10 with Configuration

use of com.robo4j.core.configuration.Configuration 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)

Aggregations

Configuration (com.robo4j.core.configuration.Configuration)12 RoboSystem (com.robo4j.core.RoboSystem)7 Test (org.junit.Test)4 ConfigurationException (com.robo4j.core.ConfigurationException)2 LifecycleState (com.robo4j.core.LifecycleState)2 RoboContext (com.robo4j.core.RoboContext)2 RoboUnit (com.robo4j.core.RoboUnit)2 StringConsumer (com.robo4j.core.StringConsumer)2 RoboHttpUtils (com.robo4j.core.client.util.RoboHttpUtils)2 Constants (com.robo4j.core.httpunit.Constants)2 CameraMessage (com.robo4j.core.httpunit.codec.CameraMessage)2 CameraMessageCodec (com.robo4j.core.httpunit.codec.CameraMessageCodec)2 HttpCommandTestController (com.robo4j.core.httpunit.test.HttpCommandTestController)2 SimpleLoggingUtil (com.robo4j.core.logging.SimpleLoggingUtil)2 Robo4JSystem (com.robo4j.db.sql.model.Robo4JSystem)2 RoboEntity (com.robo4j.db.sql.model.RoboEntity)2 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 Base64 (java.util.Base64)2 HashMap (java.util.HashMap)2