@Test public void testEvaluate() { SimpleBusinessValuesEvaluator bvEval = new SimpleBusinessValuesEvaluator(); bvEval.setCompensationRepository(new DummyViolationRepository(Arrays.asList(violations))); IGuaranteeTerm term = contract.getGuaranteeTerms().get(0); List<? extends ICompensation> compensations; for (int i = 0; i < times.length; i++) { Date now = new Date(i * 1000); List<IViolation> newViolations = (times[i] != 0)? Collections.singletonList(TestAgreementFactory.newViolation(contract, term, null, now)) : Collections.<IViolation>emptyList(); compensations = bvEval.evaluate( contract, term, newViolations, now ); for (IPenaltyDefinition def : contract.getGuaranteeTerms().get(0).getBusinessValueList().getPenalties()) { int count = def.getCount(); int step = (int)def.getTimeInterval().getTime() / 1000; boolean expectedPenalty = sum(times, i - step, i) >= count; boolean actualPenalty = foundPenaltyDefinition(def, compensations); if (expectedPenalty != actualPenalty) { assertEquals(expectedPenalty, actualPenalty); } assertEquals(expectedPenalty, actualPenalty); } } }
@Override public List<? extends ICompensation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IViolation> newViolations, Date now) { logger.debug("Evaluating business for {} new violations", newViolations.size()); List<ICompensation> result = new ArrayList<ICompensation>(); IBusinessValueList businessValues = term.getBusinessValueList(); if (businessValues == null) { return Collections.emptyList(); } for (IPenaltyDefinition penaltyDef : businessValues.getPenalties()) { if (penaltyDef.getKind() != CompensationKind.CUSTOM_PENALTY) { continue; } Date violationsBegin = new Date(now.getTime() - penaltyDef.getTimeInterval().getTime()); List<IViolation> oldViolations = repository.getViolationsByTimeRange(agreement, term.getName(), violationsBegin, now); if (thereIsPenalty(penaltyDef, newViolations, oldViolations)) { IPenalty penalty = new Penalty( agreement.getAgreementId(), now, term.getKpiName(), penaltyDef, getLastViolation(newViolations, oldViolations)); result.add(penalty); logger.debug("Raised {}", penalty); } } return result; }
SimpleBusinessValuesEvaluator implements IBusinessValuesEvaluator { @Override public List<? extends ICompensation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IViolation> newViolations, Date now) { logger.debug("Evaluating business for {} new violations", newViolations.size()); List<ICompensation> result = new ArrayList<ICompensation>(); IBusinessValueList businessValues = term.getBusinessValueList(); if (businessValues == null) { return Collections.emptyList(); } for (IPenaltyDefinition penaltyDef : businessValues.getPenalties()) { if (penaltyDef.getKind() != CompensationKind.CUSTOM_PENALTY) { continue; } Date violationsBegin = new Date(now.getTime() - penaltyDef.getTimeInterval().getTime()); List<IViolation> oldViolations = repository.getViolationsByTimeRange(agreement, term.getName(), violationsBegin, now); if (thereIsPenalty(penaltyDef, newViolations, oldViolations)) { IPenalty penalty = new Penalty( agreement.getAgreementId(), now, term.getKpiName(), penaltyDef, getLastViolation(newViolations, oldViolations)); result.add(penalty); logger.debug("Raised {}", penalty); } } return result; } }
SimpleBusinessValuesEvaluator implements IBusinessValuesEvaluator { @Override public List<? extends ICompensation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IViolation> newViolations, Date now) { logger.debug("Evaluating business for {} new violations", newViolations.size()); List<ICompensation> result = new ArrayList<ICompensation>(); IBusinessValueList businessValues = term.getBusinessValueList(); if (businessValues == null) { return Collections.emptyList(); } for (IPenaltyDefinition penaltyDef : businessValues.getPenalties()) { if (penaltyDef.getKind() != CompensationKind.CUSTOM_PENALTY) { continue; } Date violationsBegin = new Date(now.getTime() - penaltyDef.getTimeInterval().getTime()); List<IViolation> oldViolations = repository.getViolationsByTimeRange(agreement, term.getName(), violationsBegin, now); if (thereIsPenalty(penaltyDef, newViolations, oldViolations)) { IPenalty penalty = new Penalty( agreement.getAgreementId(), now, term.getKpiName(), penaltyDef, getLastViolation(newViolations, oldViolations)); result.add(penalty); logger.debug("Raised {}", penalty); } } return result; }  }
SimpleBusinessValuesEvaluator implements IBusinessValuesEvaluator { @Override public List<? extends ICompensation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IViolation> newViolations, Date now) { logger.debug("Evaluating business for {} new violations", newViolations.size()); List<ICompensation> result = new ArrayList<ICompensation>(); IBusinessValueList businessValues = term.getBusinessValueList(); if (businessValues == null) { return Collections.emptyList(); } for (IPenaltyDefinition penaltyDef : businessValues.getPenalties()) { if (penaltyDef.getKind() != CompensationKind.CUSTOM_PENALTY) { continue; } Date violationsBegin = new Date(now.getTime() - penaltyDef.getTimeInterval().getTime()); List<IViolation> oldViolations = repository.getViolationsByTimeRange(agreement, term.getName(), violationsBegin, now); if (thereIsPenalty(penaltyDef, newViolations, oldViolations)) { IPenalty penalty = new Penalty( agreement.getAgreementId(), now, term.getKpiName(), penaltyDef, getLastViolation(newViolations, oldViolations)); result.add(penalty); logger.debug("Raised {}", penalty); } } return result; }  @Override List<? extends ICompensation> evaluate(
            IAgreement agreement, IGuaranteeTerm term, List<IViolation> newViolations, Date now); IViolationRepository getCompensationRepository(); void setCompensationRepository(IViolationRepository repository); }
SimpleBusinessValuesEvaluator implements IBusinessValuesEvaluator { @Override public List<? extends ICompensation> evaluate( IAgreement agreement, IGuaranteeTerm term, List<IViolation> newViolations, Date now) { logger.debug("Evaluating business for {} new violations", newViolations.size()); List<ICompensation> result = new ArrayList<ICompensation>(); IBusinessValueList businessValues = term.getBusinessValueList(); if (businessValues == null) { return Collections.emptyList(); } for (IPenaltyDefinition penaltyDef : businessValues.getPenalties()) { if (penaltyDef.getKind() != CompensationKind.CUSTOM_PENALTY) { continue; } Date violationsBegin = new Date(now.getTime() - penaltyDef.getTimeInterval().getTime()); List<IViolation> oldViolations = repository.getViolationsByTimeRange(agreement, term.getName(), violationsBegin, now); if (thereIsPenalty(penaltyDef, newViolations, oldViolations)) { IPenalty penalty = new Penalty( agreement.getAgreementId(), now, term.getKpiName(), penaltyDef, getLastViolation(newViolations, oldViolations)); result.add(penalty); logger.debug("Raised {}", penalty); } } return result; }  @Override List<? extends ICompensation> evaluate(
            IAgreement agreement, IGuaranteeTerm term, List<IViolation> newViolations, Date now); IViolationRepository getCompensationRepository(); void setCompensationRepository(IViolationRepository repository);  }