use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ExportRulesTest method canExportProductVirt.
@Test
public void canExportProductVirt() throws NoSuchMethodException {
Entitlement entitlement = mock(Entitlement.class);
Consumer consumer = mock(Consumer.class);
ConsumerType consumerType = new ConsumerType("candlepin");
consumerType.setId("consumer_type");
Pool pool = mock(Pool.class);
Product product = mock(Product.class);
when(entitlement.getPool()).thenReturn(pool);
when(entitlement.getConsumer()).thenReturn(consumer);
when(pool.getProductId()).thenReturn("12345");
when(product.getAttributes()).thenReturn(new HashMap<>());
when(pool.getAttributes()).thenReturn(new HashMap<>());
when(consumer.getTypeId()).thenReturn(consumerType.getId());
when(consumerTypeCuratorMock.find(eq(consumerType.getId()))).thenReturn(consumerType);
when(consumerTypeCuratorMock.getConsumerType(eq(consumer))).thenReturn(consumerType);
assertTrue(exportRules.canExport(entitlement));
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ExportRulesTest method canExportProductConsumer.
@Test
public void canExportProductConsumer() throws NoSuchMethodException {
Entitlement entitlement = mock(Entitlement.class);
Consumer consumer = mock(Consumer.class);
ConsumerType consumerType = new ConsumerType("system");
consumerType.setId("consumer_type");
Pool pool = mock(Pool.class);
Product product = mock(Product.class);
Map<String, String> attributes = new HashMap<>();
attributes.put(Pool.Attributes.DERIVED_POOL, "true");
when(entitlement.getPool()).thenReturn(pool);
when(entitlement.getConsumer()).thenReturn(consumer);
when(pool.getProductId()).thenReturn("12345");
when(product.getAttributes()).thenReturn(new HashMap<>());
when(pool.getAttributes()).thenReturn(attributes);
when(consumer.getTypeId()).thenReturn(consumerType.getId());
when(consumerTypeCuratorMock.find(eq(consumerType.getId()))).thenReturn(consumerType);
when(consumerTypeCuratorMock.getConsumerType(eq(consumer))).thenReturn(consumerType);
assertTrue(exportRules.canExport(entitlement));
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class PoolRulesStackDerivedTest method setUp.
@Before
public void setUp() {
// Load the default production rules:
InputStream is = this.getClass().getResourceAsStream(RulesCurator.DEFAULT_RULES_FILE);
Rules rules = new Rules(Util.readFile(is));
when(rulesCuratorMock.getUpdated()).thenReturn(new Date());
when(rulesCuratorMock.getRules()).thenReturn(rules);
when(configMock.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
poolRules = new PoolRules(poolManagerMock, configMock, entCurMock, ownerProductCuratorMock, productCurator);
principal = TestUtil.createOwnerPrincipal();
owner = principal.getOwners().get(0);
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
ctype.setId("test-ctype");
consumer = new Consumer("consumer", "registeredbybob", owner, ctype);
// Two subtly different products stacked together:
prod1 = TestUtil.createProduct("prod1", "prod1");
prod1.setAttribute(Product.Attributes.VIRT_LIMIT, "2");
prod1.setAttribute(Product.Attributes.STACKING_ID, STACK);
prod1.setAttribute("testattr1", "1");
when(ownerProductCuratorMock.getProductById(owner, prod1.getId())).thenReturn(prod1);
prod2 = TestUtil.createProduct("prod2", "prod2");
prod2.setAttribute(Product.Attributes.VIRT_LIMIT, "unlimited");
prod2.setAttribute(Product.Attributes.STACKING_ID, STACK);
prod2.setAttribute("testattr2", "2");
when(ownerProductCuratorMock.getProductById(owner, prod2.getId())).thenReturn(prod2);
prod3 = TestUtil.createProduct("prod3", "prod3");
prod3.setAttribute(Product.Attributes.VIRT_LIMIT, "9");
prod3.setAttribute(Product.Attributes.STACKING_ID, STACK + "3");
prod3.setAttribute("testattr2", "2");
when(ownerProductCuratorMock.getProductById(owner, prod3.getId())).thenReturn(prod3);
provided1 = TestUtil.createProduct();
provided2 = TestUtil.createProduct();
provided3 = TestUtil.createProduct();
provided4 = TestUtil.createProduct();
// Create three subscriptions with various start/end dates:
sub1 = createStackedVirtSub(owner, prod1, TestUtil.createDate(2010, 1, 1), TestUtil.createDate(2015, 1, 1));
sub1.getProvidedProducts().add(provided1.toDTO());
pool1 = copyFromSub(sub1);
sub2 = createStackedVirtSub(owner, prod2, TestUtil.createDate(2011, 1, 1), TestUtil.createDate(2017, 1, 1));
sub2.getProvidedProducts().add(provided2.toDTO());
pool2 = copyFromSub(sub2);
sub3 = createStackedVirtSub(owner, prod2, TestUtil.createDate(2012, 1, 1), TestUtil.createDate(2020, 1, 1));
sub3.getProvidedProducts().add(provided3.toDTO());
pool3 = copyFromSub(sub3);
sub4 = createStackedVirtSub(owner, prod3, TestUtil.createDate(2012, 1, 1), TestUtil.createDate(2020, 1, 1));
sub4.getProvidedProducts().add(provided4.toDTO());
pool4 = copyFromSub(sub4);
// Initial entitlement from one of the pools:
stackedEnts.add(createEntFromPool(pool2));
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(stackedEnts);
when(entCurMock.findByStackId(consumer, STACK)).thenReturn(cqmock);
pool2.setAttribute(Product.Attributes.VIRT_LIMIT, "60");
pool4.setAttribute(Product.Attributes.VIRT_LIMIT, "80");
List<Pool> reqPools = new ArrayList<>();
reqPools.add(pool2);
Map<String, Entitlement> entitlements = new HashMap<>();
entitlements.put(pool2.getId(), stackedEnts.get(0));
Map<String, Map<String, String>> attributes = new HashMap<>();
attributes.put(pool2.getId(), PoolHelper.getFlattenedAttributes(pool2));
when(poolManagerMock.createPools(Matchers.anyListOf(Pool.class))).then(returnsFirstArg());
List<Pool> resPools = PoolHelper.createHostRestrictedPools(poolManagerMock, consumer, reqPools, entitlements, attributes, productCurator);
stackDerivedPool = resPools.get(0);
reqPools.clear();
reqPools.add(pool4);
entitlements.clear();
entitlements.put(pool4.getId(), createEntFromPool(pool4));
attributes.clear();
attributes.put(pool4.getId(), PoolHelper.getFlattenedAttributes(pool4));
stackDerivedPool2 = PoolHelper.createHostRestrictedPools(poolManagerMock, consumer, reqPools, entitlements, attributes, productCurator).get(0);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ComplianceStatusHasherTest method createConsumer.
private Consumer createConsumer(Owner owner) {
ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM);
ctype.setId("test-ctype");
Consumer consumer = new Consumer("test-consumer", "test-consumer", owner, ctype);
consumer.setId("1");
consumer.setUuid("12345");
consumer.setFact("ram", "4");
consumer.setFact("cores", "2");
Product product1 = TestUtil.createProduct("installed-1");
Product product2 = TestUtil.createProduct("installed-2");
Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
installedProducts.add(new ConsumerInstalledProduct(product1));
installedProducts.add(new ConsumerInstalledProduct(product2));
consumer.setInstalledProducts(installedProducts);
return consumer;
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method batchHostedVirtLimitAltersBonusPoolQuantity.
@Test
public void batchHostedVirtLimitAltersBonusPoolQuantity() {
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));
consumer.setType(ctype);
Subscription s = createVirtLimitSub("virtLimitProduct", 10, "10");
Pool p = TestUtil.copyFromSub(s);
when(poolManagerMock.isManaged(eq(p))).thenReturn(true);
List<Pool> pools = poolRules.createAndEnrichPools(p, new LinkedList<>());
assertEquals(2, pools.size());
Pool physicalPool = pools.get(0);
physicalPool.setId("physical");
Pool virtBonusPool = pools.get(1);
virtBonusPool.setId("virt");
assertEquals(new Long(10), physicalPool.getQuantity());
assertEquals(0, physicalPool.getAttributes().size());
// Quantity on bonus pool should be virt limit * sub quantity:
assertEquals(new Long(100), virtBonusPool.getQuantity());
assertEquals("true", virtBonusPool.getAttributeValue(Product.Attributes.VIRT_ONLY));
assertEquals("10", virtBonusPool.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
Entitlement e = new Entitlement(physicalPool, consumer, owner, 1);
Subscription s2 = createVirtLimitSub("virtLimitProduct2", 10, "10");
s2.setId("subId2");
Pool p2 = TestUtil.copyFromSub(s2);
when(poolManagerMock.isManaged(eq(p2))).thenReturn(true);
List<Pool> pools2 = poolRules.createAndEnrichPools(p2, new LinkedList<>());
assertEquals(2, pools.size());
Pool physicalPool2 = pools2.get(0);
physicalPool2.setId("physical2");
Pool virtBonusPool2 = pools2.get(1);
virtBonusPool2.setId("virt2");
assertEquals(new Long(10), physicalPool2.getQuantity());
assertEquals(0, physicalPool2.getAttributes().size());
// Quantity on bonus pool should be virt limit * sub quantity:
assertEquals(new Long(100), virtBonusPool2.getQuantity());
assertEquals("true", virtBonusPool2.getAttributeValue(Product.Attributes.VIRT_ONLY));
assertEquals("10", virtBonusPool2.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
Entitlement e2 = new Entitlement(physicalPool2, consumer, owner, 1);
List<Pool> poolList = new ArrayList<>();
poolList.add(virtBonusPool);
List<Pool> poolList2 = new ArrayList<>();
poolList.add(virtBonusPool2);
ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class);
when(poolManagerMock.lookupBySubscriptionIds(anyString(), captor.capture())).thenReturn(poolList);
when(poolManagerMock.lookupBySubscriptionId(eq(physicalPool.getOwner()), eq(physicalPool.getSubscriptionId()))).thenReturn(poolList);
when(poolManagerMock.lookupBySubscriptionId(eq(physicalPool.getOwner()), eq(physicalPool2.getSubscriptionId()))).thenReturn(poolList2);
Map<String, Entitlement> entitlements = new HashMap<>();
entitlements.put(physicalPool.getId(), e);
entitlements.put(physicalPool2.getId(), e2);
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
poolQuantityMap.put(physicalPool.getId(), new PoolQuantity(physicalPool, 1));
poolQuantityMap.put(physicalPool2.getId(), new PoolQuantity(physicalPool2, 1));
enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
@SuppressWarnings("unchecked") Set<String> subscriptionIds = captor.getValue();
assertEquals(2, subscriptionIds.size());
assertThat(subscriptionIds, hasItems("subId", "subId2"));
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool), eq(-10L));
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool2), eq(-10L));
enforcer.postUnbind(consumer, poolManagerMock, e);
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool), eq(10L));
enforcer.postUnbind(consumer, poolManagerMock, e2);
verify(poolManagerMock).updatePoolQuantity(eq(virtBonusPool2), eq(10L));
}
Aggregations