@Test public void getAcceptedAgreement() { Deployment deployment1 = new Deployment(); deployment1.setStatus("XXXX1"); Agreement agreement1 = new Agreement(); agreement1.setPrice("111"); agreement1.setProviderId("provider-id"); agreement1.setSlaAgreement("sla-agreement"); agreement1.setSlaAgreementId("sla-agreement-id"); agreement1.setDeployment(deployment1); agreement1.setAccepted(false); deployment1.addAgreement(agreement1); Agreement agreement2 = new Agreement(); agreement2.setPrice("121"); agreement2.setProviderId("provider-id2"); agreement2.setSlaAgreement("sla-agreement2"); agreement2.setSlaAgreementId("sla-agreement-id2"); agreement2.setDeployment(deployment1); agreement2.setAccepted(true); deployment1.addAgreement(agreement2); Agreement agreement3 = new Agreement(); agreement3.setPrice("131"); agreement3.setProviderId("provider-id3"); agreement3.setSlaAgreement("sla-agreement3"); agreement3.setSlaAgreementId("sla-agreement-id3"); agreement3.setDeployment(deployment1); agreement3.setAccepted(false); deployment1.addAgreement(agreement3); Agreement agreement4 = new Agreement(); agreement4.setPrice("431"); agreement4.setProviderId("provider-id4"); agreement4.setSlaAgreement("sla-agreement4"); agreement4.setSlaAgreementId("sla-agreement-id4"); agreement4.setAccepted(false); deploymentDAO.save(deployment1); agreementDAO.save(agreement1); agreementDAO.save(agreement2); agreementDAO.save(agreement3); agreementDAO.save(agreement4); Agreement agreementFromDB = agreementDAO.getAcceptedAgreement(deployment1); assertEquals(agreementFromDB, agreement2); Deployment deployment2 = new Deployment(); deployment2.setStatus("STATUS2"); deploymentDAO.save(deployment2); agreementFromDB = agreementDAO.getAcceptedAgreement(deployment2); assertNull(agreementFromDB); Agreement agreement5 = new Agreement(); agreement5.setPrice("531"); agreement5.setProviderId("provider-id5"); agreement5.setSlaAgreement("sla-agreement5"); agreement5.setSlaAgreementId("sla-agreement-id5"); agreement5.setAccepted(false); agreement5.setDeployment(deployment2); deployment2.addAgreement(agreement5); deployment2.addAgreement(agreement4); agreement4.setDeployment(deployment2); deploymentDAO.update(deployment2); agreementDAO.update(agreement4); agreementDAO.save(agreement5); agreementFromDB = agreementDAO.getAcceptedAgreement(deployment2); assertNull(agreementFromDB); }
@Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) @SuppressWarnings("unchecked") public Agreement getAcceptedAgreement(Deployment deployment) { Query query = entityManager.createQuery("SELECT a FROM Agreement a " + "WHERE a.accepted = :accepted " + "AND a.deployment = :deployment "); query.setParameter("accepted", true); query.setParameter("deployment", deployment); List<Agreement> agreements = (List<Agreement>) query.getResultList(); if(agreements.size() > 0) { return agreements.get(0); } return null; }
AgreementDAOJpa implements AgreementDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) @SuppressWarnings("unchecked") public Agreement getAcceptedAgreement(Deployment deployment) { Query query = entityManager.createQuery("SELECT a FROM Agreement a " + "WHERE a.accepted = :accepted " + "AND a.deployment = :deployment "); query.setParameter("accepted", true); query.setParameter("deployment", deployment); List<Agreement> agreements = (List<Agreement>) query.getResultList(); if(agreements.size() > 0) { return agreements.get(0); } return null; } }
AgreementDAOJpa implements AgreementDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) @SuppressWarnings("unchecked") public Agreement getAcceptedAgreement(Deployment deployment) { Query query = entityManager.createQuery("SELECT a FROM Agreement a " + "WHERE a.accepted = :accepted " + "AND a.deployment = :deployment "); query.setParameter("accepted", true); query.setParameter("deployment", deployment); List<Agreement> agreements = (List<Agreement>) query.getResultList(); if(agreements.size() > 0) { return agreements.get(0); } return null; }  }
AgreementDAOJpa implements AgreementDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) @SuppressWarnings("unchecked") public Agreement getAcceptedAgreement(Deployment deployment) { Query query = entityManager.createQuery("SELECT a FROM Agreement a " + "WHERE a.accepted = :accepted " + "AND a.deployment = :deployment "); query.setParameter("accepted", true); query.setParameter("deployment", deployment); List<Agreement> agreements = (List<Agreement>) query.getResultList(); if(agreements.size() > 0) { return agreements.get(0); } return null; }  @PersistenceContext (unitName = "applicationManagerDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Agreement getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Agreement> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) @SuppressWarnings("unchecked") Agreement getAcceptedAgreement(Deployment deployment); }
AgreementDAOJpa implements AgreementDAO { @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) @SuppressWarnings("unchecked") public Agreement getAcceptedAgreement(Deployment deployment) { Query query = entityManager.createQuery("SELECT a FROM Agreement a " + "WHERE a.accepted = :accepted " + "AND a.deployment = :deployment "); query.setParameter("accepted", true); query.setParameter("deployment", deployment); List<Agreement> agreements = (List<Agreement>) query.getResultList(); if(agreements.size() > 0) { return agreements.get(0); } return null; }  @PersistenceContext (unitName = "applicationManagerDB") void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) Agreement getById(int id); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) List<Agreement> getAll(); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean save(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean update(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) boolean delete(Agreement agreement); @Override @Transactional(readOnly=false, propagation=Propagation.REQUIRED) @SuppressWarnings("unchecked") Agreement getAcceptedAgreement(Deployment deployment);  }