### Question:
VMDAOJpa implements VMDAO { @Override @SuppressWarnings("unchecked") @Transactional(readOnly=false, propagation=Propagation.REQUIRED) public List<VM> getVMsWithOvfIdAndActive(int deploymentId, String ovfId) { Query query = entityManager.createQuery("SELECT v FROM VM v " + "WHERE v.status = :status " + "AND v.ovfId = :ovfid " + "AND v.deployment.id = :id"); query.setParameter("status", STATE_VM_ACTIVE); query.setParameter("id", deploymentId); query.setParameter("ovfid", ovfId); return (List<VM>) query.getResultList(); }  @PersistenceContext (unitName = "applicationManagerDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) VM getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<VM> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(VM vm); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(VM vm); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(VM vm); @Override @SuppressWarnings("unchecked") List<VM> getNotDeletedVMsWithImage(Image image); @Override @SuppressWarnings("unchecked") @Transactional(readOnly=false, propagation=Propagation.REQUIRED) VM getVMWithProviderVMId(String proivderVMId, String providerId); @Override @SuppressWarnings("unchecked") @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<VM> getVMsWithOVfIdForDeploymentNotDeleted(String ovfId, int deploymentId); @Override @SuppressWarnings("unchecked") @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<VM> getVMsWithOvfIdAndActive(int deploymentId, String ovfId);  }### Answer:
@Test public void getVMsWithOvfIdAndActive() { Deployment deployment1 = new Deployment(); deployment1.setStatus("RUNNING"); deployment1.setPrice("expensive"); VM vm1 = new VM(); vm1.setOvfId("ovfid1"); vm1.setStatus(STATE_VM_ACTIVE); VM vm2 = new VM(); vm2.setOvfId("ovfid1"); vm2.setStatus(STATE_VM_ACTIVE); VM vm3 = new VM(); vm3.setOvfId("ovfid1"); vm3.setStatus(STATE_VM_DELETED); VM vm4 = new VM(); vm4.setOvfId("ovfid2"); vm4.setStatus(STATE_VM_DELETED); VM vm5 = new VM(); vm5.setOvfId("ovfid1"); vm5.setStatus("whatever"); deployment1.addVM(vm1); deployment1.addVM(vm2); deployment1.addVM(vm3); deployment1.addVM(vm4); deployment1.addVM(vm5); deploymentDAO.save(deployment1); List<VM> vms = vmDAO.getVMsWithOvfIdAndActive(deployment1.getId(), "ovfid1"); assertEquals(2, vms.size()); assertEquals(vm1, vms.get(0)); assertEquals(vm2, vms.get(1)); vms = vmDAO.getVMsWithOvfIdAndActive(deployment1.getId(), "ovfid2"); assertEquals(0, vms.size()); }