Пример #1
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()));
 }
Пример #2
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());
  }
Пример #3
0
  @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());
  }
Пример #4
0
  @Test
  public void addFilter_table_filtersResults() throws SQLException {
    // Ville, Kalle, Pelle, Börje
    assertEquals(4, container.size());
    assertEquals("Börje", container.getContainerProperty(container.lastItemId(), NAME).getValue());

    container.addContainerFilter(new Like(NAME, "%lle"));
    // Ville, Kalle, Pelle
    assertEquals(3, container.size());
    assertEquals("Pelle", container.getContainerProperty(container.lastItemId(), NAME).getValue());
  }
Пример #5
0
 @Test
 public void rollback_tableItemAdded_discardsAddedItem() throws SQLException {
   int size = container.size();
   Object id = container.addItem();
   container.getContainerProperty(id, NAME).setValue("foo");
   assertEquals(size + 1, container.size());
   container.rollback();
   assertEquals(size, container.size());
   Assert.assertFalse(
       "foo".equals(container.getContainerProperty(container.lastItemId(), NAME).getValue()));
 }
Пример #6
0
  @Test
  public void commit_tableAddedItem_shouldBeWrittenToDB() throws SQLException {
    Object id = container.addItem();
    container.getContainerProperty(id, NAME).setValue("New Name");

    assertTrue(id instanceof TemporaryRowId);
    Assert.assertSame(id, container.lastItemId());
    container.commit();
    Assert.assertFalse(container.lastItemId() instanceof TemporaryRowId);
    assertEquals(
        "New Name", container.getContainerProperty(container.lastItemId(), NAME).getValue());
  }
Пример #7
0
  @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());
  }
Пример #8
0
  @Test
  public void commit_tableTwoAddedItems_shouldBeWrittenToDB() throws SQLException {
    Object id = container.addItem();
    Object id2 = container.addItem();
    container.getContainerProperty(id, NAME).setValue("Herbert");
    container.getContainerProperty(id2, NAME).setValue("Larry");
    assertTrue(id2 instanceof TemporaryRowId);
    Assert.assertSame(id2, container.lastItemId());
    container.commit();
    Object nextToLast = container.getIdByIndex(container.size() - 2);

    Assert.assertFalse(nextToLast instanceof TemporaryRowId);
    assertEquals("Herbert", container.getContainerProperty(nextToLast, NAME).getValue());
    Assert.assertFalse(container.lastItemId() instanceof TemporaryRowId);
    assertEquals("Larry", container.getContainerProperty(container.lastItemId(), NAME).getValue());
  }
Пример #9
0
  @Test
  public void removeContainerFilters_table_noFiltering() throws SQLException {
    // Ville, Kalle, Pelle, Börje
    assertEquals(4, container.size());

    container.addContainerFilter(NAME, "Vi", false, false);

    // Ville
    assertEquals(1, container.size());
    assertEquals("Ville", container.getContainerProperty(container.lastItemId(), NAME).getValue());

    container.removeContainerFilters(NAME);

    assertEquals(4, container.size());
    assertEquals("Börje", container.getContainerProperty(container.lastItemId(), NAME).getValue());
  }
Пример #10
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());
 }
Пример #11
0
  @Test
  public void addContainerFilter_ignoreCase_filtersResults() throws SQLException {
    // Ville, Kalle, Pelle, Börje
    assertEquals(4, container.size());

    container.addContainerFilter(NAME, "vi", true, false);

    // Ville
    assertEquals(1, container.size());
    assertEquals("Ville", container.getContainerProperty(container.lastItemId(), NAME).getValue());
  }
Пример #12
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());
  }
Пример #13
0
  @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());
  }
Пример #14
0
 @Test
 public void containerDoesNotContainExistingPropertyForNonExistingItem() {
   assertThat(container.getContainerProperty(nonExistingItemId, NAME), is(nullValue()));
 }
Пример #15
0
 @Test
 public void containerDoesNotContainPropertyForExistingItem() {
   assertThat(container.getContainerProperty(existingItemId, "asdf"), is(nullValue()));
 }
Пример #16
0
 @Test
 public void propertyIsFetchedForExistingItem() {
   assertThat(
       container.getContainerProperty(existingItemId, NAME).getValue().toString(), is("Kalle"));
 }
Пример #17
0
 @Test
 public void isModified_tableChangedItem_returnsTrue() throws SQLException {
   Assert.assertFalse(container.isModified());
   container.getContainerProperty(container.lastItemId(), NAME).setValue("foo");
   assertTrue(container.isModified());
 }