Search in sources :

Example 21 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class PoolManagerTest method testEntitleByProductsEmptyArray.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testEntitleByProductsEmptyArray() throws Exception {
    Product product = TestUtil.createProduct();
    List<Pool> pools = new ArrayList<>();
    Pool pool1 = TestUtil.createPool(product);
    pools.add(pool1);
    Date now = new Date();
    ValidationResult result = mock(ValidationResult.class);
    // Setup an installed product for the consumer, we'll make the bind request
    // with no products specified, so this should get used instead:
    String[] installedPids = new String[] { product.getUuid() };
    ComplianceStatus mockCompliance = new ComplianceStatus(now);
    mockCompliance.addNonCompliantProduct(installedPids[0]);
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class), any(Boolean.class))).thenReturn(mockCompliance);
    Page page = mock(Page.class);
    when(page.getPageData()).thenReturn(pools);
    when(mockPoolCurator.listAvailableEntitlementPools(any(Consumer.class), any(String.class), anyString(), anyString(), eq(now), any(PoolFilterBuilder.class), any(PageRequest.class), anyBoolean(), anyBoolean(), anyBoolean(), any(Date.class))).thenReturn(page);
    CandlepinQuery mockQuery = mock(CandlepinQuery.class);
    when(mockPoolCurator.listAllByIds(any(List.class))).thenReturn(mockQuery);
    when(mockQuery.iterator()).thenReturn(Arrays.asList(pool1).listIterator());
    when(enforcerMock.preEntitlement(any(Consumer.class), any(Pool.class), anyInt(), any(CallerType.class))).thenReturn(result);
    when(result.isSuccessful()).thenReturn(true);
    List<PoolQuantity> bestPools = new ArrayList<>();
    bestPools.add(new PoolQuantity(pool1, 1));
    when(autobindRules.selectBestPools(any(Consumer.class), any(String[].class), any(List.class), any(ComplianceStatus.class), any(String.class), any(Set.class), eq(false))).thenReturn(bestPools);
    // Make the call but provide a null array of product IDs (simulates healing):
    ConsumerType ctype = this.mockConsumerType(TestUtil.createConsumerType());
    Consumer consumer = TestUtil.createConsumer(ctype, owner);
    AutobindData data = AutobindData.create(consumer, owner).on(now);
    manager.entitleByProducts(data);
    verify(autobindRules).selectBestPools(any(Consumer.class), eq(installedPids), any(List.class), eq(mockCompliance), any(String.class), any(Set.class), eq(false));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Set(java.util.Set) HashSet(java.util.HashSet) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Page(org.candlepin.common.paging.Page) CandlepinQuery(org.candlepin.model.CandlepinQuery) Matchers.anyString(org.mockito.Matchers.anyString) CallerType(org.candlepin.policy.js.entitlement.Enforcer.CallerType) ValidationResult(org.candlepin.policy.ValidationResult) Date(java.util.Date) PageRequest(org.candlepin.common.paging.PageRequest) Consumer(org.candlepin.model.Consumer) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) AutobindData(org.candlepin.resource.dto.AutobindData) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Example 22 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class PoolManagerFunctionalTest method testRevocation.

@Test
public void testRevocation() throws Exception {
    AutobindData data = AutobindData.create(parentSystem, o).on(new Date()).forProducts(new String[] { monitoring.getId() });
    Entitlement e = poolManager.entitleByProducts(data).get(0);
    poolManager.revokeEntitlement(e);
    List<Entitlement> entitlements = entitlementCurator.listByConsumer(parentSystem);
    assertTrue(entitlements.isEmpty());
}
Also used : AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) Test(org.junit.Test)

Example 23 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class EntitlerTest method testDevPoolCreationAtBindNoFailMissingInstalledProduct.

@Test
public void testDevPoolCreationAtBindNoFailMissingInstalledProduct() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    Product ip1 = TestUtil.createProduct("test-product-installed-1", "Installed Test Product 1");
    Product ip2 = TestUtil.createProduct("test-product-installed-2", "Installed Test Product 2");
    devProdDTOs.add(p.toDTO());
    devProdDTOs.add(ip1.toDTO());
    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<>();
    activeList.add(activePool);
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(ip1));
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(ip2));
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
    when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
    when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
    this.mockProducts(owner, p, ip1, ip2);
    this.mockProductImport(owner, p, ip1, ip2);
    this.mockContentImport(owner, Collections.<String, Content>emptyMap());
    Pool expectedPool = entitler.assembleDevPool(devSystem, owner, p.getId());
    when(pm.createPool(any(Pool.class))).thenReturn(expectedPool);
    AutobindData ad = new AutobindData(devSystem, owner);
    entitler.bindByProducts(ad);
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) AutobindData(org.candlepin.resource.dto.AutobindData) Date(java.util.Date) Test(org.junit.Test)

Example 24 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class EntitlerTest method testDevPoolCreationAtBindFailNoSkuProduct.

@Test
public void testDevPoolCreationAtBindFailNoSkuProduct() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    Product ip = TestUtil.createProduct("test-product-installed", "Installed Test Product");
    devProdDTOs.add(ip.toDTO());
    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<>();
    activeList.add(activePool);
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(ip));
    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
    when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
    when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
    when(ownerProductCurator.getProductById(eq(owner), eq(p.getId()))).thenReturn(p);
    when(ownerProductCurator.getProductById(eq(owner), eq(ip.getId()))).thenReturn(ip);
    mockUpdateProduct(p, owner);
    mockUpdateProduct(ip, owner);
    mockProductImport(owner, p, ip);
    mockContentImport(owner, new Content[] {});
    AutobindData ad = new AutobindData(devSystem, owner);
    try {
        entitler.bindByProducts(ad);
    } catch (ForbiddenException fe) {
        assertEquals(i18n.tr("SKU product not available to this development unit: \"{0}\"", p.getId()), fe.getMessage());
    }
}
Also used : ProductData(org.candlepin.model.dto.ProductData) Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Consumer(org.candlepin.model.Consumer) Pool(org.candlepin.model.Pool) List(java.util.List) ArrayList(java.util.ArrayList) AutobindData(org.candlepin.resource.dto.AutobindData) Test(org.junit.Test)

Example 25 with AutobindData

use of org.candlepin.resource.dto.AutobindData in project candlepin by candlepin.

the class EntitlerTest method bindByProductErrorTest.

private void bindByProductErrorTest(String msg) throws Exception {
    try {
        String[] pids = { "prod1", "prod2", "prod3" };
        Map<String, ValidationResult> fakeResult = new HashMap<>();
        fakeResult.put("blah", fakeOutResult(msg));
        EntitlementRefusedException ere = new EntitlementRefusedException(fakeResult);
        AutobindData data = AutobindData.create(consumer, owner).forProducts(pids);
        when(pm.entitleByProducts(data)).thenThrow(ere);
        entitler.bindByProducts(data);
    } catch (EntitlementRefusedException e) {
        fail(msg + ": threw unexpected error");
    }
}
Also used : HashMap(java.util.HashMap) EntitlementRefusedException(org.candlepin.policy.EntitlementRefusedException) AutobindData(org.candlepin.resource.dto.AutobindData) ValidationResult(org.candlepin.policy.ValidationResult)

Aggregations

AutobindData (org.candlepin.resource.dto.AutobindData)27 Test (org.junit.Test)22 Date (java.util.Date)18 Consumer (org.candlepin.model.Consumer)17 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)16 Product (org.candlepin.model.Product)15 ArrayList (java.util.ArrayList)13 Pool (org.candlepin.model.Pool)13 Owner (org.candlepin.model.Owner)12 HashSet (java.util.HashSet)11 Entitlement (org.candlepin.model.Entitlement)10 List (java.util.List)8 ProductData (org.candlepin.model.dto.ProductData)5 LinkedList (java.util.LinkedList)4 CandlepinQuery (org.candlepin.model.CandlepinQuery)4 ValidationResult (org.candlepin.policy.ValidationResult)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Set (java.util.Set)3 Page (org.candlepin.common.paging.Page)3 PageRequest (org.candlepin.common.paging.PageRequest)3