use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.
the class TankExampleTests method legoTankExampleTest.
@Test
@Disabled("rethink and remove dependency")
void legoTankExampleTest() throws Exception {
RoboBuilder builder = new RoboBuilder();
Configuration config = new ConfigurationBuilder().addString("target", ID_UNIT_CONTROLLER).addInteger("port", PORT).addString("packages", "com.robo4j.units.lego.example.codec").addString(RoboHttpUtils.PROPERTY_UNIT_PATHS_CONFIG, HttpPathConfigJsonBuilder.Builder().addPath(ID_UNIT_CONTROLLER, HttpMethod.GET).build()).build();
builder.add(HttpServerUnit.class, config, ID_HTTP);
builder.add(TankExampleController.class, new ConfigurationBuilder().addString("target", ID_PLATFORM).build(), ID_UNIT_CONTROLLER);
/* platform is listening to the bus */
config = new ConfigurationBuilder().addString("leftMotorPort", "B").addCharacter("leftMotorType", 'N').addString("rightMotorPort", "C").addCharacter("rightMotorType", 'N').build();
builder.add(SimpleTankTestUnit.class, config, ID_PLATFORM);
/* lcd is listening to the bus */
builder.add(LcdTestUnit.class, ID_LCD);
RoboContext context = builder.build();
context.start();
context.getReference(ID_LCD).sendMessage("Press <Enter> to quit!");
System.in.read();
context.shutdown();
}
use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.
the class RemoteContextTests method buildRemoteReceiverContext.
/*
* Builds a system ready to receive TestMessageType messages, which contains a
* reference to which the String message "acknowledge" will be sent when a
* message is received.
*/
private RoboContext buildRemoteReceiverContext(String name) throws RoboBuilderException, ConfigurationException {
RoboBuilder builder = new RoboBuilder(SystemUtil.getInputStreamByResourceName("testRemoteReceiver.xml"));
Configuration configuration = new ConfigurationBuilder().addInteger(AckingStringConsumer.ATTR_TOTAL_NUMBER_MESSAGES, 1).build();
builder.add(AckingStringConsumer.class, configuration, name);
return builder.build();
}
use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.
the class RemoteContextTests method buildReceiverSystemStringConsumer.
/*
* Builds a system ready to receive strings.
*/
private RoboContext buildReceiverSystemStringConsumer() throws RoboBuilderException, ConfigurationException {
RoboBuilder builder = new RoboBuilder(SystemUtil.getInputStreamByResourceName("testRemoteReceiver.xml"));
Configuration configuration = new ConfigurationBuilder().addInteger("totalNumberMessages", 1).build();
StringConsumer stringConsumer = new StringConsumer(builder.getContext(), UNIT_STRING_CONSUMER);
stringConsumer.initialize(configuration);
builder.add(stringConsumer);
RoboContext receiverSystem = builder.build();
receiverSystem.start();
return receiverSystem;
}
use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.
the class MessageServerTest method createTestContext.
public static RoboContext createTestContext() {
RoboTestContext testContext = new RoboTestContext("TestContext", ConfigurationFactory.createEmptyConfiguration());
Configuration configuration = new ConfigurationBuilder().addString("name", "Test").addString("description", "Lalalala").build();
testContext.addRef(new RoboTestReference("test", configuration));
return testContext;
}
use of com.robo4j.configuration.Configuration in project robo4j by Robo4J.
the class MessageServerTest method testMessageTypes.
@Test
void testMessageTypes() throws Exception {
final String messageText = "Lalala";
final int messagesNumber = 8;
final List<Object> messages = new ArrayList<>(messagesNumber);
final CountDownLatch messageLatch = new CountDownLatch(messagesNumber);
Configuration serverConfig = new ConfigurationBuilder().addString(PROPERTY_SERVER_NAME, "Server Name").addString(MessageServer.KEY_HOST_NAME, "localhost").build();
MessageServer server = new MessageServer((uuid, id, message) -> {
System.out.println("Got uuid: " + uuid + " got id:" + id + " message:" + message);
messages.add(message);
messageLatch.countDown();
}, serverConfig);
Thread t = new Thread(() -> {
try {
server.start();
} catch (IOException e) {
exception = e;
fail(e.getMessage());
}
}, "Server Listener");
t.setDaemon(true);
t.start();
for (int i = 0; i < 10; i++) {
if (server.getListeningPort() == 0) {
Thread.sleep(250);
} else {
break;
}
}
Configuration clientConfig = ConfigurationFactory.createEmptyConfiguration();
MessageClient client = new MessageClient(server.getListeningURI(), CONST_MYUUID, clientConfig);
if (exception != null) {
throw exception;
}
client.connect();
client.sendMessage("test1", Byte.valueOf((byte) 1));
client.sendMessage("test2", Short.valueOf((short) 2));
client.sendMessage("test3", Character.valueOf((char) 3));
client.sendMessage("test4", Integer.valueOf(4));
client.sendMessage("test5", Float.valueOf(5.0f));
client.sendMessage("test6", Long.valueOf(6));
client.sendMessage("test7", Double.valueOf(7));
client.sendMessage("test8", new TestMessageType(8, messageText, null));
messageLatch.await(24, TimeUnit.HOURS);
assertEquals(messagesNumber, messages.size());
if (messages.get(0) instanceof Byte) {
assertEquals(((Byte) messages.get(0)).byteValue(), 1);
} else {
fail("Expected Byte!");
}
if (messages.get(1) instanceof Short) {
assertEquals(((Short) messages.get(1)).shortValue(), 2);
} else {
fail("Expected Short!");
}
if (messages.get(2) instanceof Character) {
assertEquals(((Character) messages.get(2)).charValue(), 3);
} else {
fail("Expected Character!");
}
if (messages.get(3) instanceof Integer) {
assertEquals(((Integer) messages.get(3)).intValue(), 4);
} else {
fail("Expected Integer!");
}
if (messages.get(4) instanceof Float) {
assertEquals(((Float) messages.get(4)).floatValue(), 5.0f, 0.000001);
} else {
fail("Expected Float!");
}
if (messages.get(5) instanceof Long) {
assertEquals(((Long) messages.get(5)).longValue(), 6);
} else {
fail("Expected Long!");
}
if (messages.get(6) instanceof Double) {
assertEquals(((Double) messages.get(6)).doubleValue(), 7.0, 0.000001);
} else {
fail("Expected Double!");
}
if (messages.get(7) instanceof TestMessageType) {
TestMessageType message = (TestMessageType) messages.get(7);
assertEquals(message.getNumber(), 8);
assertEquals(message.getText(), messageText);
} else {
fail("Expected TestMessageType!");
}
}
Aggregations