Search in sources :

Example 91 with ValidationResult

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

the class PreEntitlementRulesTest method consumerHavingEqualRamAsProductShouldNotGenerateWarning.

@Test
public void consumerHavingEqualRamAsProductShouldNotGenerateWarning() {
    // Fact specified in kb
    Pool pool = setupArchTest("ram", "2", "memory.memtotal", "2000000");
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 92 with ValidationResult

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

the class PreEntitlementRulesTest method testCommaSplitArchesTrailingComma.

@Test
public void testCommaSplitArchesTrailingComma() {
    Pool pool = setupArchTest("arch", "x86_64,x86_64,", "uname.machine", "x86_64");
    ValidationResult result = enforcer.preEntitlement(consumer, pool, 1);
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 93 with ValidationResult

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

the class PoolManagerTest method testBatchRevokeCleansUpCorrectPoolsWithSourceEnt.

@Test
public void testBatchRevokeCleansUpCorrectPoolsWithSourceEnt() throws Exception {
    Consumer c = TestUtil.createConsumer(owner);
    Pool pool2 = TestUtil.createPool(owner, product);
    Entitlement e = new Entitlement(pool, c, owner, 1);
    Entitlement e2 = new Entitlement(pool2, c, owner, 1);
    Entitlement e3 = new Entitlement(pool2, c, owner, 1);
    List<Entitlement> entsToDelete = new ArrayList<>();
    entsToDelete.add(e);
    entsToDelete.add(e2);
    List<Pool> poolsWithSource = createPoolsWithSourceEntitlement(e, product);
    poolsWithSource.get(0).getEntitlements().add(e3);
    Set<Pool> poolsWithSourceAsSet = new HashSet<>(poolsWithSource);
    when(mockPoolCurator.listBySourceEntitlements(entsToDelete)).thenReturn(poolsWithSourceAsSet);
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    when(mockConfig.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    when(mockPoolCurator.lockAndLoad(eq(pool))).thenReturn(pool);
    when(mockPoolCurator.lockAndLoad(eq(pool2))).thenReturn(pool2);
    manager.revokeEntitlements(entsToDelete);
    entsToDelete.add(e3);
    verify(entitlementCurator).batchDelete(eq(entsToDelete));
    verify(mockPoolCurator).batchDelete(eq(poolsWithSourceAsSet), anySetOf(String.class));
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Entitlement(org.candlepin.model.Entitlement) ValidationResult(org.candlepin.policy.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 94 with ValidationResult

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

the class PoolManagerTest method testCleanupExpiredPools.

@Test
public void testCleanupExpiredPools() {
    Pool p = createPoolWithEntitlements();
    p.setSubscriptionId("subid");
    List<Pool> pools = new LinkedList<>();
    pools.add(p);
    when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(p);
    when(mockPoolCurator.listExpiredPools(anyInt())).thenReturn(pools);
    when(mockPoolCurator.entitlementsIn(p)).thenReturn(new ArrayList<>(p.getEntitlements()));
    Subscription sub = new Subscription();
    sub.setId(p.getSubscriptionId());
    when(mockSubAdapter.getSubscription(any(String.class))).thenReturn(sub);
    when(mockSubAdapter.isReadOnly()).thenReturn(false);
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    manager.cleanupExpiredPools();
    // And the pool should be deleted:
    when(mockPoolCurator.lockAndLoadByIds(anyCollection())).thenReturn(pools);
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) ValidationResult(org.candlepin.policy.ValidationResult) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 95 with ValidationResult

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

the class PoolManagerTest method testRevokeCleansUpPoolsWithSourceEnt.

@Test
public void testRevokeCleansUpPoolsWithSourceEnt() throws Exception {
    Entitlement e = new Entitlement(pool, TestUtil.createConsumer(owner), owner, 1);
    List<Pool> poolsWithSource = createPoolsWithSourceEntitlement(e, product);
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(poolsWithSource);
    when(mockPoolCurator.listBySourceEntitlement(e)).thenReturn(cqmock);
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    when(mockConfig.getBoolean(ConfigProperties.STANDALONE)).thenReturn(true);
    when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(pool);
    manager.revokeEntitlement(e);
    List<Entitlement> entsToDelete = Arrays.asList(e);
    verify(entitlementCurator).batchDelete(eq(entsToDelete));
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) 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