use of com.robo4j.db.sql.model.RoboEntity 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));
}
use of com.robo4j.db.sql.model.RoboEntity 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));
}
Aggregations