Search in sources :

Example 11 with GroupWidget

use of org.csstudio.display.builder.model.widgets.GroupWidget in project org.csstudio.display.builder by kasemir.

the class PersistenceUnitTest method testWidgetReading.

/**
 * Read widgets from XML
 *  @throws Exception on error
 */
@Test
public void testWidgetReading() throws Exception {
    final String xml = getExampleFile();
    final InputStream stream = new ByteArrayInputStream(xml.getBytes());
    final ModelReader reader = new ModelReader(stream);
    final DisplayModel model = reader.readModel();
    final List<Widget> widgets = model.getChildren();
    for (final Widget widget : widgets) {
        System.out.println(widget);
        System.out.println(widget.getProperties().stream().map(Object::toString).collect(Collectors.joining("\n")));
    }
    assertThat(widgets.size(), equalTo(2));
    final List<String> names = widgets.stream().map(Widget::getName).collect(Collectors.toList());
    assertThat(names, equalTo(Arrays.asList("Demo", "My Group")));
    assertThat(widgets.get(1), instanceOf(GroupWidget.class));
    assertThat(((GroupWidget) widgets.get(1)).runtimeChildren().getValue().get(0).getName(), equalTo("Jänner"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CustomWidget(org.csstudio.display.builder.model.CustomWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Widget(org.csstudio.display.builder.model.Widget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) WidgetFactoryUnitTest(org.csstudio.display.builder.model.WidgetFactoryUnitTest) Test(org.junit.Test)

Aggregations

GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)11 DisplayModel (org.csstudio.display.builder.model.DisplayModel)6 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)6 Widget (org.csstudio.display.builder.model.Widget)5 Test (org.junit.Test)5 CustomWidget (org.csstudio.display.builder.model.CustomWidget)2 WidgetFactoryUnitTest (org.csstudio.display.builder.model.WidgetFactoryUnitTest)2 EmbeddedDisplayWidget (org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Level (java.util.logging.Level)1 Collectors (java.util.stream.Collectors)1