diff options
author | Artur Signell <artur@vaadin.com> | 2015-09-04 15:05:27 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-09-04 15:05:27 +0300 |
commit | f46be1b2792755cb7d9b111068dd6cf202398c4a (patch) | |
tree | 74f7098faee688cc1f1ca1b6ffe9e912338bbcaf /server/tests/src/com | |
parent | e603ea3cf91e5dd0893b766f27d400947527fba9 (diff) | |
parent | ebceef4d44bcd61605fa92fcf7be8d3678537599 (diff) | |
download | vaadin-framework-f46be1b2792755cb7d9b111068dd6cf202398c4a.tar.gz vaadin-framework-f46be1b2792755cb7d9b111068dd6cf202398c4a.zip |
Merge remote-tracking branch 'origin/master' into reconnect-dialog
Change-Id: Ie622160a83116c83b255a26bec297f73f3223ac7
Diffstat (limited to 'server/tests/src/com')
14 files changed, 495 insertions, 200 deletions
diff --git a/server/tests/src/com/vaadin/data/util/AbstractContainerTestBase.java b/server/tests/src/com/vaadin/data/util/AbstractContainerTestBase.java index 54cbc5305d..55dccc6455 100644 --- a/server/tests/src/com/vaadin/data/util/AbstractContainerTestBase.java +++ b/server/tests/src/com/vaadin/data/util/AbstractContainerTestBase.java @@ -11,6 +11,7 @@ import com.vaadin.data.Container; import com.vaadin.data.Container.Filterable; import com.vaadin.data.Container.ItemSetChangeEvent; import com.vaadin.data.Container.ItemSetChangeListener; +import com.vaadin.data.Container.Ordered; import com.vaadin.data.Container.Sortable; import com.vaadin.data.Item; import com.vaadin.data.util.filter.SimpleStringFilter; @@ -161,54 +162,54 @@ public abstract class AbstractContainerTestBase extends TestCase { validateContainer(container, sampleData[0], sampleData[sampleData.length - 1], sampleData[10], "abc", true, sampleData.length); + + validateRemovingItems(container); + } + + protected void validateRemovingItems(Container container) { + int sizeBeforeRemoving = container.size(); + + List<Object> itemIdList = new ArrayList<Object>(container.getItemIds()); + // There should be at least four items in the list + Object first = itemIdList.get(0); + Object middle = itemIdList.get(2); + Object last = itemIdList.get(itemIdList.size() - 1); + + container.removeItem(first); + container.removeItem(middle); // Middle now that first has been removed + container.removeItem(last); + + assertEquals(sizeBeforeRemoving - 3, container.size()); + + container.removeAllItems(); + + assertEquals(0, container.size()); } protected void testContainerOrdered(Container.Ordered container) { + // addItem with empty container Object id = container.addItem(); - assertNotNull(id); + assertOrderedContents(container, id); Item item = container.getItem(id); assertNotNull(item); - assertEquals(id, container.firstItemId()); - assertEquals(id, container.lastItemId()); - - // isFirstId - assertTrue(container.isFirstId(id)); - assertTrue(container.isFirstId(container.firstItemId())); - // isLastId - assertTrue(container.isLastId(id)); - assertTrue(container.isLastId(container.lastItemId())); + // addItemAfter with empty container + container.removeAllItems(); + assertOrderedContents(container); + id = container.addItemAfter(null); + assertOrderedContents(container, id); + item = container.getItem(id); + assertNotNull(item); // Add a new item before the first // addItemAfter Object newFirstId = container.addItemAfter(null); - assertNotNull(newFirstId); - assertNotNull(container.getItem(newFirstId)); - - // isFirstId - assertTrue(container.isFirstId(newFirstId)); - assertTrue(container.isFirstId(container.firstItemId())); - // isLastId - assertTrue(container.isLastId(id)); - assertTrue(container.isLastId(container.lastItemId())); - - // nextItemId - assertEquals(id, container.nextItemId(newFirstId)); - assertNull(container.nextItemId(id)); - assertNull(container.nextItemId("not-in-container")); - - // prevItemId - assertEquals(newFirstId, container.prevItemId(id)); - assertNull(container.prevItemId(newFirstId)); - assertNull(container.prevItemId("not-in-container")); + assertOrderedContents(container, newFirstId, id); // addItemAfter(Object) Object newSecondItemId = container.addItemAfter(newFirstId); // order is now: newFirstId, newSecondItemId, id - assertNotNull(newSecondItemId); - assertNotNull(container.getItem(newSecondItemId)); - assertEquals(id, container.nextItemId(newSecondItemId)); - assertEquals(newFirstId, container.prevItemId(newSecondItemId)); + assertOrderedContents(container, newFirstId, newSecondItemId, id); // addItemAfter(Object,Object) String fourthId = "id of the fourth item"; @@ -216,8 +217,8 @@ public abstract class AbstractContainerTestBase extends TestCase { // order is now: newFirstId, fourthId, newSecondItemId, id assertNotNull(fourth); assertEquals(fourth, container.getItem(fourthId)); - assertEquals(newSecondItemId, container.nextItemId(fourthId)); - assertEquals(newFirstId, container.prevItemId(fourthId)); + assertOrderedContents(container, newFirstId, fourthId, newSecondItemId, + id); // addItemAfter(Object,Object) Object fifthId = new Object(); @@ -225,8 +226,86 @@ public abstract class AbstractContainerTestBase extends TestCase { // order is now: fifthId, newFirstId, fourthId, newSecondItemId, id assertNotNull(fifth); assertEquals(fifth, container.getItem(fifthId)); - assertEquals(newFirstId, container.nextItemId(fifthId)); - assertNull(container.prevItemId(fifthId)); + assertOrderedContents(container, fifthId, newFirstId, fourthId, + newSecondItemId, id); + + // addItemAfter(Object,Object) + Object sixthId = new Object(); + Item sixth = container.addItemAfter(id, sixthId); + // order is now: fifthId, newFirstId, fourthId, newSecondItemId, id, + // sixthId + assertNotNull(sixth); + assertEquals(sixth, container.getItem(sixthId)); + assertOrderedContents(container, fifthId, newFirstId, fourthId, + newSecondItemId, id, sixthId); + + // Test order after removing first item 'fifthId' + container.removeItem(fifthId); + // order is now: newFirstId, fourthId, newSecondItemId, id, sixthId + assertOrderedContents(container, newFirstId, fourthId, newSecondItemId, + id, sixthId); + + // Test order after removing last item 'sixthId' + container.removeItem(sixthId); + // order is now: newFirstId, fourthId, newSecondItemId, id + assertOrderedContents(container, newFirstId, fourthId, newSecondItemId, + id); + + // Test order after removing item from the middle 'fourthId' + container.removeItem(fourthId); + // order is now: newFirstId, newSecondItemId, id + assertOrderedContents(container, newFirstId, newSecondItemId, id); + + // Delete remaining items + container.removeItem(newFirstId); + container.removeItem(newSecondItemId); + container.removeItem(id); + assertOrderedContents(container); + + Object finalItem = container.addItem(); + assertOrderedContents(container, finalItem); + } + + private void assertOrderedContents(Ordered container, Object... ids) { + assertEquals(ids.length, container.size()); + for (int i = 0; i < ids.length - 1; i++) { + assertNotNull("The item id should not be null", ids[i]); + } + if (ids.length == 0) { + assertNull("The first id is wrong", container.firstItemId()); + assertNull("The last id is wrong", container.lastItemId()); + return; + } + + assertEquals("The first id is wrong", ids[0], container.firstItemId()); + assertEquals("The last id is wrong", ids[ids.length - 1], + container.lastItemId()); + + // isFirstId & isLastId + assertTrue(container.isFirstId(container.firstItemId())); + assertTrue(container.isLastId(container.lastItemId())); + + // nextId + Object ref = container.firstItemId(); + for (int i = 1; i < ids.length; i++) { + Object next = container.nextItemId(ref); + assertEquals("The id after " + ref + " is wrong", ids[i], next); + ref = next; + } + assertNull("The last id should not have a next id", + container.nextItemId(ids[ids.length - 1])); + assertNull(container.nextItemId("not-in-container")); + + // prevId + ref = container.lastItemId(); + for (int i = ids.length - 2; i >= 0; i--) { + Object prev = container.prevItemId(ref); + assertEquals("The id before " + ref + " is wrong", ids[i], prev); + ref = prev; + } + assertNull("The first id should not have a prev id", + container.prevItemId(ids[0])); + assertNull(container.prevItemId("not-in-container")); } diff --git a/server/tests/src/com/vaadin/data/util/AbstractHierarchicalContainerTestBase.java b/server/tests/src/com/vaadin/data/util/AbstractHierarchicalContainerTestBase.java index 3bd00cce3c..9cede77162 100644 --- a/server/tests/src/com/vaadin/data/util/AbstractHierarchicalContainerTestBase.java +++ b/server/tests/src/com/vaadin/data/util/AbstractHierarchicalContainerTestBase.java @@ -253,4 +253,33 @@ public abstract class AbstractHierarchicalContainerTestBase extends } } + protected void testRemoveHierarchicalWrapperSubtree( + Container.Hierarchical container) { + initializeContainer(container); + + // remove root item + removeItemRecursively(container, "org"); + + int packages = 21 + 3 - 3; + int expectedSize = sampleData.length + packages - 1; + + validateContainer(container, "com", "com.vaadin.util.SerializerHelper", + "com.vaadin.server.ApplicationResource", "blah", true, + expectedSize); + + // rootItemIds + Collection<?> rootIds = container.rootItemIds(); + assertEquals(1, rootIds.size()); + } + + private void removeItemRecursively(Container.Hierarchical container, + Object itemId) { + if (container instanceof ContainerHierarchicalWrapper) { + ((ContainerHierarchicalWrapper) container) + .removeItemRecursively("org"); + } else { + HierarchicalContainer.removeItemRecursively(container, itemId); + } + } + } diff --git a/server/tests/src/com/vaadin/data/util/ContainerHierarchicalWrapperTest.java b/server/tests/src/com/vaadin/data/util/ContainerHierarchicalWrapperTest.java index 2fd21ef118..8e554d5030 100644 --- a/server/tests/src/com/vaadin/data/util/ContainerHierarchicalWrapperTest.java +++ b/server/tests/src/com/vaadin/data/util/ContainerHierarchicalWrapperTest.java @@ -1,6 +1,5 @@ package com.vaadin.data.util; -import java.util.Collection; public class ContainerHierarchicalWrapperTest extends AbstractHierarchicalContainerTestBase { @@ -20,23 +19,4 @@ public class ContainerHierarchicalWrapperTest extends new IndexedContainer())); } - protected void testRemoveHierarchicalWrapperSubtree( - ContainerHierarchicalWrapper container) { - initializeContainer(container); - - // remove root item - container.removeItemRecursively("org"); - - int packages = 21 + 3 - 3; - int expectedSize = sampleData.length + packages - 1; - - validateContainer(container, "com", "com.vaadin.util.SerializerHelper", - "com.vaadin.server.ApplicationResource", "blah", true, - expectedSize); - - // rootItemIds - Collection<?> rootIds = container.rootItemIds(); - assertEquals(1, rootIds.size()); - } - } diff --git a/server/tests/src/com/vaadin/data/util/ContainerOrderedWrapperTest.java b/server/tests/src/com/vaadin/data/util/ContainerOrderedWrapperTest.java new file mode 100644 index 0000000000..422e9756f8 --- /dev/null +++ b/server/tests/src/com/vaadin/data/util/ContainerOrderedWrapperTest.java @@ -0,0 +1,102 @@ +package com.vaadin.data.util; + +import java.util.Collection; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.Property; + +public class ContainerOrderedWrapperTest extends AbstractContainerTestBase { + + // This class is needed to get an implementation of container + // which is not an implementation of Ordered interface. + private class NotOrderedContainer implements Container { + + private IndexedContainer container; + + public NotOrderedContainer() { + container = new IndexedContainer(); + } + + @Override + public Item getItem(Object itemId) { + return container.getItem(itemId); + } + + @Override + public Collection<?> getContainerPropertyIds() { + return container.getContainerPropertyIds(); + } + + @Override + public Collection<?> getItemIds() { + return container.getItemIds(); + } + + @Override + public Property getContainerProperty(Object itemId, Object propertyId) { + return container.getContainerProperty(itemId, propertyId); + } + + @Override + public Class<?> getType(Object propertyId) { + return container.getType(propertyId); + } + + @Override + public int size() { + return container.size(); + } + + @Override + public boolean containsId(Object itemId) { + return container.containsId(itemId); + } + + @Override + public Item addItem(Object itemId) throws UnsupportedOperationException { + return container.addItem(itemId); + } + + @Override + public Object addItem() throws UnsupportedOperationException { + return container.addItem(); + } + + @Override + public boolean removeItem(Object itemId) + throws UnsupportedOperationException { + return container.removeItem(itemId); + } + + @Override + public boolean addContainerProperty(Object propertyId, Class<?> type, + Object defaultValue) throws UnsupportedOperationException { + return container.addContainerProperty(propertyId, type, + defaultValue); + } + + @Override + public boolean removeContainerProperty(Object propertyId) + throws UnsupportedOperationException { + return container.removeContainerProperty(propertyId); + } + + @Override + public boolean removeAllItems() throws UnsupportedOperationException { + return container.removeAllItems(); + } + + } + + public void testBasicOperations() { + testBasicContainerOperations(new ContainerOrderedWrapper( + new NotOrderedContainer())); + } + + public void testOrdered() { + testContainerOrdered(new ContainerOrderedWrapper( + new NotOrderedContainer())); + } + +} diff --git a/server/tests/src/com/vaadin/data/util/HierarchicalContainerOrderedWrapperTest.java b/server/tests/src/com/vaadin/data/util/HierarchicalContainerOrderedWrapperTest.java new file mode 100644 index 0000000000..7ecf59c309 --- /dev/null +++ b/server/tests/src/com/vaadin/data/util/HierarchicalContainerOrderedWrapperTest.java @@ -0,0 +1,27 @@ +package com.vaadin.data.util; + +public class HierarchicalContainerOrderedWrapperTest extends + AbstractHierarchicalContainerTestBase { + + private HierarchicalContainerOrderedWrapper createContainer() { + return new HierarchicalContainerOrderedWrapper( + new ContainerHierarchicalWrapper(new IndexedContainer())); + } + + public void testBasicOperations() { + testBasicContainerOperations(createContainer()); + } + + public void testHierarchicalContainer() { + testHierarchicalContainer(createContainer()); + } + + public void testContainerOrdered() { + testContainerOrdered(createContainer()); + } + + public void testRemoveSubtree() { + testRemoveHierarchicalWrapperSubtree(createContainer()); + } + +} diff --git a/server/tests/src/com/vaadin/server/communication/FileUploadHandlerTest.java b/server/tests/src/com/vaadin/server/communication/FileUploadHandlerTest.java index 2cb4c3bf4d..286163541e 100644 --- a/server/tests/src/com/vaadin/server/communication/FileUploadHandlerTest.java +++ b/server/tests/src/com/vaadin/server/communication/FileUploadHandlerTest.java @@ -15,50 +15,136 @@ */ package com.vaadin.server.communication; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import com.vaadin.server.ClientConnector; +import com.vaadin.server.ServletPortletHelper; +import com.vaadin.server.StreamVariable; import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinResponse; +import com.vaadin.server.VaadinSession; +import com.vaadin.ui.ConnectorTracker; +import com.vaadin.ui.UI; -/** - * Tests whether we get infinite loop if InputStream is already read (#10096) - */ public class FileUploadHandlerTest { private FileUploadHandler handler; - private VaadinRequest request; + @Mock private VaadinResponse response; + @Mock private StreamVariable streamVariable; + @Mock private ClientConnector clientConnector; + @Mock private VaadinRequest request; + @Mock private UI ui; + @Mock private ConnectorTracker connectorTracker; + @Mock private VaadinSession session; + @Mock private OutputStream responseOutput; + + private int uiId = 123; + private final String connectorId = "connectorId"; + private final String variableName = "name"; + private final String expectedSecurityKey = "key"; @Before public void setup() throws Exception { + MockitoAnnotations.initMocks(this); + handler = new FileUploadHandler(); - InputStream inputStream = new InputStream() { - private int counter = 0; + + mockRequest(); + mockConnectorTracker(); + mockUi(); + + when(clientConnector.isConnectorEnabled()).thenReturn(true); + when(streamVariable.getOutputStream()).thenReturn(mock(OutputStream.class)); + when(response.getOutputStream()).thenReturn(responseOutput); + } + + private void mockConnectorTracker() { + when(connectorTracker.getSeckey(streamVariable)).thenReturn(expectedSecurityKey); + when(connectorTracker.getStreamVariable(connectorId, variableName)).thenReturn(streamVariable); + when(connectorTracker.getConnector(connectorId)).thenReturn(clientConnector); + } + + private void mockRequest() throws IOException { + when(request.getPathInfo()).thenReturn("/" + ServletPortletHelper.UPLOAD_URL_PREFIX + uiId + "/"+ connectorId + "/" + variableName + "/" + expectedSecurityKey); + when(request.getInputStream()).thenReturn(createInputStream("foobar")); + when(request.getHeader("Content-Length")).thenReturn("6"); + when(request.getContentType()).thenReturn("foobar"); + } + + private InputStream createInputStream(final String content) { + return new InputStream() { + int counter = 0; + byte[] msg = content.getBytes(); @Override public int read() throws IOException { - counter++; - if (counter > 6) { - throw new RuntimeException( - "-1 is ignored by FileUploadHandler"); + if(counter > msg.length + 1) { + throw new AssertionError("-1 was ignored by FileUploadHandler."); + } + + if(counter >= msg.length) { + counter++; + return -1; } - return -1; - } + return msg[counter++]; + } }; - request = Mockito.mock(VaadinRequest.class); - Mockito.when(request.getInputStream()).thenReturn(inputStream); - Mockito.when(request.getHeader("Content-Length")).thenReturn("211"); } + private void mockUi() { + when(ui.getConnectorTracker()).thenReturn(connectorTracker); + when(session.getUIById(uiId)).thenReturn(ui); + } + + /** + * Tests whether we get infinite loop if InputStream is already read (#10096) + */ @Test(expected = IOException.class) - public void testStreamEnded() throws IOException { + public void exceptionIsThrownOnUnexpectedEnd() throws IOException { + when(request.getInputStream()).thenReturn(createInputStream("")); + when(request.getHeader("Content-Length")).thenReturn("1"); + handler.doHandleSimpleMultipartFileUpload(null, request, null, null, null, null, null); + } + + @Test + public void responseIsSentOnCorrectSecurityKey() throws IOException { + when(connectorTracker.getSeckey(streamVariable)).thenReturn(expectedSecurityKey); + + handler.handleRequest(session, request, response); + verify(responseOutput).close(); } + @Test + public void responseIsNotSentOnIncorrectSecurityKey() throws IOException { + when(connectorTracker.getSeckey(streamVariable)).thenReturn("another key expected"); + + handler.handleRequest(session, request, response); + + verifyZeroInteractions(responseOutput); + } + + @Test + public void responseIsNotSentOnMissingSecurityKey() throws IOException { + when(connectorTracker.getSeckey(streamVariable)).thenReturn(null); + + handler.handleRequest(session, request, response); + + verifyZeroInteractions(responseOutput); + } } diff --git a/server/tests/src/com/vaadin/tests/data/converter/StringToBooleanConverterTest.java b/server/tests/src/com/vaadin/tests/data/converter/StringToBooleanConverterTest.java index f734d76633..6e81af97a3 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/StringToBooleanConverterTest.java +++ b/server/tests/src/com/vaadin/tests/data/converter/StringToBooleanConverterTest.java @@ -4,9 +4,25 @@ import junit.framework.TestCase; import com.vaadin.data.util.converter.StringToBooleanConverter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + public class StringToBooleanConverterTest extends TestCase { StringToBooleanConverter converter = new StringToBooleanConverter(); + StringToBooleanConverter yesNoConverter = new StringToBooleanConverter("yes","no"); + StringToBooleanConverter localeConverter = new StringToBooleanConverter() { + @Override + public String getFalseString(Locale locale) { + return SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG,locale).format(new Date(3000000000000L)); + } + + @Override + public String getTrueString(Locale locale) { + return SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG,locale).format(new Date(2000000000000L)); + } + }; public void testNullConversion() { assertEquals(null, converter.convertToModel(null, Boolean.class, null)); @@ -20,4 +36,22 @@ public class StringToBooleanConverterTest extends TestCase { assertTrue(converter.convertToModel("true", Boolean.class, null)); assertFalse(converter.convertToModel("false", Boolean.class, null)); } + + public void testYesNoValueConversion() { + assertTrue(yesNoConverter.convertToModel("yes", Boolean.class, null)); + assertFalse(yesNoConverter.convertToModel("no", Boolean.class, null)); + + assertEquals("yes", yesNoConverter.convertToPresentation(true, String.class, null)); + assertEquals("no", yesNoConverter.convertToPresentation(false, String.class, null)); + } + + + public void testLocale() { + assertEquals("May 18, 2033", localeConverter.convertToPresentation(true, String.class, Locale.US)); + assertEquals("January 24, 2065", localeConverter.convertToPresentation(false, String.class, Locale.US)); + + assertEquals("18. Mai 2033", localeConverter.convertToPresentation(true, String.class, Locale.GERMANY)); + assertEquals("24. Januar 2065", localeConverter.convertToPresentation(false, String.class, Locale.GERMANY)); + } + } diff --git a/server/tests/src/com/vaadin/tests/data/converter/StringToEnumConverterTest.java b/server/tests/src/com/vaadin/tests/data/converter/StringToEnumConverterTest.java index a4c3732e1f..59c1ed133a 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/StringToEnumConverterTest.java +++ b/server/tests/src/com/vaadin/tests/data/converter/StringToEnumConverterTest.java @@ -1,13 +1,14 @@ package com.vaadin.tests.data.converter; -import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; 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; -public class StringToEnumConverterTest extends TestCase { +public class StringToEnumConverterTest { public static enum FooEnum { VALUE1, SOME_VALUE, FOO_BAR_BAZ, Bar, nonStandardCase, _HUGH; @@ -17,56 +18,64 @@ public class StringToEnumConverterTest extends TestCase { Converter<Enum, String> reverseConverter = new ReverseConverter<Enum, String>( converter); + @Test public void testEmptyStringConversion() { - assertEquals(null, converter.convertToModel("", Enum.class, null)); + Assert.assertEquals(null, + converter.convertToModel("", Enum.class, null)); } + @Test public void testInvalidEnumClassConversion() { try { converter.convertToModel("Foo", Enum.class, null); - fail("No exception thrown"); + Assert.fail("No exception thrown"); } catch (ConversionException e) { // OK } } + @Test public void testNullConversion() { - assertEquals(null, converter.convertToModel(null, Enum.class, null)); + Assert.assertEquals(null, + converter.convertToModel(null, Enum.class, null)); } + @Test public void testReverseNullConversion() { - assertEquals(null, + Assert.assertEquals(null, reverseConverter.convertToModel(null, String.class, null)); } + @Test public void testValueConversion() { - assertEquals(FooEnum.VALUE1, + Assert.assertEquals(FooEnum.VALUE1, converter.convertToModel("Value1", FooEnum.class, null)); - assertEquals(FooEnum.SOME_VALUE, + Assert.assertEquals(FooEnum.SOME_VALUE, converter.convertToModel("Some value", FooEnum.class, null)); - assertEquals(FooEnum.FOO_BAR_BAZ, + Assert.assertEquals(FooEnum.FOO_BAR_BAZ, converter.convertToModel("Foo bar baz", FooEnum.class, null)); - assertEquals(FooEnum.Bar, + Assert.assertEquals(FooEnum.Bar, converter.convertToModel("Bar", FooEnum.class, null)); - assertEquals(FooEnum.nonStandardCase, converter.convertToModel( + Assert.assertEquals(FooEnum.nonStandardCase, converter.convertToModel( "Nonstandardcase", FooEnum.class, null)); - assertEquals(FooEnum._HUGH, + Assert.assertEquals(FooEnum._HUGH, converter.convertToModel("_hugh", FooEnum.class, null)); } + @Test public void testReverseValueConversion() { - assertEquals("Value1", reverseConverter.convertToModel(FooEnum.VALUE1, - String.class, null)); - assertEquals("Some value", reverseConverter.convertToModel( + Assert.assertEquals("Value1", reverseConverter.convertToModel( + FooEnum.VALUE1, String.class, null)); + Assert.assertEquals("Some value", reverseConverter.convertToModel( FooEnum.SOME_VALUE, String.class, null)); - assertEquals("Foo bar baz", reverseConverter.convertToModel( + Assert.assertEquals("Foo bar baz", reverseConverter.convertToModel( FooEnum.FOO_BAR_BAZ, String.class, null)); - assertEquals("Bar", reverseConverter.convertToModel(FooEnum.Bar, + Assert.assertEquals("Bar", reverseConverter.convertToModel(FooEnum.Bar, String.class, null)); - assertEquals("Nonstandardcase", reverseConverter.convertToModel( + Assert.assertEquals("Nonstandardcase", reverseConverter.convertToModel( FooEnum.nonStandardCase, String.class, null)); - assertEquals("_hugh", reverseConverter.convertToModel(FooEnum._HUGH, - String.class, null)); + Assert.assertEquals("_hugh", reverseConverter.convertToModel( + FooEnum._HUGH, String.class, null)); } diff --git a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java index acee3e2ca8..6510d8ad40 100644 --- a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java +++ b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java @@ -203,7 +203,7 @@ public class DesignFormatterTest { ShortcutAction action = new ShortcutAction("&^d"); String formatted = formatter.format(action); // note the space here - it separates key combination from caption - assertEquals("alt-ctrl-d d", formatted); + assertEquals("ctrl-alt-d d", formatted); ShortcutAction result = formatter .parse(formatted, ShortcutAction.class); @@ -215,7 +215,7 @@ public class DesignFormatterTest { ShortcutAction action = new ShortcutAction(null, KeyCode.D, new int[] { ModifierKey.ALT, ModifierKey.CTRL }); String formatted = formatter.format(action); - assertEquals("alt-ctrl-d", formatted); + assertEquals("ctrl-alt-d", formatted); ShortcutAction result = formatter .parse(formatted, ShortcutAction.class); diff --git a/server/tests/src/com/vaadin/tests/server/ClassesSerializableTest.java b/server/tests/src/com/vaadin/tests/server/ClassesSerializableTest.java index 9603032ce5..829ad0455d 100644 --- a/server/tests/src/com/vaadin/tests/server/ClassesSerializableTest.java +++ b/server/tests/src/com/vaadin/tests/server/ClassesSerializableTest.java @@ -73,7 +73,7 @@ public class ClassesSerializableTest extends TestCase { "com\\.vaadin\\.server\\.AbstractClientConnector\\$1\\$1", // "com\\.vaadin\\.server\\.JsonCodec\\$1", // "com\\.vaadin\\.server\\.communication\\.PushConnection", // - "com\\.vaadin\\.server\\.communication\\.AtmospherePushConnection", // + "com\\.vaadin\\.server\\.communication\\.AtmospherePushConnection.*", // "com\\.vaadin\\.util\\.ConnectorHelper", // "com\\.vaadin\\.server\\.VaadinSession\\$FutureAccess", // "com\\.vaadin\\.external\\..*", // diff --git a/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java index 51abf6be96..b1c10789b4 100644 --- a/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/button/ButtonDeclarativeTest.java @@ -98,7 +98,7 @@ public class ButtonDeclarativeTest extends DeclarativeTestBase<Button> { @Test public void testAttributes() { String design = "<v-button tabindex=3 plain-text='' icon-alt=OK " - + "click-shortcut=ctrl-shift-o></v-button>"; + + "click-shortcut=shift-ctrl-o></v-button>"; Button b = new Button(""); b.setTabIndex(3); b.setIconAlternateText("OK"); diff --git a/server/tests/src/com/vaadin/tests/server/component/grid/DataProviderExtension.java b/server/tests/src/com/vaadin/tests/server/component/grid/DataProviderExtension.java deleted file mode 100644 index 9ecf131c5b..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/grid/DataProviderExtension.java +++ /dev/null @@ -1,88 +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.server.component.grid; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; - -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.data.Container; -import com.vaadin.data.Container.Indexed; -import com.vaadin.data.Item; -import com.vaadin.data.Property; -import com.vaadin.data.RpcDataProviderExtension; -import com.vaadin.data.RpcDataProviderExtension.DataProviderKeyMapper; -import com.vaadin.data.util.IndexedContainer; - -public class DataProviderExtension { - private RpcDataProviderExtension dataProvider; - private DataProviderKeyMapper keyMapper; - private Container.Indexed container; - - private static final Object ITEM_ID1 = "itemid1"; - private static final Object ITEM_ID2 = "itemid2"; - private static final Object ITEM_ID3 = "itemid3"; - - private static final Object PROPERTY_ID1_STRING = "property1"; - - @Before - public void setup() { - container = new IndexedContainer(); - populate(container); - - dataProvider = new RpcDataProviderExtension(container); - keyMapper = dataProvider.getKeyMapper(); - } - - private static void populate(Indexed container) { - container.addContainerProperty(PROPERTY_ID1_STRING, String.class, ""); - for (Object itemId : Arrays.asList(ITEM_ID1, ITEM_ID2, ITEM_ID3)) { - final Item item = container.addItem(itemId); - @SuppressWarnings("unchecked") - final Property<String> stringProperty = item - .getItemProperty(PROPERTY_ID1_STRING); - stringProperty.setValue(itemId.toString()); - } - } - - @Test - public void pinBasics() { - assertFalse("itemId1 should not start as pinned", - keyMapper.isPinned(ITEM_ID2)); - - keyMapper.pin(ITEM_ID1); - assertTrue("itemId1 should now be pinned", keyMapper.isPinned(ITEM_ID1)); - - keyMapper.unpin(ITEM_ID1); - assertFalse("itemId1 should not be pinned anymore", - keyMapper.isPinned(ITEM_ID2)); - } - - @Test(expected = IllegalStateException.class) - public void doublePinning() { - keyMapper.pin(ITEM_ID1); - keyMapper.pin(ITEM_ID1); - } - - @Test(expected = IllegalStateException.class) - public void nonexistentUnpin() { - keyMapper.unpin(ITEM_ID1); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/window/WindowDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/window/WindowDeclarativeTest.java index 1d233af494..607fb471b9 100644 --- a/server/tests/src/com/vaadin/tests/server/component/window/WindowDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/window/WindowDeclarativeTest.java @@ -71,8 +71,9 @@ public class WindowDeclarativeTest extends DeclarativeTestBase<Window> { expected.setClosable(!expected.isClosable()); expected.setDraggable(!expected.isDraggable()); - expected.setCloseShortcut(KeyCode.ESCAPE, ModifierKey.CTRL, - ModifierKey.ALT); + expected.removeAllCloseShortcuts(); + expected.addCloseShortcut(KeyCode.ESCAPE, ModifierKey.ALT, + ModifierKey.CTRL); expected.setAssistivePrefix("Hello"); expected.setAssistivePostfix("World"); @@ -86,6 +87,40 @@ public class WindowDeclarativeTest extends DeclarativeTestBase<Window> { } @Test + public void testMultiCloseShortcuts() { + + Window expected = new Window(); + + // Add two shortcuts - should now contain three (default escape + two + // added) + expected.addCloseShortcut(KeyCode.SPACEBAR); + expected.addCloseShortcut(KeyCode.ARROW_LEFT, ModifierKey.ALT, + ModifierKey.CTRL); + + // Try to add the same shortcut again, should be no-op + expected.addCloseShortcut(KeyCode.ARROW_LEFT, ModifierKey.CTRL, + ModifierKey.ALT); + + // Add a third shortcut, should total four (default escape + three + // added) + expected.addCloseShortcut(KeyCode.ARROW_RIGHT, ModifierKey.CTRL); + + // Test validity + String design = "<v-window close-shortcut='escape spacebar ctrl-alt-left ctrl-right' />"; + testRead(design, expected); + testWrite(design, expected); + + // Try removing the spacebar shortcut + expected.removeCloseShortcut(KeyCode.SPACEBAR); + + // Test again + design = "<v-window close-shortcut='escape ctrl-alt-left ctrl-right' />"; + testRead(design, expected); + testWrite(design, expected); + + } + + @Test public void testInvalidPosition() { assertInvalidPosition(""); assertInvalidPosition("1"); diff --git a/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java b/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java index eb07fae07f..cea8df0ba6 100644 --- a/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java +++ b/server/tests/src/com/vaadin/tests/server/renderer/RendererTest.java @@ -15,8 +15,17 @@ */ package com.vaadin.tests.server.renderer; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; + +import java.util.Date; +import java.util.Locale; + +import org.junit.Before; +import org.junit.Test; + import com.vaadin.data.Item; -import com.vaadin.data.RpcDataProviderExtension; import com.vaadin.data.util.IndexedContainer; import com.vaadin.data.util.converter.Converter; import com.vaadin.data.util.converter.StringToIntegerConverter; @@ -24,22 +33,15 @@ import com.vaadin.server.VaadinSession; import com.vaadin.tests.server.component.grid.TestGrid; import com.vaadin.tests.util.AlwaysLockedVaadinSession; import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.AbstractRenderer; import com.vaadin.ui.Grid.Column; import com.vaadin.ui.renderers.ButtonRenderer; import com.vaadin.ui.renderers.DateRenderer; import com.vaadin.ui.renderers.HtmlRenderer; import com.vaadin.ui.renderers.NumberRenderer; import com.vaadin.ui.renderers.TextRenderer; -import elemental.json.JsonValue; -import org.junit.Before; -import org.junit.Test; - -import java.util.Date; -import java.util.Locale; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import elemental.json.JsonValue; public class RendererTest { @@ -259,7 +261,7 @@ public class RendererTest { } private JsonValue render(Column column, Object value) { - return RpcDataProviderExtension.encodeValue(value, - column.getRenderer(), column.getConverter(), grid.getLocale()); + return AbstractRenderer.encodeValue(value, column.getRenderer(), + column.getConverter(), grid.getLocale()); } } |