コード例 #1
0
  @Test
  public void getItem_tableAddedItemRemoved_returnsNull() throws SQLException {
    Object id = container.addItem();

    Assert.assertNotNull(container.getItem(id));
    assertTrue(container.removeItem(id));
    Assert.assertNull(container.getItem(id));
  }
コード例 #2
0
  @Test
  public void indexOfId_table5000RowsWithParameter1337_returns1337() throws SQLException {
    DataGenerator.addFiveThousandPeople(connectionPool);

    if (SQLTestsConstants.db == DB.ORACLE) {
      container.getItem(new RowId(new Object[] {new BigDecimal(1337 + offset)}));
      assertEquals(
          1337, container.indexOfId(new RowId(new Object[] {new BigDecimal(1337 + offset)})));
    } else {
      container.getItem(new RowId(new Object[] {1337 + offset}));
      assertEquals(1337, container.indexOfId(new RowId(new Object[] {1337 + offset})));
    }
  }
コード例 #3
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());
 }
コード例 #4
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());
 }
コード例 #5
0
  @Test
  public void correctItemIsFetchedFromMultipleRows() throws SQLException {
    DataGenerator.addFiveThousandPeople(connectionPool);

    Item item = container.getItem(getRowId(1337));

    assertThat((Integer) item.getItemProperty(ID).getValue(), is(equalTo(1337 + offset)));
    assertThat(item.getItemProperty(NAME).getValue().toString(), is("Person 1337"));
  }
コード例 #6
0
  @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());
  }
コード例 #7
0
  @Test
  public void addFilter_tableBufferedItems_alsoFiltersBufferedItems() throws SQLException {
    // Ville, Kalle, Pelle, Börje
    assertEquals(4, container.size());
    assertEquals("Börje", container.getContainerProperty(container.lastItemId(), NAME).getValue());

    Object id1 = container.addItem();
    container.getContainerProperty(id1, NAME).setValue("Palle");
    Object id2 = container.addItem();
    container.getContainerProperty(id2, NAME).setValue("Bengt");

    container.addContainerFilter(new Like(NAME, "%lle"));

    // Ville, Kalle, Pelle, Palle
    assertEquals(4, container.size());
    assertEquals(
        "Ville", container.getContainerProperty(container.getIdByIndex(0), NAME).getValue());
    assertEquals(
        "Kalle", container.getContainerProperty(container.getIdByIndex(1), NAME).getValue());
    assertEquals(
        "Pelle", container.getContainerProperty(container.getIdByIndex(2), NAME).getValue());
    assertEquals(
        "Palle", container.getContainerProperty(container.getIdByIndex(3), NAME).getValue());

    try {
      container.getIdByIndex(4);
      Assert.fail(
          "SQLContainer.getIdByIndex() returned a value for an index beyond the end of the container");
    } catch (IndexOutOfBoundsException e) {
      // should throw exception - item is filtered out
    }
    Assert.assertNull(container.nextItemId(container.getIdByIndex(3)));

    Assert.assertFalse(container.containsId(id2));
    Assert.assertFalse(container.getItemIds().contains(id2));

    Assert.assertNull(container.getItem(id2));
    assertEquals(-1, container.indexOfId(id2));

    Assert.assertNotSame(id2, container.lastItemId());
    Assert.assertSame(id1, container.lastItemId());
  }
コード例 #8
0
 private Item getItem(Object id) {
   return container.getItem(id);
 }
コード例 #9
0
 @Test
 public void getItem_tableNewlyAddedItem_returnsNewlyAdded() throws SQLException {
   Object id = container.addItem();
   Assert.assertNotNull(container.getItem(id));
 }
コード例 #10
0
  @Test
  public void existingItemIsFetched() {
    Item item = container.getItem(existingItemId);

    assertThat(item.getItemProperty(NAME).getValue().toString(), is("Kalle"));
  }