use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method exportAllPhysicalZeroBonusPoolQuantity.
@Test
public void exportAllPhysicalZeroBonusPoolQuantity() {
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));
consumer.setType(ctype);
Subscription s = createVirtLimitSub("virtLimitProduct", 10, "unlimited");
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 -1:
assertEquals(new Long(-1), virtBonusPool.getQuantity());
assertEquals("true", virtBonusPool.getAttributeValue(Product.Attributes.VIRT_ONLY));
assertEquals("unlimited", virtBonusPool.getProduct().getAttributeValue(Product.Attributes.VIRT_LIMIT));
Entitlement e = new Entitlement(physicalPool, consumer, owner, 10);
physicalPool.setConsumed(10L);
physicalPool.setExported(10L);
List<Pool> poolList = new ArrayList<>();
poolList.add(virtBonusPool);
ArgumentCaptor<Set> captor = ArgumentCaptor.forClass(Set.class);
when(poolManagerMock.lookupBySubscriptionIds(anyString(), captor.capture())).thenReturn(poolList);
when(poolManagerMock.lookupBySubscriptionId(eq(physicalPool.getOwner()), eq("subId"))).thenReturn(poolList);
Map<String, Entitlement> entitlements = new HashMap<>();
entitlements.put(physicalPool.getId(), e);
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
poolQuantityMap.put(physicalPool.getId(), new PoolQuantity(physicalPool, 10));
enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
@SuppressWarnings("unchecked") Set<String> subscriptionIds = captor.getValue();
assertEquals(1, subscriptionIds.size());
assertEquals("subId", subscriptionIds.iterator().next());
verify(poolManagerMock).setPoolQuantity(eq(virtBonusPool), eq(0L));
virtBonusPool.setQuantity(0L);
enforcer.postUnbind(consumer, poolManagerMock, e);
verify(poolManagerMock).setPoolQuantity(eq(virtBonusPool), eq(-1L));
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class HostedVirtLimitEntitlementRulesTest method hostedVirtLimitDoesNotAlterQuantitiesForHostLimited.
@Test
public void hostedVirtLimitDoesNotAlterQuantitiesForHostLimited() {
when(config.getBoolean(ConfigProperties.STANDALONE)).thenReturn(false);
ConsumerType ctype = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.CANDLEPIN));
consumer.setType(ctype);
Pool virtBonusPool = setupVirtLimitPool();
virtBonusPool.setQuantity(100L);
virtBonusPool.setAttribute(Product.Attributes.HOST_LIMITED, "true");
virtBonusPool.setAttribute(Product.Attributes.VIRT_ONLY, "true");
virtBonusPool.setAttribute(Product.Attributes.VIRT_LIMIT, "10");
virtBonusPool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
Entitlement e = new Entitlement(virtBonusPool, consumer, owner, 1);
List<Pool> poolList = new ArrayList<>();
poolList.add(virtBonusPool);
when(poolManagerMock.lookupBySubscriptionId(eq(virtBonusPool.getOwner()), eq(virtBonusPool.getSubscriptionId()))).thenReturn(poolList);
Map<String, Entitlement> entitlements = new HashMap<>();
entitlements.put(virtBonusPool.getId(), e);
Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
poolQuantityMap.put(virtBonusPool.getId(), new PoolQuantity(virtBonusPool, 1));
enforcer.postEntitlement(poolManagerMock, consumer, owner, entitlements, null, false, poolQuantityMap);
verify(poolManagerMock, never()).updatePoolQuantity(eq(virtBonusPool), eq(-10L));
enforcer.postUnbind(consumer, poolManagerMock, e);
verify(poolManagerMock, never()).updatePoolQuantity(eq(virtBonusPool), eq(10L));
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResourceTest method testFetchAllConsumersForOwner.
public void testFetchAllConsumersForOwner() {
ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, null, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
ArrayList<Consumer> consumers = new ArrayList<>();
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(consumers);
when(cqmock.iterator()).thenReturn(consumers.iterator());
when(mockOwnerCurator.lookupByKey(eq("taylorOwner"))).thenReturn(new Owner());
when(mockConsumerCurator.searchOwnerConsumers(any(Owner.class), anyString(), (java.util.Collection<ConsumerType>) any(Collection.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class))).thenReturn(cqmock);
List<ConsumerDTO> result = cr.list(null, null, "taylorOwner", null, null, null, null).list();
assertEquals(consumers, result);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResourceTest method testValidateShareConsumerRequiresRecipientPermissions.
@Test
public void testValidateShareConsumerRequiresRecipientPermissions() {
ConsumerType share = this.mockConsumerType(new ConsumerType(ConsumerTypeEnum.SHARE));
ConsumerTypeDTO shareDto = this.translator.translate(share, ConsumerTypeDTO.class);
OwnerDTO ownerDto = new OwnerDTO().setDisplayName("Test Owner");
ConsumerDTO c = createConsumerDTO("test-consumer", "test-user", ownerDto, shareDto);
ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, mockEntitlementCurator, null, mockEntitlementCertServiceAdapter, i18n, null, null, null, null, null, mockPoolManager, null, mockOwnerCurator, null, null, null, null, null, null, new CandlepinCommonTestConfig(), null, null, null, consumerBindUtil, null, null, factValidator, null, consumerEnricher, migrationProvider, translator);
UserPrincipal uap = mock(UserPrincipal.class);
when(uap.canAccess(any(Object.class), any(SubResource.class), any(Access.class))).thenReturn(Boolean.TRUE);
Owner o = mock(Owner.class);
when(mockOwnerCurator.lookupByKey(any(String.class))).thenReturn(o);
Owner o2 = mock(Owner.class);
c.setRecipientOwnerKey("o2");
when(mockOwnerCurator.lookupByKey(eq("o2"))).thenReturn(o2);
when(uap.canAccess(eq(o2), eq(SubResource.ENTITLEMENTS), eq(Access.CREATE))).thenReturn(Boolean.FALSE);
thrown.expect(NotFoundException.class);
thrown.expectMessage("owner with key");
consumerResource.create(c, uap, "test-user", "test-owner", null, false);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResourceTest method testFetchAllConsumersForUser.
@Test
public void testFetchAllConsumersForUser() {
ModelTranslator mockTranslator = mock(ModelTranslator.class);
ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, this.config, null, null, null, null, null, null, this.factValidator, new ConsumerTypeValidator(null, null), consumerEnricher, migrationProvider, mockTranslator);
ArrayList<Consumer> consumers = new ArrayList<>();
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(consumers);
when(cqmock.iterator()).thenReturn(consumers.iterator());
when(mockConsumerCurator.searchOwnerConsumers(any(Owner.class), anyString(), (java.util.Collection<ConsumerType>) any(Collection.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class))).thenReturn(cqmock);
when(mockTranslator.translateQuery(eq(cqmock), eq(ConsumerDTO.class))).thenReturn(cqmock);
List<ConsumerDTO> result = cr.list("TaylorSwift", null, null, null, null, null, null).list();
assertEquals(consumers, result);
}
Aggregations