예제 #1
0
  @Test
  @DataSet(DATA_FILENAME_ONE_LESS)
  @ExpectedDataSet(DATA_FILENAME_NO_CHANGEDATE)
  public void testInsertItemAssoc() {
    ItemAssocVO<Integer, Integer> itemAssoc = null;
    try {
      itemAssoc =
          new ItemAssocVO<Integer, Integer>(
              1,
              new ItemVO<Integer, Integer>(1, 2, 1),
              1,
              0.1d,
              new ItemVO<Integer, Integer>(1, 7, 1),
              2,
              "def",
              1,
              true);
    } catch (Exception e) {
      fail("caught exception: " + e);
    }
    assertTrue(itemAssoc.getId() == null);
    itemAssocDAO.insertItemAssoc(itemAssoc);

    assertThat(itemAssoc.getId(), is(not(1)));
    assertThat(itemAssoc.getId(), is(not(2)));
    assertThat(itemAssoc.getId(), is(not(3)));
    assertThat(itemAssoc.getId(), is(not(4)));
    assertThat(itemAssoc.getId(), is(not(5)));
  }
예제 #2
0
 @Test
 @DataSet(DATA_FILENAME_ONE_LESS)
 public void testInsertItemAssocViewTypeNull() {
   ItemAssocVO<Integer, Integer> itemAssoc = null;
   try {
     itemAssoc =
         new ItemAssocVO<Integer, Integer>(
             1,
             new ItemVO<Integer, Integer>(1, 2, 1),
             1,
             0.1d,
             new ItemVO<Integer, Integer>(1, 7, 1),
             2,
             "def",
             null,
             true);
   } catch (Exception e) {
     fail("caught exception: " + e);
   }
   assertTrue(itemAssoc.getId() == null);
   try {
     itemAssocDAO.insertItemAssoc(itemAssoc);
     fail("exception should be thrown, since 'viewType' is missing");
   } catch (Exception e) {
     assertTrue(
         "unexpected exception during insertion of item association: "
             + itemAssoc
             + ", "
             + e.getMessage(),
         e instanceof IllegalArgumentException);
   }
 }
예제 #3
0
 @Test
 @ExpectedDataSet(DATA_FILENAME_NO_CHANGEDATE)
 public void testUpdateItemAssocUsingUniqueKeyActiveNull() {
   ItemAssocVO<Integer, Integer> itemAssoc = itemAssocDAO.loadItemAssocByPrimaryKey(1);
   itemAssoc.setActive(null);
   // setActive(null) shouldn't be called at all, therefore the dataset shouldn't change
   itemAssocDAO.updateItemAssocUsingUniqueKey(itemAssoc);
 }
예제 #4
0
  @Test
  public void testLoadItemAssocByPrimaryKey() {
    ItemAssocVO<Integer, Integer> queryAssoc =
        new ItemAssocVO<Integer, Integer>(
            1,
            new ItemVO<Integer, Integer>(1, 1, 1),
            1,
            null,
            new ItemVO<Integer, Integer>(1, 2, 1),
            1,
            "abc",
            1,
            null);
    ItemAssocVO<Integer, Integer> resultAssoc = itemAssocDAO.loadItemAssocByUniqueKey(queryAssoc);
    ItemAssocVO<Integer, Integer> resultAssoc2 =
        itemAssocDAO.loadItemAssocByPrimaryKey(resultAssoc.getId());

    assertEquals(resultAssoc, resultAssoc2);
  }
예제 #5
0
  @Test
  @ExpectedDataSet(DATA_FILENAME_UPDATED)
  public void testUpdateItemAssocUsingUniqueKey() {
    ItemAssocVO<Integer, Integer> itemAssoc = itemAssocDAO.loadItemAssocByPrimaryKey(1);
    itemAssoc.setAssocValue(1.2d);
    itemAssocDAO.updateItemAssocUsingUniqueKey(itemAssoc);

    itemAssoc = itemAssocDAO.loadItemAssocByPrimaryKey(2);
    itemAssoc.setViewType(7);
    itemAssoc.setActive(false);
    itemAssocDAO.updateItemAssocUsingUniqueKey(itemAssoc);

    itemAssoc = itemAssocDAO.loadItemAssocByPrimaryKey(3);
    itemAssoc.setAssocValue(3.0d);
    itemAssoc.setActive(false);
    itemAssocDAO.updateItemAssocUsingUniqueKey(itemAssoc);
  }
예제 #6
0
  @Test
  public void testInsertOrUpdateItemAssocs() {
    List<ItemAssocVO<Integer, Integer>> itemAssocs = new ArrayList<ItemAssocVO<Integer, Integer>>();

    Date date = new Date();
    // shave off milliseconds since they can't be stored in mysql
    long time = (long) Math.floor(date.getTime() / 1000) * 1000L;
    date = new Date(time);

    itemAssocs.add(
        new ItemAssocVO<Integer, Integer>(
            null,
            1,
            new ItemVO<Integer, Integer>(1, 1, 1),
            1,
            1.0,
            new ItemVO<Integer, Integer>(1, 2, 1),
            1,
            "sourceInfo",
            1,
            true,
            date));
    itemAssocs.add(
        new ItemAssocVO<Integer, Integer>(
            null,
            1,
            new ItemVO<Integer, Integer>(1, 2, 1),
            1,
            1.0,
            new ItemVO<Integer, Integer>(1, 3, 1),
            1,
            "sourceInfo\t\n\r\bwith escape characters\\",
            1,
            true,
            date));
    itemAssocs.add(
        new ItemAssocVO<Integer, Integer>(
            null,
            1,
            new ItemVO<Integer, Integer>(1, 3, 1),
            1,
            1.0,
            new ItemVO<Integer, Integer>(1, 4, 1),
            1,
            "sourceInfo",
            1,
            null,
            date));
    itemAssocs.add(
        new ItemAssocVO<Integer, Integer>(
            null,
            1,
            new ItemVO<Integer, Integer>(1, 4, 1),
            1,
            1.0,
            new ItemVO<Integer, Integer>(1, 5, 1),
            1,
            "sourceInfo",
            1,
            false,
            date));

    int noRowsAdded = itemAssocDAO.insertOrUpdateItemAssocs(itemAssocs);

    assertEquals(itemAssocs.size(), noRowsAdded);

    Iterator<ItemAssocVO<Integer, Integer>> it = itemAssocDAO.getItemAssocIterator(5000);
    int itemsEqual = 0;

    // need to set active since null gets the default value true when storing
    itemAssocs.get(2).setActive(true);

    while (it.hasNext()) {
      ItemAssocVO<Integer, Integer> itemAssocGot = it.next();
      itemAssocGot.setId(null);

      if (itemAssocs.contains(itemAssocGot)) itemsEqual++;
    }

    assertEquals(itemAssocs.size(), itemsEqual);
  }