use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method testDeleteExcessEntitlementsBatch.
@Test
public void testDeleteExcessEntitlementsBatch() throws EntitlementRefusedException {
ConsumerType ctype = this.mockConsumerType(TestUtil.createConsumerType());
Consumer consumer = TestUtil.createConsumer(ctype, owner);
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setId("testing-subid");
pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
final Pool derivedPool = TestUtil.createPool(owner, product, 1);
derivedPool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
derivedPool.setSourceSubscription(new SourceSubscription(sub.getId(), "der"));
derivedPool.setConsumed(3L);
derivedPool.setId("derivedPool");
Entitlement masterEnt = new Entitlement(pool, consumer, owner, 5);
Entitlement derivedEnt = new Entitlement(derivedPool, consumer, owner, 1);
derivedEnt.setId("1");
Entitlement derivedEnt2 = new Entitlement(derivedPool, consumer, owner, 1);
derivedEnt2.setId("2");
final Pool derivedPool2 = TestUtil.createPool(owner, product, 1);
derivedPool2.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
derivedPool2.setSourceSubscription(new SourceSubscription(sub.getId(), "der"));
derivedPool2.setConsumed(2L);
derivedPool2.setId("derivedPool2");
Entitlement derivedEnt3 = new Entitlement(derivedPool2, consumer, owner, 1);
derivedEnt3.setId("3");
Set<Entitlement> ents = new HashSet<>();
ents.add(derivedEnt);
ents.add(derivedEnt2);
derivedPool.setEntitlements(ents);
Set<Entitlement> ents2 = new HashSet<>();
ents2.add(derivedEnt3);
derivedPool2.setEntitlements(ents2);
Pool derivedPool3 = TestUtil.createPool(owner, product, 1);
derivedPool3.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
derivedPool3.setSourceSubscription(new SourceSubscription(sub.getId(), "der"));
derivedPool3.setConsumed(2L);
derivedPool3.setId("derivedPool3");
// before
assertEquals(3, derivedPool.getConsumed().intValue());
assertEquals(2, derivedPool2.getConsumed().intValue());
assertEquals(2, derivedPool3.getConsumed().intValue());
when(mockPoolCurator.lockAndLoad(pool)).thenReturn(pool);
when(enforcerMock.update(any(Consumer.class), any(Entitlement.class), any(Integer.class))).thenReturn(new ValidationResult());
when(mockPoolCurator.lookupOversubscribedBySubscriptionIds(any(String.class), anyMap())).thenReturn(Arrays.asList(derivedPool, derivedPool2, derivedPool3));
when(mockPoolCurator.retrieveOrderedEntitlementsOf(eq(Arrays.asList(derivedPool)))).thenReturn(Arrays.asList(derivedEnt, derivedEnt2));
when(mockPoolCurator.retrieveOrderedEntitlementsOf(eq(Arrays.asList(derivedPool2)))).thenReturn(Arrays.asList(derivedEnt3));
when(mockPoolCurator.retrieveOrderedEntitlementsOf(eq(Arrays.asList(derivedPool3)))).thenReturn(new ArrayList<>());
Collection<Pool> overPools = new ArrayList<Pool>() {
{
add(derivedPool);
add(derivedPool2);
}
};
when(mockPoolCurator.lockAndLoad(any(Collection.class))).thenReturn(overPools);
when(mockPoolCurator.lockAndLoad(eq(derivedPool))).thenReturn(derivedPool);
when(mockPoolCurator.lockAndLoad(eq(derivedPool2))).thenReturn(derivedPool2);
when(mockPoolCurator.lockAndLoad(eq(derivedPool3))).thenReturn(derivedPool3);
pool.setId("masterpool");
manager.adjustEntitlementQuantity(consumer, masterEnt, 3);
Class<List<Entitlement>> listClass = (Class<List<Entitlement>>) (Class) ArrayList.class;
ArgumentCaptor<List<Entitlement>> arg = ArgumentCaptor.forClass(listClass);
verify(entitlementCurator).batchDelete(arg.capture());
List<Entitlement> entsDeleted = arg.getValue();
assertThat(entsDeleted, hasItems(derivedEnt, derivedEnt2, derivedEnt3));
assertEquals(1, derivedPool.getConsumed().intValue());
assertEquals(1, derivedPool2.getConsumed().intValue());
assertEquals(2, derivedPool3.getConsumed().intValue());
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method testCreatePoolForSubscription.
@Test
public void testCreatePoolForSubscription() {
Product product = TestUtil.createProduct();
Subscription s = TestUtil.createSubscription(getOwner(), product);
List<Pool> newPools = new LinkedList<>();
Pool p = TestUtil.createPool(product);
p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
newPools.add(p);
when(poolRulesMock.createAndEnrichPools(eq(s), any(List.class))).thenReturn(newPools);
this.manager.createAndEnrichPools(s);
verify(this.mockPoolCurator, times(1)).create(any(Pool.class));
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method mockSubsList.
private void mockSubsList(List<Subscription> subs) {
List<String> subIds = new LinkedList<>();
for (Subscription sub : subs) {
subIds.add(sub.getId());
when(mockSubAdapter.getSubscription(eq(sub.getId()))).thenReturn(sub);
}
when(mockSubAdapter.getSubscriptionIds(any(Owner.class))).thenReturn(subIds);
when(mockSubAdapter.getSubscriptions(any(Owner.class))).thenReturn(subs);
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method derivedProvidedProductsCopiedOntoMasterPoolWhenCreatingNewPool.
@Test
public void derivedProvidedProductsCopiedOntoMasterPoolWhenCreatingNewPool() {
Product product = TestUtil.createProduct();
Product subProduct = TestUtil.createProduct();
Product subProvidedProduct = TestUtil.createProduct();
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setDerivedProduct(subProduct.toDTO());
Set<ProductData> subProvided = new HashSet<>();
subProvided.add(subProvidedProduct.toDTO());
sub.setDerivedProvidedProducts(subProvided);
this.mockProducts(owner, product, subProduct, subProvidedProduct);
PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
List<Pool> pools = pRules.createAndEnrichPools(sub);
assertEquals(1, pools.size());
Pool resultPool = pools.get(0);
assertEquals(1, resultPool.getDerivedProvidedProducts().size());
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method testCleanupExpiredPoolsReadOnlySubscriptions.
@Test
public void testCleanupExpiredPoolsReadOnlySubscriptions() {
Pool p = createPoolWithEntitlements();
p.setSubscriptionId("subid");
List<Pool> pools = Arrays.asList(p);
when(mockPoolCurator.lockAndLoadByIds(anyCollection())).thenReturn(pools);
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(true);
PreUnbindHelper preHelper = mock(PreUnbindHelper.class);
ValidationResult result = new ValidationResult();
when(preHelper.getResult()).thenReturn(result);
manager.cleanupExpiredPools();
// And the pool should be deleted:
verify(mockPoolCurator).batchDelete(eq(pools), anySetOf(String.class));
verify(mockSubAdapter, never()).getSubscription(any(String.class));
verify(mockSubAdapter, never()).deleteSubscription(any(Subscription.class));
}
Aggregations