/** Ensures removing a VM pool works as expected. */
  @Test
  public void testRemoveVmPool() {
    dao.remove(deletableVmPool.getvm_pool_id());

    vm_pools result = dao.get(deletableVmPool.getvm_pool_id());

    assertNull(result);
  }
  /** Ensures that saving a VM pool works as expected. */
  @Test
  public void testSaveVmPool() {
    dao.save(newVmPool);

    vm_pools result = dao.getByName(newVmPool.getvm_pool_name());

    assertNotNull(result);
    assertEquals(newVmPool, result);
  }
  /** Ensures that updating a VM pool works as expected. */
  @Test
  public void testUpdateVmPool() {
    existingVmPool.setvm_pool_description("This is an updated VM pool.");

    dao.update(existingVmPool);

    vm_pools result = dao.get(existingVmPool.getvm_pool_id());

    assertEquals(existingVmPool, result);
  }
  @Test
  public void testRemoveTimeLeaseVmPoolMap() {
    dao.removeTimeLeasedVmPoolMap(
        existingTimeLeaseVmPoolMap.getid(), existingTimeLeaseVmPoolMap.getvm_pool_id());

    time_lease_vm_pool_map result =
        dao.getTimeLeasedVmPoolMapByIdForVmPool(
            existingTimeLeaseVmPoolMap.getid(), existingTimeLeaseVmPoolMap.getvm_pool_id());

    assertNull(result);
  }
  @Test
  public void testAddTimeLeaseVmPoolMap() {
    dao.addTimeLeasedVmPoolMap(newTimeLeaseVmPoolMap);

    time_lease_vm_pool_map result =
        dao.getTimeLeasedVmPoolMapByIdForVmPool(
            newTimeLeaseVmPoolMap.getid(), newTimeLeaseVmPoolMap.getvm_pool_id());

    assertNotNull(result);
    assertEquals(newTimeLeaseVmPoolMap, result);
  }
  @Test
  public void testUpdateTimeLeaseVmPoolMap() {
    existingTimeLeaseVmPoolMap.settype(100 - existingTimeLeaseVmPoolMap.gettype());

    dao.updateTimeLeasedVmPoolMap(existingTimeLeaseVmPoolMap);

    time_lease_vm_pool_map result =
        dao.getTimeLeasedVmPoolMapByIdForVmPool(
            existingTimeLeaseVmPoolMap.getid(), existingTimeLeaseVmPoolMap.getvm_pool_id());

    assertEquals(existingTimeLeaseVmPoolMap, result);
  }
  @Test
  public void testRemoveVmFromPool() {
    int before = dao.getVmPoolsMapByVmPoolId(existingVmPoolMap.getvm_pool_id()).size();

    dao.removeVmFromVmPool(EXISTING_VM_ID);

    int after = dao.getVmPoolsMapByVmPoolId(existingVmPoolMap.getvm_pool_id()).size();

    assertEquals(before - 1, after);

    vm_pool_map result = dao.getVmPoolMapByVmGuid(EXISTING_VM_ID);

    assertNull(result);
  }
  @Test
  public void testAddVmToPool() {
    int before = dao.getVmPoolsMapByVmPoolId(newVmPoolMap.getvm_pool_id()).size();

    dao.addVmToPool(newVmPoolMap);

    int after = dao.getVmPoolsMapByVmPoolId(newVmPoolMap.getvm_pool_id()).size();

    assertEquals(before + 1, after);

    vm_pool_map result = dao.getVmPoolMapByVmGuid(newVmPoolMap.getvm_guid());

    assertNotNull(result);
    assertEquals(newVmPoolMap, result);
  }
  /** Ensures an empty collection is returned. */
  @Test
  public void testGetAllVmPoolsForUserWithNoVmPools() {
    List<vm_pools> result = dao.getAllForUser(Guid.NewGuid());

    assertNotNull(result);
    assertTrue(result.isEmpty());
  }
  @Test
  public void testGetVmPoolMap() {
    vm_pool_map result = dao.getVmPoolMapByVmGuid(EXISTING_VM_ID);

    assertNotNull(result);
    assertEquals(existingVmPoolMap, result);
  }
  /** Ensures a collection of pools are returned. */
  @Test
  public void testGetAllVmPoolsForUser() {
    List<vm_pools> result = dao.getAllForUser(USER_ID);

    assertNotNull(result);
    assertFalse(result.isEmpty());
  }
  @Test
  public void testGetAllTimeLeaseVmPoolMaps() {
    List<time_lease_vm_pool_map> result = dao.getAllTimeLeasedVmPoolMaps();

    assertNotNull(result);
    assertFalse(result.isEmpty());
  }
  /** Ensures that getting a VM pool by name works as expected. */
  @Test
  public void testGetByName() {
    vm_pools result = dao.getByName(existingVmPool.getvm_pool_name());

    assertNotNull(result);
    assertEquals(existingVmPool, result);
  }
  /** Ensures the right number of pools are returned. */
  @Test
  public void testGetAllVmPools() {
    List<vm_pools> result = dao.getAll();

    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertEquals(VM_POOL_COUNT, result.size());
  }
  @Test
  public void testGetTimeLeaseVmPoolMap() {
    time_lease_vm_pool_map result =
        dao.getTimeLeasedVmPoolMapByIdForVmPool(
            existingTimeLeaseVmPoolMap.getid(), existingTimeLeaseVmPoolMap.getvm_pool_id());

    assertNotNull(result);
    assertEquals(existingTimeLeaseVmPoolMap, result);
  }
  @Override
  public void setUp() throws Exception {
    super.setUp();

    dao = prepareDAO(dbFacade.getVmPoolDAO());

    existingVmPool = dao.get(EXISTING_VM_POOL_ID);
    deletableVmPool = dao.get(DELETABLE_VM_POOL_ID);

    newVmPool = new vm_pools();
    newVmPool.setvm_pool_name("New VM Pool");
    newVmPool.setvm_pool_description("This is a new VM pool.");
    newVmPool.setvds_group_id(VDS_GROUP_ID);

    existingVmPoolMap = dao.getVmPoolMapByVmGuid(new Guid("77296e00-0cad-4e5a-9299-008a7b6f4355"));
    newVmPoolMap = new vm_pool_map(FREE_VM_ID, existingVmPool.getvm_pool_id());

    existingTimeLeaseVmPoolMap =
        dao.getTimeLeasedVmPoolMapByIdForVmPool(EXISTING_LEASE_ID, EXISTING_VM_POOL_ID);
    newTimeLeaseVmPoolMap =
        new time_lease_vm_pool_map(new Date(), Guid.NewGuid(), new Date(), 1, FREE_VM_POOL_ID);
  }
  /** Ensures that getting a VM pool by an invalid name returns null. */
  @Test
  public void testGetByNameWithInvalidName() {
    vm_pools result = dao.getByName("farkle");

    assertNull(result);
  }
  /** Ensures that null is returned when the id is invalid. */
  @Test
  public void testGetVmPoolWithInvalidId() {
    vm_pools result = dao.get(NGuid.NewGuid());

    assertNull(result);
  }