use of org.candlepin.model.dto.ProductData in project candlepin by candlepin.
the class RefresherTest method testPoolOnlyExaminedOnceProductAndOwner.
@Test
public void testPoolOnlyExaminedOnceProductAndOwner() {
Owner owner = TestUtil.createOwner();
Product product = mock(Product.class);
ProductData productData = mock(ProductData.class);
when(product.getUuid()).thenReturn("product id");
when(product.toDTO()).thenReturn(productData);
Pool pool = new Pool();
pool.setSourceSubscription(new SourceSubscription("subId", "master"));
pool.setOwner(owner);
Subscription subscription = new Subscription();
subscription.setId("subId");
subscription.setOwner(owner);
List<Pool> pools = new ArrayList<>();
pools.add(pool);
List<Subscription> subscriptions = new ArrayList<>();
subscriptions.add(subscription);
when(subAdapter.getSubscriptions(eq(productData))).thenReturn(subscriptions);
when(subAdapter.getSubscriptions(owner)).thenReturn(subscriptions);
when(subAdapter.getSubscription("subId")).thenReturn(subscription);
when(poolManager.lookupBySubscriptionId(owner, "subId")).thenReturn(pools);
refresher.add(owner);
refresher.add(product);
refresher.run();
verify(poolManager, times(1)).refreshPoolsWithRegeneration(eq(subAdapter), eq(owner), eq(false));
verify(poolManager, times(0)).updatePoolsForMasterPool(any(List.class), any(Pool.class), eq(pool.getQuantity()), eq(false), any(Map.class));
}
use of org.candlepin.model.dto.ProductData in project candlepin by candlepin.
the class EntitlerTest method testCreatedDevSkuWithNoSla.
@Test
public void testCreatedDevSkuWithNoSla() {
Owner owner = TestUtil.createOwner("o");
List<ProductData> devProdDTOs = new ArrayList<>();
final Product p1 = TestUtil.createProduct("dev-product", "Dev Product");
devProdDTOs.add(p1.toDTO());
Consumer devSystem = TestUtil.createConsumer(owner);
devSystem.setFact("dev_sku", p1.getId());
when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);
mockUpdateProduct(p1, owner);
this.mockContentImport(owner, Collections.<String, Content>emptyMap());
when(productManager.importProducts(eq(owner), any(Map.class), any(Map.class))).thenAnswer(new Answer<ImportResult<Product>>() {
@Override
public ImportResult<Product> answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
Map<String, ProductData> productData = (Map<String, ProductData>) args[1];
ImportResult<Product> importResult = new ImportResult<>();
Map<String, Product> output = importResult.getCreatedEntities();
// simulate a proper update.
for (ProductData pdata : productData.values()) {
if (pdata != null) {
if (p1.getId().equals(pdata.getId())) {
p1.clearAttributes();
if (pdata.getAttributes() != null) {
p1.setAttributes(pdata.getAttributes());
}
output.put(p1.getId(), p1);
} else {
Product product = new Product(pdata.getId(), pdata.getName());
// Do we care about this product? Probably not.
output.put(product.getId(), product);
}
}
}
return importResult;
}
});
Pool created = entitler.assembleDevPool(devSystem, owner, devSystem.getFact("dev_sku"));
assertEquals(entitler.DEFAULT_DEV_SLA, created.getProduct().getAttributeValue(Product.Attributes.SUPPORT_LEVEL));
}
use of org.candlepin.model.dto.ProductData in project candlepin by candlepin.
the class EntitlerTest method testDevPoolCreationAtBindFailStandalone.
@Test(expected = ForbiddenException.class)
public void testDevPoolCreationAtBindFailStandalone() throws Exception {
Owner owner = TestUtil.createOwner("o");
List<ProductData> devProdDTOs = new ArrayList<>();
Product p = TestUtil.createProduct("test-product", "Test Product");
devProdDTOs.add(p.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(p));
when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(true);
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);
AutobindData ad = new AutobindData(devSystem, owner);
entitler.bindByProducts(ad);
}
use of org.candlepin.model.dto.ProductData in project candlepin by candlepin.
the class EntitlerTest method testDevPoolCreationAtBind.
@Test
public void testDevPoolCreationAtBind() throws Exception {
Owner owner = TestUtil.createOwner("o");
List<ProductData> devProdDTOs = new ArrayList<>();
Product p = TestUtil.createProduct("test-product", "Test Product");
p.setAttribute(Product.Attributes.SUPPORT_LEVEL, "Premium");
devProdDTOs.add(p.toDTO());
Pool activePool = TestUtil.createPool(owner, p);
List<Pool> activeList = new ArrayList<>();
activeList.add(activePool);
Pool devPool = mock(Pool.class);
Consumer devSystem = TestUtil.createConsumer(owner);
devSystem.setFact("dev_sku", p.getId());
when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(true);
when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);
this.mockProducts(owner, p);
this.mockProductImport(owner, p);
this.mockContentImport(owner, Collections.<String, Content>emptyMap());
when(pm.createPool(any(Pool.class))).thenReturn(devPool);
when(devPool.getId()).thenReturn("test_pool_id");
AutobindData ad = new AutobindData(devSystem, owner);
entitler.bindByProducts(ad);
verify(pm).createPool(any(Pool.class));
}
use of org.candlepin.model.dto.ProductData in project candlepin by candlepin.
the class EntitlerTest method testDevPoolCreationAtBindFailNotActive.
@Test(expected = ForbiddenException.class)
public void testDevPoolCreationAtBindFailNotActive() throws Exception {
Owner owner = TestUtil.createOwner("o");
List<ProductData> devProdDTOs = new ArrayList<>();
Product p = TestUtil.createProduct("test-product", "Test Product");
devProdDTOs.add(p.toDTO());
Consumer devSystem = TestUtil.createConsumer(owner);
devSystem.setFact("dev_sku", p.getId());
devSystem.addInstalledProduct(new ConsumerInstalledProduct(p));
when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
when(poolCurator.hasActiveEntitlementPools(eq(owner.getId()), any(Date.class))).thenReturn(false);
when(productAdapter.getProductsByIds(any(Owner.class), any(List.class))).thenReturn(devProdDTOs);
when(ownerProductCurator.getProductById(eq(owner), eq(p.getId()))).thenReturn(p);
AutobindData ad = new AutobindData(devSystem, owner);
entitler.bindByProducts(ad);
}
Aggregations