diff options
Diffstat (limited to 'server/tests')
8 files changed, 200 insertions, 7 deletions
diff --git a/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java b/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java index 5c78965092..5da0bdc8a2 100644 --- a/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java +++ b/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java @@ -306,7 +306,7 @@ public class TestIndexedContainer extends AbstractInMemoryContainerTest { Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener); EasyMock.replay(addListener); - Object itemId = container.addItemAt(1); + container.addItemAt(1); assertEquals(1, capturedEvent.getValue().getFirstIndex()); } diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java index 844ef705b1..4c132eba30 100644 --- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java +++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java @@ -1917,7 +1917,6 @@ public class SQLContainerTest { EasyMock.expect(delegate.getCountStatement()) .andAnswer(new IAnswer<StatementHelper>() { @Override - @SuppressWarnings("deprecation") public StatementHelper answer() throws Throwable { StatementHelper sh = new StatementHelper(); StringBuffer query = new StringBuffer( @@ -1990,7 +1989,6 @@ public class SQLContainerTest { EasyMock.expect(delegate.getCountStatement()) .andAnswer(new IAnswer<StatementHelper>() { @Override - @SuppressWarnings("deprecation") public StatementHelper answer() throws Throwable { StatementHelper sh = new StatementHelper(); StringBuffer query = new StringBuffer( @@ -2134,7 +2132,6 @@ public class SQLContainerTest { EasyMock.expect(delegate.getCountStatement()) .andAnswer(new IAnswer<StatementHelper>() { @Override - @SuppressWarnings("deprecation") public StatementHelper answer() throws Throwable { StatementHelper sh = new StatementHelper(); StringBuffer query = new StringBuffer( @@ -2213,7 +2210,6 @@ public class SQLContainerTest { EasyMock.expect(delegate.getCountStatement()) .andAnswer(new IAnswer<StatementHelper>() { @Override - @SuppressWarnings("deprecation") public StatementHelper answer() throws Throwable { StatementHelper sh = new StatementHelper(); StringBuffer query = new StringBuffer( @@ -2292,7 +2288,6 @@ public class SQLContainerTest { EasyMock.expect(delegate.getCountStatement()) .andAnswer(new IAnswer<StatementHelper>() { @Override - @SuppressWarnings("deprecation") public StatementHelper answer() throws Throwable { StatementHelper sh = new StatementHelper(); StringBuffer query = new StringBuffer( diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/TicketTests.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/TicketTests.java index 8e8c83d234..110225e206 100644 --- a/server/tests/src/com/vaadin/data/util/sqlcontainer/TicketTests.java +++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/TicketTests.java @@ -88,7 +88,6 @@ public class TicketTests { EasyMock.expect(delegate.getCountStatement()) .andAnswer(new IAnswer<StatementHelper>() { @Override - @SuppressWarnings("deprecation") public StatementHelper answer() throws Throwable { StatementHelper sh = new StatementHelper(); StringBuffer query = new StringBuffer( diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/filters/CompareTest.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/filters/CompareTest.java new file mode 100644 index 0000000000..c8faa71e66 --- /dev/null +++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/filters/CompareTest.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2013 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.data.util.sqlcontainer.filters; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.data.util.filter.Compare; + +public class CompareTest { + + @Test + public void testEquals() { + Compare c1 = new Compare.Equal("prop1", "val1"); + Compare c2 = new Compare.Equal("prop1", "val1"); + Assert.assertTrue(c1.equals(c2)); + } + + @Test + public void testDifferentTypeEquals() { + Compare c1 = new Compare.Equal("prop1", "val1"); + Compare c2 = new Compare.Greater("prop1", "val1"); + Assert.assertFalse(c1.equals(c2)); + } + + @Test + public void testEqualsNull() { + Compare c1 = new Compare.Equal("prop1", "val1"); + Assert.assertFalse(c1.equals(null)); + } +} diff --git a/server/tests/src/com/vaadin/tests/event/EventRouterTest.java b/server/tests/src/com/vaadin/tests/event/EventRouterTest.java new file mode 100644 index 0000000000..dbbeaf778e --- /dev/null +++ b/server/tests/src/com/vaadin/tests/event/EventRouterTest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2000-2013 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.event; + +import java.lang.reflect.Method; + +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.event.EventRouter; +import com.vaadin.server.ErrorEvent; +import com.vaadin.server.ErrorHandler; +import com.vaadin.ui.Component; +import com.vaadin.ui.Component.Listener; +import com.vaadin.util.ReflectTools; + +/** + * Test EventRouter and related error handling. + */ +public class EventRouterTest { + + private static final Method COMPONENT_EVENT_METHOD = ReflectTools + .findMethod(Component.Listener.class, "componentEvent", + Component.Event.class); + + private EventRouter router; + private Component component; + private ErrorHandler errorHandler; + private Listener listener; + + @Before + public void createMocks() { + router = new EventRouter(); + component = EasyMock.createNiceMock(Component.class); + errorHandler = EasyMock.createMock(ErrorHandler.class); + listener = EasyMock.createMock(Component.Listener.class); + router.addListener(Component.Event.class, listener, + COMPONENT_EVENT_METHOD); + } + + @Test + public void fireEvent_noException_eventReceived() { + listener.componentEvent(EasyMock.<Component.Event> anyObject()); + + EasyMock.replay(component, listener, errorHandler); + router.fireEvent(new Component.Event(component), errorHandler); + EasyMock.verify(listener, errorHandler); + } + + @Test + public void fireEvent_exceptionFromListenerAndNoHandler_exceptionPropagated() { + listener.componentEvent(EasyMock.<Component.Event> anyObject()); + EasyMock.expectLastCall().andThrow( + new RuntimeException("listener failed")); + + EasyMock.replay(component, listener); + try { + router.fireEvent(new Component.Event(component)); + Assert.fail("Did not receive expected exception from listener"); + } catch (RuntimeException e) { + // e is a ListenerMethod@MethodException + Assert.assertEquals("listener failed", e.getCause().getMessage()); + } + EasyMock.verify(listener); + } + + @Test + public void fireEvent_exceptionFromListener_errorHandlerCalled() { + listener.componentEvent(EasyMock.<Component.Event> anyObject()); + EasyMock.expectLastCall().andThrow( + new RuntimeException("listener failed")); + errorHandler.error(EasyMock.<ErrorEvent> anyObject()); + + EasyMock.replay(component, listener, errorHandler); + router.fireEvent(new Component.Event(component), errorHandler); + EasyMock.verify(listener, errorHandler); + } + + @Test + public void fireEvent_multipleListenersAndException_errorHandlerCalled() { + Listener listener2 = EasyMock.createMock(Component.Listener.class); + router.addListener(Component.Event.class, listener2, + COMPONENT_EVENT_METHOD); + + listener.componentEvent(EasyMock.<Component.Event> anyObject()); + EasyMock.expectLastCall().andThrow( + new RuntimeException("listener failed")); + errorHandler.error(EasyMock.<ErrorEvent> anyObject()); + // second listener should be called despite an error in the first + listener2.componentEvent(EasyMock.<Component.Event> anyObject()); + + EasyMock.replay(component, listener, listener2, errorHandler); + router.fireEvent(new Component.Event(component), errorHandler); + EasyMock.verify(listener, listener2, errorHandler); + } +} diff --git a/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java b/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java index e5420b8921..0a36c7f7ce 100644 --- a/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java +++ b/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java @@ -42,6 +42,7 @@ public class TestClassesSerializable extends TestCase { "com\\.vaadin\\.event\\.FieldEvents", // "com\\.vaadin\\.event\\.LayoutEvents", // "com\\.vaadin\\.event\\.MouseEvents", // + "com\\.vaadin\\.event\\.UIEvents", // "com\\.vaadin\\.server\\.VaadinPortlet", // "com\\.vaadin\\.server\\.MockServletConfig", // "com\\.vaadin\\.server\\.MockServletContext", // @@ -49,6 +50,8 @@ public class TestClassesSerializable extends TestCase { "com\\.vaadin\\.server\\.communication\\.FileUploadHandler\\$SimpleMultiPartInputStream", // "com\\.vaadin\\.server\\.communication\\.PushRequestHandler.*", "com\\.vaadin\\.server\\.communication\\.PushHandler.*", // PushHandler + "com\\.vaadin\\.server\\.communication\\.DateSerializer", // + "com\\.vaadin\\.server\\.communication\\.JSONSerializer", // // and its inner classes do not need to be serializable "com\\.vaadin\\.util\\.SerializerHelper", // fully static // class level filtering, also affecting nested classes and diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java index ad762f8931..887f1b8ff3 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java @@ -54,6 +54,21 @@ public class AbsFieldValueConversionError extends TestCase { } + public void testNullConversionMessages() { + TextField tf = new TextField(); + tf.setConverter(new StringToIntegerConverter()); + tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age")); + tf.setConversionError(null); + tf.setValue("abc"); + try { + tf.validate(); + fail(); + } catch (InvalidValueException e) { + Assert.assertEquals(null, e.getMessage()); + } + + } + public void testDefaultConversionErrorMessage() { TextField tf = new TextField(); tf.setConverter(new StringToIntegerConverter()); diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java b/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java new file mode 100644 index 0000000000..5575b8fd3d --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.server.component.abstractselect; + +import java.util.Collection; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.vaadin.ui.OptionGroup; + +public class TestVarargsItemAddition extends TestCase { + + public void itemAddition() throws Exception { + + OptionGroup optionGroup = new OptionGroup(); + + optionGroup.addItems("foo", "bar", "car"); + + Collection<?> itemIds = optionGroup.getItemIds(); + Assert.assertEquals(3, itemIds.size()); + Assert.assertTrue(itemIds.contains("foo")); + Assert.assertTrue(itemIds.contains("bar")); + Assert.assertTrue(itemIds.contains("car")); + + } +} |