Search in sources :

Example 6 with PoolIdAndQuantity

use of org.candlepin.model.dto.PoolIdAndQuantity in project candlepin by candlepin.

the class EntitlerJob method bindByPool.

public static JobDetail bindByPool(String poolId, Consumer consumer, String ownerKey, Integer qty) {
    PoolIdAndQuantity[] poolQuantities = new PoolIdAndQuantity[1];
    poolQuantities[0] = new PoolIdAndQuantity(poolId, qty);
    return bindByPoolAndQuantities(consumer, ownerKey, poolQuantities);
}
Also used : PoolIdAndQuantity(org.candlepin.model.dto.PoolIdAndQuantity)

Example 7 with PoolIdAndQuantity

use of org.candlepin.model.dto.PoolIdAndQuantity in project candlepin by candlepin.

the class EntitlerJobTest method bindByPoolExec.

@Test
public void bindByPoolExec() throws JobExecutionException, EntitlementRefusedException {
    String pool = "pool10";
    PoolIdAndQuantity[] pQs = new PoolIdAndQuantity[1];
    pQs[0] = new PoolIdAndQuantity(pool, 1);
    JobDetail detail = EntitlerJob.bindByPoolAndQuantities(consumer, owner.getKey(), pQs);
    JobExecutionContext ctx = mock(JobExecutionContext.class);
    when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
    List<Entitlement> ents = new ArrayList<>();
    Pool p = new Pool();
    p.setId(pool);
    Entitlement ent = new Entitlement();
    ent.setPool(p);
    ent.setQuantity(100);
    ents.add(ent);
    when(e.bindByPoolQuantities(eq(consumerUuid), anyMapOf(String.class, Integer.class))).thenReturn(ents);
    EntitlerJob job = new EntitlerJob(e, null, pC, null);
    injector.injectMembers(job);
    job.execute(ctx);
    verify(e).bindByPoolQuantities(eq(consumerUuid), anyMapOf(String.class, Integer.class));
    verify(e).sendEvents(eq(ents));
    ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
    verify(ctx).setResult(argumentCaptor.capture());
    List<PoolIdAndQuantity> result = (List<PoolIdAndQuantity>) argumentCaptor.getValue();
    assertEquals(1, result.size());
    assertEquals(pool, result.get(0).getPoolId());
    assertEquals(100, result.get(0).getQuantity().intValue());
}
Also used : PoolIdAndQuantity(org.candlepin.model.dto.PoolIdAndQuantity) ArrayList(java.util.ArrayList) JobDetail(org.quartz.JobDetail) JobExecutionContext(org.quartz.JobExecutionContext) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 8 with PoolIdAndQuantity

use of org.candlepin.model.dto.PoolIdAndQuantity in project candlepin by candlepin.

the class EntitlerJobTest method bindByPoolSetup.

@Test
public void bindByPoolSetup() {
    String pool = "pool10";
    PoolIdAndQuantity[] pQs = new PoolIdAndQuantity[1];
    pQs[0] = new PoolIdAndQuantity(pool, 1);
    JobDetail detail = EntitlerJob.bindByPoolAndQuantities(consumer, owner.getKey(), pQs);
    assertNotNull(detail);
    PoolIdAndQuantity[] resultPools = (PoolIdAndQuantity[]) detail.getJobDataMap().get("pool_and_quantities");
    assertEquals("pool10", resultPools[0].getPoolId());
    assertEquals(1, resultPools[0].getQuantity().intValue());
    assertEquals(consumerUuid, detail.getJobDataMap().get(JobStatus.TARGET_ID));
    assertTrue(detail.getKey().getName().startsWith("bind_by_pool_"));
}
Also used : JobDetail(org.quartz.JobDetail) PoolIdAndQuantity(org.candlepin.model.dto.PoolIdAndQuantity) Test(org.junit.Test)

Aggregations

PoolIdAndQuantity (org.candlepin.model.dto.PoolIdAndQuantity)8 Test (org.junit.Test)6 JobDetail (org.quartz.JobDetail)6 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Pool (org.candlepin.model.Pool)3 JobExecutionContext (org.quartz.JobExecutionContext)3 Entitlement (org.candlepin.model.Entitlement)2 PoolIdAndErrors (org.candlepin.model.dto.PoolIdAndErrors)2 EntitlementRefusedException (org.candlepin.policy.EntitlementRefusedException)2 Map (java.util.Map)1 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)1 CandlepinQuery (org.candlepin.model.CandlepinQuery)1 ValidationError (org.candlepin.policy.ValidationError)1 ValidationResult (org.candlepin.policy.ValidationResult)1 EntitlementRulesTranslator (org.candlepin.policy.js.entitlement.EntitlementRulesTranslator)1 Map (org.hibernate.mapping.Map)1 JobDataMap (org.quartz.JobDataMap)1 JobExecutionException (org.quartz.JobExecutionException)1