@Test @Transactional public void testCreateEnforcementJob() throws Exception { Date firstExecuted = new Date(); IAgreement agreement = saveAgreement(); EnforcementJob job = new EnforcementJob(); job.setAgreement(agreement); job.setEnabled(true); job.setFirstExecuted(firstExecuted); Date lastExecuted = new Date(); job.setLastExecuted(lastExecuted); IEnforcementJob stored = service.createEnforcementJob(job); assertTrue(stored.getId() != null); stored = enforcementJobDao.getById(stored.getId()); assertEquals(job.getEnabled(), stored.getEnabled()); assertEquals(job.getFirstExecuted(), stored.getFirstExecuted()); assertEquals(job.getLastExecuted(), stored.getLastExecuted()); }
@Override public IEnforcementJob createEnforcementJob(IEnforcementJob job) { String agreementId = job.getAgreement().getAgreementId(); if (enforcementJobDAO.getByAgreementId(agreementId) != null) { throw new IllegalStateException("Agreement " + agreementId + " already has EnforcementJob"); } IAgreement agreement = agreementDAO.getByAgreementId(agreementId); if (agreement==null) throw new IllegalStateException("Agreement " + agreementId + " doesn't exist in the database, cannot be associated to the enforcement"); job.setAgreement(agreement); IEnforcementJob saved = enforcementJobDAO.save(job); return saved; }
EnforcementService implements IEnforcementService { @Override public IEnforcementJob createEnforcementJob(IEnforcementJob job) { String agreementId = job.getAgreement().getAgreementId(); if (enforcementJobDAO.getByAgreementId(agreementId) != null) { throw new IllegalStateException("Agreement " + agreementId + " already has EnforcementJob"); } IAgreement agreement = agreementDAO.getByAgreementId(agreementId); if (agreement==null) throw new IllegalStateException("Agreement " + agreementId + " doesn't exist in the database, cannot be associated to the enforcement"); job.setAgreement(agreement); IEnforcementJob saved = enforcementJobDAO.save(job); return saved; } }
EnforcementService implements IEnforcementService { @Override public IEnforcementJob createEnforcementJob(IEnforcementJob job) { String agreementId = job.getAgreement().getAgreementId(); if (enforcementJobDAO.getByAgreementId(agreementId) != null) { throw new IllegalStateException("Agreement " + agreementId + " already has EnforcementJob"); } IAgreement agreement = agreementDAO.getByAgreementId(agreementId); if (agreement==null) throw new IllegalStateException("Agreement " + agreementId + " doesn't exist in the database, cannot be associated to the enforcement"); job.setAgreement(agreement); IEnforcementJob saved = enforcementJobDAO.save(job); return saved; }  }
EnforcementService implements IEnforcementService { @Override public IEnforcementJob createEnforcementJob(IEnforcementJob job) { String agreementId = job.getAgreement().getAgreementId(); if (enforcementJobDAO.getByAgreementId(agreementId) != null) { throw new IllegalStateException("Agreement " + agreementId + " already has EnforcementJob"); } IAgreement agreement = agreementDAO.getByAgreementId(agreementId); if (agreement==null) throw new IllegalStateException("Agreement " + agreementId + " doesn't exist in the database, cannot be associated to the enforcement"); job.setAgreement(agreement); IEnforcementJob saved = enforcementJobDAO.save(job); return saved; }  @Override IEnforcementJob getEnforcementJob(Long id); @Override IEnforcementJob getEnforcementJobByAgreementId(String agreementId); @Override List<IEnforcementJob> getEnforcementJobs(); @Override IEnforcementJob createEnforcementJob(IEnforcementJob job); @Override IEnforcementJob createEnforcementJob(String agreementId); @Override boolean deleteEnforcementJobByAgreementId(String agreementId); @Override boolean startEnforcement(String agreementId); @Override boolean stopEnforcement(String agreementId); @Override void saveEnforcementResult(IAgreement agreement,
            Map<IGuaranteeTerm, GuaranteeTermEvaluationResult> enforcementResult); void enforceReceivedMetrics(
            IAgreement agreement, String guaranteeTermName, List<IMonitoringMetric> metrics); @Override void doEnforcement(IAgreement agreement,
            Map<IGuaranteeTerm, List<IMonitoringMetric>> metrics); @Override void saveCheckedGuaranteeTerm(IGuaranteeTerm term); }
EnforcementService implements IEnforcementService { @Override public IEnforcementJob createEnforcementJob(IEnforcementJob job) { String agreementId = job.getAgreement().getAgreementId(); if (enforcementJobDAO.getByAgreementId(agreementId) != null) { throw new IllegalStateException("Agreement " + agreementId + " already has EnforcementJob"); } IAgreement agreement = agreementDAO.getByAgreementId(agreementId); if (agreement==null) throw new IllegalStateException("Agreement " + agreementId + " doesn't exist in the database, cannot be associated to the enforcement"); job.setAgreement(agreement); IEnforcementJob saved = enforcementJobDAO.save(job); return saved; }  @Override IEnforcementJob getEnforcementJob(Long id); @Override IEnforcementJob getEnforcementJobByAgreementId(String agreementId); @Override List<IEnforcementJob> getEnforcementJobs(); @Override IEnforcementJob createEnforcementJob(IEnforcementJob job); @Override IEnforcementJob createEnforcementJob(String agreementId); @Override boolean deleteEnforcementJobByAgreementId(String agreementId); @Override boolean startEnforcement(String agreementId); @Override boolean stopEnforcement(String agreementId); @Override void saveEnforcementResult(IAgreement agreement,
            Map<IGuaranteeTerm, GuaranteeTermEvaluationResult> enforcementResult); void enforceReceivedMetrics(
            IAgreement agreement, String guaranteeTermName, List<IMonitoringMetric> metrics); @Override void doEnforcement(IAgreement agreement,
            Map<IGuaranteeTerm, List<IMonitoringMetric>> metrics); @Override void saveCheckedGuaranteeTerm(IGuaranteeTerm term);  }