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));
}
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);
}
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
}
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());
}
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);
}
Aggregations