Search in sources :

Example 16 with ValidationResult

use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.

the class EntitlerJobTest method respondWithValidationErrors.

@Test
public void respondWithValidationErrors() throws JobExecutionException, EntitlementRefusedException {
    PoolIdAndQuantity[] pQs = new PoolIdAndQuantity[1];
    pQs[0] = new PoolIdAndQuantity("pool10", 1);
    JobDetail detail = EntitlerJob.bindByPoolAndQuantities(consumer, owner.getKey(), pQs);
    JobExecutionContext ctx = mock(JobExecutionContext.class);
    when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
    HashMap<String, ValidationResult> mapResult = new HashMap<>();
    ValidationResult result = new ValidationResult();
    result.addError("rulefailed.no.entitlements.available");
    mapResult.put("hello", result);
    when(e.bindByPoolQuantities(eq(consumerUuid), anyMapOf(String.class, Integer.class))).thenThrow(new EntitlementRefusedException(mapResult));
    EntitlerJob job = new EntitlerJob(e, null, pC, i18n);
    injector.injectMembers(job);
    Pool p = new Pool();
    p.setId("hello");
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.iterator()).thenReturn(Arrays.asList(p).iterator());
    when(pC.listAllByIds(anyListOf(String.class))).thenReturn(cqmock);
    job.execute(ctx);
    ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
    verify(ctx).setResult(argumentCaptor.capture());
    List<PoolIdAndErrors> resultErrors = (List<PoolIdAndErrors>) argumentCaptor.getValue();
    assertEquals(1, resultErrors.size());
    assertEquals("hello", resultErrors.get(0).getPoolId());
    assertEquals(1, resultErrors.get(0).getErrors().size());
    assertEquals("No subscriptions are available from the pool with ID \"hello\".", resultErrors.get(0).getErrors().get(0));
}
Also used : PoolIdAndQuantity(org.candlepin.model.dto.PoolIdAndQuantity) PoolIdAndErrors(org.candlepin.model.dto.PoolIdAndErrors) HashMap(java.util.HashMap) EntitlementRefusedException(org.candlepin.policy.EntitlementRefusedException) CandlepinQuery(org.candlepin.model.CandlepinQuery) ValidationResult(org.candlepin.policy.ValidationResult) JobDetail(org.quartz.JobDetail) JobExecutionContext(org.quartz.JobExecutionContext) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 17 with ValidationResult

use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.

the class ManifestEntitlementRulesTest method preEntitlementNoRamCapableBindError.

@Test
public void preEntitlementNoRamCapableBindError() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    c.setFact("memory.memtotal", "2000000");
    Set<ConsumerCapability> caps = new HashSet<>();
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.RAM, "2");
    Pool p = TestUtil.createPool(prod);
    p.setId("poolId");
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BIND);
    assertNotNull(results);
    assertEquals(0, results.getWarnings().size());
    ValidationError error = results.getErrors().get(0);
    assertEquals("rulefailed.ram.unsupported.by.consumer", error.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with ValidationResult

use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.

the class ManifestEntitlementRulesTest method preEntitlementSuccessRamCapable.

@Test
public void preEntitlementSuccessRamCapable() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    c.setFact("memory.memtotal", "2000000");
    Set<ConsumerCapability> caps = new HashSet<>();
    ConsumerCapability cc = new ConsumerCapability(c, "ram");
    caps.add(cc);
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.RAM, "2");
    Pool p = TestUtil.createPool(prod);
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
    assertNotNull(results);
    assertEquals(0, results.getErrors().size());
    assertEquals(0, results.getWarnings().size());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with ValidationResult

use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.

the class ManifestEntitlementRulesTest method preEntitlementSuccessCoreCapable.

@Test
public void preEntitlementSuccessCoreCapable() {
    // Test with sockets to make sure that they are skipped.
    Consumer c = this.createMockConsumer(true);
    c.setFact("cpu.core(s)_per_socket", "2");
    Set<ConsumerCapability> caps = new HashSet<>();
    ConsumerCapability cc = new ConsumerCapability(c, "cores");
    caps.add(cc);
    c.setCapabilities(caps);
    Product prod = TestUtil.createProduct();
    prod.setAttribute(Product.Attributes.CORES, "2");
    Pool p = TestUtil.createPool(prod);
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
    assertNotNull(results);
    assertEquals(0, results.getErrors().size());
    assertEquals(0, results.getWarnings().size());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerCapability(org.candlepin.model.ConsumerCapability) Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with ValidationResult

use of org.candlepin.policy.ValidationResult in project candlepin by candlepin.

the class ManifestEntitlementRulesTest method preEntitlementShouldNotAllowConsumptionFromDerivedPools.

@Test
public void preEntitlementShouldNotAllowConsumptionFromDerivedPools() {
    Consumer c = this.createMockConsumer(true);
    Product prod = TestUtil.createProduct();
    Pool p = TestUtil.createPool(prod);
    p.setAttribute(Product.Attributes.VIRT_ONLY, "true");
    p.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    p.setId("poolId");
    ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BIND);
    assertNotNull(results);
    assertEquals(1, results.getErrors().size());
    ValidationError error = results.getErrors().get(0);
    assertEquals("pool.not.available.to.manifest.consumers", error.getResourceKey());
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationResult (org.candlepin.policy.ValidationResult)116 Pool (org.candlepin.model.Pool)111 Test (org.junit.Test)105 Product (org.candlepin.model.Product)38 Consumer (org.candlepin.model.Consumer)36 ConsumerType (org.candlepin.model.ConsumerType)22 HashSet (java.util.HashSet)19 Entitlement (org.candlepin.model.Entitlement)15 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)14 ValidationError (org.candlepin.policy.ValidationError)13 ArrayList (java.util.ArrayList)11 LinkedList (java.util.LinkedList)11 ConsumerCapability (org.candlepin.model.ConsumerCapability)11 Date (java.util.Date)10 HashMap (java.util.HashMap)9 Matchers.anyString (org.mockito.Matchers.anyString)9 List (java.util.List)8 EntitlementRefusedException (org.candlepin.policy.EntitlementRefusedException)8 PreUnbindHelper (org.candlepin.policy.js.entitlement.PreUnbindHelper)8 PoolQuantity (org.candlepin.model.PoolQuantity)7