Search in sources :

Example 1 with RoboSystem

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

the class RoboHttpDynamicTests method simpleHttpNonUnitTest.

/**
	 * Motivation Client system is sending messages to the main system over HTTP
	 * Main System receives desired number of messages.
	 *
	 * Values are requested by Attributes
	 * 
	 * @throws Exception
	 */
@Test
public void simpleHttpNonUnitTest() throws Exception {
    /* tested system configuration */
    RoboSystem mainSystem = getServerRoboSystem();
    System.out.println(SystemUtil.printStateReport(mainSystem));
    System.out.println("Server start after start:");
    /* system which is testing main system */
    RoboSystem clientSystem = getClientRoboSystem();
    RoboReference<Object> httpClientReference = clientSystem.getReference(CLIENT_UNIT_ID);
    System.out.println(SystemUtil.printStateReport(clientSystem));
    System.out.println("Client State after start:");
    System.out.println("State after start:");
    System.out.println(SystemUtil.printStateReport(mainSystem));
    /* client system sending a messages to the main system */
    for (int i = 0; i < MESSAGES_NUMBER; i++) {
        httpClientReference.sendMessage(RoboHttpUtils.createPostRequest(HOST_SYSTEM, "/".concat(TARGET_UNIT), JSON_STRING));
    }
    clientSystem.stop();
    clientSystem.shutdown();
    System.out.println("Going Down!");
    mainSystem.stop();
    mainSystem.shutdown();
    System.out.println("System is Down!");
    Assert.assertNotNull(mainSystem.getUnits());
    Assert.assertEquals(mainSystem.getUnits().size(), MESSAGES_NUMBER);
}
Also used : RoboSystem(com.robo4j.core.RoboSystem) Test(org.junit.Test)

Example 2 with RoboSystem

use of com.robo4j.core.RoboSystem 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 3 with RoboSystem

use of com.robo4j.core.RoboSystem 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 4 with RoboSystem

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

the class HttpUriRegisterTests method registerSimpleTest.

@Test
public void registerSimpleTest() {
    /* tested system configuration */
    RoboSystem system = new RoboSystem();
    HttpUriRegister register = HttpUriRegister.getInstance();
    register.addNote(TARGET_UNIT, METHODS[0]);
    register.addNote(TARGET_UNIT, METHODS[1]);
    HttpCommandTestController ctrl = new HttpCommandTestController(system, TARGET_UNIT);
    register.addUnitToNote(TARGET_UNIT, ctrl);
    assertNotNull(register.getMethodsBytPath(TARGET_UNIT));
    assertEquals(register.getMethodsBytPath(TARGET_UNIT).getUnit(), ctrl);
    assertTrue(register.getMethodsBytPath(TARGET_UNIT).getMethods().containsAll(Arrays.asList(METHODS)));
}
Also used : RoboSystem(com.robo4j.core.RoboSystem) HttpCommandTestController(com.robo4j.core.httpunit.test.HttpCommandTestController) Test(org.junit.Test)

Example 5 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)

Aggregations

RoboSystem (com.robo4j.core.RoboSystem)10 Configuration (com.robo4j.core.configuration.Configuration)7 Test (org.junit.Test)6 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 Robo4JUnit (com.robo4j.db.sql.model.Robo4JUnit)1