Exemplo n.º 1
0
  @Test
  public void getIdByIndex_tableOneItemAddedLastIndexInContainer_returnsAddedItem()
      throws SQLException {
    Object id = container.addItem();

    assertEquals(id, container.getIdByIndex(container.size() - 1));
  }
Exemplo n.º 2
0
 @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());
 }
Exemplo n.º 3
0
 @Test
 public void setAutoCommit_table_shouldSucceed() throws SQLException {
   container.setAutoCommit(true);
   assertTrue(container.isAutoCommit());
   container.setAutoCommit(false);
   Assert.assertFalse(container.isAutoCommit());
 }
Exemplo n.º 4
0
 @Test
 public void setPageLength_table_shouldSucceed() throws SQLException {
   container.setPageLength(20);
   assertEquals(20, container.getPageLength());
   container.setPageLength(200);
   assertEquals(200, container.getPageLength());
 }
Exemplo n.º 5
0
 @Test
 public void refresh_table_sizeShouldUpdate() throws SQLException {
   assertEquals(4, container.size());
   DataGenerator.addFiveThousandPeople(connectionPool);
   container.refresh();
   assertEquals(5000, container.size());
 }
Exemplo n.º 6
0
  @Test
  public void getIdByIndex_tableItemRemoved_resultChanges() throws SQLException {
    Object id = container.getIdByIndex(2);

    assertTrue(container.removeItem(id));
    Assert.assertNotSame(id, container.getIdByIndex(2));
  }
Exemplo n.º 7
0
  @Test
  public void getItem_tableItemRemoved_returnsNull() throws SQLException {
    Object id = container.firstItemId();

    assertTrue(container.removeItem(id));
    Assert.assertNull(container.getItem(id));
  }
Exemplo n.º 8
0
  @Test
  public void isLastId_tableLastItemRemoved_returnsFalse() throws SQLException {
    Object last = container.lastItemId();

    assertTrue(container.removeItem(last));
    Assert.assertFalse(container.isLastId(last));
  }
Exemplo n.º 9
0
  @Test
  public void indexOfId_tableItemRemoved_returnsNegOne() throws SQLException {
    Object id = container.getIdByIndex(2);

    assertTrue(container.removeItem(id));
    assertEquals(-1, container.indexOfId(id));
  }
Exemplo n.º 10
0
  @Test
  public void prevItemId_tableTwoNewlyAddedItems_returnsFirstAddedItem() throws SQLException {
    Object id1 = container.addItem();
    Object id2 = container.addItem();

    assertEquals(id1, container.prevItemId(id2));
  }
Exemplo n.º 11
0
  @Test
  public void lastItemId_tableLastItemRemoved_resultChanges() throws SQLException {
    Object last = container.lastItemId();

    assertTrue(container.removeItem(last));
    Assert.assertNotSame(last, container.lastItemId());
  }
Exemplo n.º 12
0
 @Test
 public void addItem_tableAddOneNewItem_autoCommit_sizeIsIncreased() throws SQLException {
   container.setAutoCommit(true);
   int originalSize = container.size();
   container.addItem();
   assertEquals(originalSize + 1, container.size());
 }
Exemplo n.º 13
0
 @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());
 }
Exemplo n.º 14
0
  @Test
  public void itemWithExistingVersionColumnIsRemoved() throws SQLException {
    container.setAutoCommit(true);
    query.setVersionColumn(ID);

    assertTrue(container.removeItem(container.lastItemId()));
  }
Exemplo n.º 15
0
  @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));
  }
Exemplo n.º 16
0
  @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));
  }
Exemplo n.º 17
0
  @Test
  public void allIdsFound_table5000RowsLastId_shouldSucceed() throws SQLException {
    DataGenerator.addFiveThousandPeople(connectionPool);

    for (int i = 0; i < 5000; i++) {
      assertTrue(container.containsId(container.getIdByIndex(i)));
    }
  }
Exemplo n.º 18
0
  @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());
  }
Exemplo n.º 19
0
  @Test
  public void removeAllItems_tableAddedItems_shouldSucceed() throws SQLException {
    container.addItem();
    container.addItem();

    assertTrue(container.removeAllItems());
    assertEquals(0, container.size());
  }
Exemplo n.º 20
0
  @Test
  public void firstItemId_tableEmptyResultSet_returnsFirstAddedItem() throws SQLException {
    SQLContainer garbageContainer = getGarbageContainer();

    Object id = garbageContainer.addItem();

    Assert.assertSame(id, garbageContainer.firstItemId());
  }
Exemplo n.º 21
0
 @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());
 }
Exemplo n.º 22
0
  @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));
  }
Exemplo n.º 23
0
  @Test
  public void isFirstId_tableEmptyResultSet_returnsFirstAddedItem() throws SQLException {
    SQLContainer garbageContainer = getGarbageContainer();

    Object id = garbageContainer.addItem();

    assertTrue(garbageContainer.isFirstId(id));
  }
Exemplo n.º 24
0
 @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);
 }
Exemplo n.º 25
0
  @Test
  public void commit_tableRemovedItem_shouldBeRemovedFromDB() throws SQLException {
    Object last = container.lastItemId();
    container.removeItem(last);
    container.commit();

    Assert.assertFalse(last.equals(container.lastItemId()));
  }
Exemplo n.º 26
0
  @Test
  public void isLastId_tableTwoItemsAdded_returnsTrueForLastAddedItem() throws SQLException {
    container.addItem();

    Object id2 = container.addItem();

    assertTrue(container.isLastId(id2));
  }
Exemplo n.º 27
0
 @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()));
 }
Exemplo n.º 28
0
 @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})));
   }
 }
Exemplo n.º 29
0
 @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})));
   }
 }
Exemplo n.º 30
0
 @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})));
   }
 }