diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-17 11:29:23 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-17 11:29:51 +0200 |
commit | 03b01ed2f330ccbe49c6952306e6c15ba30c6b84 (patch) | |
tree | adc1283978b6a256737429f5b159ddf1ed965a95 /server | |
parent | 27231ed5c5ecf1760fb15f33a0c5e10e8cc03f27 (diff) | |
parent | a9f24b00e9ddcd5ca19ac2907e0bf2413f036af4 (diff) | |
download | vaadin-framework-03b01ed2f330ccbe49c6952306e6c15ba30c6b84.tar.gz vaadin-framework-03b01ed2f330ccbe49c6952306e6c15ba30c6b84.zip |
Merge remote-tracking branch 'origin/master' into grid
Change-Id: If3dd8380afe425491dfb877c08c4ff078312a3aa
Diffstat (limited to 'server')
10 files changed, 311 insertions, 217 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java index 257a958f3a..23a72ee1e5 100644 --- a/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/BeanFieldGroup.java @@ -15,18 +15,20 @@ */ package com.vaadin.data.fieldgroup; +import java.beans.IntrospectionException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import com.vaadin.data.Item; import com.vaadin.data.util.BeanItem; +import com.vaadin.data.util.BeanUtil; import com.vaadin.data.validator.BeanValidator; import com.vaadin.ui.Field; public class BeanFieldGroup<T> extends FieldGroup { - private Class<T> beanType; + private final Class<T> beanType; private static Boolean beanValidationImplementationAvailable = null; private final Map<Field<?>, BeanValidator> defaultValidators; @@ -47,17 +49,20 @@ public class BeanFieldGroup<T> extends FieldGroup { * form "fieldName" or "fieldName.subField[.subField2]" but the * method declaration comes from parent. */ - java.lang.reflect.Field f; try { - f = getField(beanType, propertyId.toString()); - return f.getType(); - } catch (SecurityException e) { - throw new BindException("Cannot determine type of propertyId '" - + propertyId + "'.", e); - } catch (NoSuchFieldException e) { + Class<?> type = BeanUtil.getPropertyType(beanType, + propertyId.toString()); + if (type == null) { + throw new BindException( + "Cannot determine type of propertyId '" + + propertyId + + "'. The propertyId was not found in " + + beanType.getName()); + } + return type; + } catch (IntrospectionException e) { throw new BindException("Cannot determine type of propertyId '" - + propertyId + "'. The propertyId was not found in " - + beanType.getName(), e); + + propertyId + "'. Unable to introspect " + beanType, e); } } } @@ -79,32 +84,6 @@ public class BeanFieldGroup<T> extends FieldGroup { return null; } - private static java.lang.reflect.Field getField(Class<?> cls, - String propertyId) throws SecurityException, NoSuchFieldException { - if (propertyId.contains(".")) { - String[] parts = propertyId.split("\\.", 2); - // Get the type of the field in the "cls" class - java.lang.reflect.Field field1 = getField(cls, parts[0]); - // Find the rest from the sub type - return getField(field1.getType(), parts[1]); - } else { - try { - // Try to find the field directly in the given class - java.lang.reflect.Field field1 = cls - .getDeclaredField(propertyId); - return field1; - } catch (NoSuchFieldException e) { - // Try super classes until we reach Object - Class<?> superClass = cls.getSuperclass(); - if (superClass != null && superClass != Object.class) { - return getField(superClass, propertyId); - } else { - throw e; - } - } - } - } - private static String getFieldName(Class<?> cls, String propertyId) throws SecurityException, NoSuchFieldException { for (java.lang.reflect.Field field1 : cls.getDeclaredFields()) { diff --git a/server/src/com/vaadin/data/util/BeanItem.java b/server/src/com/vaadin/data/util/BeanItem.java index 64f30261c2..1be8b70f47 100644 --- a/server/src/com/vaadin/data/util/BeanItem.java +++ b/server/src/com/vaadin/data/util/BeanItem.java @@ -16,12 +16,8 @@ package com.vaadin.data.util; -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -189,7 +185,8 @@ public class BeanItem<BT> extends PropertysetItem { // Try to introspect, if it fails, we just have an empty Item try { - List<PropertyDescriptor> propertyDescriptors = getBeanPropertyDescriptor(beanClass); + List<PropertyDescriptor> propertyDescriptors = BeanUtil + .getBeanPropertyDescriptor(beanClass); // Add all the bean properties as MethodProperties to this Item // later entries on the list overwrite earlier ones @@ -210,106 +207,6 @@ public class BeanItem<BT> extends PropertysetItem { } /** - * Returns the property descriptors of a class or an interface. - * - * For an interface, superinterfaces are also iterated as Introspector does - * not take them into account (Oracle Java bug 4275879), but in that case, - * both the setter and the getter for a property must be in the same - * interface and should not be overridden in subinterfaces for the discovery - * to work correctly. - * - * For interfaces, the iteration is depth first and the properties of - * superinterfaces are returned before those of their subinterfaces. - * - * @param beanClass - * @return - * @throws IntrospectionException - */ - private static List<PropertyDescriptor> getBeanPropertyDescriptor( - final Class<?> beanClass) throws IntrospectionException { - // Oracle bug 4275879: Introspector does not consider superinterfaces of - // an interface - if (beanClass.isInterface()) { - List<PropertyDescriptor> propertyDescriptors = new ArrayList<PropertyDescriptor>(); - - for (Class<?> cls : beanClass.getInterfaces()) { - propertyDescriptors.addAll(getBeanPropertyDescriptor(cls)); - } - - BeanInfo info = Introspector.getBeanInfo(beanClass); - propertyDescriptors.addAll(getPropertyDescriptors(info)); - - return propertyDescriptors; - } else { - BeanInfo info = Introspector.getBeanInfo(beanClass); - return getPropertyDescriptors(info); - } - } - - // Workaround for Java6 bug JDK-6788525. Do nothing for JDK7+. - private static List<PropertyDescriptor> getPropertyDescriptors( - BeanInfo beanInfo) { - PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); - List<PropertyDescriptor> result = new ArrayList<PropertyDescriptor>( - descriptors.length); - for (PropertyDescriptor descriptor : descriptors) { - try { - Method readMethod = getMethodFromBridge(descriptor - .getReadMethod()); - if (readMethod != null) { - Method writeMethod = getMethodFromBridge( - descriptor.getWriteMethod(), - readMethod.getReturnType()); - if (writeMethod == null) { - writeMethod = descriptor.getWriteMethod(); - } - PropertyDescriptor descr = new PropertyDescriptor( - descriptor.getName(), readMethod, writeMethod); - result.add(descr); - } else { - result.add(descriptor); - } - } catch (SecurityException ignore) { - // handle next descriptor - } catch (IntrospectionException e) { - result.add(descriptor); - } - } - return result; - } - - /** - * Return not bridged method for bridge {@code bridgeMethod} method. If - * method {@code bridgeMethod} is not bridge method then return null. - */ - private static Method getMethodFromBridge(Method bridgeMethod) - throws SecurityException { - if (bridgeMethod == null) { - return null; - } - return getMethodFromBridge(bridgeMethod, - bridgeMethod.getParameterTypes()); - } - - /** - * Return not bridged method for bridge {@code bridgeMethod} method and - * declared {@code paramTypes}. If method {@code bridgeMethod} is not bridge - * method then return null. - */ - private static Method getMethodFromBridge(Method bridgeMethod, - Class<?>... paramTypes) throws SecurityException { - if (bridgeMethod == null || !bridgeMethod.isBridge()) { - return null; - } - try { - return bridgeMethod.getDeclaringClass().getMethod( - bridgeMethod.getName(), paramTypes); - } catch (NoSuchMethodException e) { - return null; - } - } - - /** * Expands nested bean properties by replacing a top-level property with * some or all of its sub-properties. The expansion is not recursive. * diff --git a/server/src/com/vaadin/data/util/BeanUtil.java b/server/src/com/vaadin/data/util/BeanUtil.java new file mode 100644 index 0000000000..e2f85a765c --- /dev/null +++ b/server/src/com/vaadin/data/util/BeanUtil.java @@ -0,0 +1,177 @@ +/* + * 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.data.util; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +/** + * Utility class for Java Beans information access. + * + * @author Vaadin Ltd + */ +public final class BeanUtil implements Serializable { + // Prevent instantiation of util class + private BeanUtil() { + } + + /** + * Returns the property descriptors of a class or an interface. + * + * For an interface, superinterfaces are also iterated as Introspector does + * not take them into account (Oracle Java bug 4275879), but in that case, + * both the setter and the getter for a property must be in the same + * interface and should not be overridden in subinterfaces for the discovery + * to work correctly. + * + * NOTE : This utility method relies on introspection (and returns + * PropertyDescriptor) which is a part of java.beans package. The latter + * package could require bigger JDK in the future (with Java 9+). So it may + * be changed in the future. + * + * For interfaces, the iteration is depth first and the properties of + * superinterfaces are returned before those of their subinterfaces. + * + * @param beanClass + * @return + * @throws IntrospectionException + */ + public static List<PropertyDescriptor> getBeanPropertyDescriptor( + final Class<?> beanClass) throws IntrospectionException { + // Oracle bug 4275879: Introspector does not consider superinterfaces of + // an interface + if (beanClass.isInterface()) { + List<PropertyDescriptor> propertyDescriptors = new ArrayList<PropertyDescriptor>(); + + for (Class<?> cls : beanClass.getInterfaces()) { + propertyDescriptors.addAll(getBeanPropertyDescriptor(cls)); + } + + BeanInfo info = Introspector.getBeanInfo(beanClass); + propertyDescriptors.addAll(getPropertyDescriptors(info)); + + return propertyDescriptors; + } else { + BeanInfo info = Introspector.getBeanInfo(beanClass); + return getPropertyDescriptors(info); + } + } + + /** + * Returns {@code propertyId} class for property declared in {@code clazz}. + * Property could be of form "property.subProperty[.subProperty2]" i.e. + * refer to some nested property. + * + * @param clazz + * class where property is declared + * @param propertyId + * property of form "property" or + * "property.subProperty[.subProperty2]" + * @return class of the property + * @throws IntrospectionException + */ + public static Class<?> getPropertyType(Class<?> clazz, String propertyId) + throws IntrospectionException { + if (propertyId.contains(".")) { + String[] parts = propertyId.split("\\.", 2); + // Get the type of the field in the "cls" class + Class<?> propertyBean = getPropertyType(clazz, parts[0]); + // Find the rest from the sub type + return getPropertyType(propertyBean, parts[1]); + } else { + List<PropertyDescriptor> descriptors = getBeanPropertyDescriptor(clazz); + + for (PropertyDescriptor descriptor : descriptors) { + final Method getMethod = descriptor.getReadMethod(); + if (descriptor.getName().equals(propertyId) + && getMethod != null + && getMethod.getDeclaringClass() != Object.class) { + return descriptor.getPropertyType(); + } + } + return null; + } + } + + // Workaround for Java6 bug JDK-6788525. Do nothing for JDK7+. + private static List<PropertyDescriptor> getPropertyDescriptors( + BeanInfo beanInfo) { + PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); + List<PropertyDescriptor> result = new ArrayList<PropertyDescriptor>( + descriptors.length); + for (PropertyDescriptor descriptor : descriptors) { + try { + Method readMethod = getMethodFromBridge(descriptor + .getReadMethod()); + if (readMethod != null) { + Method writeMethod = getMethodFromBridge( + descriptor.getWriteMethod(), + readMethod.getReturnType()); + if (writeMethod == null) { + writeMethod = descriptor.getWriteMethod(); + } + PropertyDescriptor descr = new PropertyDescriptor( + descriptor.getName(), readMethod, writeMethod); + result.add(descr); + } else { + result.add(descriptor); + } + } catch (SecurityException ignore) { + // handle next descriptor + } catch (IntrospectionException e) { + result.add(descriptor); + } + } + return result; + } + + /** + * Return declared method for which {@code bridgeMethod} is generated. If + * {@code bridgeMethod} is not a bridge method then return null. + */ + private static Method getMethodFromBridge(Method bridgeMethod) + throws SecurityException { + if (bridgeMethod == null) { + return null; + } + return getMethodFromBridge(bridgeMethod, + bridgeMethod.getParameterTypes()); + } + + /** + * Return declared method for which {@code bridgeMethod} is generated using + * its {@code paramTypes}. If {@code bridgeMethod} is not a bridge method + * then return null. + */ + private static Method getMethodFromBridge(Method bridgeMethod, + Class<?>... paramTypes) throws SecurityException { + if (bridgeMethod == null || !bridgeMethod.isBridge()) { + return null; + } + try { + return bridgeMethod.getDeclaringClass().getMethod( + bridgeMethod.getName(), paramTypes); + } catch (NoSuchMethodException e) { + return null; + } + } +} diff --git a/server/src/com/vaadin/data/util/sqlcontainer/query/generator/DefaultSQLGenerator.java b/server/src/com/vaadin/data/util/sqlcontainer/query/generator/DefaultSQLGenerator.java index 84dfe9b865..21a486a017 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/query/generator/DefaultSQLGenerator.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/query/generator/DefaultSQLGenerator.java @@ -262,6 +262,12 @@ public class DefaultSQLGenerator implements SQLGenerator { count++; } if (versionColumn != null) { + if(!item.getItemPropertyIds().contains(versionColumn)) { + throw new IllegalArgumentException(String.format( + "Table '%s' does not contain version column '%s'.", + tableName, versionColumn)); + } + query.append(String.format(" AND %s = ?", QueryBuilder.quote(versionColumn))); sh.addParameterValue( diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index 80dad2244e..591f73dc75 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -371,6 +371,7 @@ public class Navigator implements Serializable { private View currentView = null; private List<ViewChangeListener> listeners = new LinkedList<ViewChangeListener>(); private List<ViewProvider> providers = new LinkedList<ViewProvider>(); + private String currentNavigationState = null; private ViewProvider errorProvider; /** @@ -551,6 +552,11 @@ public class Navigator implements Serializable { ViewChangeEvent event = new ViewChangeEvent(this, currentView, view, viewName, parameters); if (!fireBeforeViewChange(event)) { + // #10901. Revert URL to previous state if back-button navigation + // was canceled + if (currentNavigationState != null) { + getStateManager().setState(currentNavigationState); + } return; } @@ -561,6 +567,7 @@ public class Navigator implements Serializable { } if (!navigationState.equals(getStateManager().getState())) { getStateManager().setState(navigationState); + currentNavigationState = navigationState; } } diff --git a/server/src/com/vaadin/server/ClientConnector.java b/server/src/com/vaadin/server/ClientConnector.java index 50ce2754cb..b784aa5d35 100644 --- a/server/src/com/vaadin/server/ClientConnector.java +++ b/server/src/com/vaadin/server/ClientConnector.java @@ -26,6 +26,7 @@ import com.vaadin.shared.Connector; import com.vaadin.shared.communication.SharedState; import com.vaadin.ui.UI; import com.vaadin.util.ReflectTools; + import elemental.json.JsonObject; /** @@ -277,9 +278,8 @@ public interface ClientConnector extends Connector { * . * * @return a JSON object with the encoded connector state - * if the state can not be encoded */ - public JsonObject encodeState() ; + public JsonObject encodeState(); /** * Handle a request directed to this connector. This can be used by diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index fb93a44d37..36d6910a7a 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -703,12 +703,12 @@ public abstract class VaadinService implements Serializable { final boolean closeApplication = hasParameter(request, URL_PARAMETER_CLOSE_APPLICATION); - if (restartApplication) { - closeSession(session, request.getWrappedSession(false)); - return createAndRegisterSession(request); - } else if (closeApplication) { + if (closeApplication) { closeSession(session, request.getWrappedSession(false)); return null; + } else if (restartApplication) { + closeSession(session, request.getWrappedSession(false)); + return createAndRegisterSession(request); } else { return session; } diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java index c2b80fae35..4af93113f9 100644 --- a/server/src/com/vaadin/ui/ComboBox.java +++ b/server/src/com/vaadin/ui/ComboBox.java @@ -622,7 +622,7 @@ public class ComboBox extends AbstractSelect implements if (caption == null || caption.equals("")) { continue; } else { - caption = caption.toLowerCase(); + caption = caption.toLowerCase(getLocale()); } switch (filteringMode) { case CONTAINS: @@ -682,7 +682,7 @@ public class ComboBox extends AbstractSelect implements currentPage = ((Integer) variables.get("page")).intValue(); filterstring = newFilter; if (filterstring != null) { - filterstring = filterstring.toLowerCase(); + filterstring = filterstring.toLowerCase(getLocale()); } requestRepaint(); } else if (isNewItemsAllowed()) { diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java index d5700c4b65..3d683f4902 100644 --- a/server/src/com/vaadin/ui/DateField.java +++ b/server/src/com/vaadin/ui/DateField.java @@ -319,7 +319,8 @@ public class DateField extends AbstractField<Date> implements // Create a defensive copy against issues when using java.sql.Date (and // also against mutable Date). - getState().rangeStart = new Date(startDate.getTime()); + getState().rangeStart = startDate != null ? new Date( + startDate.getTime()) : null; updateRangeValidator(); } @@ -439,7 +440,8 @@ public class DateField extends AbstractField<Date> implements // Create a defensive copy against issues when using java.sql.Date (and // also against mutable Date). - getState().rangeEnd = new Date(endDate.getTime()); + getState().rangeEnd = endDate != null ? new Date(endDate.getTime()) + : null; updateRangeValidator(); } 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 fbae0ee159..f82ba49c3e 100644 --- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java +++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTableQueryTest.java @@ -24,11 +24,15 @@ import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool; import com.vaadin.data.util.sqlcontainer.query.OrderBy; import com.vaadin.data.util.sqlcontainer.query.TableQuery; +import static org.junit.Assert.assertTrue; + public class SQLContainerTableQueryTest { private static final int offset = SQLTestsConstants.offset; private static final String createGarbage = SQLTestsConstants.createGarbage; private JDBCConnectionPool connectionPool; + private TableQuery peopleQuery; + private SQLContainer peopleContainer; @Before public void setUp() throws SQLException { @@ -43,6 +47,10 @@ public class SQLContainerTableQueryTest { } DataGenerator.addPeopleToDatabase(connectionPool); + + peopleQuery = new TableQuery("people", connectionPool, + SQLTestsConstants.sqlGen); + peopleContainer = new SQLContainer(peopleQuery); } @After @@ -53,6 +61,24 @@ public class SQLContainerTableQueryTest { } @Test + public void itemWithExistingVersionColumnIsRemoved() + throws SQLException { + peopleContainer.setAutoCommit(true); + peopleQuery.setVersionColumn("ID"); + + assertTrue(peopleContainer.removeItem(peopleContainer.lastItemId())); + } + + @Test(expected = IllegalArgumentException.class) + public void itemWithNonExistingVersionColumnCannotBeRemoved() throws SQLException { + peopleQuery.setVersionColumn("version"); + + peopleContainer.removeItem(peopleContainer.lastItemId()); + + peopleContainer.commit(); + } + + @Test public void constructor_withTableQuery_shouldSucceed() throws SQLException { new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); @@ -63,8 +89,8 @@ public class SQLContainerTableQueryTest { throws SQLException { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); - Assert.assertTrue(container.containsId(new RowId( - new Object[] { 1 + offset }))); + assertTrue(container.containsId(new RowId( + new Object[]{1 + offset}))); } @Test @@ -410,11 +436,11 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { - Assert.assertTrue(container.isFirstId(new RowId( - new Object[] { new BigDecimal(0 + offset) }))); + assertTrue(container.isFirstId(new RowId( + new Object[]{new BigDecimal(0 + offset)}))); } else { - Assert.assertTrue(container.isFirstId(new RowId( - new Object[] { 0 + offset }))); + assertTrue(container.isFirstId(new RowId( + new Object[]{0 + offset}))); } } @@ -449,11 +475,11 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { - Assert.assertTrue(container.isLastId(new RowId( - new Object[] { new BigDecimal(3 + offset) }))); + assertTrue(container.isLastId(new RowId( + new Object[]{new BigDecimal(3 + offset)}))); } else { - Assert.assertTrue(container.isLastId(new RowId( - new Object[] { 3 + offset }))); + assertTrue(container.isLastId(new RowId( + new Object[]{3 + offset}))); } } @@ -463,11 +489,11 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); if (SQLTestsConstants.db == DB.ORACLE) { - Assert.assertTrue(container.isLastId(new RowId( - new Object[] { new BigDecimal(4999 + offset) }))); + assertTrue(container.isLastId(new RowId( + new Object[]{new BigDecimal(4999 + offset)}))); } else { - Assert.assertTrue(container.isLastId(new RowId( - new Object[] { 4999 + offset }))); + assertTrue(container.isLastId(new RowId( + new Object[]{4999 + offset}))); } } @@ -478,7 +504,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); for (int i = 0; i < 5000; i++) { - Assert.assertTrue(container.containsId(container.getIdByIndex(i))); + assertTrue(container.containsId(container.getIdByIndex(i))); } } @@ -490,7 +516,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); container.setAutoCommit(true); for (int i = 0; i < 5000; i++) { - Assert.assertTrue(container.containsId(container.getIdByIndex(i))); + assertTrue(container.containsId(container.getIdByIndex(i))); } } @@ -523,7 +549,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); container.setAutoCommit(true); - Assert.assertTrue(container.isAutoCommit()); + assertTrue(container.isAutoCommit()); container.setAutoCommit(false); Assert.assertFalse(container.isAutoCommit()); } @@ -613,7 +639,7 @@ public class SQLContainerTableQueryTest { container.setAutoCommit(true); Object itemId = container.addItem(); Assert.assertNotNull(itemId); - Assert.assertTrue(itemId instanceof RowId); + assertTrue(itemId instanceof RowId); Assert.assertFalse(itemId instanceof TemporaryRowId); } @@ -696,7 +722,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); - Assert.assertTrue(container.getItemIds().contains(id)); + assertTrue(container.getItemIds().contains(id)); } @Test @@ -717,7 +743,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); - Assert.assertTrue(container.containsId(id)); + assertTrue(container.containsId(id)); } @Test @@ -747,7 +773,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("garbage", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); - Assert.assertTrue(container.isFirstId(id)); + assertTrue(container.isFirstId(id)); } @Test @@ -756,7 +782,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); - Assert.assertTrue(container.isLastId(id)); + assertTrue(container.isLastId(id)); } @Test @@ -766,7 +792,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); container.addItem(); Object id2 = container.addItem(); - Assert.assertTrue(container.isLastId(id2)); + assertTrue(container.isLastId(id2)); } @Test @@ -785,7 +811,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); int size = container.size(); Object id = container.firstItemId(); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.removeItem(id)); Assert.assertNotSame(id, container.firstItemId()); Assert.assertEquals(size - 1, container.size()); } @@ -795,7 +821,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.firstItemId(); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); } @@ -806,7 +832,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); int size = container.size(); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); Assert.assertEquals(size - 1, container.size()); } @@ -816,7 +842,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.firstItemId(); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.removeItem(id)); Assert.assertNull(container.getItem(id)); } @@ -826,7 +852,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); Assert.assertNotNull(container.getItem(id)); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.removeItem(id)); Assert.assertNull(container.getItem(id)); } @@ -836,8 +862,8 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.firstItemId(); - Assert.assertTrue(container.getItemIds().contains(id)); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.getItemIds().contains(id)); + assertTrue(container.removeItem(id)); Assert.assertFalse(container.getItemIds().contains(id)); } @@ -847,8 +873,8 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); - Assert.assertTrue(container.getItemIds().contains(id)); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.getItemIds().contains(id)); + assertTrue(container.removeItem(id)); Assert.assertFalse(container.getItemIds().contains(id)); } @@ -857,8 +883,8 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.firstItemId(); - Assert.assertTrue(container.containsId(id)); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.containsId(id)); + assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); } @@ -869,8 +895,8 @@ public class SQLContainerTableQueryTest { SQLTestsConstants.sqlGen); SQLContainer container = new SQLContainer(query); Object id = container.addItem(); - Assert.assertTrue(container.containsId(id)); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.containsId(id)); + assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); } @@ -882,7 +908,7 @@ public class SQLContainerTableQueryTest { Object first = container.getIdByIndex(0); Object second = container.getIdByIndex(1); Object third = container.getIdByIndex(2); - Assert.assertTrue(container.removeItem(second)); + assertTrue(container.removeItem(second)); Assert.assertEquals(third, container.nextItemId(first)); } @@ -894,7 +920,7 @@ public class SQLContainerTableQueryTest { Object first = container.lastItemId(); Object second = container.addItem(); Object third = container.addItem(); - Assert.assertTrue(container.removeItem(second)); + assertTrue(container.removeItem(second)); Assert.assertEquals(third, container.nextItemId(first)); } @@ -906,7 +932,7 @@ public class SQLContainerTableQueryTest { Object first = container.getIdByIndex(0); Object second = container.getIdByIndex(1); Object third = container.getIdByIndex(2); - Assert.assertTrue(container.removeItem(second)); + assertTrue(container.removeItem(second)); Assert.assertEquals(first, container.prevItemId(third)); } @@ -918,7 +944,7 @@ public class SQLContainerTableQueryTest { Object first = container.lastItemId(); Object second = container.addItem(); Object third = container.addItem(); - Assert.assertTrue(container.removeItem(second)); + assertTrue(container.removeItem(second)); Assert.assertEquals(first, container.prevItemId(third)); } @@ -928,7 +954,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object first = container.firstItemId(); - Assert.assertTrue(container.removeItem(first)); + assertTrue(container.removeItem(first)); Assert.assertNotSame(first, container.firstItemId()); } @@ -941,7 +967,7 @@ public class SQLContainerTableQueryTest { Object first = container.addItem(); Object second = container.addItem(); Assert.assertSame(first, container.firstItemId()); - Assert.assertTrue(container.removeItem(first)); + assertTrue(container.removeItem(first)); Assert.assertSame(second, container.firstItemId()); } @@ -951,7 +977,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object last = container.lastItemId(); - Assert.assertTrue(container.removeItem(last)); + assertTrue(container.removeItem(last)); Assert.assertNotSame(last, container.lastItemId()); } @@ -962,7 +988,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); Object last = container.addItem(); Assert.assertSame(last, container.lastItemId()); - Assert.assertTrue(container.removeItem(last)); + assertTrue(container.removeItem(last)); Assert.assertNotSame(last, container.lastItemId()); } @@ -972,7 +998,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object first = container.firstItemId(); - Assert.assertTrue(container.removeItem(first)); + assertTrue(container.removeItem(first)); Assert.assertFalse(container.isFirstId(first)); } @@ -985,7 +1011,7 @@ public class SQLContainerTableQueryTest { Object first = container.addItem(); container.addItem(); Assert.assertSame(first, container.firstItemId()); - Assert.assertTrue(container.removeItem(first)); + assertTrue(container.removeItem(first)); Assert.assertFalse(container.isFirstId(first)); } @@ -995,7 +1021,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object last = container.lastItemId(); - Assert.assertTrue(container.removeItem(last)); + assertTrue(container.removeItem(last)); Assert.assertFalse(container.isLastId(last)); } @@ -1006,7 +1032,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); Object last = container.addItem(); Assert.assertSame(last, container.lastItemId()); - Assert.assertTrue(container.removeItem(last)); + assertTrue(container.removeItem(last)); Assert.assertFalse(container.isLastId(last)); } @@ -1015,7 +1041,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.getIdByIndex(2); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.removeItem(id)); Assert.assertEquals(-1, container.indexOfId(id)); } @@ -1025,8 +1051,8 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.addItem(); - Assert.assertTrue(container.indexOfId(id) != -1); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.indexOfId(id) != -1); + assertTrue(container.removeItem(id)); Assert.assertEquals(-1, container.indexOfId(id)); } @@ -1036,7 +1062,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Object id = container.getIdByIndex(2); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.removeItem(id)); Assert.assertNotSame(id, container.getIdByIndex(2)); } @@ -1048,7 +1074,7 @@ public class SQLContainerTableQueryTest { Object id = container.addItem(); container.addItem(); int index = container.indexOfId(id); - Assert.assertTrue(container.removeItem(id)); + assertTrue(container.removeItem(id)); Assert.assertNotSame(id, container.getIdByIndex(index)); } @@ -1056,7 +1082,7 @@ public class SQLContainerTableQueryTest { public void removeAllItems_table_shouldSucceed() throws SQLException { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); - Assert.assertTrue(container.removeAllItems()); + assertTrue(container.removeAllItems()); Assert.assertEquals(0, container.size()); } @@ -1067,7 +1093,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); container.addItem(); container.addItem(); - Assert.assertTrue(container.removeAllItems()); + assertTrue(container.removeAllItems()); Assert.assertEquals(0, container.size()); } @@ -1086,7 +1112,7 @@ public class SQLContainerTableQueryTest { } container.commit(); Assert.assertEquals(container.size(), itemNumber); - Assert.assertTrue(container.removeAllItems()); + assertTrue(container.removeAllItems()); container.commit(); Assert.assertEquals(container.size(), 0); } @@ -1098,7 +1124,7 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(query); Object id = container.addItem(); container.getContainerProperty(id, "NAME").setValue("New Name"); - Assert.assertTrue(id instanceof TemporaryRowId); + assertTrue(id instanceof TemporaryRowId); Assert.assertSame(id, container.lastItemId()); container.commit(); Assert.assertFalse(container.lastItemId() instanceof TemporaryRowId); @@ -1117,7 +1143,7 @@ public class SQLContainerTableQueryTest { Object id2 = container.addItem(); container.getContainerProperty(id, "NAME").setValue("Herbert"); container.getContainerProperty(id2, "NAME").setValue("Larry"); - Assert.assertTrue(id2 instanceof TemporaryRowId); + assertTrue(id2 instanceof TemporaryRowId); Assert.assertSame(id2, container.lastItemId()); container.commit(); Object nextToLast = container.getIdByIndex(container.size() - 2); @@ -1165,7 +1191,7 @@ public class SQLContainerTableQueryTest { Object key = container.firstItemId(); Item row = container.getItem(key); row.getItemProperty("NAME").setValue("Pekka"); - Assert.assertTrue(container.removeItem(key)); + assertTrue(container.removeItem(key)); container.commit(); Assert.assertEquals(size - 1, container.size()); } @@ -1217,7 +1243,7 @@ public class SQLContainerTableQueryTest { Assert.assertFalse(container.isModified()); RowItem last = (RowItem) container.getItem(container.lastItemId()); container.itemChangeNotification(last); - Assert.assertTrue(container.isModified()); + assertTrue(container.isModified()); } @Test @@ -1273,7 +1299,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); Assert.assertFalse(container.isModified()); container.removeItem(container.lastItemId()); - Assert.assertTrue(container.isModified()); + assertTrue(container.isModified()); } @Test @@ -1282,7 +1308,7 @@ public class SQLContainerTableQueryTest { connectionPool, SQLTestsConstants.sqlGen)); Assert.assertFalse(container.isModified()); container.addItem(); - Assert.assertTrue(container.isModified()); + assertTrue(container.isModified()); } @Test @@ -1292,7 +1318,7 @@ public class SQLContainerTableQueryTest { Assert.assertFalse(container.isModified()); container.getContainerProperty(container.lastItemId(), "NAME") .setValue("foo"); - Assert.assertTrue(container.isModified()); + assertTrue(container.isModified()); } @Test @@ -1301,9 +1327,9 @@ public class SQLContainerTableQueryTest { SQLContainer container = new SQLContainer(new TableQuery("people", connectionPool, SQLTestsConstants.sqlGen)); Collection<?> sortableIds = container.getSortableContainerPropertyIds(); - Assert.assertTrue(sortableIds.contains("ID")); - Assert.assertTrue(sortableIds.contains("NAME")); - Assert.assertTrue(sortableIds.contains("AGE")); + assertTrue(sortableIds.contains("ID")); + assertTrue(sortableIds.contains("NAME")); + assertTrue(sortableIds.contains("AGE")); Assert.assertEquals(3, sortableIds.size()); if (SQLTestsConstants.db == DB.MSSQL || SQLTestsConstants.db == DB.ORACLE) { |