Search in sources :

Example 71 with Subscription

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());
}
Also used : Subscription(org.candlepin.model.dto.Subscription) Test(org.junit.Test)

Example 72 with Subscription

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"));
}
Also used : Owner(org.candlepin.model.Owner) PoolRules(org.candlepin.policy.js.pool.PoolRules) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 73 with Subscription

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());
}
Also used : ProductData(org.candlepin.model.dto.ProductData) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 74 with Subscription

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));
}
Also used : PoolRules(org.candlepin.policy.js.pool.PoolRules) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Branding(org.candlepin.model.Branding) Test(org.junit.Test)

Example 75 with Subscription

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));
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) PoolType(org.candlepin.model.Pool.PoolType) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Subscription (org.candlepin.model.dto.Subscription)101 Test (org.junit.Test)77 Pool (org.candlepin.model.Pool)60 Product (org.candlepin.model.Product)48 SourceSubscription (org.candlepin.model.SourceSubscription)36 LinkedList (java.util.LinkedList)35 ArrayList (java.util.ArrayList)34 Owner (org.candlepin.model.Owner)33 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)27 HashMap (java.util.HashMap)20 HashSet (java.util.HashSet)18 Matchers.anyString (org.mockito.Matchers.anyString)18 Entitlement (org.candlepin.model.Entitlement)16 Date (java.util.Date)15 PoolType (org.candlepin.model.Pool.PoolType)13 ImportSubscriptionServiceAdapter (org.candlepin.service.impl.ImportSubscriptionServiceAdapter)13 List (java.util.List)11 OwnerServiceAdapter (org.candlepin.service.OwnerServiceAdapter)11 ConsumerType (org.candlepin.model.ConsumerType)10 ProductData (org.candlepin.model.dto.ProductData)9