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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations