@Test public void firstItemId_tableFirstItemRemoved_resultChanges() throws SQLException { Object first = container.firstItemId(); assertTrue(container.removeItem(first)); Assert.assertNotSame(first, container.firstItemId()); }
@Test public void firstItemId_table_returnsItemId0() throws SQLException { if (SQLTestsConstants.db == DB.ORACLE) { assertEquals( new RowId(new Object[] {0 + offset}).toString(), container.firstItemId().toString()); } else { assertEquals(new RowId(new Object[] {0 + offset}), container.firstItemId()); } }
@Test public void removeItem_tableNoAddedItems_removesItemFromContainer() throws SQLException { int originalSize = container.size(); Object id = container.firstItemId(); assertTrue(container.removeItem(id)); Assert.assertNotSame(id, container.firstItemId()); assertEquals(originalSize - 1, container.size()); }
@Test public void firstItemId_tableNewlyAddedFirstItemRemoved_resultChanges() throws SQLException { SQLContainer garbageContainer = getGarbageContainer(); Object first = garbageContainer.addItem(); Object second = garbageContainer.addItem(); Assert.assertSame(first, garbageContainer.firstItemId()); assertTrue(garbageContainer.removeItem(first)); Assert.assertSame(second, garbageContainer.firstItemId()); }
@Test public void addOrderBy_table_shouldReorderResults() throws SQLException { // Ville, Kalle, Pelle, Börje assertEquals("Ville", container.getContainerProperty(container.firstItemId(), NAME).getValue()); assertEquals("Börje", container.getContainerProperty(container.lastItemId(), NAME).getValue()); container.addOrderBy(new OrderBy(NAME, true)); // Börje, Kalle, Pelle, Ville assertEquals("Börje", container.getContainerProperty(container.firstItemId(), NAME).getValue()); assertEquals("Ville", container.getContainerProperty(container.lastItemId(), NAME).getValue()); }
@Test public void sort_table_sortsByName() throws SQLException { // Ville, Kalle, Pelle, Börje assertEquals("Ville", container.getContainerProperty(container.firstItemId(), NAME).getValue()); assertEquals("Börje", container.getContainerProperty(container.lastItemId(), NAME).getValue()); container.sort(new Object[] {NAME}, new boolean[] {true}); // Börje, Kalle, Pelle, Ville assertEquals("Börje", container.getContainerProperty(container.firstItemId(), NAME).getValue()); assertEquals("Ville", container.getContainerProperty(container.lastItemId(), NAME).getValue()); }
@Test public void isFirstId_tableFirstItemRemoved_returnsFalse() throws SQLException { Object first = container.firstItemId(); assertTrue(container.removeItem(first)); Assert.assertFalse(container.isFirstId(first)); }
@Test public void getItem_tableItemRemoved_returnsNull() throws SQLException { Object id = container.firstItemId(); assertTrue(container.removeItem(id)); Assert.assertNull(container.getItem(id)); }
@Test public void containsId_tableItemRemoved_returnsFalse() throws SQLException { Object id = container.firstItemId(); assertTrue(container.containsId(id)); assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); }
@Test public void getItemIds_tableItemRemoved_shouldNotContainRemovedItem() throws SQLException { Object id = container.firstItemId(); assertTrue(container.getItemIds().contains(id)); assertTrue(container.removeItem(id)); Assert.assertFalse(container.getItemIds().contains(id)); }
@Test public void firstItemId_tableEmptyResultSet_returnsFirstAddedItem() throws SQLException { SQLContainer garbageContainer = getGarbageContainer(); Object id = garbageContainer.addItem(); Assert.assertSame(id, garbageContainer.firstItemId()); }
@Test public void commit_removeModifiedItem_shouldSucceed() throws SQLException { int size = container.size(); Object key = container.firstItemId(); Item row = container.getItem(key); row.getItemProperty(NAME).setValue("Pekka"); assertTrue(container.removeItem(key)); container.commit(); assertEquals(size - 1, container.size()); }
@Test public void isFirstId_tableAddedFirstItemRemoved_returnsFalse() throws SQLException { SQLContainer garbageContainer = getGarbageContainer(); Object first = garbageContainer.addItem(); garbageContainer.addItem(); Assert.assertSame(first, garbageContainer.firstItemId()); assertTrue(garbageContainer.removeItem(first)); Assert.assertFalse(garbageContainer.isFirstId(first)); }
@Test public void sort_tableBufferedItems_sortsBufferedItemsLastInOrderAdded() throws SQLException { // Ville, Kalle, Pelle, Börje assertEquals("Ville", container.getContainerProperty(container.firstItemId(), NAME).getValue()); assertEquals("Börje", container.getContainerProperty(container.lastItemId(), NAME).getValue()); Object id1 = container.addItem(); container.getContainerProperty(id1, NAME).setValue("Wilbert"); Object id2 = container.addItem(); container.getContainerProperty(id2, NAME).setValue("Albert"); container.sort(new Object[] {NAME}, new boolean[] {true}); // Börje, Kalle, Pelle, Ville, Wilbert, Albert assertEquals("Börje", container.getContainerProperty(container.firstItemId(), NAME).getValue()); assertEquals( "Wilbert", container .getContainerProperty(container.getIdByIndex(container.size() - 2), NAME) .getValue()); assertEquals("Albert", container.getContainerProperty(container.lastItemId(), NAME).getValue()); }