Search in sources :

Example 1 with CustomWidget

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

the class PersistenceUnitTest method testWidgetWriting.

/**
 * Writing widgets as XML
 *  @throws Exception on error
 */
@Test
public void testWidgetWriting() throws Exception {
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    try (final ModelWriter writer = new ModelWriter(stream)) {
        final Widget widget = new CustomWidget();
        widget.setPropertyValue(propName, "Demo");
        widget.getProperty(CustomWidget.propZeroTen).setValue(7);
        writer.writeWidget(widget);
        final GroupWidget group = new GroupWidget();
        group.setPropertyValue(propName, "My Group");
        final Widget child = new Widget("base");
        child.setPropertyValue(propName, "Jänner");
        group.runtimeChildren().addChild(child);
        writer.writeWidget(group);
    }
    final String xml = stream.toString();
    System.out.println(xml);
    final String desired = getExampleFile();
    assertThat(xml.replace("\r", ""), equalTo(desired));
}
Also used : 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) CustomWidget(org.csstudio.display.builder.model.CustomWidget) WidgetFactoryUnitTest(org.csstudio.display.builder.model.WidgetFactoryUnitTest) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CustomWidget (org.csstudio.display.builder.model.CustomWidget)1 Widget (org.csstudio.display.builder.model.Widget)1 WidgetFactoryUnitTest (org.csstudio.display.builder.model.WidgetFactoryUnitTest)1 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)1 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1