Search in sources :

Example 36 with Entitlement

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

the class EntitlementCertificateGeneratorTest method testNonLazyRegenerate.

@Test
public void testNonLazyRegenerate() throws Exception {
    Owner owner = TestUtil.createOwner("test-owner", "Test Owner");
    Product product = TestUtil.createProduct();
    Pool pool = TestUtil.createPool(owner, product);
    pool.setSourceSubscription(new SourceSubscription("source-sub-id", "master"));
    Map<String, EntitlementCertificate> entCerts = new HashMap<>();
    entCerts.put(pool.getId(), new EntitlementCertificate());
    when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), anyMapOf(String.class, PoolQuantity.class), anyMapOf(String.class, Entitlement.class), anyMapOf(String.class, Product.class), eq(true))).thenReturn(entCerts);
    Consumer consumer = TestUtil.createConsumer(owner);
    Entitlement entitlement = new Entitlement(pool, consumer, owner, 1);
    entitlement.setDirty(true);
    this.ecGenerator.regenerateCertificatesOf(entitlement, false);
    assertFalse(entitlement.isDirty());
    verify(this.mockEntCertAdapter).generateEntitlementCerts(eq(consumer), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor.capture(), eq(true));
    assertEquals(entitlement, this.entMapCaptor.getValue().get(pool.getId()));
    assertEquals(product, this.productMapCaptor.getValue().get(pool.getId()));
    verify(this.mockEventSink, times(1)).queueEvent(any(Event.class));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Event(org.candlepin.audit.Event) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 37 with Entitlement

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

the class ManifestManagerTest method testGenerateManifest.

@Test
public void testGenerateManifest() throws Exception {
    Consumer consumer = this.createMockConsumer(true);
    Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
    String webAppPrefix = "webapp-prefix";
    String apiUrl = "api-url";
    Map<String, String> extData = new HashMap<>();
    Event event = mock(Event.class);
    when(eventFactory.exportCreated(eq(consumer))).thenReturn(event);
    List<Entitlement> ents = new ArrayList<>();
    when(entitlementCurator.listByConsumer(eq(consumer))).thenReturn(ents);
    when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
    when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
    File manifestFile = mock(File.class);
    when(exporter.getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData))).thenReturn(manifestFile);
    File result = manager.generateManifest(consumer.getUuid(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
    assertEquals(manifestFile, result);
    verify(entitlementCurator).listByConsumer(eq(consumer));
    verify(exporter).getFullExport(eq(consumer), eq(cdn.getLabel()), eq(webAppPrefix), eq(apiUrl), eq(extData));
    verify(eventFactory).exportCreated(eq(consumer));
    verify(eventSink).queueEvent(eq(event));
    verifyZeroInteractions(fileService);
}
Also used : Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Event(org.candlepin.audit.Event) Cdn(org.candlepin.model.Cdn) Entitlement(org.candlepin.model.Entitlement) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) Test(org.junit.Test)

Example 38 with Entitlement

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

the class PoolManagerTest method testRevokeAllEntitlements.

@Test
public void testRevokeAllEntitlements() {
    Consumer c = TestUtil.createConsumer(owner);
    Entitlement e1 = new Entitlement(pool, c, owner, 1);
    Entitlement e2 = new Entitlement(pool, c, owner, 1);
    List<Entitlement> entitlementList = new ArrayList<>();
    entitlementList.add(e1);
    entitlementList.add(e2);
    when(entitlementCurator.listByConsumer(eq(c))).thenReturn(entitlementList);
    when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(pool);
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    int total = manager.revokeAllEntitlements(c);
    assertEquals(2, total);
    verify(entitlementCurator, times(1)).markDependentEntitlementsDirty(any(List.class));
// TODO assert batch revokes have been called
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Consumer(org.candlepin.model.Consumer) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Entitlement(org.candlepin.model.Entitlement) ValidationResult(org.candlepin.policy.ValidationResult) Test(org.junit.Test)

Example 39 with Entitlement

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

the class PoolManagerTest method testRefreshPoolsRemovesOtherOwnerPoolsForSameSub.

@Test
public void testRefreshPoolsRemovesOtherOwnerPoolsForSameSub() {
    PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
    Owner other = new Owner("otherkey", "othername");
    List<Subscription> subscriptions = new ArrayList<>();
    Owner owner = this.getOwner();
    Product product = TestUtil.createProduct();
    product.setLocked(true);
    Subscription sub = TestUtil.createSubscription(owner, product);
    sub.setId("123");
    subscriptions.add(sub);
    mockSubsList(subscriptions);
    List<Pool> pools = new ArrayList<>();
    Pool p = TestUtil.copyFromSub(sub);
    p.setOwner(other);
    p.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
    p.setConsumed(1L);
    pools.add(p);
    when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(p);
    mockPoolsList(pools);
    List<Entitlement> poolEntitlements = new ArrayList<>();
    Entitlement ent = TestUtil.createEntitlement();
    ent.setPool(p);
    ent.setQuantity(1);
    poolEntitlements.add(ent);
    when(mockPoolCurator.entitlementsIn(eq(p))).thenReturn(poolEntitlements);
    ValidationResult result = new ValidationResult();
    when(preHelper.getResult()).thenReturn(result);
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    this.mockProducts(owner, product);
    this.mockProductImport(owner, product);
    this.mockContentImport(owner, new Content[] {});
    CandlepinQuery<Pool> cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(pools);
    when(cqmock.iterator()).thenReturn(pools.iterator());
    when(mockPoolCurator.listByOwnerAndType(eq(owner), any(PoolType.class))).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    // The pool left over from the pre-migrated subscription should be deleted
    // and granted entitlements should be revoked
    List<Entitlement> entsToDelete = Arrays.asList(ent);
    verify(mockPoolCurator).delete(eq(p));
    verify(entitlementCurator).batchDelete(eq(entsToDelete));
    // Make sure pools that don't match the owner were removed from the list
    // They shouldn't cause us to attempt to update existing pools when we
    // haven't created them in the first place
    ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
    verify(poolRulesMock).createAndEnrichPools(argPool.capture(), any(List.class));
    TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(sub), argPool.getValue());
}
Also used : PreUnbindHelper(org.candlepin.policy.js.entitlement.PreUnbindHelper) Owner(org.candlepin.model.Owner) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ValidationResult(org.candlepin.policy.ValidationResult) SourceSubscription(org.candlepin.model.SourceSubscription) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 40 with Entitlement

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

the class PoolManagerTest method testIsManaged.

@Test
@Parameters(method = "getParametersForIsManagedTests")
public void testIsManaged(PoolType type, SourceSubscription srcSub, String upstreamPoolId, boolean hosted, boolean expected) {
    Pool pool = TestUtil.createPool(owner, product);
    when(mockConfig.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(!hosted);
    when(mockConfig.getBoolean(eq(ConfigProperties.STANDALONE), anyBoolean())).thenReturn(!hosted);
    pool.setSourceSubscription(srcSub);
    pool.setUpstreamPoolId(upstreamPoolId);
    switch(type) {
        case UNMAPPED_GUEST:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            pool.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
            break;
        case ENTITLEMENT_DERIVED:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            pool.setSourceEntitlement(new Entitlement());
            break;
        case STACK_DERIVED:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            pool.setSourceStack(new SourceStack());
            break;
        case BONUS:
            pool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
            break;
        case DEVELOPMENT:
            pool.setAttribute(Pool.Attributes.DEVELOPMENT_POOL, "true");
            break;
        case NORMAL:
        default:
    }
    boolean output = manager.isManaged(pool);
    assertEquals(expected, output);
}
Also used : SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

Entitlement (org.candlepin.model.Entitlement)301 Test (org.junit.Test)201 Consumer (org.candlepin.model.Consumer)164 Pool (org.candlepin.model.Pool)125 LinkedList (java.util.LinkedList)84 Product (org.candlepin.model.Product)68 Date (java.util.Date)62 ArrayList (java.util.ArrayList)61 HashSet (java.util.HashSet)59 HashMap (java.util.HashMap)55 Owner (org.candlepin.model.Owner)44 PoolQuantity (org.candlepin.model.PoolQuantity)35 ConsumerType (org.candlepin.model.ConsumerType)34 List (java.util.List)30 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)24 Matchers.anyString (org.mockito.Matchers.anyString)17 Set (java.util.Set)16 Subscription (org.candlepin.model.dto.Subscription)16 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15