summaryrefslogtreecommitdiffstats
path: root/server/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/src')
-rw-r--r--server/tests/src/com/vaadin/data/util/BeanContainerTest.java13
-rw-r--r--server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java58
-rw-r--r--server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java34
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestDefaultConverterFactory.java128
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java28
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java16
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToEnumConverter.java14
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java15
-rw-r--r--server/tests/src/com/vaadin/tests/server/FileResourceTest.java36
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java21
-rw-r--r--server/tests/src/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java50
-rw-r--r--server/tests/src/com/vaadin/ui/AbstractSelectTest.java71
-rw-r--r--server/tests/src/com/vaadin/ui/RichTextAreaTest.java47
-rw-r--r--server/tests/src/com/vaadin/ui/TextAreaTest.java47
-rw-r--r--server/tests/src/com/vaadin/ui/UIThemeEscaping.java89
15 files changed, 642 insertions, 25 deletions
diff --git a/server/tests/src/com/vaadin/data/util/BeanContainerTest.java b/server/tests/src/com/vaadin/data/util/BeanContainerTest.java
index 4e0e98ec43..f22ab8478e 100644
--- a/server/tests/src/com/vaadin/data/util/BeanContainerTest.java
+++ b/server/tests/src/com/vaadin/data/util/BeanContainerTest.java
@@ -68,6 +68,19 @@ public class BeanContainerTest extends AbstractBeanContainerTest {
return false;
}
+ public void testGetType_existingProperty_typeReturned() {
+ BeanContainer<String, ClassName> container = getContainer();
+ Assert.assertEquals(
+ "Unexpected type is returned for property 'simpleName'",
+ String.class, container.getType("simpleName"));
+ }
+
+ public void testGetType_notExistingProperty_nullReturned() {
+ BeanContainer<String, ClassName> container = getContainer();
+ Assert.assertNull("Not null type is returned for property ''",
+ container.getType(""));
+ }
+
public void testBasicOperations() {
testBasicContainerOperations(getContainer());
}
diff --git a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java
index 463f0c92c1..2cf64bbc7c 100644
--- a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java
+++ b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java
@@ -8,16 +8,16 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Assert;
-
import org.easymock.Capture;
import org.easymock.EasyMock;
+import org.junit.Assert;
import com.vaadin.data.Container;
import com.vaadin.data.Container.Indexed.ItemAddEvent;
import com.vaadin.data.Container.Indexed.ItemRemoveEvent;
import com.vaadin.data.Container.ItemSetChangeListener;
import com.vaadin.data.Item;
+import com.vaadin.data.util.NestedMethodPropertyTest.Address;
import com.vaadin.data.util.filter.Compare;
/**
@@ -78,6 +78,19 @@ public class BeanItemContainerTest extends AbstractBeanContainerTest {
return false;
}
+ public void testGetType_existingProperty_typeReturned() {
+ BeanItemContainer<ClassName> container = getContainer();
+ Assert.assertEquals(
+ "Unexpected type is returned for property 'simpleName'",
+ String.class, container.getType("simpleName"));
+ }
+
+ public void testGetType_notExistingProperty_nullReturned() {
+ BeanItemContainer<ClassName> container = getContainer();
+ Assert.assertNull("Not null type is returned for property ''",
+ container.getType(""));
+ }
+
public void testBasicOperations() {
testBasicContainerOperations(getContainer());
}
@@ -912,4 +925,45 @@ public class BeanItemContainerTest extends AbstractBeanContainerTest {
container.addItemSetChangeListener(listener);
return listener;
}
+
+ public void testAddNestedContainerBeanBeforeData() {
+ BeanItemContainer<NestedMethodPropertyTest.Person> container = new BeanItemContainer<NestedMethodPropertyTest.Person>(
+ NestedMethodPropertyTest.Person.class);
+
+ container.addNestedContainerBean("address");
+
+ assertTrue(container.getContainerPropertyIds().contains(
+ "address.street"));
+
+ NestedMethodPropertyTest.Person john = new NestedMethodPropertyTest.Person(
+ "John", new Address("streetname", 12345));
+ container.addBean(john);
+
+ assertTrue(container.getItem(john).getItemPropertyIds()
+ .contains("address.street"));
+ assertEquals("streetname",
+ container.getItem(john).getItemProperty("address.street")
+ .getValue());
+
+ }
+
+ public void testAddNestedContainerBeanAfterData() {
+ BeanItemContainer<NestedMethodPropertyTest.Person> container = new BeanItemContainer<NestedMethodPropertyTest.Person>(
+ NestedMethodPropertyTest.Person.class);
+
+ NestedMethodPropertyTest.Person john = new NestedMethodPropertyTest.Person(
+ "John", new Address("streetname", 12345));
+ container.addBean(john);
+
+ container.addNestedContainerBean("address");
+
+ assertTrue(container.getContainerPropertyIds().contains(
+ "address.street"));
+ assertTrue(container.getItem(john).getItemPropertyIds()
+ .contains("address.street"));
+ assertEquals("streetname",
+ container.getItem(john).getItemProperty("address.street")
+ .getValue());
+
+ }
}
diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java
index d907f12321..fbae0ee159 100644
--- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java
+++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java
@@ -1071,6 +1071,26 @@ public class SQLContainerTableQueryTest {
Assert.assertEquals(0, container.size());
}
+ // Set timeout to ensure there is no infinite looping (#12882)
+ @Test(timeout = 1000)
+ public void removeAllItems_manyItems_commit_shouldSucceed()
+ throws SQLException {
+ SQLContainer container = new SQLContainer(new TableQuery("people",
+ connectionPool, SQLTestsConstants.sqlGen));
+ final int itemNumber = (SQLContainer.CACHE_RATIO + 1)
+ * SQLContainer.DEFAULT_PAGE_LENGTH + 1;
+ container.removeAllItems();
+ Assert.assertEquals(container.size(), 0);
+ for (int i = 0; i < itemNumber; ++i) {
+ container.addItem();
+ }
+ container.commit();
+ Assert.assertEquals(container.size(), itemNumber);
+ Assert.assertTrue(container.removeAllItems());
+ container.commit();
+ Assert.assertEquals(container.size(), 0);
+ }
+
@Test
public void commit_tableAddedItem_shouldBeWrittenToDB() throws SQLException {
TableQuery query = new TableQuery("people", connectionPool,
@@ -1137,6 +1157,20 @@ public class SQLContainerTableQueryTest {
}
@Test
+ public void commit_removeModifiedItem_shouldSucceed() throws SQLException {
+ TableQuery query = new TableQuery("people", connectionPool,
+ SQLTestsConstants.sqlGen);
+ SQLContainer container = new SQLContainer(query);
+ int size = container.size();
+ Object key = container.firstItemId();
+ Item row = container.getItem(key);
+ row.getItemProperty("NAME").setValue("Pekka");
+ Assert.assertTrue(container.removeItem(key));
+ container.commit();
+ Assert.assertEquals(size - 1, container.size());
+ }
+
+ @Test
public void rollback_tableItemAdded_discardsAddedItem() throws SQLException {
SQLContainer container = new SQLContainer(new TableQuery("people",
connectionPool, SQLTestsConstants.sqlGen));
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestDefaultConverterFactory.java b/server/tests/src/com/vaadin/tests/data/converter/TestDefaultConverterFactory.java
new file mode 100644
index 0000000000..e1becf43e1
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestDefaultConverterFactory.java
@@ -0,0 +1,128 @@
+/*
+ * 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.data.converter;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.Locale;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.data.util.converter.DefaultConverterFactory;
+
+public class TestDefaultConverterFactory {
+
+ private DefaultConverterFactory factory = new DefaultConverterFactory();
+
+ @Test
+ public void stringToBigDecimal() {
+ assertConverter("14", new BigDecimal("14"));
+ }
+
+ @Test
+ public void stringToBigInteger() {
+ assertConverter("14", new BigInteger("14"));
+ }
+
+ @Test
+ public void stringToDouble() {
+ assertConverter("14", new Double("14"));
+ }
+
+ @Test
+ public void stringToFloat() {
+ assertConverter("14", new Float("14"));
+ }
+
+ @Test
+ public void stringToInteger() {
+ assertConverter("14", new Integer("14"));
+ }
+
+ @Test
+ public void stringToLong() {
+ assertConverter("14", new Long("14"));
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void stringToDate() {
+ assertConverter("Oct 12, 2014 12:00:00 AM", new Date(2014 - 1900,
+ 10 - 1, 12));
+ }
+
+ @Test
+ public void sqlDateToDate() {
+ long l = 1413071210000L;
+ assertConverter(new java.sql.Date(l), new java.util.Date(l));
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void longToDate() {
+ assertConverter(1413061200000L, new Date(2014 - 1900, 10 - 1, 12));
+ }
+
+ public enum Foo {
+ BAR, BAZ;
+ }
+
+ @Test
+ public void stringToEnum() {
+ assertConverter("Bar", Foo.BAR);
+ }
+
+ @Test
+ public void stringToShort() {
+ assertConverter("14", new Short("14"));
+ }
+
+ @Test
+ public void stringToByte() {
+ assertConverter("14", new Byte("14"));
+ }
+
+ private <T, U> void assertConverter(T t, U u) {
+ Class<T> tClass = (Class<T>) t.getClass();
+ Class<U> uClass = (Class<U>) u.getClass();
+
+ U tConvertedToU = factory.createConverter(tClass, uClass)
+ .convertToModel(t, uClass, Locale.ENGLISH);
+ Assert.assertEquals(
+ "Incorrect type of value converted from "
+ + tClass.getSimpleName() + " to "
+ + uClass.getSimpleName(), uClass,
+ tConvertedToU.getClass());
+ Assert.assertEquals(
+ "Incorrect conversion of " + t + " to "
+ + uClass.getSimpleName(), u, tConvertedToU);
+
+ T uConvertedToT = factory.createConverter(uClass, tClass)
+ .convertToModel(u, tClass, Locale.ENGLISH);
+ Assert.assertEquals(
+ "Incorrect type of value converted from "
+ + uClass.getSimpleName() + " to "
+ + tClass.getSimpleName(), tClass,
+ uConvertedToT.getClass());
+ Assert.assertEquals(
+ "Incorrect conversion of " + u + " to "
+ + tClass.getSimpleName(), t, uConvertedToT);
+
+ }
+
+}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java
index 641f18c865..8d493609fe 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java
@@ -15,39 +15,43 @@
*/
package com.vaadin.tests.data.converter;
-import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.Locale;
import junit.framework.TestCase;
-import com.vaadin.data.util.converter.StringToBigDecimalConverter;
+import com.vaadin.data.util.converter.StringToBigIntegerConverter;
public class TestStringToBigIntegerConverter extends TestCase {
- StringToBigDecimalConverter converter = new StringToBigDecimalConverter();
+ StringToBigIntegerConverter converter = new StringToBigIntegerConverter();
public void testNullConversion() {
- assertEquals(null,
- converter.convertToModel(null, BigDecimal.class, null));
+ assertEquals("Null value was converted incorrectly", null,
+ converter.convertToModel(null, BigInteger.class, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", BigDecimal.class, null));
+ assertEquals("Empty value was converted incorrectly", null,
+ converter.convertToModel("", BigInteger.class, null));
}
public void testValueParsing() {
- BigDecimal converted = converter.convertToModel("10", BigDecimal.class,
- null);
- BigDecimal expected = new BigDecimal(10);
- assertEquals(expected, converted);
+ String bigInt = "1180591620717411303424"; // 2^70 > 2^63 - 1
+ BigInteger converted = converter.convertToModel(bigInt,
+ BigInteger.class, null);
+ BigInteger expected = new BigInteger(bigInt);
+ assertEquals("Value bigger than max long was converted incorrectly",
+ expected, converted);
}
public void testValueFormatting() {
- BigDecimal bd = new BigDecimal(1000);
+ BigInteger bd = new BigInteger("1000");
String expected = "1.000";
String converted = converter.convertToPresentation(bd, String.class,
Locale.GERMAN);
- assertEquals(expected, converted);
+ assertEquals("Value with specific locale was converted incorrectly",
+ expected, converted);
}
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java
index 440d056c06..19a68fbfdb 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java
@@ -16,25 +16,28 @@ public class TestStringToByteConverter extends TestCase {
converter);
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Byte.class, null));
+ assertEquals("Null value was converted incorrectly", null,
+ converter.convertToModel(null, Byte.class, null));
}
public void testReverseNullConversion() {
- assertEquals(null,
+ assertEquals("Null value reversely was converted incorrectly", null,
reverseConverter.convertToModel(null, String.class, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Byte.class, null));
+ assertEquals("Empty value was converted incorrectly", null,
+ converter.convertToModel("", Byte.class, null));
}
public void testValueConversion() {
- assertEquals(Byte.valueOf((byte) 10),
+ assertEquals("Byte value was converted incorrectly",
+ Byte.valueOf((byte) 10),
converter.convertToModel("10", Byte.class, null));
}
public void testReverseValueConversion() {
- assertEquals(
+ assertEquals("Byte value reversely was converted incorrectly",
reverseConverter.convertToModel((byte) 10, String.class, null),
"10");
}
@@ -43,7 +46,8 @@ public class TestStringToByteConverter extends TestCase {
byte b = converter.convertToModel("127", Byte.class, null);
Assert.assertEquals(Byte.MAX_VALUE, b);
b = converter.convertToModel("-128", Byte.class, null);
- assertEquals(Byte.MIN_VALUE, b);
+ assertEquals("Min byte value was converted incorrectly",
+ Byte.MIN_VALUE, b);
}
public void testValueOutOfRange() {
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToEnumConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToEnumConverter.java
index 2b19395c08..5dc24ca43a 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToEnumConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToEnumConverter.java
@@ -3,6 +3,7 @@ package com.vaadin.tests.data.converter;
import junit.framework.TestCase;
import com.vaadin.data.util.converter.Converter;
+import com.vaadin.data.util.converter.Converter.ConversionException;
import com.vaadin.data.util.converter.ReverseConverter;
import com.vaadin.data.util.converter.StringToEnumConverter;
@@ -16,6 +17,19 @@ public class TestStringToEnumConverter extends TestCase {
Converter<Enum, String> reverseConverter = new ReverseConverter<Enum, String>(
converter);
+ public void testEmptyStringConversion() {
+ assertEquals(null, converter.convertToModel("", Enum.class, null));
+ }
+
+ public void testInvalidEnumClassConversion() {
+ try {
+ converter.convertToModel("Foo", Enum.class, null);
+ fail("No exception thrown");
+ } catch (ConversionException e) {
+ // OK
+ }
+ }
+
public void testNullConversion() {
assertEquals(null, converter.convertToModel(null, Enum.class, null));
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java
index 35547d2570..542c580025 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java
@@ -16,25 +16,29 @@ public class TestStringToShortConverter extends TestCase {
converter);
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Short.class, null));
+ assertEquals("Null value was converted incorrectly", null,
+ converter.convertToModel(null, Short.class, null));
}
public void testReverseNullConversion() {
- assertEquals(null,
+ assertEquals("Null value reversely was converted incorrectly", null,
reverseConverter.convertToModel(null, String.class, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Short.class, null));
+ assertEquals("Empty value was converted incorrectly", null,
+ converter.convertToModel("", Short.class, null));
}
public void testValueConversion() {
- assertEquals(Short.valueOf((short) 10),
+ assertEquals("Short value was converted incorrectly",
+ Short.valueOf((short) 10),
converter.convertToModel("10", Short.class, null));
}
public void testReverseValueConversion() {
assertEquals(
+ "Short value reversely was converted incorrectly",
reverseConverter.convertToModel((short) 10, String.class, null),
"10");
}
@@ -43,7 +47,8 @@ public class TestStringToShortConverter extends TestCase {
short b = converter.convertToModel("32767", Short.class, null);
Assert.assertEquals(Short.MAX_VALUE, b);
b = converter.convertToModel("-32768", Short.class, null);
- assertEquals(Short.MIN_VALUE, b);
+ assertEquals("Min short value was converted incorrectly",
+ Short.MIN_VALUE, b);
}
public void testValueOutOfRange() {
diff --git a/server/tests/src/com/vaadin/tests/server/FileResourceTest.java b/server/tests/src/com/vaadin/tests/server/FileResourceTest.java
new file mode 100644
index 0000000000..4798fb9f05
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/FileResourceTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.server;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import com.vaadin.server.FileResource;
+
+public class FileResourceTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void nullFile() {
+ new FileResource(null);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void nonExistingFile() {
+ new FileResource(new File("nonexisting")).getStream();
+ }
+
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java b/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java
index 112d36d884..9c37b91ef5 100644
--- a/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java
+++ b/server/tests/src/com/vaadin/tests/server/component/fieldgroup/BeanFieldGroupTest.java
@@ -5,9 +5,11 @@ import static org.junit.Assert.assertEquals;
import org.junit.Assert;
import org.junit.Test;
+import com.vaadin.data.Item;
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.ui.Field;
import com.vaadin.ui.TextField;
@@ -133,4 +135,23 @@ public class BeanFieldGroupTest {
assertEquals(bean.nestedBean.hello, helloField.getValue().toString());
}
+ @Test
+ public void setDataSource_nullBean_nullBeanIsSetInDataSource() {
+ BeanFieldGroup<MyBean> group = new BeanFieldGroup<MyBean>(MyBean.class);
+
+ group.setItemDataSource((MyBean) null);
+
+ BeanItem<MyBean> dataSource = group.getItemDataSource();
+ Assert.assertNull("Data source is null for null bean", dataSource);
+ }
+
+ @Test
+ public void setDataSource_nullItem_nullDataSourceIsSet() {
+ BeanFieldGroup<MyBean> group = new BeanFieldGroup<MyBean>(MyBean.class);
+
+ group.setItemDataSource((Item) null);
+ BeanItem<MyBean> dataSource = group.getItemDataSource();
+ Assert.assertNull("Group returns not null data source", dataSource);
+ }
+
}
diff --git a/server/tests/src/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java b/server/tests/src/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java
index df515795eb..d8b366ffbc 100644
--- a/server/tests/src/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java
+++ b/server/tests/src/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java
@@ -9,6 +9,7 @@ import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
+import com.vaadin.ui.CustomLayout;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.GridLayout.Area;
import com.vaadin.ui.HasComponents;
@@ -25,6 +26,7 @@ public class ComponentAttachDetachListenerTest extends TestCase {
private GridLayout gridlayout;
private AbsoluteLayout absolutelayout;
private CssLayout csslayout;
+ private CustomLayout customlayout;
// General variables
private int attachCounter = 0;
@@ -143,6 +145,10 @@ public class ComponentAttachDetachListenerTest extends TestCase {
csslayout = new CssLayout();
csslayout.addComponentAttachListener(new MyAttachListener());
csslayout.addComponentDetachListener(new MyDetachListener());
+
+ customlayout = new CustomLayout("<div location='loc'/>");
+ customlayout.addComponentAttachListener(new MyAttachListener());
+ customlayout.addComponentDetachListener(new MyDetachListener());
}
public void testOrderedLayoutAttachListener() {
@@ -342,4 +348,48 @@ public class ComponentAttachDetachListenerTest extends TestCase {
// The detached component should not be found in the container
assertFalse(foundInContainer);
}
+
+ public void testCustomLayoutAttachListener() {
+ // Reset state variables
+ resetVariables();
+
+ // Add component -> Should trigger attach listener
+ Component comp = new Label();
+ customlayout.addComponent(comp, "loc");
+
+ assertEquals("Attach counter should get incremented", 1, attachCounter);
+
+ assertSame("The attached component should be the label", comp,
+ attachedComponent);
+
+ assertSame("The attached target should be the layout", customlayout,
+ attachTarget);
+
+ assertTrue("The attached component should be found in the container",
+ foundInContainer);
+ }
+
+ public void testCustomLayoutDetachListener() {
+ // Add a component to detach
+ Component comp = new Label();
+ customlayout.addComponent(comp);
+
+ // Reset state variables (since they are set by the attach listener)
+ resetVariables();
+
+ // Detach the component -> triggers the detach listener
+ customlayout.removeComponent(comp);
+
+ assertEquals("Detach counter should get incremented", 1, detachCounter);
+
+ assertSame("The detached component should be the label", comp,
+ detachedComponent);
+
+ assertSame("The detached target should be the layout", customlayout,
+ detachedTarget);
+
+ assertFalse(
+ "The detached component should not be found in the container",
+ foundInContainer);
+ }
}
diff --git a/server/tests/src/com/vaadin/ui/AbstractSelectTest.java b/server/tests/src/com/vaadin/ui/AbstractSelectTest.java
index 83d66ee9d5..bd399f088c 100644
--- a/server/tests/src/com/vaadin/ui/AbstractSelectTest.java
+++ b/server/tests/src/com/vaadin/ui/AbstractSelectTest.java
@@ -16,10 +16,13 @@
package com.vaadin.ui;
import java.util.ArrayList;
+import java.util.HashSet;
import org.junit.Assert;
import org.junit.Test;
+import com.vaadin.data.util.ObjectProperty;
+
public class AbstractSelectTest {
@Test
@@ -73,4 +76,72 @@ public class AbstractSelectTest {
.toArray());
}
+
+ @Test
+ public void singleSelectInitiallyEmpty() {
+ AbstractSelect s = new ListSelect();
+ Assert.assertTrue(s.isEmpty());
+ }
+
+ @Test
+ public void singleSelectEmptyAfterClearUsingPDS() {
+ AbstractSelect s = new ListSelect();
+ s.addItem("foo");
+ s.addItem("bar");
+ s.setPropertyDataSource(new ObjectProperty<String>("foo"));
+
+ Assert.assertFalse(s.isEmpty());
+ s.clear();
+ Assert.assertTrue(s.isEmpty());
+ }
+
+ @Test
+ public void singleSelectEmptyAfterClear() {
+ AbstractSelect s = new ListSelect();
+ s.addItem("foo");
+ s.addItem("bar");
+ s.setValue("bar");
+
+ Assert.assertFalse(s.isEmpty());
+ s.clear();
+ Assert.assertTrue(s.isEmpty());
+ }
+
+ @Test
+ public void multiSelectInitiallyEmpty() {
+ AbstractSelect s = new ListSelect();
+ s.setMultiSelect(true);
+ Assert.assertTrue(s.isEmpty());
+ }
+
+ @Test
+ public void multiSelectEmptyAfterClearUsingPDS() {
+ AbstractSelect s = new ListSelect();
+ s.setMultiSelect(true);
+ s.addItem("foo");
+ s.addItem("bar");
+ HashSet<String> sel = new HashSet<String>();
+ sel.add("foo");
+ sel.add("bar");
+ s.setPropertyDataSource(new ObjectProperty<HashSet>(sel));
+
+ Assert.assertFalse(s.isEmpty());
+ s.clear();
+ Assert.assertTrue(s.isEmpty());
+ }
+
+ @Test
+ public void multiSelectEmptyAfterClear() {
+ AbstractSelect s = new ListSelect();
+ s.setMultiSelect(true);
+ s.addItem("foo");
+ s.addItem("bar");
+ s.select("foo");
+ s.select("bar");
+
+ Assert.assertFalse(s.isEmpty());
+ s.clear();
+ Assert.assertTrue(s.isEmpty());
+ }
+
}
diff --git a/server/tests/src/com/vaadin/ui/RichTextAreaTest.java b/server/tests/src/com/vaadin/ui/RichTextAreaTest.java
new file mode 100644
index 0000000000..ce0dfdc696
--- /dev/null
+++ b/server/tests/src/com/vaadin/ui/RichTextAreaTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.ui;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.data.util.ObjectProperty;
+
+public class RichTextAreaTest {
+ @Test
+ public void initiallyEmpty() {
+ RichTextArea tf = new RichTextArea();
+ Assert.assertTrue(tf.isEmpty());
+ }
+
+ @Test
+ public void emptyAfterClearUsingPDS() {
+ RichTextArea tf = new RichTextArea(new ObjectProperty<String>("foo"));
+ Assert.assertFalse(tf.isEmpty());
+ tf.clear();
+ Assert.assertTrue(tf.isEmpty());
+ }
+
+ @Test
+ public void emptyAfterClear() {
+ RichTextArea tf = new RichTextArea();
+ tf.setValue("foobar");
+ Assert.assertFalse(tf.isEmpty());
+ tf.clear();
+ Assert.assertTrue(tf.isEmpty());
+ }
+
+}
diff --git a/server/tests/src/com/vaadin/ui/TextAreaTest.java b/server/tests/src/com/vaadin/ui/TextAreaTest.java
new file mode 100644
index 0000000000..e7e99c19e9
--- /dev/null
+++ b/server/tests/src/com/vaadin/ui/TextAreaTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.ui;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.data.util.ObjectProperty;
+
+public class TextAreaTest {
+ @Test
+ public void initiallyEmpty() {
+ TextArea tf = new TextArea();
+ Assert.assertTrue(tf.isEmpty());
+ }
+
+ @Test
+ public void emptyAfterClearUsingPDS() {
+ TextArea tf = new TextArea(new ObjectProperty<String>("foo"));
+ Assert.assertFalse(tf.isEmpty());
+ tf.clear();
+ Assert.assertTrue(tf.isEmpty());
+ }
+
+ @Test
+ public void emptyAfterClear() {
+ TextArea tf = new TextArea();
+ tf.setValue("foobar");
+ Assert.assertFalse(tf.isEmpty());
+ tf.clear();
+ Assert.assertTrue(tf.isEmpty());
+ }
+
+}
diff --git a/server/tests/src/com/vaadin/ui/UIThemeEscaping.java b/server/tests/src/com/vaadin/ui/UIThemeEscaping.java
new file mode 100644
index 0000000000..236f283823
--- /dev/null
+++ b/server/tests/src/com/vaadin/ui/UIThemeEscaping.java
@@ -0,0 +1,89 @@
+/*
+ * 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.ui;
+
+import com.vaadin.server.VaadinRequest;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class UIThemeEscaping {
+
+ private UI ui;
+
+ private void initUiWithTheme(String theme) {
+ VaadinRequest request = getRequestWithTheme(theme);
+
+ ui.doInit(request, 1234, "foobar");
+ }
+
+ private VaadinRequest getRequestWithTheme(String theme) {
+ VaadinRequest request = mock(VaadinRequest.class);
+
+ when(request.getParameter("theme")).thenReturn(theme);
+
+ return request;
+ }
+
+ @Before
+ public void setup() {
+ ui = new UI() {
+ @Override
+ protected void init(VaadinRequest request) {
+ // Nothing to do
+ }
+ };
+ }
+
+ @Test
+ public void dangerousCharactersAreRemoved() {
+ ui.setTheme("a<å(_\"$");
+
+ assertThat(ui.getTheme(), is("aå_$"));
+ }
+
+ @Test
+ public void nullThemeIsSet() {
+ ui.setTheme("foobar");
+
+ ui.setTheme(null);
+
+ assertThat(ui.getTheme(), is(nullValue()));
+ }
+
+ @Test
+ public void themeIsSetOnInit() {
+ ui.setTheme("foobar");
+
+ initUiWithTheme("bar");
+
+ assertThat(ui.getTheme(), is("bar"));
+ }
+
+ @Test
+ public void nullThemeIsSetOnInit() {
+ ui.setTheme("foobar");
+
+ initUiWithTheme(null);
+
+ assertThat(ui.getTheme(), is(nullValue()));
+ }
+}