Search in sources :

Example 51 with ConsumerType

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));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyLong(org.mockito.Matchers.anyLong) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) Subscription(org.candlepin.model.dto.Subscription) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 52 with ConsumerType

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));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Pool(org.candlepin.model.Pool) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 53 with ConsumerType

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);
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) CandlepinQuery(org.candlepin.model.CandlepinQuery) ArrayList(java.util.ArrayList) List(java.util.List) ConsumerType(org.candlepin.model.ConsumerType)

Example 54 with ConsumerType

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);
}
Also used : SubResource(org.candlepin.auth.SubResource) Owner(org.candlepin.model.Owner) CandlepinCommonTestConfig(org.candlepin.config.CandlepinCommonTestConfig) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.api.v1.OwnerDTO) Access(org.candlepin.auth.Access) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerType(org.candlepin.model.ConsumerType) ConsumerTypeDTO(org.candlepin.dto.api.v1.ConsumerTypeDTO) UserPrincipal(org.candlepin.auth.UserPrincipal) Test(org.junit.Test)

Example 55 with ConsumerType

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);
}
Also used : Owner(org.candlepin.model.Owner) ArrayList(java.util.ArrayList) CandlepinQuery(org.candlepin.model.CandlepinQuery) ConsumerTypeValidator(org.candlepin.resource.util.ConsumerTypeValidator) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) List(java.util.List) ModelTranslator(org.candlepin.dto.ModelTranslator) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16