Search in sources :

Example 91 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testDevPoolRemovalAtUnbind.

@Test
public void testDevPoolRemovalAtUnbind() throws EntitlementRefusedException {
    Owner owner = createOwner();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    productCurator.create(p);
    Consumer devSystem = new Consumer("dev", "user", owner, systemType);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
    consumerCurator.create(devSystem);
    Pool pool1 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    pool1.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
    pool1.setAttribute(Pool.Attributes.REQUIRES_CONSUMER, devSystem.getUuid());
    poolCurator.create(pool1);
    Pool pool2 = createPool(owner, p, 10L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool2);
    List<String> possPools = new ArrayList<>();
    possPools.add(pool1.getId());
    AutobindData ad = new AutobindData(devSystem, owner);
    ad.setPossiblePools(possPools);
    List<Entitlement> results = poolManager.entitleByProducts(ad);
    assertEquals(1, results.size());
    assertEquals(results.get(0).getPool(), pool1);
    Entitlement e = entitlementCurator.find(results.get(0).getId());
    poolManager.revokeEntitlement(e);
    assertNull(poolCurator.find(pool1.getId()));
    assertNotNull(poolCurator.find(pool2.getId()));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 92 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testDeletePool.

@Test
public void testDeletePool() throws Exception {
    Pool pool = createPool(o, socketLimitedProduct, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool);
    List<Pool> pools = poolCurator.listByOwner(o).list();
    assertEquals(5, poolCurator.listByOwner(o).list().size());
    poolManager.deletePools(Arrays.asList(pool, pools.get(0)));
    pools = poolCurator.listByOwner(o).list();
    assertEquals(3, pools.size());
    poolManager.deletePools(pools);
    pools = poolCurator.listByOwner(o).list();
    assertTrue(pools.isEmpty());
}
Also used : Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 93 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testCleanupExpiredPools.

@Test
public void testCleanupExpiredPools() {
    long ct = System.currentTimeMillis();
    Date activeStart = new Date(ct + 3600000);
    Date activeEnd = new Date(ct + 7200000);
    Date expiredStart = new Date(ct - 7200000);
    Date expiredEnd = new Date(ct - 3600000);
    Owner owner = this.createOwner();
    Product product1 = this.createProduct("test-product-1", "Test Product 1", owner);
    Product product2 = this.createProduct("test-product-2", "Test Product 2", owner);
    Pool activePool = this.createPool(owner, product1, 1L, activeStart, activeEnd);
    Pool expiredPool = this.createPool(owner, product2, 1L, expiredStart, expiredEnd);
    this.poolManager.cleanupExpiredPools();
    assertNotNull(this.poolCurator.find(activePool.getId()));
    assertNull(this.poolCurator.find(expiredPool.getId()));
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) Date(java.util.Date) Test(org.junit.Test)

Example 94 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testListForConsumerExcludesWarnings.

@Test
public void testListForConsumerExcludesWarnings() {
    Page<List<Pool>> results = poolManager.listAvailableEntitlementPools(parentSystem, null, parentSystem.getOwnerId(), (String) null, null, null, true, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    assertEquals(4, results.getPageData().size());
    Pool pool = createPool(o, socketLimitedProduct, 100L, TestUtil.createDate(2000, 3, 2), TestUtil.createDate(2050, 3, 2));
    poolCurator.create(pool);
    parentSystem.setFact("cpu.cpu_socket(s)", "4");
    results = poolManager.listAvailableEntitlementPools(parentSystem, null, parentSystem.getOwnerId(), (String) null, null, null, false, new PoolFilterBuilder(), new PageRequest(), false, false, null);
    // Pool in error should not be included. Should have the same number of
    // initial pools.
    assertEquals(4, results.getPageData().size());
}
Also used : PageRequest(org.candlepin.common.paging.PageRequest) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 95 with Pool

use of org.candlepin.model.Pool in project candlepin by candlepin.

the class TrustedUserPrincipalTest method access.

@Test
public void access() {
    Consumer c = mock(Consumer.class);
    Pool p = mock(Pool.class);
    assertTrue(principal.canAccess(c, SubResource.NONE, Access.ALL));
    assertTrue(principal.canAccess(null, SubResource.NONE, Access.NONE));
    assertTrue(principal.canAccessAll(null, SubResource.NONE, Access.NONE));
    assertTrue(principal.canAccess(p, SubResource.NONE, Access.ALL));
    assertTrue(principal.canAccess("always true", SubResource.NONE, Access.READ_ONLY));
}
Also used : Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Aggregations

Pool (org.candlepin.model.Pool)508 Test (org.junit.Test)358 Product (org.candlepin.model.Product)217 Entitlement (org.candlepin.model.Entitlement)125 Consumer (org.candlepin.model.Consumer)115 ValidationResult (org.candlepin.policy.ValidationResult)111 ArrayList (java.util.ArrayList)100 LinkedList (java.util.LinkedList)100 Owner (org.candlepin.model.Owner)80 HashSet (java.util.HashSet)76 HashMap (java.util.HashMap)67 PoolQuantity (org.candlepin.model.PoolQuantity)66 Date (java.util.Date)65 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)62 Subscription (org.candlepin.model.dto.Subscription)60 List (java.util.List)48 ConsumerType (org.candlepin.model.ConsumerType)48 SourceSubscription (org.candlepin.model.SourceSubscription)47 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)38 Matchers.anyString (org.mockito.Matchers.anyString)30