summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-12-10 09:48:40 +0200
committerArtur Signell <artur@vaadin.com>2015-01-29 14:25:39 +0200
commit51acaa67dbe2683137416810c3ca4e4e5fb4b359 (patch)
tree60d7cfbc8d18db55499abff76fc906d1b1b7f224
parenta66eeb58e8c1144c8d01cc37f727638139db711d (diff)
downloadvaadin-framework-51acaa67dbe2683137416810c3ca4e4e5fb4b359.tar.gz
vaadin-framework-51acaa67dbe2683137416810c3ca4e4e5fb4b359.zip
Basic CRUD test
Change-Id: I4aa0c6e0051731849cd960fb7376b3e01d0005b5
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/AbstractBasicCrud.java191
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/BasicCrud.java110
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGrid.java60
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java61
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTable.java59
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTableTest.java (renamed from uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTest.java)17
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/ComplexAddress.java70
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/ComplexPerson.java110
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/Country.java22
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/Gender.java20
-rw-r--r--uitest/src/com/vaadin/tests/util/PersonContainer.java72
-rw-r--r--uitest/src/com/vaadin/tests/util/TestDataGenerator.java110
12 files changed, 727 insertions, 175 deletions
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/AbstractBasicCrud.java b/uitest/src/com/vaadin/tests/fieldgroup/AbstractBasicCrud.java
new file mode 100644
index 0000000000..30cc5676bb
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/AbstractBasicCrud.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.fieldgroup;
+
+import java.util.Iterator;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.fieldgroup.BeanFieldGroup;
+import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
+import com.vaadin.data.fieldgroup.PropertyId;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.util.SharedUtil;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.Field;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.TextField;
+
+@Theme("valo")
+public abstract class AbstractBasicCrud extends AbstractTestUIWithLog {
+
+ protected AbstractForm form;
+ protected static String[] columns = new String[] { "firstName", "lastName",
+ "gender", "birthDate", "age", "alive", "address.streetAddress",
+ "address.postalCode", "address.city", "address.country" };
+ protected BeanItemContainer<ComplexPerson> container = ComplexPerson
+ .createContainer(100);;
+ {
+ container.addNestedContainerBean("address");
+ }
+ protected ComboBox formType;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
+ * VaadinRequest)
+ */
+ @Override
+ protected void setup(VaadinRequest request) {
+ getLayout().setSizeFull();
+ getLayout().setSpacing(true);
+ getContent().setSizeFull();
+ form = new CustomForm();
+
+ formType = new ComboBox();
+ formType.setNullSelectionAllowed(false);
+ formType.setWidth("300px");
+ formType.addItem(form);
+ formType.setValue(form);
+ formType.addItem(new AutoGeneratedForm(TextField.class));
+ formType.addItem(new AutoGeneratedForm(Field.class));
+ Iterator<?> iterator = formType.getItemIds().iterator();
+ formType.setItemCaption(iterator.next(), "TextField based form");
+ formType.setItemCaption(iterator.next(),
+ "Auto generated form (TextFields)");
+ formType.setItemCaption(iterator.next(),
+ "Auto generated form (Any fields)");
+ formType.addValueChangeListener(new ValueChangeListener() {
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ AbstractForm oldForm = form;
+ form = (AbstractForm) formType.getValue();
+ replaceComponent(oldForm, form);
+ }
+ });
+
+ addComponent(formType);
+
+ }
+
+ public class CustomForm extends AbstractForm {
+
+ private TextField firstName = new TextField("First name");
+ private TextField lastName = new TextField("Last name");
+ private TextField gender = new TextField("Gender");
+ private TextField birthDate = new TextField("Birth date");
+ private TextField age = new TextField("Age");
+ private CheckBox alive = new CheckBox("Alive");
+
+ @PropertyId("address.streetAddress")
+ private TextField address_streetAddress = new TextField(
+ "Street address");
+ @PropertyId("address.postalCode")
+ private TextField address_postalCode = new TextField("Postal code");
+ @PropertyId("address.city")
+ private TextField address_city = new TextField("City");
+ @PropertyId("address.country")
+ private TextField address_country = new TextField("Country");
+
+ public CustomForm() {
+ fieldGroup.bindMemberFields(this);
+
+ address_postalCode.setNullRepresentation("");
+ gender.setNullRepresentation("");
+ age.setNullRepresentation("");
+ address_country.setNullRepresentation("");
+ birthDate.setNullRepresentation("");
+
+ setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
+ addComponents(firstName, lastName, gender, birthDate, age, alive,
+ address_streetAddress, address_postalCode, address_city,
+ address_country);
+
+ HorizontalLayout hl = new HorizontalLayout(save, cancel);
+ hl.setSpacing(true);
+ addComponent(hl);
+
+ }
+
+ }
+
+ protected abstract void deselectAll();
+
+ public class AbstractForm extends GridLayout {
+ protected Button save = new Button("Save");
+ protected Button cancel = new Button("Cancel");
+
+ protected BeanFieldGroup<ComplexPerson> fieldGroup = new BeanFieldGroup<ComplexPerson>(
+ ComplexPerson.class);
+
+ public AbstractForm() {
+ super(5, 1);
+ setSpacing(true);
+ setId("form");
+ save.addClickListener(new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ try {
+ fieldGroup.commit();
+ log("Saved " + fieldGroup.getItemDataSource());
+ } catch (CommitException e) {
+ log("Commit failed: " + e.getMessage());
+ }
+ }
+ });
+ cancel.addClickListener(new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ log("Discarded " + fieldGroup.getItemDataSource());
+ deselectAll();
+ }
+ });
+ }
+
+ public void edit(BeanItem<ComplexPerson> item) {
+ fieldGroup.setItemDataSource(item);
+ }
+ }
+
+ public class AutoGeneratedForm extends AbstractForm {
+
+ public AutoGeneratedForm(Class<? extends Field> class1) {
+ for (String p : columns) {
+ Field f = fieldGroup.getFieldFactory().createField(
+ container.getType(p), class1);
+ f.setCaption(SharedUtil.propertyIdToHumanFriendly(p));
+ fieldGroup.bind(f, p);
+ addComponent(f);
+ }
+
+ HorizontalLayout hl = new HorizontalLayout(save, cancel);
+ hl.setSpacing(true);
+ addComponent(hl);
+ }
+
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrud.java b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrud.java
deleted file mode 100644
index be0368f4ae..0000000000
--- a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrud.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.fieldgroup;
-
-import com.vaadin.annotations.Theme;
-import com.vaadin.data.Property.ValueChangeEvent;
-import com.vaadin.data.Property.ValueChangeListener;
-import com.vaadin.data.fieldgroup.BeanFieldGroup;
-import com.vaadin.data.fieldgroup.PropertyId;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.util.Person;
-import com.vaadin.tests.util.PersonContainer;
-import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.ui.Table;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.UI;
-import com.vaadin.ui.VerticalLayout;
-
-@Theme("valo")
-public class BasicCrud extends UI {
-
- private Form form;
-
- @Override
- protected void init(VaadinRequest request) {
- VerticalLayout main = new VerticalLayout();
- main.setMargin(true);
- main.setSpacing(true);
- final Table t = new Table();
- // t.setSelectionMode(SelectionMode.SINGLE);
- t.setSelectable(true);
-
- PersonContainer c = PersonContainer.createWithTestData();
-
- c.addBean(new Person("first", "Last", "email", "phone", "street",
- 12332, "Turku"));
- c.addBean(new Person("Foo", "Bar", "me@some.where", "123",
- "homestreet 12", 10000, "Glasgow"));
- t.setContainerDataSource(c);
- // t.removeColumn("address");
- // t.setColumnOrder("firstName", "lastName", "email", "phoneNumber",
- // "address.streetAddress", "address.postalCode", "address.city");
- t.setVisibleColumns("firstName", "lastName", "email", "phoneNumber",
- "address.streetAddress", "address.postalCode", "address.city");
-
- // t.addSelectionChangeListener(new SelectionChangeListener() {
- // @Override
- // public void selectionChange(SelectionChangeEvent event) {
- // form.edit((Person) t.getSelectedRow());
- // }
- // });
- t.addValueChangeListener(new ValueChangeListener() {
-
- @Override
- public void valueChange(ValueChangeEvent event) {
- form.edit((Person) t.getValue());
- }
- });
-
- form = new Form();
-
- t.setSizeFull();
-
- main.setSizeFull();
- main.addComponent(t);
- main.addComponent(form);
- main.setExpandRatio(t, 1);
- setContent(main);
- }
-
- public static class Form extends HorizontalLayout {
- private TextField firstName = new TextField("First name");
- private TextField lastName = new TextField("Last name");
- private TextField email = new TextField("E-mail");
- @PropertyId("address.streetAddress")
- private TextField streetAddress = new TextField("Street address");
- @PropertyId("address.postalCode")
- private TextField postalCode = new TextField("Postal code");
-
- BeanFieldGroup<Person> fieldGroup = new BeanFieldGroup<Person>(
- Person.class);
-
- public Form() {
- setSpacing(true);
- setId("form");
- fieldGroup.bindMemberFields(this);
-
- // Stupid integer binding
- postalCode.setNullRepresentation("");
- addComponents(firstName, lastName, email, streetAddress, postalCode);
- }
-
- public void edit(Person p) {
- fieldGroup.setItemDataSource(p);
- }
- }
-}
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGrid.java b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGrid.java
new file mode 100644
index 0000000000..d7f66b0cd9
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGrid.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.fieldgroup;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.event.SelectionEvent;
+import com.vaadin.event.SelectionEvent.SelectionListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Grid;
+
+public class BasicCrudGrid extends AbstractBasicCrud {
+
+ private Grid grid;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ super.setup(request);
+ grid = new Grid();
+
+ grid.setContainerDataSource(container);
+
+ grid.setColumnOrder((Object[]) columns);
+ grid.removeColumn("salary");
+ grid.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void select(SelectionEvent event) {
+ Item item = grid.getContainerDataSource().getItem(
+ grid.getSelectedRow());
+ form.edit((BeanItem<ComplexPerson>) item);
+ }
+ });
+
+ grid.setSizeFull();
+
+ addComponent(grid);
+ addComponent(form);
+ getLayout().setExpandRatio(grid, 1);
+ }
+
+ @Override
+ protected void deselectAll() {
+ grid.select(null);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java
new file mode 100644
index 0000000000..63ba2986e1
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRow.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.fieldgroup;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.data.validator.IntegerRangeValidator;
+import com.vaadin.event.SelectionEvent;
+import com.vaadin.event.SelectionEvent.SelectionListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Grid;
+
+public class BasicCrudGridEditorRow extends AbstractBasicCrud {
+
+ private Grid grid;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ super.setup(request);
+ formType.setVisible(false);
+ grid = new Grid();
+
+ grid.setContainerDataSource(container);
+
+ grid.setColumnOrder((Object[]) columns);
+ grid.removeColumn("salary");
+ grid.addSelectionListener(new SelectionListener() {
+ @Override
+ public void select(SelectionEvent event) {
+ Item item = grid.getContainerDataSource().getItem(
+ grid.getSelectedRow());
+ form.edit((BeanItem<ComplexPerson>) item);
+ }
+ });
+ grid.setEditorEnabled(true);
+ grid.setSizeFull();
+ grid.getEditorField("age").addValidator(
+ new IntegerRangeValidator("Must be between 0 and 100", 0, 100));
+ addComponent(grid);
+ getLayout().setExpandRatio(grid, 1);
+ }
+
+ @Override
+ protected void deselectAll() {
+ grid.select(null);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTable.java b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTable.java
new file mode 100644
index 0000000000..ad54cd55ba
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTable.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.fieldgroup;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Table;
+
+public class BasicCrudTable extends AbstractBasicCrud {
+
+ private Table table;
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ super.setup(request);
+
+ table = new Table();
+ table.setSelectable(true);
+
+ table.setContainerDataSource(container);
+
+ table.setVisibleColumns((Object[]) columns);
+ table.addValueChangeListener(new ValueChangeListener() {
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ form.edit((BeanItem<ComplexPerson>) table.getItem(table
+ .getValue()));
+ }
+ });
+
+ table.setSizeFull();
+
+ addComponent(table);
+ addComponent(form);
+ getLayout().setExpandRatio(table, 1);
+ }
+
+ @Override
+ protected void deselectAll() {
+ table.setValue(null);
+
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTest.java b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTableTest.java
index a41725dbc9..86441b09f9 100644
--- a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTest.java
+++ b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudTableTest.java
@@ -20,19 +20,18 @@ import java.util.List;
import org.junit.Assert;
import org.junit.Test;
-import com.vaadin.testbench.elements.AbstractOrderedLayoutElement;
+import com.vaadin.testbench.AbstractHasTestBenchCommandExecutor;
+import com.vaadin.testbench.elements.AbstractComponentElement;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.tests.tb3.SingleBrowserTest;
-public class BasicCrudTest extends SingleBrowserTest {
+public class BasicCrudTableTest extends SingleBrowserTest {
@Test
public void fieldsInitiallyEmpty() {
openTestURL();
- AbstractOrderedLayoutElement fieldsLayout = $(
- AbstractOrderedLayoutElement.class).id("form");
- List<TextFieldElement> textFields = fieldsLayout.$(
+ List<TextFieldElement> textFields = getFieldsLayout().$(
TextFieldElement.class).all();
for (TextFieldElement e : textFields) {
@@ -40,16 +39,18 @@ public class BasicCrudTest extends SingleBrowserTest {
}
}
+ private AbstractHasTestBenchCommandExecutor getFieldsLayout() {
+ return $(AbstractComponentElement.class).id("form");
+ }
+
@Test
public void fieldsClearedOnDeselect() {
openTestURL();
- AbstractOrderedLayoutElement fieldsLayout = $(
- AbstractOrderedLayoutElement.class).id("form");
// Select row
$(TableElement.class).first().getCell(2, 2).click();
- List<TextFieldElement> textFields = fieldsLayout.$(
+ List<TextFieldElement> textFields = getFieldsLayout().$(
TextFieldElement.class).all();
for (TextFieldElement e : textFields) {
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/ComplexAddress.java b/uitest/src/com/vaadin/tests/fieldgroup/ComplexAddress.java
new file mode 100644
index 0000000000..d6d657379a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/ComplexAddress.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.fieldgroup;
+
+import java.util.Random;
+
+import com.vaadin.tests.util.TestDataGenerator;
+
+public class ComplexAddress {
+
+ private String streetAddress = "";
+ private String postalCode = "";
+ private String city = "";
+ private Country country = null;
+
+ public String getStreetAddress() {
+ return streetAddress;
+ }
+
+ public void setStreetAddress(String streetAddress) {
+ this.streetAddress = streetAddress;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public void setPostalCode(String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public Country getCountry() {
+ return country;
+ }
+
+ public void setCountry(Country country) {
+ this.country = country;
+ }
+
+ public static ComplexAddress create(Random r) {
+ ComplexAddress ca = new ComplexAddress();
+ ca.setCity(TestDataGenerator.getCity(r));
+ ca.setCountry(TestDataGenerator.getEnum(Country.class, r));
+ ca.setPostalCode(TestDataGenerator.getPostalCode(r) + "");
+ ca.setStreetAddress(TestDataGenerator.getStreetAddress(r));
+ return ca;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/ComplexPerson.java b/uitest/src/com/vaadin/tests/fieldgroup/ComplexPerson.java
new file mode 100644
index 0000000000..2fb7c2ac04
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/ComplexPerson.java
@@ -0,0 +1,110 @@
+package com.vaadin.tests.fieldgroup;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.Random;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.tests.util.TestDataGenerator;
+
+public class ComplexPerson {
+
+ private String firstName, lastName;
+ private Integer age;
+ private Date birthDate;
+ private BigDecimal salary;
+ private boolean alive;
+ private Gender gender;
+ private ComplexAddress address;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public Integer getAge() {
+ return age;
+ }
+
+ public void setAge(Integer age) {
+ this.age = age;
+ }
+
+ public Date getBirthDate() {
+ return birthDate;
+ }
+
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+
+ public BigDecimal getSalary() {
+ return salary;
+ }
+
+ public void setSalary(BigDecimal salary) {
+ this.salary = salary;
+ }
+
+ public boolean isAlive() {
+ return alive;
+ }
+
+ public void setAlive(boolean alive) {
+ this.alive = alive;
+ }
+
+ public Gender getGender() {
+ return gender;
+ }
+
+ public void setGender(Gender gender) {
+ this.gender = gender;
+ }
+
+ public ComplexAddress getAddress() {
+ return address;
+ }
+
+ public void setAddress(ComplexAddress address) {
+ this.address = address;
+ }
+
+ public static BeanItemContainer<ComplexPerson> createContainer(int size) {
+ BeanItemContainer<ComplexPerson> bic = new BeanItemContainer<ComplexPerson>(
+ ComplexPerson.class);
+ Random r = new Random(size);
+
+ for (int i = 0; i < size; i++) {
+ ComplexPerson cp = ComplexPerson.create(r);
+ bic.addBean(cp);
+ }
+
+ return bic;
+ }
+
+ public static ComplexPerson create(Random r) {
+ ComplexPerson cp = new ComplexPerson();
+ cp.setFirstName(TestDataGenerator.getFirstName(r));
+ cp.setLastName(TestDataGenerator.getLastName(r));
+ cp.setAlive(r.nextBoolean());
+ cp.setBirthDate(TestDataGenerator.getBirthDate(r));
+ cp.setAge((int) ((new Date(2014 - 1900, 1, 1).getTime() - cp
+ .getBirthDate().getTime()) / 1000 / 3600 / 24 / 365));
+ cp.setSalary(TestDataGenerator.getSalary(r));
+ cp.setAddress(ComplexAddress.create(r));
+ cp.setGender(TestDataGenerator.getEnum(Gender.class, r));
+ return cp;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/Country.java b/uitest/src/com/vaadin/tests/fieldgroup/Country.java
new file mode 100644
index 0000000000..4956f0a085
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/Country.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.fieldgroup;
+
+
+public enum Country {
+ FINLAND, SWEDEN, NORWAY, DENMARK, ICELAND, USA, RUSSIA, ESTONIA;
+
+}
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/Gender.java b/uitest/src/com/vaadin/tests/fieldgroup/Gender.java
new file mode 100644
index 0000000000..dcc6687c17
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/fieldgroup/Gender.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.fieldgroup;
+
+public enum Gender {
+ MALE, FEMALE, UNDISCLOSED;
+}
diff --git a/uitest/src/com/vaadin/tests/util/PersonContainer.java b/uitest/src/com/vaadin/tests/util/PersonContainer.java
index a3cf28b083..611e5d3adb 100644
--- a/uitest/src/com/vaadin/tests/util/PersonContainer.java
+++ b/uitest/src/com/vaadin/tests/util/PersonContainer.java
@@ -24,8 +24,7 @@ public class PersonContainer extends BeanItemContainer<Person> implements
"First name", "Last name", "Email", "Phone number",
"Street Address", "Postal Code", "City" };
- public PersonContainer() throws InstantiationException,
- IllegalAccessException {
+ public PersonContainer() {
super(Person.class);
addNestedContainerProperty("address.streetAddress");
addNestedContainerProperty("address.postalCode");
@@ -33,63 +32,22 @@ public class PersonContainer extends BeanItemContainer<Person> implements
}
public static PersonContainer createWithTestData() {
- final String[] fnames = { "Peter", "Alice", "Joshua", "Mike", "Olivia",
- "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene",
- "Lisa", "Marge" };
- final String[] lnames = { "Smith", "Gordon", "Simpson", "Brown",
- "Clavel", "Simons", "Verne", "Scott", "Allison", "Gates",
- "Rowling", "Barks", "Ross", "Schneider", "Tate" };
- final String cities[] = { "Amsterdam", "Berlin", "Helsinki",
- "Hong Kong", "London", "Luxemburg", "New York", "Oslo",
- "Paris", "Rome", "Stockholm", "Tokyo", "Turku" };
- final String streets[] = { "4215 Blandit Av.", "452-8121 Sem Ave",
- "279-4475 Tellus Road", "4062 Libero. Av.", "7081 Pede. Ave",
- "6800 Aliquet St.", "P.O. Box 298, 9401 Mauris St.",
- "161-7279 Augue Ave", "P.O. Box 496, 1390 Sagittis. Rd.",
- "448-8295 Mi Avenue", "6419 Non Av.",
- "659-2538 Elementum Street", "2205 Quis St.",
- "252-5213 Tincidunt St.", "P.O. Box 175, 4049 Adipiscing Rd.",
- "3217 Nam Ave", "P.O. Box 859, 7661 Auctor St.",
- "2873 Nonummy Av.", "7342 Mi, Avenue",
- "539-3914 Dignissim. Rd.", "539-3675 Magna Avenue",
- "Ap #357-5640 Pharetra Avenue", "416-2983 Posuere Rd.",
- "141-1287 Adipiscing Avenue", "Ap #781-3145 Gravida St.",
- "6897 Suscipit Rd.", "8336 Purus Avenue", "2603 Bibendum. Av.",
- "2870 Vestibulum St.", "Ap #722 Aenean Avenue",
- "446-968 Augue Ave", "1141 Ultricies Street",
- "Ap #992-5769 Nunc Street", "6690 Porttitor Avenue",
- "Ap #105-1700 Risus Street",
- "P.O. Box 532, 3225 Lacus. Avenue", "736 Metus Street",
- "414-1417 Fringilla Street", "Ap #183-928 Scelerisque Road",
- "561-9262 Iaculis Avenue" };
PersonContainer c = null;
Random r = new Random(0);
- try {
- c = new PersonContainer();
- for (int i = 0; i < 100; i++) {
- Person p = new Person();
- p.setFirstName(fnames[r.nextInt(fnames.length)]);
- p.setLastName(lnames[r.nextInt(lnames.length)]);
- p.getAddress().setCity(cities[r.nextInt(cities.length)]);
- p.setEmail(p.getFirstName().toLowerCase() + "."
- + p.getLastName().toLowerCase() + "@vaadin.com");
- p.setPhoneNumber("+358 02 555 " + r.nextInt(10) + r.nextInt(10)
- + r.nextInt(10) + r.nextInt(10));
- int n = r.nextInt(100000);
- if (n < 10000) {
- n += 10000;
- }
- p.getAddress().setPostalCode(n);
- p.getAddress().setStreetAddress(
- streets[r.nextInt(streets.length)]);
- c.addItem(p);
- }
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ c = new PersonContainer();
+ for (int i = 0; i < 100; i++) {
+ Person p = new Person();
+ p.setFirstName(TestDataGenerator.getFirstName(r));
+ p.setLastName(TestDataGenerator.getLastName(r));
+ p.getAddress().setCity(TestDataGenerator.getCity(r));
+ p.setEmail(p.getFirstName().toLowerCase() + "."
+ + p.getLastName().toLowerCase() + "@vaadin.com");
+ p.setPhoneNumber(TestDataGenerator.getPhoneNumber(r));
+
+ p.getAddress().setPostalCode(TestDataGenerator.getPostalCode(r));
+ p.getAddress().setStreetAddress(
+ TestDataGenerator.getStreetAddress(r));
+ c.addItem(p);
}
return c;
diff --git a/uitest/src/com/vaadin/tests/util/TestDataGenerator.java b/uitest/src/com/vaadin/tests/util/TestDataGenerator.java
new file mode 100644
index 0000000000..8becb709f0
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/util/TestDataGenerator.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.util;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.EnumSet;
+import java.util.Locale;
+import java.util.Random;
+import java.util.TimeZone;
+
+public class TestDataGenerator {
+
+ final static String[] fnames = { "Peter", "Alice", "Joshua", "Mike",
+ "Olivia", "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik",
+ "Rene", "Lisa", "Marge" };
+ final static String[] lnames = { "Smith", "Gordon", "Simpson", "Brown",
+ "Clavel", "Simons", "Verne", "Scott", "Allison", "Gates",
+ "Rowling", "Barks", "Ross", "Schneider", "Tate" };
+ final static String cities[] = { "Amsterdam", "Berlin", "Helsinki",
+ "Hong Kong", "London", "Luxemburg", "New York", "Oslo", "Paris",
+ "Rome", "Stockholm", "Tokyo", "Turku" };
+ final static String streets[] = { "4215 Blandit Av.", "452-8121 Sem Ave",
+ "279-4475 Tellus Road", "4062 Libero. Av.", "7081 Pede. Ave",
+ "6800 Aliquet St.", "P.O. Box 298, 9401 Mauris St.",
+ "161-7279 Augue Ave", "P.O. Box 496, 1390 Sagittis. Rd.",
+ "448-8295 Mi Avenue", "6419 Non Av.", "659-2538 Elementum Street",
+ "2205 Quis St.", "252-5213 Tincidunt St.",
+ "P.O. Box 175, 4049 Adipiscing Rd.", "3217 Nam Ave",
+ "P.O. Box 859, 7661 Auctor St.", "2873 Nonummy Av.",
+ "7342 Mi, Avenue", "539-3914 Dignissim. Rd.",
+ "539-3675 Magna Avenue", "Ap #357-5640 Pharetra Avenue",
+ "416-2983 Posuere Rd.", "141-1287 Adipiscing Avenue",
+ "Ap #781-3145 Gravida St.", "6897 Suscipit Rd.",
+ "8336 Purus Avenue", "2603 Bibendum. Av.", "2870 Vestibulum St.",
+ "Ap #722 Aenean Avenue", "446-968 Augue Ave",
+ "1141 Ultricies Street", "Ap #992-5769 Nunc Street",
+ "6690 Porttitor Avenue", "Ap #105-1700 Risus Street",
+ "P.O. Box 532, 3225 Lacus. Avenue", "736 Metus Street",
+ "414-1417 Fringilla Street", "Ap #183-928 Scelerisque Road",
+ "561-9262 Iaculis Avenue" };
+
+ public static String getStreetAddress(Random r) {
+ return streets[r.nextInt(streets.length)];
+ }
+
+ public static Integer getPostalCode(Random r) {
+ int n = r.nextInt(100000);
+ if (n < 10000) {
+ n += 10000;
+ }
+ return n;
+ }
+
+ public static String getPhoneNumber(Random r) {
+ return "+358 02 555 " + r.nextInt(10) + r.nextInt(10) + r.nextInt(10)
+ + r.nextInt(10);
+ }
+
+ public static String getCity(Random r) {
+ return cities[r.nextInt(cities.length)];
+ }
+
+ public static String getLastName(Random r) {
+ return lnames[r.nextInt(lnames.length)];
+ }
+
+ public static String getFirstName(Random r) {
+ return fnames[r.nextInt(fnames.length)];
+ }
+
+ public static int getAge(Random r) {
+ return r.nextInt(100) + 10;
+ }
+
+ public static Date getBirthDate(Random r) {
+ Calendar c = Calendar.getInstance(TimeZone.getTimeZone("EET"),
+ new Locale("FI", "fi"));
+ c.setLenient(true);
+ c.setTimeInMillis(0);
+ c.set(Calendar.YEAR, r.nextInt(100) + 1900);
+ c.set(Calendar.MONTH, r.nextInt(12));
+ c.set(Calendar.DAY_OF_MONTH, r.nextInt(31));
+
+ return c.getTime();
+ }
+
+ public static BigDecimal getSalary(Random r) {
+ return new BigDecimal(r.nextInt(80000));
+ }
+
+ public static <T extends Enum<T>> T getEnum(Class<T> class1, Random r) {
+ EnumSet<T> foo = EnumSet.allOf(class1);
+ return (T) foo.toArray()[r.nextInt(foo.size() - 1)];
+ }
+}