Search in sources :

Example 1 with XYPlotWidget

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

the class WidgetPropertiesUnitTest method testLegacyProperties.

@Test
public void testLegacyProperties() {
    final Widget plot = new XYPlotWidget();
    // Old and current name should lead to the same property
    WidgetProperty<?> legacy = plot.getProperty("axis_0_axis_title");
    WidgetProperty<?> current = plot.getProperty("x_axis.title");
    assertThat(legacy, sameInstance(current));
    legacy = plot.getProperty("axis_1_minimum");
    current = plot.getProperty("y_axes[0].minimum");
    assertThat(legacy, sameInstance(current));
    legacy = plot.getProperty("axis_1_auto_scale");
    current = plot.getProperty("y_axes[0].autoscale");
    assertThat(legacy, sameInstance(current));
    // getProperty() throws an exception for unknown names
    try {
        plot.getProperty("x_axis.not_the_title");
        fail("Didn't catch property name typo");
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
        assertThat(ex.getMessage(), containsString("not_the_title"));
    }
    // checkProperty does _not_ resolve paths nor legacy names
    assertThat(plot.checkProperty("x_axis").isPresent(), equalTo(true));
    assertThat(plot.checkProperty("x_axis.title").isPresent(), equalTo(false));
    assertThat(plot.checkProperty("axis_0_axis_title").isPresent(), equalTo(false));
}
Also used : XYPlotWidget(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget) XYPlotWidget(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget) MultiStateLEDWidget(org.csstudio.display.builder.model.widgets.MultiStateLEDWidget) Test(org.junit.Test)

Example 2 with XYPlotWidget

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

the class XYPlotWidgetTest method testXML.

/**
 * Check if XML out/in preserves the Y axis
 *  @throws Exception on error
 */
@Test
public void testXML() throws Exception {
    XYPlotWidget plot = new XYPlotWidget();
    assertYAxis(plot);
    final String xml = ModelWriter.getXML(Arrays.asList(plot));
    System.out.println(xml);
    final DisplayModel model = ModelReader.parseXML(xml);
    final List<Widget> widgets = model.getChildren();
    assertThat(widgets.size(), equalTo(1));
    assertThat(widgets.get(0), instanceOf(XYPlotWidget.class));
    plot = (XYPlotWidget) widgets.get(0);
    assertYAxis(plot);
}
Also used : XYPlotWidget(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget) DisplayModel(org.csstudio.display.builder.model.DisplayModel) XYPlotWidget(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget) Widget(org.csstudio.display.builder.model.Widget) Test(org.junit.Test)

Example 3 with XYPlotWidget

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

the class ArrayWidgetPropertyUnitTest method testPathAccess.

@Test
public void testPathAccess() throws Exception {
    final XYPlotWidget widget = new XYPlotWidget();
    widget.propTitle().setValue("The Title");
    widget.propXAxis().title().setValue("X Axis");
    widget.propYAxes().getElement(0).title().setValue("Y 1");
    String value;
    value = widget.getPropertyValue("title");
    assertThat(value, equalTo("The Title"));
    value = widget.getPropertyValue("x_axis.title");
    assertThat(value, equalTo("X Axis"));
    value = widget.getPropertyValue("y_axes[0].title");
    assertThat(value, equalTo("Y 1"));
    try {
        widget.getPropertyValue("y_axes[5].title");
        fail("Access beyond array size");
    } catch (IndexOutOfBoundsException ex) {
        assertThat(ex.getMessage(), containsString("only 1 element"));
    }
    try {
        widget.getPropertyValue("y_axes[5.title");
        fail("Bad array element syntax");
    } catch (IllegalArgumentException ex) {
        assertThat(ex.getMessage().toLowerCase(), containsString("missing"));
    }
}
Also used : XYPlotWidget(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

XYPlotWidget (org.csstudio.display.builder.model.widgets.plots.XYPlotWidget)3 Test (org.junit.Test)3 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1 Widget (org.csstudio.display.builder.model.Widget)1 MultiStateLEDWidget (org.csstudio.display.builder.model.widgets.MultiStateLEDWidget)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1