summaryrefslogtreecommitdiffstats
path: root/tests/server-side/com/vaadin
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-12-09 09:40:51 +0200
committerLeif Åstrand <leif@vaadin.com>2011-12-09 09:40:51 +0200
commit0e08e671f9fd85d8396abafcbd14dc6803823987 (patch)
tree55bd62bd03d148e759c74bfe05d3a2472f7d87f8 /tests/server-side/com/vaadin
parentc6b6e3f972bf6a25f94be11c7dcc0b0a57943523 (diff)
parentccdef3ddfd79938215cadc947b08a73faf5d0788 (diff)
downloadvaadin-framework-0e08e671f9fd85d8396abafcbd14dc6803823987.tar.gz
vaadin-framework-0e08e671f9fd85d8396abafcbd14dc6803823987.zip
Merge remote branch 'origin/6.8'
Conflicts: src/com/vaadin/Application.java src/com/vaadin/data/Property.java src/com/vaadin/data/util/PropertyFormatter.java src/com/vaadin/terminal/ParameterHandler.java src/com/vaadin/terminal/URIHandler.java src/com/vaadin/terminal/gwt/client/HistoryImplIEVaadin.java src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java src/com/vaadin/terminal/gwt/server/PortletApplicationContext.java src/com/vaadin/ui/Field.java src/com/vaadin/ui/LoginForm.java src/com/vaadin/ui/UriFragmentUtility.java
Diffstat (limited to 'tests/server-side/com/vaadin')
-rw-r--r--tests/server-side/com/vaadin/data/util/BeanContainerTest.java34
-rw-r--r--tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java2
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/abstractorderedlayout/AddComponentsTest.java115
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/csslayout/AddComponentsTest.java109
4 files changed, 258 insertions, 2 deletions
diff --git a/tests/server-side/com/vaadin/data/util/BeanContainerTest.java b/tests/server-side/com/vaadin/data/util/BeanContainerTest.java
index 5a753e19d0..d9fa8d896e 100644
--- a/tests/server-side/com/vaadin/data/util/BeanContainerTest.java
+++ b/tests/server-side/com/vaadin/data/util/BeanContainerTest.java
@@ -1,7 +1,9 @@
package com.vaadin.data.util;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -10,7 +12,6 @@ import junit.framework.Assert;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.AbstractBeanContainer.BeanIdResolver;
-import com.vaadin.data.util.BeanContainer;
public class BeanContainerTest extends AbstractBeanContainerTest {
@@ -324,6 +325,37 @@ public class BeanContainerTest extends AbstractBeanContainerTest {
assertEquals(0, container.size());
}
+ public void testAddAllWithNullItemId() {
+ BeanContainer<String, Person> container = new BeanContainer<String, Person>(
+ Person.class);
+ // resolver that returns null as item id
+ container
+ .setBeanIdResolver(new BeanIdResolver<String, AbstractBeanContainerTest.Person>() {
+
+ public String getIdForBean(Person bean) {
+ return bean.getName();
+ }
+ });
+
+ List<Person> persons = new ArrayList<Person>();
+ persons.add(new Person("John"));
+ persons.add(new Person("Marc"));
+ persons.add(new Person(null));
+ persons.add(new Person("foo"));
+
+ try {
+ container.addAll(persons);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // should get exception
+ }
+
+ container.removeAllItems();
+ persons.remove(2);
+ container.addAll(persons);
+ assertEquals(3, container.size());
+ }
+
public void testAddBeanWithNullResolver() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
diff --git a/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java b/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java
index bb462a0f97..abde241451 100644
--- a/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java
+++ b/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java
@@ -49,7 +49,7 @@ public class LicenseInJavaFiles extends TestCase {
private void checkForLicenseInFile(File f, HashSet<String> missing)
throws IOException {
String contents = IOUtils.toString(new FileInputStream(f));
- if (!contents.contains("@" + "ITMillApache2LicenseForJavaFiles" + "@")) {
+ if (!contents.contains("@" + "VaadinApache2LicenseForJavaFiles" + "@")) {
missing.add(f.getPath());
}
diff --git a/tests/server-side/com/vaadin/tests/server/component/abstractorderedlayout/AddComponentsTest.java b/tests/server-side/com/vaadin/tests/server/component/abstractorderedlayout/AddComponentsTest.java
new file mode 100644
index 0000000000..ba5ea62181
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/component/abstractorderedlayout/AddComponentsTest.java
@@ -0,0 +1,115 @@
+package com.vaadin.tests.server.component.abstractorderedlayout;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.junit.Test;
+
+import com.vaadin.ui.AbstractOrderedLayout;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.VerticalLayout;
+
+public class AddComponentsTest {
+
+ Component[] children = new Component[] { new Label("A"), new Label("B"),
+ new Label("C"), new Label("D") };
+
+ @Test
+ public void moveComponentsBetweenLayouts() {
+ AbstractOrderedLayout layout1 = new HorizontalLayout();
+ AbstractOrderedLayout layout2 = new VerticalLayout();
+
+ layout1.addComponent(children[0]);
+ layout1.addComponent(children[1]);
+
+ layout2.addComponent(children[2]);
+ layout2.addComponent(children[3]);
+
+ layout2.addComponent(children[1], 1);
+ assertOrder(layout1, new int[] { 0 });
+ assertOrder(layout2, new int[] { 2, 1, 3 });
+
+ layout1.addComponent(children[3], 0);
+ assertOrder(layout1, new int[] { 3, 0 });
+ assertOrder(layout2, new int[] { 2, 1 });
+
+ layout2.addComponent(children[0]);
+ assertOrder(layout1, new int[] { 3 });
+ assertOrder(layout2, new int[] { 2, 1, 0 });
+
+ layout1.addComponentAsFirst(children[1]);
+ assertOrder(layout1, new int[] { 1, 3 });
+ assertOrder(layout2, new int[] { 2, 0 });
+ }
+
+ @Test
+ public void shuffleChildComponents() {
+ shuffleChildComponents(new HorizontalLayout());
+ shuffleChildComponents(new VerticalLayout());
+ }
+
+ private void shuffleChildComponents(AbstractOrderedLayout layout) {
+
+ for (int i = 0; i < children.length; ++i) {
+ layout.addComponent(children[i], i);
+ }
+
+ assertOrder(layout, new int[] { 0, 1, 2, 3 });
+
+ // Move C from #2 to #1
+ // Exhibits defect #7668
+ layout.addComponent(children[2], 1);
+ assertOrder(layout, new int[] { 0, 2, 1, 3 });
+
+ // Move C from #1 to #4 (which becomes #3 when #1 is erased)
+ layout.addComponent(children[2], 4);
+ assertOrder(layout, new int[] { 0, 1, 3, 2 });
+
+ // Keep everything in place
+ layout.addComponent(children[1], 1);
+ assertOrder(layout, new int[] { 0, 1, 3, 2 });
+
+ // Move D from #2 to #0
+ layout.addComponent(children[3], 0);
+ assertOrder(layout, new int[] { 3, 0, 1, 2 });
+
+ // Move A from #1 to end (#4 which becomes #3)
+ layout.addComponent(children[0]);
+ assertOrder(layout, new int[] { 3, 1, 2, 0 });
+
+ // Keep everything in place
+ layout.addComponent(children[0]);
+ assertOrder(layout, new int[] { 3, 1, 2, 0 });
+
+ // Move C from #2 to #0
+ layout.addComponentAsFirst(children[2]);
+ assertOrder(layout, new int[] { 2, 3, 1, 0 });
+
+ // Keep everything in place
+ layout.addComponentAsFirst(children[2]);
+ assertOrder(layout, new int[] { 2, 3, 1, 0 });
+ }
+
+ /**
+ * Asserts that layout has the components in children in the order specified
+ * by indices.
+ */
+ private void assertOrder(Layout layout, int[] indices) {
+ Iterator<?> i = layout.getComponentIterator();
+ try {
+ for (int index : indices) {
+ assertSame(children[index], i.next());
+ }
+ assertFalse("Too many components in layout", i.hasNext());
+ } catch (NoSuchElementException e) {
+ fail("Too few components in layout");
+ }
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/server/component/csslayout/AddComponentsTest.java b/tests/server-side/com/vaadin/tests/server/component/csslayout/AddComponentsTest.java
new file mode 100644
index 0000000000..29657830e8
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/component/csslayout/AddComponentsTest.java
@@ -0,0 +1,109 @@
+package com.vaadin.tests.server.component.csslayout;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import com.vaadin.ui.Component;
+import com.vaadin.ui.CssLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Layout;
+
+public class AddComponentsTest {
+
+ private Component[] children = new Component[] { new Label("A"),
+ new Label("B"), new Label("C"), new Label("D") };
+
+ @Test
+ public void moveComponentsBetweenLayouts() {
+ CssLayout layout1 = new CssLayout();
+ CssLayout layout2 = new CssLayout();
+
+ layout1.addComponent(children[0]);
+ layout1.addComponent(children[1]);
+
+ layout2.addComponent(children[2]);
+ layout2.addComponent(children[3]);
+
+ layout2.addComponent(children[1], 1);
+ assertOrder(layout1, new int[] { 0 });
+ assertOrder(layout2, new int[] { 2, 1, 3 });
+
+ layout1.addComponent(children[3], 0);
+ assertOrder(layout1, new int[] { 3, 0 });
+ assertOrder(layout2, new int[] { 2, 1 });
+
+ layout2.addComponent(children[0]);
+ assertOrder(layout1, new int[] { 3 });
+ assertOrder(layout2, new int[] { 2, 1, 0 });
+
+ layout1.addComponentAsFirst(children[1]);
+ assertOrder(layout1, new int[] { 1, 3 });
+ assertOrder(layout2, new int[] { 2, 0 });
+ }
+
+ @Test
+ public void shuffleChildComponents() {
+ CssLayout layout = new CssLayout();
+
+ for (int i = 0; i < children.length; ++i) {
+ layout.addComponent(children[i], i);
+ }
+
+ assertOrder(layout, new int[] { 0, 1, 2, 3 });
+
+ // Move C from #2 to #1
+ // Exhibits defect #7668
+ layout.addComponent(children[2], 1);
+ assertOrder(layout, new int[] { 0, 2, 1, 3 });
+
+ // Move C from #1 to #4 (which becomes #3 when #1 is erased)
+ layout.addComponent(children[2], 4);
+ assertOrder(layout, new int[] { 0, 1, 3, 2 });
+
+ // Keep everything in place
+ layout.addComponent(children[1], 1);
+ assertOrder(layout, new int[] { 0, 1, 3, 2 });
+
+ // Move D from #2 to #0
+ layout.addComponent(children[3], 0);
+ assertOrder(layout, new int[] { 3, 0, 1, 2 });
+
+ // Move A from #1 to end (#4 which becomes #3)
+ layout.addComponent(children[0]);
+ assertOrder(layout, new int[] { 3, 1, 2, 0 });
+
+ // Keep everything in place
+ layout.addComponent(children[0]);
+ assertOrder(layout, new int[] { 3, 1, 2, 0 });
+
+ // Move C from #2 to #0
+ layout.addComponentAsFirst(children[2]);
+ assertOrder(layout, new int[] { 2, 3, 1, 0 });
+
+ // Keep everything in place
+ layout.addComponentAsFirst(children[2]);
+ assertOrder(layout, new int[] { 2, 3, 1, 0 });
+ }
+
+ /**
+ * Asserts that layout has the components in children in the order specified
+ * by indices.
+ */
+ private void assertOrder(Layout layout, int[] indices) {
+ Iterator<?> i = layout.getComponentIterator();
+ try {
+ for (int index : indices) {
+ assertSame(children[index], i.next());
+ }
+ assertFalse("Too many components in layout", i.hasNext());
+ } catch (NoSuchElementException e) {
+ fail("Too few components in layout");
+ }
+ }
+}