LayoutInflater { public Component inflate(InputStream xml) { Map<String, Component> empty = Collections.emptyMap(); return inflate(xml, empty); }  Component inflate(InputStream xml); Component inflate(InputStream xml,
            Map<String, Component> componentOverrideMap); Component inflate(InputStream xml,
            Map<String, Component> componentOverrideMap,
            ComponentProvider... additionalComponentProviders); Component inflate(InputStream xml,
            ComponentProvider... componentProviders); Component inflate(InputStream xml,
            List<ComponentProvider> componentProviders); void addAttributeFilter(AttributeFilter attributeFilter); void removeAttributeFilter(AttributeFilter attributeFilter); void addAttributeParser(AttributeParser attributeParser);  }
@Test public void inflate_customComponent_deprecatedMethodNeverCalled() { try { inflater.inflate(getXml("custom-component.xml")); } catch (AttributeHandlerException e) { fail(); } }
@Test public void inflate_alignmentTest_alignmentAssignedCorrectly() { VerticalLayout layout = (VerticalLayout) inflater .inflate(getXml("alignment-test.xml")); Component child = layout.getComponent(0); assertEquals(Alignment.TOP_RIGHT, layout.getComponentAlignment(child)); }
@Test public void inflate_layoutAttributes_layoutAttributesApplied() { Component layout = inflater.inflate(getXml("layout-attributes.xml")); assertEquals(com.vaadin.ui.VerticalLayout.class, layout.getClass()); VerticalLayout verticalLayout = (VerticalLayout) layout; Component button = verticalLayout.getComponentIterator().next(); assertEquals(1.0f, verticalLayout.getExpandRatio(button), 0.0f); }
@Test public void inflate_componentHasWidth_widthAttributeApplied() { Component layout = inflater.inflate(getXml("component-width.xml")); Button button200px = (Button) Clara.findComponentById(layout, "button200px"); assertEquals(200.0f, button200px.getWidth(), 0.0f); }
@Test public void inflate_componentWithEnumAttribute_attributeApplied() { Label htmlModeLabel = (Label) inflater .inflate(getXml("enum-label.xml")); assertEquals(ContentMode.HTML, htmlModeLabel.getContentMode()); }
@Test public void inflate_singleButton_findByIdWorks() { Component view = inflater.inflate(getXml("single-button.xml")); assertEquals(com.vaadin.ui.Button.class, Clara.findComponentById(view, "myButton").getClass()); assertEquals(null, Clara.findComponentById(view, "non-existing-id")); }
@Test public void inflate_checkBox_valueTrue() { CheckBox checkBox = (CheckBox) inflater.inflate(getXml("checkbox.xml")); assertEquals(true, checkBox.getValue()); }
@Test(expected = LayoutInflaterException.class) public void inflate_nonComponent_exceptionThrown() { inflater.inflate(getXml("non-component.xml")); }
@Test(expected = LayoutInflaterException.class) public void inflate_duplicateId_exceptionThrown() { inflater.inflate(getXml("duplicate-id.xml")); }
@Test(expected = LayoutInflaterException.class) public void inflate_IOException_exceptionThrown() { inflater.inflate(new InputStream() { @Override public int read() throws IOException { throw new IOException(); } }); }
@Test(expected = LayoutInflaterException.class) public void inflate_invalidXml_exceptionThrown() { inflater.inflate(new ByteArrayInputStream("THIS IS NOT XML!".getBytes())); }
@Test public void inflate_singleButton_buttonInstantiated() { Button button = (Button) inflater.inflate(getXml("single-button.xml")); assertEquals(com.vaadin.ui.Button.class, button.getClass()); assertEquals("My Button", button.getCaption()); assertEquals(1, button.getTabIndex()); }
@Test public void inflate_inflaterListener_called() { VerticalLayoutWithInflaterListener layout = (VerticalLayoutWithInflaterListener) inflater .inflate(getXml("component-with-inflaterlistener.xml")); assertTrue("Expected componentInflated to have been called", layout.isComponentInflatedCalled()); assertEquals( "Expected id to have been set before call to componentInflated", "idOfVerticalLayoutWithInflaterListener", layout.getIdAfterInflate()); assertEquals( "Expected child components to have been added before componentInflated", 1, layout.getComponentCountAfterInflate()); }
@Test public void inflate_panel() { Panel panel = (Panel) inflater.inflate(getXml("panel.xml")); assertEquals(1, panel.getComponentCount()); assertEquals(Button.class, panel.getContent().getClass()); }
@Test public void inflate_tabSheet_captionsAssigned() { TabSheet layout = (TabSheet) inflater.inflate(getXml("tabsheet.xml")); assertEquals("caption-tab1", layout.getTab(0).getCaption()); assertEquals("caption-tab2", layout.getTab(1).getCaption()); }
@Test public void inflate_absoluteLayout() { AbsoluteLayout layout = (AbsoluteLayout) inflater .inflate(getXml("absolutelayout.xml")); Button button = (Button) layout.getComponentIterator().next(); assertEquals(20, layout.getPosition(button).getTopValue(), 0); assertEquals(10, layout.getPosition(button).getLeftValue(), 0); assertEquals(Unit.PIXELS, layout.getPosition(button).getTopUnits()); assertEquals(Unit.PERCENTAGE, layout.getPosition(button).getLeftUnits()); }
@Test public void inflate_singleButtonNoNamespace_buttonInstantiated() { Component button = inflater .inflate(getXml("single-button-no-namespace.xml")); assertEquals(com.vaadin.ui.Button.class, button.getClass()); assertEquals("My Button", button.getCaption()); assertEquals(true, button.isReadOnly()); }
@Test public void inflate_singleLayout_layoutWithMarginsInstantiated() { Component layout = inflater.inflate(getXml("single-layout.xml")); assertEquals(new MarginInfo(true, false, false, true), ((VerticalLayout) layout).getMargin()); }
@Test public void inflate_singleLayout_sizeFull() { Component layout = inflater.inflate(getXml("single-layout.xml")); assertEquals(100, layout.getWidth(), 0); assertEquals(100, layout.getHeight(), 0); assertEquals(Unit.PERCENTAGE, layout.getWidthUnits()); assertEquals(Unit.PERCENTAGE, layout.getHeightUnits()); }
@Test public void inflate_simpleMargin_layoutMarginTrue() { Component layout = inflater.inflate(getXml("simple-margin.xml")); assertEquals(new MarginInfo(true), ((VerticalLayout) layout).getMargin()); }
@Test public void inflate_simpleMargin_innerLayoutMarginFalse() { VerticalLayout layout = (VerticalLayout) inflater .inflate(getXml("simple-margin.xml")); assertEquals(new MarginInfo(false), ((VerticalLayout) layout.getComponent(0)).getMargin()); }