Search in sources :

Example 61 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method ensureGuestEntitlementsUntouchedWhenGuestIsNewWithNoOtherHost.

@Test
public void ensureGuestEntitlementsUntouchedWhenGuestIsNewWithNoOtherHost() {
    String uuid = "TEST_CONSUMER";
    Consumer host = createConsumerWithGuests(createOwner());
    host.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(host);
    ConsumerDTO updatedHost = createConsumerDTOWithGuests("Guest 1");
    updatedHost.setUuid(uuid);
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "1");
    entitlement.getPool().setAttribute(Pool.Attributes.REQUIRES_HOST, uuid);
    Consumer guest1 = new Consumer();
    guest1.setUuid("Guest 1");
    guest1.addEntitlement(entitlement);
    guest1.setAutoheal(true);
    when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(mockVirtConsumerMap("Guest 1", guest1));
    // Ensure that the guest was not reported by another host.
    when(this.consumerCurator.find(eq(guest1.getId()))).thenReturn(guest1);
    this.resource.updateConsumer(host.getUuid(), updatedHost, principal);
    verify(poolManager, never()).revokeEntitlement(eq(entitlement));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 62 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method ensureNewGuestIsHealedIfItWasMigratedFromAnotherHost.

// ignored out per mkhusid, see 768872 comment #41
@Ignore
@Test
public void ensureNewGuestIsHealedIfItWasMigratedFromAnotherHost() throws Exception {
    String uuid = "TEST_CONSUMER";
    Owner owner = createOwner();
    Consumer existingHost = createConsumerWithGuests(owner, "Guest 1", "Guest 2");
    existingHost.setUuid(uuid);
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "1");
    entitlement.getPool().setAttribute(Pool.Attributes.REQUIRES_HOST, uuid);
    Consumer guest1 = new Consumer();
    guest1.setUuid("Guest 1");
    guest1.addEntitlement(entitlement);
    ConsumerInstalledProduct installed = mock(ConsumerInstalledProduct.class);
    guest1.addInstalledProduct(installed);
    when(consumerCurator.findByVirtUuid("Guest 1", owner.getId())).thenReturn(guest1);
    // Ensure that the guests host is the existing.
    when(consumerCurator.getHost("Guest 1", owner.getId())).thenReturn(existingHost);
    when(consumerCurator.findByUuid("Guest 1")).thenReturn(guest1);
    Consumer existingMigratedTo = createConsumerWithGuests(owner);
    existingMigratedTo.setUuid("MIGRATED_TO");
    when(this.consumerCurator.findByUuid(existingMigratedTo.getUuid())).thenReturn(existingMigratedTo);
    this.resource.updateConsumer(existingMigratedTo.getUuid(), createConsumerDTOWithGuests("Guest 1"), principal);
    verify(poolManager).revokeEntitlement(eq(entitlement));
    verify(entitler).bindByProducts(AutobindData.create(guest1, owner));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Entitlement(org.candlepin.model.Entitlement) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 63 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method ensureGuestEntitlementsUntouchedWhenGuestExistsWithNoOtherHost.

@Test
public void ensureGuestEntitlementsUntouchedWhenGuestExistsWithNoOtherHost() {
    String uuid = "TEST_CONSUMER";
    Consumer host = createConsumerWithGuests(createOwner(), "Guest 1");
    host.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(host);
    ConsumerDTO updatedHost = createConsumerDTOWithGuests("Guest 1");
    updatedHost.setUuid(uuid);
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "1");
    entitlement.getPool().setAttribute(Pool.Attributes.REQUIRES_HOST, uuid);
    Consumer guest1 = new Consumer();
    guest1.setUuid("Guest 1");
    guest1.addEntitlement(entitlement);
    // Ensure that the guest was already reported by same host.
    when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(mockVirtConsumerMap("Guest 1", guest1));
    this.resource.updateConsumer(host.getUuid(), updatedHost, principal);
    verify(poolManager, never()).revokeEntitlement(eq(entitlement));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 64 with Entitlement

use of org.candlepin.model.Entitlement in project candlepin by candlepin.

the class ConsumerResourceUpdateTest method guestEntitlementsNotRemovedIfEntitlementIsVirtOnlyButRequiresHostNotSet.

@Test
public void guestEntitlementsNotRemovedIfEntitlementIsVirtOnlyButRequiresHostNotSet() {
    String uuid = "TEST_CONSUMER";
    Consumer host = createConsumerWithGuests(createOwner(), "Guest 1", "Guest 2");
    host.setUuid(uuid);
    when(this.consumerCurator.verifyAndLookupConsumer(uuid)).thenReturn(host);
    ConsumerDTO updatedHost = createConsumerDTOWithGuests("Guest 1");
    updatedHost.setUuid(uuid);
    Entitlement entitlement = TestUtil.createEntitlement();
    entitlement.getPool().setAttribute(Product.Attributes.VIRT_ONLY, "1");
    Consumer guest1 = new Consumer();
    guest1.setUuid("Guest 1");
    guest1.addEntitlement(entitlement);
    guest1.setAutoheal(true);
    when(this.consumerCurator.getGuestConsumersMap(any(String.class), any(Set.class))).thenReturn(mockVirtConsumerMap("Guest 1", guest1));
    when(this.consumerCurator.find(eq(guest1.getId()))).thenReturn(guest1);
    this.resource.updateConsumer(host.getUuid(), updatedHost, principal);
    // verify(consumerCurator).findByVirtUuid(eq("Guest 1"));
    verify(poolManager, never()).revokeEntitlement(eq(entitlement));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 65 with Entitlement

use of org.candlepin.model.Entitlement 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));
}
Also used : Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Aggregations

Entitlement (org.candlepin.model.Entitlement)301 Test (org.junit.Test)201 Consumer (org.candlepin.model.Consumer)164 Pool (org.candlepin.model.Pool)125 LinkedList (java.util.LinkedList)84 Product (org.candlepin.model.Product)68 Date (java.util.Date)62 ArrayList (java.util.ArrayList)61 HashSet (java.util.HashSet)59 HashMap (java.util.HashMap)55 Owner (org.candlepin.model.Owner)44 PoolQuantity (org.candlepin.model.PoolQuantity)35 ConsumerType (org.candlepin.model.ConsumerType)34 List (java.util.List)30 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)24 Matchers.anyString (org.mockito.Matchers.anyString)17 Set (java.util.Set)16 Subscription (org.candlepin.model.dto.Subscription)16 ApiOperation (io.swagger.annotations.ApiOperation)15 ApiResponses (io.swagger.annotations.ApiResponses)15