Search in sources :

Example 76 with Owner

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

the class OwnerManagerTest method testContentAccessModeBlankSelection.

@Test(expected = IllegalStateException.class)
public void testContentAccessModeBlankSelection() {
    Owner owner = new Owner("test_owner", "test_owner");
    when(ownerCurator.lockAndLoad(eq(owner))).thenReturn(owner);
    when(ownerServiceAdapter.getContentAccessModeList(eq(owner.getKey()))).thenReturn("one,two");
    when(ownerServiceAdapter.getContentAccessMode(eq(owner.getKey()))).thenReturn("");
    ownerManager.refreshContentAccessMode(ownerServiceAdapter, owner);
}
Also used : Owner(org.candlepin.model.Owner) Test(org.junit.Test)

Example 77 with Owner

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

the class OwnerManagerTest method testContentAccessSetNull.

@Test
public void testContentAccessSetNull() {
    Owner owner = new Owner();
    when(ownerCurator.lockAndLoad(eq(owner))).thenReturn(owner);
    when(ownerServiceAdapter.getContentAccessModeList(eq(owner.getKey()))).thenReturn(null);
    when(ownerServiceAdapter.getContentAccessMode(eq(owner.getKey()))).thenReturn(null);
    ownerManager.refreshContentAccessMode(ownerServiceAdapter, owner);
    Assert.assertEquals(owner.getContentAccessModeList(), ContentAccessCertServiceAdapter.DEFAULT_CONTENT_ACCESS_MODE);
    Assert.assertEquals(owner.getContentAccessMode(), ContentAccessCertServiceAdapter.DEFAULT_CONTENT_ACCESS_MODE);
}
Also used : Owner(org.candlepin.model.Owner) Test(org.junit.Test)

Example 78 with Owner

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

the class PoolManagerTest method createPoolsForExistingSubscriptionsMasterExist.

@Test
public void createPoolsForExistingSubscriptionsMasterExist() {
    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);
    // productCache.addProducts(products);
    prod.setAttribute(Product.Attributes.VIRT_LIMIT, "4");
    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<>();
    Pool p = TestUtil.createPool(prod);
    p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
    existingPools.add(p);
    List<Pool> newPools = pRules.createAndEnrichPools(s, existingPools);
    assertEquals(newPools.size(), 1);
    assertEquals(newPools.get(0).getSourceSubscription().getSubscriptionSubKey(), "derived");
}
Also used : Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) 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 79 with Owner

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

the class PoolManagerTest method refreshPoolsCreatingPoolsForExistingSubscriptions.

@Test
public void refreshPoolsCreatingPoolsForExistingSubscriptions() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    Owner owner = this.getOwner();
    Product product = TestUtil.createProduct();
    product.setLocked(true);
    Subscription s = TestUtil.createSubscription(owner, product);
    subscriptions.add(s);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    List<Pool> newPools = new LinkedList<>();
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(new SourceSubscription(s.getId(), "master"));
    newPools.add(p);
    ArgumentCaptor<Pool> argPool = ArgumentCaptor.forClass(Pool.class);
    when(poolRulesMock.createAndEnrichPools(argPool.capture(), any(List.class))).thenReturn(newPools);
    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);
    cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(Collections.<Pool>emptyList());
    when(mockPoolCurator.getPoolsBySubscriptionIds(anyList())).thenReturn(cqmock);
    cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(Collections.<Pool>emptyList());
    when(mockPoolCurator.getPoolsBySubscriptionId(anyString())).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    TestUtil.assertPoolsAreEqual(TestUtil.copyFromSub(s), argPool.getValue());
    verify(this.mockPoolCurator, times(1)).create(any(Pool.class));
}
Also used : 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) CandlepinQuery(org.candlepin.model.CandlepinQuery) LinkedList(java.util.LinkedList) 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) Test(org.junit.Test)

Example 80 with Owner

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

the class PoolManagerTest method testRefreshPoolsDeletesOrphanedHostedVirtBonusPool.

@Test
public void testRefreshPoolsDeletesOrphanedHostedVirtBonusPool() {
    List<Subscription> subscriptions = new ArrayList<>();
    List<Pool> pools = new ArrayList<>();
    Product product = TestUtil.createProduct();
    Pool p = TestUtil.createPool(product);
    p.setSourceSubscription(new SourceSubscription("112", "master"));
    // Make it look like a hosted virt bonus pool:
    p.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
    p.setSourceStack(null);
    p.setSourceEntitlement(null);
    pools.add(p);
    mockSubsList(subscriptions);
    mockPoolsList(pools);
    Owner owner = getOwner();
    when(mockOwnerCurator.lookupByKey(owner.getKey())).thenReturn(owner);
    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);
    cqmock = mock(CandlepinQuery.class);
    when(cqmock.list()).thenReturn(Collections.<Pool>emptyList());
    when(mockPoolCurator.getPoolsBySubscriptionIds(anyList())).thenReturn(cqmock);
    this.manager.getRefresher(mockSubAdapter, mockOwnerAdapter).add(owner).run();
    List<Pool> delPools = Arrays.asList(p);
    verify(this.manager).deletePools(eq(delPools));
}
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) CandlepinQuery(org.candlepin.model.CandlepinQuery) Subscription(org.candlepin.model.dto.Subscription) SourceSubscription(org.candlepin.model.SourceSubscription) Test(org.junit.Test)

Aggregations

Owner (org.candlepin.model.Owner)405 Test (org.junit.Test)254 Product (org.candlepin.model.Product)153 Consumer (org.candlepin.model.Consumer)127 Pool (org.candlepin.model.Pool)79 Date (java.util.Date)72 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)71 ArrayList (java.util.ArrayList)58 Produces (javax.ws.rs.Produces)52 ConsumerType (org.candlepin.model.ConsumerType)52 ApiOperation (io.swagger.annotations.ApiOperation)50 HashSet (java.util.HashSet)44 Entitlement (org.candlepin.model.Entitlement)44 Path (javax.ws.rs.Path)42 HashMap (java.util.HashMap)41 ApiResponses (io.swagger.annotations.ApiResponses)40 Content (org.candlepin.model.Content)39 BadRequestException (org.candlepin.common.exceptions.BadRequestException)37 Subscription (org.candlepin.model.dto.Subscription)32 List (java.util.List)29