use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class SubscriptionReconcilerTest method testThreeExistThreeNewOneDifferent.
@Test
public void testThreeExistThreeNewOneDifferent() {
Subscription testSub2 = createSubscription(owner, "test-prod-1", "up1", "ue2", "uc1", 20);
Subscription testSub3 = createSubscription(owner, "test-prod-1", "up1", "ue3", "uc1", 15);
Subscription testSub4 = createSubscription(owner, "test-prod-1", "up1", "ue4", "uc1", 10);
Subscription testSub5 = createSubscription(owner, "test-prod-1", "up1", "ue5", "uc1", 5);
createPoolsFor(testSub2, testSub3, testSub4);
reconciler.reconcile(owner, Arrays.asList(testSub2, testSub4, testSub5));
assertUpstream(testSub2, testSub2.getId());
assertUpstream(testSub4, testSub4.getId());
// Should assume subscription 3's ID:
assertUpstream(testSub5, testSub3.getId());
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method createPoolsForExistingSubscriptionsNoneExist.
@Test
public void createPoolsForExistingSubscriptionsNoneExist() {
Owner owner = this.getOwner();
PoolRules pRules = new PoolRules(manager, mockConfig, entitlementCurator, mockOwnerProductCurator, mockProductCurator);
List<Subscription> subscriptions = new ArrayList<>();
Product prod = TestUtil.createProduct();
Set<Product> products = new HashSet<>();
products.add(prod);
prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
// productCache.addProducts(products);
Subscription s = TestUtil.createSubscription(owner, prod);
subscriptions.add(s);
this.mockProducts(owner, prod);
when(mockSubAdapter.getSubscriptions(any(Owner.class))).thenReturn(subscriptions);
when(mockConfig.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
List<Pool> existingPools = new LinkedList<>();
List<Pool> newPools = pRules.createAndEnrichPools(s, existingPools);
assertEquals(newPools.size(), 2);
assertTrue(newPools.get(0).getSourceSubscription().getSubscriptionSubKey().equals("derived") || newPools.get(1).getSourceSubscription().getSubscriptionSubKey().equals("derived"));
assertTrue(newPools.get(0).getSourceSubscription().getSubscriptionSubKey().startsWith("master") || newPools.get(1).getSourceSubscription().getSubscriptionSubKey().startsWith("master"));
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method testFabricateSubscriptionFromPool.
@Test
public void testFabricateSubscriptionFromPool() {
Product product = TestUtil.createProduct("product", "Product");
Product provided1 = TestUtil.createProduct("provided-1", "Provided 1");
Product provided2 = TestUtil.createProduct("provided-2", "Provided 2");
product.setLocked(true);
provided1.setLocked(true);
provided2.setLocked(true);
ProductData productDTO = product.toDTO();
ProductData provided1DTO = provided1.toDTO();
ProductData provided2DTO = provided2.toDTO();
Pool pool = mock(Pool.class);
HashSet<Product> provided = new HashSet<>();
HashSet<ProductData> providedDTOs = new HashSet<>();
provided.add(provided1);
provided.add(provided2);
providedDTOs.add(provided1DTO);
providedDTOs.add(provided2DTO);
Long quantity = new Long(42);
Date startDate = new Date(System.currentTimeMillis() - 86400000);
Date endDate = new Date(System.currentTimeMillis() + 86400000);
Date updated = new Date();
String subscriptionId = "test-subscription-1";
when(pool.getOwner()).thenReturn(owner);
when(pool.getProduct()).thenReturn(product);
when(mockProductCurator.getPoolProvidedProductsCached(any(Pool.class))).thenReturn(provided);
when(pool.getQuantity()).thenReturn(quantity);
when(pool.getStartDate()).thenReturn(startDate);
when(pool.getEndDate()).thenReturn(endDate);
when(pool.getUpdated()).thenReturn(updated);
when(pool.getSubscriptionId()).thenReturn(subscriptionId);
// TODO: Add other attributes to check here.
Subscription fabricated = manager.fabricateSubscriptionFromPool(pool);
pool.populateAllTransientProvidedProducts(mockProductCurator);
assertEquals(owner, fabricated.getOwner());
assertEquals(productDTO, fabricated.getProduct());
assertEquals(providedDTOs, fabricated.getProvidedProducts());
assertEquals(quantity, fabricated.getQuantity());
assertEquals(startDate, fabricated.getStartDate());
assertEquals(endDate, fabricated.getEndDate());
assertEquals(updated, fabricated.getModified());
assertEquals(subscriptionId, fabricated.getId());
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method brandingCopiedWhenCreatingPools.
@Test
public void brandingCopiedWhenCreatingPools() {
Product product = TestUtil.createProduct();
Subscription sub = TestUtil.createSubscription(owner, product);
Branding b1 = new Branding("8000", "OS", "Branded Awesome OS");
Branding b2 = new Branding("8001", "OS", "Branded Awesome OS 2");
sub.getBranding().add(b1);
sub.getBranding().add(b2);
this.mockProducts(owner, product);
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(2, resultPool.getBranding().size());
assertTrue(resultPool.getBranding().contains(b1));
assertTrue(resultPool.getBranding().contains(b2));
}
use of org.candlepin.model.dto.Subscription in project candlepin by candlepin.
the class PoolManagerTest method testRefreshPoolsOnlyRegeneratesFloatingWhenNecessary.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRefreshPoolsOnlyRegeneratesFloatingWhenNecessary() {
List<Subscription> subscriptions = new ArrayList<>();
Owner owner = this.getOwner();
Product product = TestUtil.createProduct();
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setId("testing-subid");
subscriptions.add(sub);
// Set up pools
List<Pool> pools = new ArrayList<>();
// Should be unchanged
Pool p = TestUtil.createPool(product);
p.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
pools.add(p);
// Should be regenerated because it has no subscription id
Pool floating = TestUtil.createPool(TestUtil.createProduct());
floating.setSourceSubscription(null);
pools.add(floating);
mockSubsList(subscriptions);
mockPoolsList(pools);
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();
List<Pool> expectedFloating = new LinkedList();
// Make sure that only the floating pool was regenerated
expectedFloating.add(floating);
verify(this.manager).updateFloatingPools(eq(expectedFloating), eq(true), any(Map.class));
}
Aggregations