@Test public void getIdByIndex_tableOneItemAddedLastIndexInContainer_returnsAddedItem() throws SQLException { Object id = container.addItem(); assertEquals(id, container.getIdByIndex(container.size() - 1)); }
@Test public void itemChangeNotification_table_isModifiedReturnsTrue() throws SQLException { Assert.assertFalse(container.isModified()); RowItem last = (RowItem) container.getItem(container.lastItemId()); container.itemChangeNotification(last); assertTrue(container.isModified()); }
@Test public void setAutoCommit_table_shouldSucceed() throws SQLException { container.setAutoCommit(true); assertTrue(container.isAutoCommit()); container.setAutoCommit(false); Assert.assertFalse(container.isAutoCommit()); }
@Test public void setPageLength_table_shouldSucceed() throws SQLException { container.setPageLength(20); assertEquals(20, container.getPageLength()); container.setPageLength(200); assertEquals(200, container.getPageLength()); }
@Test public void refresh_table_sizeShouldUpdate() throws SQLException { assertEquals(4, container.size()); DataGenerator.addFiveThousandPeople(connectionPool); container.refresh(); assertEquals(5000, container.size()); }
@Test public void getIdByIndex_tableItemRemoved_resultChanges() throws SQLException { Object id = container.getIdByIndex(2); assertTrue(container.removeItem(id)); Assert.assertNotSame(id, container.getIdByIndex(2)); }
@Test public void getItem_tableItemRemoved_returnsNull() throws SQLException { Object id = container.firstItemId(); assertTrue(container.removeItem(id)); Assert.assertNull(container.getItem(id)); }
@Test public void isLastId_tableLastItemRemoved_returnsFalse() throws SQLException { Object last = container.lastItemId(); assertTrue(container.removeItem(last)); Assert.assertFalse(container.isLastId(last)); }
@Test public void indexOfId_tableItemRemoved_returnsNegOne() throws SQLException { Object id = container.getIdByIndex(2); assertTrue(container.removeItem(id)); assertEquals(-1, container.indexOfId(id)); }
@Test public void prevItemId_tableTwoNewlyAddedItems_returnsFirstAddedItem() throws SQLException { Object id1 = container.addItem(); Object id2 = container.addItem(); assertEquals(id1, container.prevItemId(id2)); }
@Test public void lastItemId_tableLastItemRemoved_resultChanges() throws SQLException { Object last = container.lastItemId(); assertTrue(container.removeItem(last)); Assert.assertNotSame(last, container.lastItemId()); }
@Test public void addItem_tableAddOneNewItem_autoCommit_sizeIsIncreased() throws SQLException { container.setAutoCommit(true); int originalSize = container.size(); container.addItem(); assertEquals(originalSize + 1, container.size()); }
@Test public void lastItemId_tableNewlyAddedItem_returnsNewlyAdded() throws SQLException { Object lastId = container.lastItemId(); Object id = container.addItem(); assertEquals(id, container.lastItemId()); Assert.assertNotSame(lastId, container.lastItemId()); }
@Test public void itemWithExistingVersionColumnIsRemoved() throws SQLException { container.setAutoCommit(true); query.setVersionColumn(ID); assertTrue(container.removeItem(container.lastItemId())); }
@Test public void containsId_tableAddedItemRemoved_returnsFalse() throws SQLException { Object id = container.addItem(); assertTrue(container.containsId(id)); assertTrue(container.removeItem(id)); Assert.assertFalse(container.containsId(id)); }
@Test public void getItemIds_tableAddedItemRemoved_shouldNotContainRemovedItem() throws SQLException { Object id = container.addItem(); assertTrue(container.getItemIds().contains(id)); assertTrue(container.removeItem(id)); Assert.assertFalse(container.getItemIds().contains(id)); }
@Test public void allIdsFound_table5000RowsLastId_shouldSucceed() throws SQLException { DataGenerator.addFiveThousandPeople(connectionPool); for (int i = 0; i < 5000; i++) { assertTrue(container.containsId(container.getIdByIndex(i))); } }
@Test public void commit_tableLastItemUpdated_shouldUpdateRowInDB() throws SQLException { Object last = container.lastItemId(); container.getContainerProperty(last, NAME).setValue("Donald"); container.commit(); assertEquals("Donald", container.getContainerProperty(container.lastItemId(), NAME).getValue()); }
@Test public void removeAllItems_tableAddedItems_shouldSucceed() throws SQLException { container.addItem(); container.addItem(); assertTrue(container.removeAllItems()); assertEquals(0, container.size()); }
@Test public void firstItemId_tableEmptyResultSet_returnsFirstAddedItem() throws SQLException { SQLContainer garbageContainer = getGarbageContainer(); Object id = garbageContainer.addItem(); Assert.assertSame(id, garbageContainer.firstItemId()); }
@Test public void getContainerProperty_tableNewlyAddedItem_returnsPropertyOfNewlyAddedItem() throws SQLException { Object id = container.addItem(); Item item = container.getItem(id); item.getItemProperty(NAME).setValue("asdf"); assertEquals("asdf", container.getContainerProperty(id, NAME).getValue()); }
@Test public void indexOfId_tableAddedItemRemoved_returnsNegOne() throws SQLException { Object id = container.addItem(); assertTrue(container.indexOfId(id) != -1); assertTrue(container.removeItem(id)); assertEquals(-1, container.indexOfId(id)); }
@Test public void isFirstId_tableEmptyResultSet_returnsFirstAddedItem() throws SQLException { SQLContainer garbageContainer = getGarbageContainer(); Object id = garbageContainer.addItem(); assertTrue(garbageContainer.isFirstId(id)); }
@Test public void addItem_tableAddOneNewItem_autoCommit_returnsFinalItemId() throws SQLException { container.setAutoCommit(true); Object itemId = container.addItem(); Assert.assertNotNull(itemId); assertTrue(itemId instanceof RowId); Assert.assertFalse(itemId instanceof TemporaryRowId); }
@Test public void commit_tableRemovedItem_shouldBeRemovedFromDB() throws SQLException { Object last = container.lastItemId(); container.removeItem(last); container.commit(); Assert.assertFalse(last.equals(container.lastItemId())); }
@Test public void isLastId_tableTwoItemsAdded_returnsTrueForLastAddedItem() throws SQLException { container.addItem(); Object id2 = container.addItem(); assertTrue(container.isLastId(id2)); }
@Test public void rollback_tableItemChanged_discardsChanges() throws SQLException { Object last = container.lastItemId(); container.getContainerProperty(last, NAME).setValue("foo"); container.rollback(); Assert.assertFalse( "foo".equals(container.getContainerProperty(container.lastItemId(), NAME).getValue())); }
@Test public void isLastId_tableSecondId_returnsFalse() throws SQLException { if (SQLTestsConstants.db == DB.ORACLE) { Assert.assertFalse(container.isLastId(new RowId(new Object[] {new BigDecimal(1 + offset)}))); } else { Assert.assertFalse(container.isLastId(new RowId(new Object[] {1 + offset}))); } }
@Test public void indexOfId_tableWithParameterThree_returnsThree() throws SQLException { if (SQLTestsConstants.db == DB.ORACLE) { assertEquals(3, container.indexOfId(new RowId(new Object[] {new BigDecimal(3 + offset)}))); } else { assertEquals(3, container.indexOfId(new RowId(new Object[] {3 + offset}))); } }
@Test public void isLastId_tableLastId_returnsTrue() throws SQLException { if (SQLTestsConstants.db == DB.ORACLE) { assertTrue(container.isLastId(new RowId(new Object[] {new BigDecimal(3 + offset)}))); } else { assertTrue(container.isLastId(new RowId(new Object[] {3 + offset}))); } }