From: John Alhroos Date: Fri, 16 Apr 2010 14:32:18 +0000 (+0000) Subject: Added JUnit tests and Vaadin test application for Table footer #1553 X-Git-Tag: 6.7.0.beta1~1727 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f5b1b31a7187c6574edc880be6dc20ab8c70274c;p=vaadin-framework.git Added JUnit tests and Vaadin test application for Table footer #1553 svn changeset:12615/svn branch:6.4 --- diff --git a/tests/src/com/vaadin/tests/components/table/Footer.java b/tests/src/com/vaadin/tests/components/table/Footer.java new file mode 100644 index 0000000000..2519766cfe --- /dev/null +++ b/tests/src/com/vaadin/tests/components/table/Footer.java @@ -0,0 +1,138 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.Property; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Table; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +@SuppressWarnings("serial") +public class Footer extends TestBase { + + @Override + protected void setup() { + HorizontalLayout layout = new HorizontalLayout(); + layout.setSpacing(true); + + final Table table = new Table(); + table.setWidth("400px"); + table.setHeight("400px"); + + table.setContainerDataSource(createContainer()); + table.setImmediate(true); + + table.setColumnCollapsingAllowed(true); + table.setColumnReorderingAllowed(true); + + table.setFooterVisible(true); + + table.setColumnFooter("col1", "Footer1"); + table.setColumnFooter("col2", "Footer2"); + table.setColumnFooter("col3", "Footer3"); + + table.setColumnAlignment("col2", Table.ALIGN_CENTER); + table.setColumnAlignment("col3", Table.ALIGN_RIGHT); + + layout.addComponent(table); + + // Add some options to play with + VerticalLayout options = new VerticalLayout(); + options.setSpacing(true); + + final CheckBox visible = new CheckBox("Footers Visible", true); + visible.setImmediate(true); + visible.addListener(new Property.ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + table.setFooterVisible(visible.booleanValue()); + + } + }); + + options.addComponent(visible); + + final TextField footer1Value = new TextField(null, "Footer1"); + footer1Value.setImmediate(true); + Button footer1Btn = new Button("Change", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + table.setColumnFooter("col1", + footer1Value.getValue() == null ? "" : footer1Value + .getValue().toString()); + } + }); + HorizontalLayout footer1 = new HorizontalLayout(); + footer1.addComponent(footer1Value); + footer1.addComponent(footer1Btn); + options.addComponent(footer1); + + final TextField footer2Value = new TextField(null, "Footer2"); + footer2Value.setImmediate(true); + Button footer2Btn = new Button("Change", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + table.setColumnFooter("col2", + footer2Value.getValue() == null ? "" : footer2Value + .getValue().toString()); + } + }); + HorizontalLayout footer2 = new HorizontalLayout(); + footer2.addComponent(footer2Value); + footer2.addComponent(footer2Btn); + options.addComponent(footer2); + + final TextField footer3Value = new TextField(null, "Footer3"); + footer3Value.setImmediate(true); + Button footer3Btn = new Button("Change", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + table.setColumnFooter("col3", + footer3Value.getValue() == null ? "" : footer3Value + .getValue().toString()); + } + }); + HorizontalLayout footer3 = new HorizontalLayout(); + footer3.addComponent(footer3Value); + footer3.addComponent(footer3Btn); + options.addComponent(footer3); + + layout.addComponent(options); + + addComponent(layout); + } + + @Override + protected String getDescription() { + return "Table with footer"; + } + + @Override + protected Integer getTicketNumber() { + return 1553; + } + + private Container createContainer() { + IndexedContainer container = new IndexedContainer(); + container.addContainerProperty("col1", String.class, ""); + container.addContainerProperty("col2", String.class, ""); + container.addContainerProperty("col3", String.class, ""); + + for (int i = 0; i < 100; i++) { + Item item = container.addItem("item " + i); + item.getItemProperty("col1").setValue("first" + i); + item.getItemProperty("col2").setValue("middle" + i); + item.getItemProperty("col3").setValue("last" + i); + } + + return container; + } + +} diff --git a/tests/src/com/vaadin/tests/server/component/table/TestFooter.java b/tests/src/com/vaadin/tests/server/component/table/TestFooter.java new file mode 100644 index 0000000000..ae880f8f09 --- /dev/null +++ b/tests/src/com/vaadin/tests/server/component/table/TestFooter.java @@ -0,0 +1,94 @@ +package com.vaadin.tests.server.component.table; + +import junit.framework.TestCase; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.ui.Table; + +/** + * Test case for testing the footer API + * + */ +public class TestFooter extends TestCase { + + /** + * Tests if setting the footer visibility works properly + */ + public void testFooterVisibility() { + Table table = new Table("Test table", createContainer()); + + // The footer should by default be hidden + assertFalse(table.isFooterVisible()); + + // Set footer visibility to tru should be reflected in the + // isFooterVisible() method + table.setFooterVisible(true); + assertTrue(table.isFooterVisible()); + } + + /** + * Tests adding footers to the columns + */ + public void testAddingFooters() { + Table table = new Table("Test table", createContainer()); + + // Table should not contain any footers at initialization + assertNull(table.getColumnFooter("col1")); + assertNull(table.getColumnFooter("col2")); + assertNull(table.getColumnFooter("col3")); + + // Adding column footer + table.setColumnFooter("col1", "Footer1"); + assertEquals("Footer1", table.getColumnFooter("col1")); + + // Add another footer + table.setColumnFooter("col2", "Footer2"); + assertEquals("Footer2", table.getColumnFooter("col2")); + + // Add footer for a non-existing column + table.setColumnFooter("fail", "FooterFail"); + } + + /** + * Test removing footers + */ + public void testRemovingFooters() { + Table table = new Table("Test table", createContainer()); + table.setColumnFooter("col1", "Footer1"); + table.setColumnFooter("col2", "Footer2"); + + // Test removing footer + assertNotNull(table.getColumnFooter("col1")); + table.setColumnFooter("col1", null); + assertNull(table.getColumnFooter("col1")); + + // The other footer should still be there + assertNotNull(table.getColumnFooter("col2")); + + // Remove non-existing footer + table.setColumnFooter("fail", null); + } + + /** + * Creates a container with three properties "col1,col2,col3" with 100 items + * + * @return Returns the created table + */ + private static Container createContainer() { + IndexedContainer container = new IndexedContainer(); + container.addContainerProperty("col1", String.class, ""); + container.addContainerProperty("col2", String.class, ""); + container.addContainerProperty("col3", String.class, ""); + + for (int i = 0; i < 100; i++) { + Item item = container.addItem("item " + i); + item.getItemProperty("col1").setValue("first" + i); + item.getItemProperty("col2").setValue("middle" + i); + item.getItemProperty("col3").setValue("last" + i); + } + + return container; + } +}