@Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    ResourceBlock newResourceBlock = addResourceBlock();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newResourceBlock.getPrimaryKey());

    Map<Serializable, ResourceBlock> resourceBlocks = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, resourceBlocks.size());
    Assert.assertEquals(newResourceBlock, resourceBlocks.get(newResourceBlock.getPrimaryKey()));
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    ResourceBlock newResourceBlock = addResourceBlock();

    _persistence.clearCache();

    ResourceBlockModelImpl existingResourceBlockModelImpl =
        (ResourceBlockModelImpl) _persistence.findByPrimaryKey(newResourceBlock.getPrimaryKey());

    Assert.assertEquals(
        existingResourceBlockModelImpl.getCompanyId(),
        existingResourceBlockModelImpl.getOriginalCompanyId());
    Assert.assertEquals(
        existingResourceBlockModelImpl.getGroupId(),
        existingResourceBlockModelImpl.getOriginalGroupId());
    Assert.assertTrue(
        Validator.equals(
            existingResourceBlockModelImpl.getName(),
            existingResourceBlockModelImpl.getOriginalName()));
    Assert.assertTrue(
        Validator.equals(
            existingResourceBlockModelImpl.getPermissionsHash(),
            existingResourceBlockModelImpl.getOriginalPermissionsHash()));
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    ResourceBlock newResourceBlock = _persistence.create(pk);

    newResourceBlock.setMvccVersion(RandomTestUtil.nextLong());

    newResourceBlock.setCompanyId(RandomTestUtil.nextLong());

    newResourceBlock.setGroupId(RandomTestUtil.nextLong());

    newResourceBlock.setName(RandomTestUtil.randomString());

    newResourceBlock.setPermissionsHash(RandomTestUtil.randomString());

    newResourceBlock.setReferenceCount(RandomTestUtil.nextLong());

    _resourceBlocks.add(_persistence.update(newResourceBlock));

    ResourceBlock existingResourceBlock =
        _persistence.findByPrimaryKey(newResourceBlock.getPrimaryKey());

    Assert.assertEquals(existingResourceBlock.getMvccVersion(), newResourceBlock.getMvccVersion());
    Assert.assertEquals(
        existingResourceBlock.getResourceBlockId(), newResourceBlock.getResourceBlockId());
    Assert.assertEquals(existingResourceBlock.getCompanyId(), newResourceBlock.getCompanyId());
    Assert.assertEquals(existingResourceBlock.getGroupId(), newResourceBlock.getGroupId());
    Assert.assertEquals(existingResourceBlock.getName(), newResourceBlock.getName());
    Assert.assertEquals(
        existingResourceBlock.getPermissionsHash(), newResourceBlock.getPermissionsHash());
    Assert.assertEquals(
        existingResourceBlock.getReferenceCount(), newResourceBlock.getReferenceCount());
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    ResourceBlock newResourceBlock = addResourceBlock();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newResourceBlock.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, ResourceBlock> resourceBlocks = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, resourceBlocks.size());
    Assert.assertEquals(newResourceBlock, resourceBlocks.get(newResourceBlock.getPrimaryKey()));
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    ResourceBlock newResourceBlock1 = addResourceBlock();
    ResourceBlock newResourceBlock2 = addResourceBlock();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newResourceBlock1.getPrimaryKey());
    primaryKeys.add(newResourceBlock2.getPrimaryKey());

    Map<Serializable, ResourceBlock> resourceBlocks = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, resourceBlocks.size());
    Assert.assertEquals(newResourceBlock1, resourceBlocks.get(newResourceBlock1.getPrimaryKey()));
    Assert.assertEquals(newResourceBlock2, resourceBlocks.get(newResourceBlock2.getPrimaryKey()));
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    ResourceBlock newResourceBlock = addResourceBlock();

    ResourceBlock existingResourceBlock =
        _persistence.fetchByPrimaryKey(newResourceBlock.getPrimaryKey());

    Assert.assertEquals(existingResourceBlock, newResourceBlock);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    ResourceBlock resourceBlock = _persistence.create(pk);

    Assert.assertNotNull(resourceBlock);

    Assert.assertEquals(resourceBlock.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    ResourceBlock newResourceBlock = addResourceBlock();

    _persistence.remove(newResourceBlock);

    ResourceBlock existingResourceBlock =
        _persistence.fetchByPrimaryKey(newResourceBlock.getPrimaryKey());

    Assert.assertNull(existingResourceBlock);
  }