@Test
@Transactional
public void testEnforceReceivedMetrics() throws Exception {

    
    String kpiName = "responsetime";
    /*
     * create provider
     */
    IProvider provider = new Provider(null, "provider-test", "provider-test");
    providerDao.save(provider);
    
    ITemplate template = new Template();
    template.setUuid(UUID.randomUUID().toString());
    template.setText("");
    provider.addTemplate(template);
    template.setProvider(provider);
    templateDao.save(template);
    
    /* create agreement */
    IGuaranteeTerm term = TestAgreementFactory.newGuaranteeTerm(kpiName, kpiName + " LT 100");
    IAgreement agreement = TestAgreementFactory.newAgreement(
        UUID.randomUUID().toString(),
        provider,
        "consumer",
        Arrays.asList(
            term,
            TestAgreementFactory.newGuaranteeTerm("performance", "performance GT 0.9")
        )
    );
    agreement.setTemplate(template);
    agreementDao.save(agreement);
    
    /* create ejob */
    IEnforcementJob job = new EnforcementJob();
    job.setAgreement(agreement);
    service.createEnforcementJob(job);
    
    
        
    List<IMonitoringMetric> metrics = Arrays.asList(
            (IMonitoringMetric) new MonitoringMetric(kpiName, 99, new Date()),
            (IMonitoringMetric) new MonitoringMetric(kpiName, 100, new Date()) 
    );
    Map<IGuaranteeTerm, List<IMonitoringMetric>> metricsMap = 
            new HashMap<IGuaranteeTerm, List<IMonitoringMetric>>();
    metricsMap.put(term, metrics);
    
    service.doEnforcement(agreement, metricsMap);
}