Search in sources :

Example 11 with RoboBuilder

use of com.robo4j.RoboBuilder in project robo4j by Robo4J.

the class RoboHttpUnitGetTestApp method twoAttributesSystem.

private RoboContext twoAttributesSystem() throws Exception {
    Configuration systemConfiguration = new ConfigurationBuilder().addInteger("poolSizeScheduler", 4).addInteger("poolSizeWorker", 2).addInteger("poolSizeBlocking", 3).build();
    RoboBuilder builder = new RoboBuilder(systemConfiguration);
    final HttpPathConfigJsonBuilder pathBuilder = HttpPathConfigJsonBuilder.Builder().addPath("controller", HttpMethod.GET);
    Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, SERVER_PORT).addString("packages", PACKAGE_CODECS).addString(PROPERTY_UNIT_PATHS_CONFIG, pathBuilder.build()).build();
    builder.add(HttpServerUnit.class, config, "http_server");
    config = new ConfigurationBuilder().addInteger(StringConsumer.PROP_TOTAL_NUMBER_MESSAGES, 1).build();
    builder.add(StringConsumer.class, config, "request_consumer");
    config = new ConfigurationBuilder().addString("target", "request_consumer").build();
    builder.add(HttpTwoAttributesGetController.class, config, "controller");
    return builder.build();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) HttpPathConfigJsonBuilder(com.robo4j.socket.http.util.HttpPathConfigJsonBuilder) RoboBuilder(com.robo4j.RoboBuilder)

Example 12 with RoboBuilder

use of com.robo4j.RoboBuilder in project robo4j by Robo4J.

the class RoboHttpPingPongTest method configurePingSystem.

private RoboContext configurePingSystem() throws Exception {
    /* system which is testing main system */
    RoboBuilder builder = new RoboBuilder();
    Configuration config = new ConfigurationBuilder().addString(PROPERTY_HOST, HOST_SYSTEM).addInteger(PROPERTY_SOCKET_PORT, PORT).build();
    builder.add(HttpClientUnit.class, config, ID_HTTP_CLIENT);
    config = new ConfigurationBuilder().addString(PROPERTY_TARGET, ID_HTTP_CLIENT).addString(PROPERTY_UNIT_PATHS_CONFIG, "[{\"roboUnit\":\"" + CONTROLLER_PING_PONG + "\",\"method\":\"POST\"}]").addString("message", RoboHttpDynamicTests.JSON_STRING).build();
    builder.add(SocketMessageDecoratedProducerUnit.class, config, DECORATED_PRODUCER);
    return builder.build();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder)

Example 13 with RoboBuilder

use of com.robo4j.RoboBuilder in project robo4j by Robo4J.

the class HttpContextTests method clientSimpleContextTest.

@Test
void clientSimpleContextTest() throws Exception {
    RoboBuilder builderProducer = new RoboBuilder();
    InputStream contextIS = Thread.currentThread().getContextClassLoader().getResourceAsStream("robo_client_context.xml");
    builderProducer.add(contextIS);
    List<HttpPathMethodDTO> paths = Collections.singletonList(new HttpPathMethodDTO(StringConstants.EMPTY, HttpMethod.GET, Collections.singletonList(StringConsumer.NAME)));
    ClientContext context = new ClientContext();
    HttpPathUtils.updateHttpClientContextPaths(context, paths);
    PathHttpMethod basicGet = new PathHttpMethod(Utf8Constant.UTF8_SOLIDUS, HttpMethod.GET);
    System.out.println("context: " + context);
    assertNotNull(context);
    assertNotNull(context.getPathConfig(basicGet));
    assertTrue(!context.getPathConfig(basicGet).getCallbacks().isEmpty());
    assertEquals(HttpMethod.GET, context.getPathConfig(basicGet).getMethod());
    assertEquals(1, context.getPathConfig(basicGet).getCallbacks().size());
    assertEquals(StringConsumer.NAME, context.getPathConfig(basicGet).getCallbacks().get(0));
}
Also used : InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder) HttpPathMethodDTO(com.robo4j.socket.http.dto.HttpPathMethodDTO) Test(org.junit.jupiter.api.Test)

Example 14 with RoboBuilder

use of com.robo4j.RoboBuilder in project robo4j by Robo4J.

the class HttpServerUnitTests method httpServerUnitNoPathTest.

@Test
void httpServerUnitNoPathTest() throws Exception {
    RoboBuilder builder = new RoboBuilder();
    Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT).addString(PROPERTY_CODEC_PACKAGES, PACKAGE_CODECS).build();
    builder.add(HttpServerUnit.class, config, ID_HTTP_SERVER);
    RoboContext system = builder.build();
    system.start();
    System.out.println("system: State after start:");
    System.out.println(SystemUtil.printStateReport(system));
    RoboReference<HttpServerUnit> systemReference = system.getReference(ID_HTTP_SERVER);
    system.shutdown();
    System.out.println("system: State after shutdown:");
    System.out.println(SystemUtil.printStateReport(system));
    assertEquals(LifecycleState.SHUTDOWN, systemReference.getState());
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) Test(org.junit.jupiter.api.Test)

Example 15 with RoboBuilder

use of com.robo4j.RoboBuilder in project robo4j by Robo4J.

the class RoboContextUtils method loadRoboContextBySystemAndContextXml.

public static RoboContext loadRoboContextBySystemAndContextXml(String... xmlFilename) throws RoboBuilderException {
    if (xmlFilename == null || xmlFilename.length == 0 || xmlFilename.length > 2) {
        throw new IllegalArgumentException("usage: systemConf.xml contextConf.xml");
    }
    InputStream systemIS = RoboContextUtils.class.getClassLoader().getResourceAsStream(xmlFilename[0]);
    InputStream contextIS = RoboContextUtils.class.getClassLoader().getResourceAsStream(xmlFilename[1]);
    RoboBuilder builder = new RoboBuilder(systemIS);
    builder.add(contextIS);
    return builder.build();
}
Also used : InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder)

Aggregations

RoboBuilder (com.robo4j.RoboBuilder)45 RoboContext (com.robo4j.RoboContext)33 InputStream (java.io.InputStream)20 Configuration (com.robo4j.configuration.Configuration)18 ConfigurationBuilder (com.robo4j.configuration.ConfigurationBuilder)17 Test (org.junit.jupiter.api.Test)13 FileInputStream (java.io.FileInputStream)5 HttpPathConfigJsonBuilder (com.robo4j.socket.http.util.HttpPathConfigJsonBuilder)4 RoboBuilderException (com.robo4j.RoboBuilderException)3 IOException (java.io.IOException)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 StringConsumer (com.robo4j.StringConsumer)2 BiColor (com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor)2 DataEvent3f (com.robo4j.hw.rpi.imu.bno.DataEvent3f)2 CameraMessage (com.robo4j.socket.http.codec.CameraMessage)2 BnoRequest (com.robo4j.units.rpi.imu.BnoRequest)2 FileNotFoundException (java.io.FileNotFoundException)2 Path (java.nio.file.Path)2 Scanner (java.util.Scanner)2