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));
}
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());
}
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);
}
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());
}
}
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");
}
}
Aggregations