Search in sources :

Example 26 with Pool

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

the class OwnerResourceTest method ownerAdminCannotAccessAnotherOwnersPools.

@Test(expected = NotFoundException.class)
public void ownerAdminCannotAccessAnotherOwnersPools() {
    Owner evilOwner = new Owner("evilowner");
    ownerCurator.create(evilOwner);
    Principal principal = setupPrincipal(evilOwner, Access.ALL);
    Product p = this.createProduct(owner);
    Pool pool1 = TestUtil.createPool(owner, p);
    Pool pool2 = TestUtil.createPool(owner, p);
    poolCurator.create(pool1);
    poolCurator.create(pool2);
    securityInterceptor.enable();
    // Filtering should just cause this to return no results:
    ownerResource.listPools(owner.getKey(), null, null, null, null, true, null, null, new ArrayList<>(), false, false, null, null, principal, null);
}
Also used : Owner(org.candlepin.model.Owner) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) UserPrincipal(org.candlepin.auth.UserPrincipal) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 27 with Pool

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

the class OwnerResourceTest method testComplexDeleteOwner.

@Test
public void testComplexDeleteOwner() throws Exception {
    // Create some consumers:
    Consumer c1 = createConsumer(owner);
    Consumer c2 = createConsumer(owner);
    // Create a pool for this owner:
    Pool pool = TestUtil.createPool(owner, product);
    poolCurator.create(pool);
    // Give those consumers entitlements:
    Map<String, Integer> pQs = new HashMap<>();
    pQs.put(pool.getId(), 1);
    poolManager.entitleByPools(c1, pQs);
    assertEquals(2, consumerCurator.listByOwner(owner).list().size());
    assertEquals(1, poolCurator.listByOwner(owner).list().size());
    assertEquals(1, entitlementCurator.listByOwner(owner).list().size());
    // Generate an ueber certificate for the Owner. This will need to
    // be cleaned up along with the owner deletion.
    UeberCertificate uCert = ueberCertGenerator.generate(owner.getKey(), setupAdminPrincipal("test"));
    assertNotNull(uCert);
    ownerResource.deleteOwner(owner.getKey(), true, false);
    assertEquals(0, consumerCurator.listByOwner(owner).list().size());
    assertNull(consumerCurator.findByUuid(c1.getUuid()));
    assertNull(consumerCurator.findByUuid(c2.getUuid()));
    assertEquals(0, poolCurator.listByOwner(owner).list().size());
    assertEquals(0, entitlementCurator.listByOwner(owner).list().size());
    assertNull(ueberCertCurator.findForOwner(owner));
}
Also used : UpstreamConsumer(org.candlepin.model.UpstreamConsumer) Consumer(org.candlepin.model.Consumer) UeberCertificate(org.candlepin.model.UeberCertificate) HashMap(java.util.HashMap) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 28 with Pool

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

the class OwnerResourceTest method testEntitlementsRevocationWithNoOverflow.

@Test
public void testEntitlementsRevocationWithNoOverflow() throws Exception {
    Pool pool = doTestEntitlementsRevocationCommon(10, 4, 5);
    assertEquals(9L, this.poolCurator.find(pool.getId()).getConsumed().longValue());
}
Also used : Pool(org.candlepin.model.Pool) Test(org.junit.Test)

Example 29 with Pool

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

the class OwnerResourceTest method testRefreshPoolsWithRemovedMasterPool.

// test covers scenario from bug 1012386
@Test
public void testRefreshPoolsWithRemovedMasterPool() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
    productCurator.merge(prod);
    config.setProperty(ConfigProperties.STANDALONE, "false");
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
    Subscription sub = TestUtil.createSubscription(owner, prod, new HashSet<>());
    sub.setId(Util.generateDbUUID());
    sub.setQuantity(2000L);
    sub.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub.setModified(TestUtil.createDate(2010, 2, 12));
    subscriptions.add(sub);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    List<Pool> pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
    assertEquals(2, pools.size());
    String bonusId = "";
    String masterId = "";
    for (Pool p : pools) {
        if (p.getSourceSubscription().getSubscriptionSubKey().equals("master")) {
            poolCurator.delete(p);
            masterId = p.getId();
        } else {
            bonusId = p.getId();
        }
    }
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    assertNull("Original Master Pool should be gone", poolCurator.find(masterId));
    assertNotNull("Bonus Pool should be the same", poolCurator.find(bonusId));
    // master pool should have been recreated
    pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
    assertEquals(2, pools.size());
    boolean newMaster = false;
    for (Pool p : pools) {
        if (p.getSourceSubscription().getSubscriptionSubKey().equals("master")) {
            newMaster = true;
        }
    }
    assertTrue(newMaster);
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Test(org.junit.Test)

Example 30 with Pool

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

the class OwnerResourceTest method testRefreshPoolsWithRemovedBonusPool.

// test covers a corollary scenario from bug 1012386
@Test
public void testRefreshPoolsWithRemovedBonusPool() {
    Product prod = this.createProduct(owner);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
    productCurator.merge(prod);
    config.setProperty(ConfigProperties.STANDALONE, "false");
    List<Subscription> subscriptions = new LinkedList<>();
    ImportSubscriptionServiceAdapter subAdapter = new ImportSubscriptionServiceAdapter(subscriptions);
    OwnerServiceAdapter ownerAdapter = new DefaultOwnerServiceAdapter(this.ownerCurator, this.i18n);
    Subscription sub = TestUtil.createSubscription(owner, prod, new HashSet<>());
    sub.setId(Util.generateDbUUID());
    sub.setQuantity(2000L);
    sub.setStartDate(TestUtil.createDate(2010, 2, 9));
    sub.setEndDate(TestUtil.createDate(3000, 2, 9));
    sub.setModified(TestUtil.createDate(2010, 2, 12));
    subscriptions.add(sub);
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    List<Pool> pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
    assertEquals(2, pools.size());
    String bonusId = "";
    String masterId = "";
    for (Pool p : pools) {
        if (p.getSourceSubscription().getSubscriptionSubKey().equals("derived")) {
            poolCurator.delete(p);
            bonusId = p.getId();
        } else {
            masterId = p.getId();
        }
    }
    // Trigger the refresh:
    poolManager.getRefresher(subAdapter, ownerAdapter).add(owner).run();
    assertNull("Original bonus pool should be gone", poolCurator.find(bonusId));
    assertNotNull("Master pool should be the same", poolCurator.find(masterId));
    // master pool should have been recreated
    pools = poolCurator.lookupBySubscriptionId(owner, sub.getId());
    assertEquals(2, pools.size());
    boolean newBonus = false;
    for (Pool p : pools) {
        if (p.getSourceSubscription().getSubscriptionSubKey().equals("derived")) {
            newBonus = true;
        }
    }
    assertTrue(newBonus);
}
Also used : ImportSubscriptionServiceAdapter(org.candlepin.service.impl.ImportSubscriptionServiceAdapter) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) LinkedList(java.util.LinkedList) DefaultOwnerServiceAdapter(org.candlepin.service.impl.DefaultOwnerServiceAdapter) 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